* Using a white background instead of a gray one
[lhc/web/wiklou.git] / includes / SpecialMovepage.php
index fc52580..65708ea 100644 (file)
@@ -13,7 +13,7 @@ require_once( "LinksUpdate.php" );
 /**
  * Constructor
  */
-function wfSpecialMovepage() {
+function wfSpecialMovepage( $par = null ) {
        global $wgUser, $wgOut, $wgRequest, $action, $wgOnlySysopMayMove;
 
        # check rights. We don't want newbies to move pages to prevents possible attack
@@ -27,7 +27,7 @@ function wfSpecialMovepage() {
                return;
        }
 
-       $f = new MovePageForm();
+       $f = new MovePageForm( $par );
 
        if ( 'success' == $action ) {
                $f->showSuccess();
@@ -46,14 +46,16 @@ function wfSpecialMovepage() {
  */
 class MovePageForm {
        var $oldTitle, $newTitle, $reason; # Text input
-       var $moveTalk;
+       var $moveTalk, $deleteAndMove;
                
-       function MovePageForm() {
+       function MovePageForm( $par ) {
                global $wgRequest;
-               $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
+               $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
+               $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $target );
                $this->newTitle = $wgRequest->getText( 'wpNewTitle' );
                $this->reason = $wgRequest->getText( 'wpReason' );
                $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
+               $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' );
        }
        
        function showForm( $err ) {
@@ -75,18 +77,39 @@ class MovePageForm {
                        # when the form is first opened.
                        $encNewTitle = $oldTitle;
                } else {
+                       if( $err == '' ) {
+                               $nt = Title::newFromURL( $this->newTitle );
+                               if( $nt ) {
+                                       # If a title was supplied, probably from the move log revert
+                                       # link, check for validity. We can then show some diagnostic
+                                       # information and save a click.
+                                       $newerr = $ot->isValidMoveOperation( $nt );
+                                       if( is_string( $newerr ) ) {
+                                               $err = $newerr;
+                                       }
+                               }
+                       }
                        $encNewTitle = htmlspecialchars( $this->newTitle );
                }
                $encReason = htmlspecialchars( $this->reason );
 
-               $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
+               if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
+                       $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
+                       $movepagebtn = wfMsg( 'delete_and_move' );
+                       $submitVar = 'wpDeleteAndMove';
+                       $err = '';
+               } else {
+                       $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
+                       $movepagebtn = wfMsg( 'movepagebtn' );
+                       $submitVar = 'wpMove';
+               }
+
                if ( !$ot->isTalkPage() ) {
                        $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
                }
 
                $movearticle = wfMsg( 'movearticle' );
                $newtitle = wfMsg( 'newtitle' );
-               $movepagebtn = wfMsg( 'movepagebtn' );
                $movetalk = wfMsg( 'movetalk' );
                $movereason = wfMsg( 'movereason' );
 
@@ -96,14 +119,10 @@ class MovePageForm {
 
                if ( $err != '' ) {
                        $wgOut->setSubtitle( wfMsg( 'formerror' ) );
-                       $wgOut->addHTML( '<p class="error">'.$err."</p>\n" );
+                       $wgOut->addHTML( '<p class="error">' . wfMsg($err) . "</p>\n" );
                }
 
-               if ( $this->moveTalk ) {
-                       $moveTalkChecked = " checked='checked'";
-               } else {
-                       $moveTalkChecked = '';
-               }
+               $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
                
                $wgOut->addHTML( "
 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
@@ -122,7 +141,7 @@ class MovePageForm {
                <tr>
                        <td align='right'>{$movereason}:</td>
                        <td align='left'>
-                               <input type='text' size=40 name=\"wpReason\" value=\"{$encReason}\" />
+                               <input type='text' size='40' name=\"wpReason\" value=\"{$encReason}\" />
                        </td>
                </tr>" );
 
@@ -139,7 +158,7 @@ class MovePageForm {
                <tr>
                        <td>&nbsp;</td>
                        <td align='left'>
-                               <input type='submit' name=\"wpMove\" value=\"{$movepagebtn}\" />
+                               <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
                        </td>
                </tr>
        </table>
@@ -156,19 +175,25 @@ class MovePageForm {
                
                # Variables beginning with 'o' for old article 'n' for new article
 
-               # Attempt to move the article
                $ot = Title::newFromText( $this->oldTitle );
                $nt = Title::newFromText( $this->newTitle );
 
+               # Delete to make way if requested
+               if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) {
+                       $article = new Article( $nt );
+                       // This may output an error message and exit
+                       $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
+               }
+
                # don't allow moving to pages with # in
                if ( !$nt || $nt->getFragment() != '' ) {
-                       $this->showForm( wfMsg( "badtitletext" ) );
+                       $this->showForm( 'badtitletext' );
                        return;
                }
 
                $error = $ot->moveTo( $nt, true, $this->reason );
                if ( $error !== true ) {
-                       $this->showForm( wfMsg( $error ) );
+                       $this->showForm( $error );
                        return;
                }
 
@@ -216,6 +241,9 @@ class MovePageForm {
                        } else {
                                $talkmoved = $error;
                        }
+               } else {
+                       # Stay silent on the subject of talk.
+                       $talkmoved = '';
                }
                
                # Give back result to user.