If 'tables' is a string that starts with a space, treat it as user-enforced FROM...
[lhc/web/wiklou.git] / includes / SpecialMovepage.php
index 3c9d326..6a3e03e 100644 (file)
@@ -1,22 +1,28 @@
 <?php
 /**
  *
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
  */
 
 /**
  * Constructor
  */
 function wfSpecialMovepage( $par = null ) {
-       global $wgUser, $wgOut, $wgRequest, $action, $wgOnlySysopMayMove;
+       global $wgUser, $wgOut, $wgRequest, $action;
 
-       # check rights. We don't want newbies to move pages to prevents possible attack
-       if ( !$wgUser->isAllowed( 'move' ) or $wgUser->isBlocked() or ($wgOnlySysopMayMove and $wgUser->isNewbie())) {
-               $wgOut->errorpage( "movenologin", "movenologintext" );
+       # Check rights
+       if ( !$wgUser->isAllowed( 'move' ) ) {
+               $wgOut->showErrorPage( 'movenologin', 'movenologintext' );
                return;
        }
-       # We don't move protected pages
+
+       # Don't allow blocked users to move pages
+       if ( $wgUser->isBlocked() ) {
+               $wgOut->blockedPage();
+               return;
+       }
+
+       # Check for database lock
        if ( wfReadOnly() ) {
                $wgOut->readOnlyPage();
                return;
@@ -36,23 +42,29 @@ function wfSpecialMovepage( $par = null ) {
 
 /**
  *
- * @package MediaWiki
- * @subpackage SpecialPage
+ * @addtogroup SpecialPage
  */
 class MovePageForm {
        var $oldTitle, $newTitle, $reason; # Text input
        var $moveTalk, $deleteAndMove;
-               
+       
+       private $watch = false;
+
        function MovePageForm( $par ) {
                global $wgRequest;
                $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' );
+               if ( $wgRequest->wasPosted() ) {
+                       $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', false );
+               } else {
+                       $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
+               }
+               $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
+               $this->watch = $wgRequest->getCheck( 'wpWatch' );
        }
-       
+
        function showForm( $err ) {
                global $wgOut, $wgUser;
 
@@ -60,11 +72,11 @@ class MovePageForm {
 
                $ot = Title::newFromURL( $this->oldTitle );
                if( is_null( $ot ) ) {
-                       $wgOut->errorpage( 'notargettitle', 'notargettext' );
+                       $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
                        return;
                }
                $oldTitle = $ot->getPrefixedText();
-               
+
                $encOldTitle = htmlspecialchars( $oldTitle );
                if( $this->newTitle == '' ) {
                        # Show the current title as a default
@@ -90,15 +102,27 @@ class MovePageForm {
                if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
                        $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
                        $movepagebtn = wfMsgHtml( 'delete_and_move' );
+                       $confirmText = wfMsgHtml( 'delete_and_move_confirm' );
                        $submitVar = 'wpDeleteAndMove';
+                       $confirm = "
+                               <tr>
+                                       <td align='right'>
+                                               <input type='checkbox' name='wpConfirm' id='wpConfirm' value=\"true\" />
+                                       </td>
+                                       <td align='left'><label for='wpConfirm'>{$confirmText}</label></td>
+                               </tr>";
                        $err = '';
                } else {
                        $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
                        $movepagebtn = wfMsgHtml( 'movepagebtn' );
                        $submitVar = 'wpMove';
+                       $confirm = false;
                }
 
-               if ( !$ot->isTalkPage() ) {
+               $oldTalk = $ot->getTalkPage();
+               $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
+
+               if ( $considerTalk ) {
                        $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
                }
 
@@ -107,7 +131,7 @@ class MovePageForm {
                $movetalk = wfMsgHtml( 'movetalk' );
                $movereason = wfMsgHtml( 'movereason' );
 
-               $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
+               $titleObj = SpecialPage::getTitleFor( 'Movepage' );
                $action = $titleObj->escapeLocalURL( 'action=submit' );
                $token = htmlspecialchars( $wgUser->editToken() );
 
@@ -117,7 +141,7 @@ class MovePageForm {
                }
 
                $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
-               
+
                $wgOut->addHTML( "
 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
        <table border='0'>
@@ -139,7 +163,7 @@ class MovePageForm {
                        </td>
                </tr>" );
 
-               if ( ! $ot->isTalkPage() ) {
+               if ( $considerTalk ) {
                        $wgOut->addHTML( "
                <tr>
                        <td align='right'>
@@ -148,7 +172,16 @@ class MovePageForm {
                        <td><label for=\"wpMovetalk\">{$movetalk}</label></td>
                </tr>" );
                }
+               
+               $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) || $ot->userIsWatching();
+               $watch  = '<tr>';
+               $watch .= '<td align="right">' . Xml::check( 'wpWatch', $watchChecked, array( 'id' => 'watch' ) ) . '</td>';
+               $watch .= '<td>' . Xml::label( wfMsg( 'move-watch' ), 'watch' ) . '</td>';
+               $watch .= '</tr>';
+               $wgOut->addHtml( $watch );
+               
                $wgOut->addHTML( "
+               {$confirm}
                <tr>
                        <td>&nbsp;</td>
                        <td align='left'>
@@ -159,17 +192,18 @@ class MovePageForm {
        <input type='hidden' name='wpEditToken' value=\"{$token}\" />
 </form>\n" );
 
+       $this->showLogFragment( $ot, $wgOut );
+
        }
 
        function doSubmit() {
                global $wgOut, $wgUser, $wgRequest;
-               $fname = "MovePageForm::doSubmit";
-               
+
                if ( $wgUser->pingLimiter( 'move' ) ) {
                        $wgOut->rateLimited();
                        return;
                }
-               
+
                # Variables beginning with 'o' for old article 'n' for new article
 
                $ot = Title::newFromText( $this->oldTitle );
@@ -195,34 +229,41 @@ class MovePageForm {
                }
 
                wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
-               
-               # Move talk page if
-               # (1) the checkbox says to,
-               # (2) the namespaces are not themselves talk namespaces, and of course
-               # (3) it exists.
-               if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
-                    !$ot->isTalkPage() &&
-                    !$nt->isTalkPage() ) {
-                       
-                       $ott = $ot->getTalkPage();
-                       $ntt = $nt->getTalkPage();
-
-                       # Attempt the move
-                       $error = $ott->moveTo( $ntt, true, $this->reason );
-                       if ( $error === true ) {
-                               $talkmoved = 1;
-                               wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) )       ;
+
+               # Move the talk page if relevant, if it exists, and if we've been told to
+               $ott = $ot->getTalkPage();
+               if( $ott->exists() ) {
+                       if( $this->moveTalk && !$ot->isTalkPage() && !$nt->isTalkPage() ) {
+                               $ntt = $nt->getTalkPage();
+       
+                               # Attempt the move
+                               $error = $ott->moveTo( $ntt, true, $this->reason );
+                               if ( $error === true ) {
+                                       $talkmoved = 1;
+                                       wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) )       ;
+                               } else {
+                                       $talkmoved = $error;
+                               }
                        } else {
-                               $talkmoved = $error;
+                               # Stay silent on the subject of talk.
+                               $talkmoved = '';
                        }
                } else {
-                       # Stay silent on the subject of talk.
-                       $talkmoved = '';
+                       $talkmoved = 'notalkpage';
                }
                
+               # Deal with watches
+               if( $this->watch ) {
+                       $wgUser->addWatch( $ot );
+                       $wgUser->addWatch( $nt );
+               } else {
+                       $wgUser->removeWatch( $ot );
+                       $wgUser->removeWatch( $nt );
+               }
+
                # Give back result to user.
-               $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
-               $success = $titleObj->getFullURL( 
+               $titleObj = SpecialPage::getTitleFor( 'Movepage' );
+               $success = $titleObj->getFullURL(
                  'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
                  '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
                  '&talkmoved='.$talkmoved );
@@ -232,31 +273,39 @@ class MovePageForm {
 
        function showSuccess() {
                global $wgOut, $wgRequest, $wgRawHtml;
-
+               
                $wgOut->setPagetitle( wfMsg( 'movepage' ) );
                $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
-               $oldtitle = $wgRequest->getVal('oldtitle');
-               $newtitle = $wgRequest->getVal('newtitle');
+
+               $oldText = wfEscapeWikiText( $wgRequest->getVal('oldtitle') );
+               $newText = wfEscapeWikiText( $wgRequest->getVal('newtitle') );
                $talkmoved = $wgRequest->getVal('talkmoved');
 
-               $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
+               $text = wfMsg( 'pagemovedtext', $oldText, $newText );
                
-               # Temporarily disable raw html wikitext option out of XSS paranoia
-               $marchingantofdoom = $wgRawHtml;
+               $allowHTML = $wgRawHtml;
                $wgRawHtml = false;
                $wgOut->addWikiText( $text );
-               $wgRawHtml = $marchingantofdoom;
+               $wgRawHtml = $allowHTML;
 
                if ( $talkmoved == 1 ) {
                        $wgOut->addWikiText( wfMsg( 'talkpagemoved' ) );
                } elseif( 'articleexists' == $talkmoved ) {
                        $wgOut->addWikiText( wfMsg( 'talkexists' ) );
                } else {
-                       $ot = Title::newFromURL( $oldtitle );
-                       if ( ! $ot->isTalkPage() ) {
+                       $oldTitle = Title::newFromText( $oldText );
+                       if ( isset( $oldTitle ) && !$oldTitle->isTalkPage() && $talkmoved != 'notalkpage' ) {
                                $wgOut->addWikiText( wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) );
                        }
                }
        }
+       
+       function showLogFragment( $title, &$out ) {
+               $out->addHtml( wfElement( 'h2', NULL, LogPage::logName( 'move' ) ) );
+               $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) );
+               $viewer = new LogViewer( new LogReader( $request ) );
+               $viewer->showList( $out );
+       }
+       
 }
 ?>