* (bug 34887) Fix for r100138: make $3 and $4 parameters being substituted correctly...
[lhc/web/wiklou.git] / includes / specials / SpecialMovepage.php
index d7a8eaa..393cf7e 100644 (file)
 <?php
 /**
+ * Implements Special:Movepage
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup SpecialPage
  */
 
 /**
- * Constructor
+ * A special page that allows users to change page titles
+ *
+ * @ingroup SpecialPage
  */
-function wfSpecialMovepage( $par = null ) {
-       global $wgUser, $wgOut, $wgRequest, $action;
+class MovePageForm extends UnlistedSpecialPage {
+
+       /**
+        * @var Title
+        */
+       var $oldTitle, $newTitle; # Objects
+       var $reason; # Text input
+       var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect, $moveOverShared; # Checks
 
-       # Check for database lock
-       if ( wfReadOnly() ) {
-               $wgOut->readOnlyPage();
-               return;
+       private $watch = false;
+
+       public function __construct() {
+               parent::__construct( 'Movepage' );
        }
 
-       $target = isset( $par ) ? $par : $wgRequest->getVal( 'target' );
-       $oldTitleText = $wgRequest->getText( 'wpOldTitle', $target );
-       $newTitleText = $wgRequest->getText( 'wpNewTitle' );
+       public function execute( $par ) {
+               $this->checkReadOnly();
 
-       $oldTitle = Title::newFromText( $oldTitleText );
-       $newTitle = Title::newFromText( $newTitleText );
+               $this->setHeaders();
+               $this->outputHeader();
 
-       if( is_null( $oldTitle ) ) {
-               $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
-               return;
-       }
-       if( !$oldTitle->exists() ) {
-               $wgOut->showErrorPage( 'nopagetitle', 'nopagetext' );
-               return;
-       }
+               $request = $this->getRequest();
+               $target = !is_null( $par ) ? $par : $request->getVal( 'target' );
 
-       # Check rights
-       $permErrors = $oldTitle->getUserPermissionsErrors( 'move', $wgUser );
-       if( !empty( $permErrors ) ) {
-               $wgOut->showPermissionsErrorPage( $permErrors );
-               return;
-       }
+               // Yes, the use of getVal() and getText() is wanted, see bug 20365
 
-       $form = new MovePageForm( $oldTitle, $newTitle );
+               $oldTitleText = $request->getVal( 'wpOldTitle', $target );
+               $this->oldTitle = Title::newFromText( $oldTitleText );
 
-       if ( 'submit' == $action && $wgRequest->wasPosted()
-               && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
-               $form->doSubmit();
-       } else {
-               $form->showForm( '' );
-       }
-}
+               if( is_null( $this->oldTitle ) ) {
+                       throw new ErrorPageError( 'notargettitle', 'notargettext' );
+               }
+               if( !$this->oldTitle->exists() ) {
+                       throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
+               }
 
-/**
- * HTML form for Special:Movepage
- * @ingroup SpecialPage
- */
-class MovePageForm {
-       var $oldTitle, $newTitle; # Objects
-       var $reason; # Text input
-       var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect; # Checks
+               $newTitleTextMain = $request->getText( 'wpNewTitleMain' );
+               $newTitleTextNs = $request->getInt( 'wpNewTitleNs', $this->oldTitle->getNamespace() );
+               // Backwards compatibility for forms submitting here from other sources
+               // which is more common than it should be..
+               $newTitleText_bc = $request->getText( 'wpNewTitle' );
+               $this->newTitle = strlen( $newTitleText_bc ) > 0
+                       ? Title::newFromText( $newTitleText_bc )
+                       : Title::makeTitleSafe( $newTitleTextNs, $newTitleTextMain );
 
-       private $watch = false;
 
-       function __construct( $oldTitle, $newTitle ) {
-               global $wgRequest;
-               $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
-               $this->oldTitle = $oldTitle;
-               $this->newTitle = $newTitle;
-               $this->reason = $wgRequest->getText( 'wpReason' );
-               if ( $wgRequest->wasPosted() ) {
-                       $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', false );
-                       $this->fixRedirects = $wgRequest->getBool( 'wpFixRedirects', false );
-                       $this->leaveRedirect = $wgRequest->getBool( 'wpLeaveRedirect', false );
+               $user = $this->getUser();
+
+               # Check rights
+               $permErrors = $this->oldTitle->getUserPermissionsErrors( 'move', $user );
+               if ( count( $permErrors ) ) {
+                       // Auto-block user's IP if the account was "hard" blocked
+                       $user->spreadAnyEditBlock();
+                       throw new PermissionsError( 'move', $permErrors );
+               }
+
+               $def = !$request->wasPosted();
+
+               $this->reason = $request->getText( 'wpReason' );
+               $this->moveTalk = $request->getBool( 'wpMovetalk', $def );
+               $this->fixRedirects = $request->getBool( 'wpFixRedirects', $def );
+               $this->leaveRedirect = $request->getBool( 'wpLeaveRedirect', $def );
+               $this->moveSubpages = $request->getBool( 'wpMovesubpages', false );
+               $this->deleteAndMove = $request->getBool( 'wpDeleteAndMove' ) && $request->getBool( 'wpConfirm' );
+               $this->moveOverShared = $request->getBool( 'wpMoveOverSharedFile', false );
+               $this->watch = $request->getCheck( 'wpWatch' ) && $user->isLoggedIn();
+
+               if ( 'submit' == $request->getVal( 'action' ) && $request->wasPosted()
+                       && $user->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
+                       $this->doSubmit();
                } else {
-                       $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
-                       $this->fixRedirects = $wgRequest->getBool( 'wpFixRedirects', true );
-                       $this->leaveRedirect = $wgRequest->getBool( 'wpLeaveRedirect', true );
+                       $this->showForm( array() );
                }
-               $this->moveSubpages = $wgRequest->getBool( 'wpMovesubpages', false );
-               $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
-               $this->watch = $wgRequest->getCheck( 'wpWatch' );
        }
 
        /**
         * Show the form
-        * @param mixed $err Error message. May either be a string message name or 
-        *    array message name and parameters, like the second argument to 
-        *    OutputPage::wrapWikiMsg(). 
+        *
+        * @param $err Array: error messages. Each item is an error message.
+        *    It may either be a string message name or array message name and
+        *    parameters, like the second argument to OutputPage::wrapWikiMsg().
         */
        function showForm( $err ) {
-               global $wgOut, $wgUser, $wgFixDoubleRedirects;
+               global $wgContLang, $wgFixDoubleRedirects, $wgMaximumMovedPages;
 
-               $skin = $wgUser->getSkin();
+               $this->getSkin()->setRelevantTitle( $this->oldTitle );
 
-               $oldTitleLink = $skin->makeLinkObj( $this->oldTitle );
+               $oldTitleLink = Linker::link( $this->oldTitle );
 
-               $wgOut->setPagetitle( wfMsg( 'move-page', $this->oldTitle->getPrefixedText() ) );
-               $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
+               $out = $this->getOutput();
+               $out->setPageTitle( $this->msg( 'move-page', $this->oldTitle->getPrefixedText() ) );
+               $out->addModules( 'mediawiki.special.movePage' );
 
                $newTitle = $this->newTitle;
 
-               if( !$newTitle ) {
+               if ( !$newTitle ) {
                        # Show the current title as a default
                        # when the form is first opened.
                        $newTitle = $this->oldTitle;
-               }
-               else {
-                       if( empty($err) ) {
-                               # 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 = $this->oldTitle->isValidMoveOperation( $newTitle );
-                               if( $newerr ) {
-                                       $err = $newerr[0];
-                               }
+               } elseif ( !count( $err ) ) {
+                       # 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 = $this->oldTitle->isValidMoveOperation( $newTitle );
+                       if( is_array( $newerr ) ) {
+                               $err = $newerr;
                        }
                }
 
-               if ( !empty($err) && $err[0] == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
-                       $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
+               $user = $this->getUser();
+
+               if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists'
+                       && $newTitle->quickUserCan( 'delete', $user )
+               ) {
+                       $out->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
                        $movepagebtn = wfMsg( 'delete_and_move' );
                        $submitVar = 'wpDeleteAndMove';
                        $confirm = "
@@ -126,21 +150,43 @@ class MovePageForm {
                                                Xml::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
                                        "</td>
                                </tr>";
-                       $err = '';
+                       $err = array();
                } else {
-                       $wgOut->addWikiMsg( 'movepagetext' );
+                       if ($this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) {
+                               $out->wrapWikiMsg( "<div class=\"error mw-moveuserpage-warning\">\n$1\n</div>", 'moveuserpage-warning' );
+                       }
+                       $out->addWikiMsg( $wgFixDoubleRedirects ? 'movepagetext' :
+                               'movepagetext-noredirectfixer' );
                        $movepagebtn = wfMsg( 'movepagebtn' );
                        $submitVar = 'wpMove';
                        $confirm = false;
                }
 
+               if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'file-exists-sharedrepo'
+                       && $user->isAllowed( 'reupload-shared' )
+               ) {
+                       $out->addWikiMsg( 'move-over-sharedrepo', $newTitle->getPrefixedText() );
+                       $submitVar = 'wpMoveOverSharedFile';
+                       $err = array();
+               }
+
                $oldTalk = $this->oldTitle->getTalkPage();
-               $considerTalk = ( !$this->oldTitle->isTalkPage() && $oldTalk->exists() );
+               $oldTitleSubpages = $this->oldTitle->hasSubpages();
+               $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
+
+               $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
+                       !count( $this->oldTitle->getUserPermissionsErrors( 'move-subpages', $user ) );
+
+               # We also want to be able to move assoc. subpage talk-pages even if base page
+               # has no associated talk page, so || with $oldTitleTalkSubpages.
+               $considerTalk = !$this->oldTitle->isTalkPage() &&
+                       ( $oldTalk->exists()
+                               || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
 
                $dbr = wfGetDB( DB_SLAVE );
                if ( $wgFixDoubleRedirects ) {
-                       $hasRedirects = $dbr->selectField( 'redirect', '1', 
-                               array( 
+                       $hasRedirects = $dbr->selectField( 'redirect', '1',
+                               array(
                                        'rd_namespace' => $this->oldTitle->getNamespace(),
                                        'rd_title' => $this->oldTitle->getDBkey(),
                                ) , __METHOD__ );
@@ -149,30 +195,64 @@ class MovePageForm {
                }
 
                if ( $considerTalk ) {
-                       $wgOut->addWikiMsg( 'movepagetalktext' );
+                       $out->addWikiMsg( 'movepagetalktext' );
                }
 
-               $titleObj = SpecialPage::getTitleFor( 'Movepage' );
-               $token = htmlspecialchars( $wgUser->editToken() );
+               if ( count( $err ) ) {
+                       $out->addHTML( "<div class='error'>\n" );
+                       $action_desc = $this->msg( 'action-move' )->plain();
+                       $out->addWikiMsg( 'permissionserrorstext-withaction', count( $err ), $action_desc );
 
-               if ( !empty($err) ) {
-                       $wgOut->setSubtitle( wfMsg( 'formerror' ) );
-                       if( $err[0] == 'hookaborted' ) {
-                               $hookErr = $err[1];
-                               $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
-                               $wgOut->addHTML( $errMsg );
+                       if ( count( $err ) == 1 ) {
+                               $errMsg = $err[0];
+                               $errMsgName = array_shift( $errMsg );
+                               if ( $errMsgName == 'hookaborted' ) {
+                                       $out->addHTML( "<p>{$errMsg[0]}</p>\n" );
+                               } else {
+                                       $out->addWikiMsgArray( $errMsgName, $errMsg );
+                               }
                        } else {
-                               $wgOut->wrapWikiMsg( '<p><strong class="error">$1</strong></p>', $err );
+                               $errStr = array();
+                               foreach( $err as $errMsg ) {
+                                       if( $errMsg[0] == 'hookaborted' ) {
+                                               $errStr[] = $errMsg[1];
+                                       } else {
+                                               $errMsgName = array_shift( $errMsg );
+                                               $errStr[] = $this->msg( $errMsgName, $errMsg )->parse();
+                                       }
+                               }
+
+                               $out->addHTML( '<ul><li>' . implode( "</li>\n<li>", $errStr ) . "</li></ul>\n" );
                        }
+                       $out->addHTML( "</div>\n" );
                }
 
-               $wgOut->addHTML(
-                        Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
+               if ( $this->oldTitle->isProtected( 'move' ) ) {
+                       # Is the title semi-protected?
+                       if ( $this->oldTitle->isSemiProtected( 'move' ) ) {
+                               $noticeMsg = 'semiprotectedpagemovewarning';
+                               $classes[] = 'mw-textarea-sprotected';
+                       } else {
+                               # Then it must be protected based on static groups (regular)
+                               $noticeMsg = 'protectedpagemovewarning';
+                               $classes[] = 'mw-textarea-protected';
+                       }
+                       $out->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
+                       $out->addWikiMsg( $noticeMsg );
+                       LogEventsList::showLogExtract( $out, 'protect', $this->oldTitle, '', array( 'lim' => 1 ) );
+                       $out->addHTML( "</div>\n" );
+               }
+
+               // Byte limit (not string length limit) for wpReason and wpNewTitleMain
+               // is enforced in the mediawiki.special.movePage module
+
+               $out->addHTML(
+                        Xml::openElement( 'form', array( 'method' => 'post', 'action' => $this->getTitle()->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
                         Xml::openElement( 'fieldset' ) .
                         Xml::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
                         Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
                         "<tr>
-                               <td class='mw-label'>" .
+                               <td class='mw-label'>" .
                                        wfMsgHtml( 'movearticle' ) .
                                "</td>
                                <td class='mw-input'>
@@ -181,11 +261,19 @@ class MovePageForm {
                        </tr>
                        <tr>
                                <td class='mw-label'>" .
-                                       Xml::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
+                                       Xml::label( wfMsg( 'newtitle' ), 'wpNewTitleMain' ) .
                                "</td>
                                <td class='mw-input'>" .
-                                       Xml::input( 'wpNewTitle', 40, $newTitle->getPrefixedText(), array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
-                                       Xml::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
+                                       Html::namespaceSelector(
+                                               array( 'selected' => $newTitle->getNamespace() ),
+                                               array( 'name' => 'wpNewTitleNs', 'id' => 'wpNewTitleNs' )
+                                       ) .
+                                       Xml::input( 'wpNewTitleMain', 60, $wgContLang->recodeForEdit( $newTitle->getText() ), array(
+                                               'type' => 'text',
+                                               'id' => 'wpNewTitleMain',
+                                               'maxlength' => 255,
+                                       ) ) .
+                                       Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
                                "</td>
                        </tr>
                        <tr>
@@ -193,13 +281,14 @@ class MovePageForm {
                                        Xml::label( wfMsg( 'movereason' ), 'wpReason' ) .
                                "</td>
                                <td class='mw-input'>" .
-                                       Xml::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason ) ) .
+                                       Html::element( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2,
+                                       'maxlength' => 200 ), $this->reason ) .
                                "</td>
                        </tr>"
                );
 
                if( $considerTalk ) {
-                       $wgOut->addHTML( "
+                       $out->addHTML( "
                                <tr>
                                        <td></td>
                                        <td class='mw-input'>" .
@@ -209,12 +298,12 @@ class MovePageForm {
                        );
                }
 
-               if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
-                       $wgOut->addHTML( "
+               if ( $user->isAllowed( 'suppressredirect' ) ) {
+                       $out->addHTML( "
                                <tr>
                                        <td></td>
                                        <td class='mw-input' >" .
-                                               Xml::checkLabel( wfMsg( 'move-leave-redirect' ), 'wpLeaveRedirect', 
+                                               Xml::checkLabel( wfMsg( 'move-leave-redirect' ), 'wpLeaveRedirect',
                                                        'wpLeaveRedirect', $this->leaveRedirect ) .
                                        "</td>
                                </tr>"
@@ -222,122 +311,144 @@ class MovePageForm {
                }
 
                if ( $hasRedirects ) {
-                       $wgOut->addHTML( "
+                       $out->addHTML( "
                                <tr>
                                        <td></td>
                                        <td class='mw-input' >" .
-                                               Xml::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects', 
+                                               Xml::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects',
                                                        'wpFixRedirects', $this->fixRedirects ) .
                                        "</td>
                                </tr>"
                        );
                }
 
-               if( ($this->oldTitle->hasSubpages() || $this->oldTitle->getTalkPage()->hasSubpages())
-               && $this->oldTitle->userCan( 'move-subpages' ) ) {
-                       global $wgMaximumMovedPages, $wgLang;
-
-                       $wgOut->addHTML( "
+               if( $canMoveSubpage ) {
+                       $out->addHTML( "
                                <tr>
                                        <td></td>
                                        <td class=\"mw-input\">" .
-                               Xml::checkLabel( wfMsgExt(
+                               Xml::check(
+                                       'wpMovesubpages',
+                                       # Don't check the box if we only have talk subpages to
+                                       # move and we aren't moving the talk page.
+                                       $this->moveSubpages && ($this->oldTitle->hasSubpages() || $this->moveTalk),
+                                       array( 'id' => 'wpMovesubpages' )
+                               ) . '&#160;' .
+                               Xml::tags( 'label', array( 'for' => 'wpMovesubpages' ),
+                                       wfMsgExt(
                                                ( $this->oldTitle->hasSubpages()
                                                        ? 'move-subpages'
                                                        : 'move-talk-subpages' ),
-                                               array( 'parsemag' ),
-                                               $wgLang->formatNum( $wgMaximumMovedPages ),
+                                               array( 'parseinline' ),
+                                               $this->getLanguage()->formatNum( $wgMaximumMovedPages ),
                                                # $2 to allow use of PLURAL in message.
                                                $wgMaximumMovedPages
-                                       ),
-                                       'wpMovesubpages', 'wpMovesubpages',
-                                       # Don't check the box if we only have talk subpages to
-                                       # move and we aren't moving the talk page.
-                                       $this->moveSubpages && ($this->oldTitle->hasSubpages() || $this->moveTalk)
+                                       )
                                ) .
                                        "</td>
                                </tr>"
                        );
                }
 
-               $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) 
-                       || $this->oldTitle->userIsWatching();
-               $wgOut->addHTML( "
+               $watchChecked = $user->isLoggedIn() && ($this->watch || $user->getBoolOption( 'watchmoves' )
+                       || $this->oldTitle->userIsWatching());
+               # Don't allow watching if user is not logged in
+               if( $user->isLoggedIn() ) {
+                       $out->addHTML( "
                        <tr>
                                <td></td>
                                <td class='mw-input'>" .
                                        Xml::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
                                "</td>
-                       </tr>
+                       </tr>");
+               }
+
+               $out->addHTML( "
                                {$confirm}
                        <tr>
-                               <td>&nbsp;</td>
+                               <td>&#160;</td>
                                <td class='mw-submit'>" .
                                        Xml::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
                                "</td>
                        </tr>" .
                        Xml::closeElement( 'table' ) .
-                       Xml::hidden( 'wpEditToken', $token ) .
+                       Html::hidden( 'wpEditToken', $user->getEditToken() ) .
                        Xml::closeElement( 'fieldset' ) .
                        Xml::closeElement( 'form' ) .
                        "\n"
                );
 
-               $this->showLogFragment( $this->oldTitle, $wgOut );
-               $this->showSubpages( $this->oldTitle, $wgOut );
+               $this->showLogFragment( $this->oldTitle );
+               $this->showSubpages( $this->oldTitle );
 
        }
 
        function doSubmit() {
-               global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
-               global $wgFixDoubleRedirects;
+               global $wgMaximumMovedPages, $wgFixDoubleRedirects;
 
-               if ( $wgUser->pingLimiter( 'move' ) ) {
-                       $wgOut->rateLimited();
-                       return;
+               $user = $this->getUser();
+
+               if ( $user->pingLimiter( 'move' ) ) {
+                       throw new ThrottledError;
                }
 
                $ot = $this->oldTitle;
                $nt = $this->newTitle;
 
+               # don't allow moving to pages with # in
+               if ( !$nt || $nt->getFragment() != '' ) {
+                       $this->showForm( array( array( 'badtitletext' ) ) );
+                       return;
+               }
+
+               # Show a warning if the target file exists on a shared repo
+               if ( $nt->getNamespace() == NS_FILE
+                       && !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) )
+                       && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt )
+                       && wfFindFile( $nt ) )
+               {
+                       $this->showForm( array( array( 'file-exists-sharedrepo' ) ) );
+                       return;
+
+               }
+
                # Delete to make way if requested
-               if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) {
-                       $article = new Article( $nt );
-
-                       # Disallow deletions of big articles
-                       $bigHistory = $article->isBigDeletion();
-                       if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
-                               global $wgLang, $wgDeleteRevisionsLimit;
-                               $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
+               if ( $this->deleteAndMove ) {
+                       $permErrors = $nt->getUserPermissionsErrors( 'delete', $user );
+                       if ( count( $permErrors ) ) {
+                               # Only show the first error
+                               $this->showForm( $permErrors );
                                return;
                        }
 
+                       $reason = wfMessage( 'delete_and_move_reason', $ot )->inContentLanguage()->text();
+
                        // Delete an associated image if there is
-                       $file = wfLocalFile( $nt );
-                       if( $file->exists() ) {
-                               $file->delete( wfMsgForContent( 'delete_and_move_reason' ), false );
+                       if ( $nt->getNamespace() == NS_FILE ) {
+                               $file = wfLocalFile( $nt );
+                               if ( $file->exists() ) {
+                                       $file->delete( $reason, false );
+                               }
                        }
 
-                       // 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( 'badtitletext' );
-                       return;
+                       $error = ''; // passed by ref
+                       $page = WikiPage::factory( $nt );
+                       if ( !$page->doDeleteArticle( $reason, false, 0, true, $error, $user ) ) {
+                               $this->showForm( array( array( 'cannotdelete', wfEscapeWikiText( $nt->getPrefixedText() ) ) ) );
+                               return;
+                       }
                }
 
-               if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
+               if ( $user->isAllowed( 'suppressredirect' ) ) {
                        $createRedirect = $this->leaveRedirect;
                } else {
                        $createRedirect = true;
                }
 
+               # Do the actual move.
                $error = $ot->moveTo( $nt, true, $this->reason, $createRedirect );
                if ( $error !== true ) {
-                       # FIXME: show all the errors in a list, not just the first one
-                       $this->showForm( reset( $error ) );
+                       $this->showForm( $error );
                        return;
                }
 
@@ -345,20 +456,25 @@ class MovePageForm {
                        DoubleRedirectJob::fixRedirects( 'move', $ot, $nt );
                }
 
-               wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
+               wfRunHooks( 'SpecialMovepageAfterMove', array( &$this, &$ot, &$nt ) );
 
-               $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
+               $out = $this->getOutput();
+               $out->setPageTitle( $this->msg( 'pagemovedsub' ) );
 
-               $oldUrl = $ot->getFullUrl( 'redirect=no' );
-               $newUrl = $nt->getFullUrl();
+               $oldLink = Linker::link(
+                       $ot,
+                       null,
+                       array(),
+                       array( 'redirect' => 'no' )
+               );
+               $newLink = Linker::linkKnown( $nt );
                $oldText = $ot->getPrefixedText();
                $newText = $nt->getPrefixedText();
-               $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
-               $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
 
                $msgName = $createRedirect ? 'movepage-moved-redirect' : 'movepage-moved-noredirect';
-               $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
-               $wgOut->addWikiMsg( $msgName );
+               $out->addHTML( wfMessage( 'movepage-moved' )->rawParams( $oldLink,
+                       $newLink )->params( $oldText, $newText )->parseAsBlock() );
+               $out->addWikiMsg( $msgName );
 
                # Now we move extra pages we've been asked to move: subpages and talk
                # pages.  First, if the old page or the new page is a talk page, we
@@ -367,7 +483,7 @@ class MovePageForm {
                        $this->moveTalk = false;
                }
 
-               if( !$ot->userCan( 'move-subpages' ) ) {
+               if ( count( $ot->getUserPermissionsErrors( 'move-subpages', $user ) ) ) {
                        $this->moveSubpages = false;
                }
 
@@ -380,10 +496,10 @@ class MovePageForm {
                #
                # If the target namespace doesn't allow subpages, moving with subpages
                # would mean that you couldn't move them back in one operation, which
-               # is bad.  FIXME: A specific error message should be given in this
-               # case.
-               
-               // FIXME: Use Title::moveSubpages() here
+               # is bad.
+               # @todo FIXME: A specific error message should be given in this case.
+
+               // @todo FIXME: Use Title::moveSubpages() here
                $dbr = wfGetDB( DB_MASTER );
                if( $this->moveSubpages && (
                        MWNamespace::hasSubpages( $nt->getNamespace() ) || (
@@ -392,7 +508,7 @@ class MovePageForm {
                        )
                ) ) {
                        $conds = array(
-                               'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
+                               'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
                                        .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
                        );
                        $conds['page_namespace'] = array();
@@ -405,7 +521,7 @@ class MovePageForm {
                } elseif( $this->moveTalk ) {
                        $conds = array(
                                'page_namespace' => $ot->getTalkPage()->getNamespace(),
-                               'page_title' => $ot->getDBKey()
+                               'page_title' => $ot->getDBkey()
                        );
                } else {
                        # Skip the query
@@ -424,18 +540,17 @@ class MovePageForm {
                }
 
                $extraOutput = array();
-               $skin = $wgUser->getSkin();
                $count = 1;
                foreach( $extraPages as $oldSubpage ) {
-                       if( $oldSubpage->getArticleId() == $ot->getArticleId() ) {
+                       if( $ot->equals( $oldSubpage ) ) {
                                # Already did this one.
                                continue;
                        }
 
                        $newPageName = preg_replace(
-                               '#^'.preg_quote( $ot->getDBKey(), '#' ).'#',
-                               $nt->getDBKey(),
-                               $oldSubpage->getDBKey()
+                               '#^'.preg_quote( $ot->getDBkey(), '#' ).'#',
+                               StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
+                               $oldSubpage->getDBkey()
                        );
                        if( $oldSubpage->isTalkPage() ) {
                                $newNs = $nt->getTalkPage()->getNamespace();
@@ -446,7 +561,7 @@ class MovePageForm {
                        # be longer than 255 characters.
                        $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
                        if( !$newSubpage ) {
-                               $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
+                               $oldLink = Linker::linkKnown( $oldSubpage );
                                $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
                                        htmlspecialchars(Title::makeName( $newNs, $newPageName )));
                                continue;
@@ -454,7 +569,7 @@ class MovePageForm {
 
                        # This was copy-pasted from Renameuser, bleh.
                        if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
-                               $link = $skin->makeKnownLinkObj( $newSubpage );
+                               $link = Linker::linkKnown( $newSubpage );
                                $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
                        } else {
                                $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason, $createRedirect );
@@ -462,68 +577,78 @@ class MovePageForm {
                                        if ( $this->fixRedirects ) {
                                                DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
                                        }
-                                       $oldLink = $skin->makeKnownLinkObj( $oldSubpage, '', 'redirect=no' );
-                                       $newLink = $skin->makeKnownLinkObj( $newSubpage );
+                                       $oldLink = Linker::link(
+                                               $oldSubpage,
+                                               null,
+                                               array(),
+                                               array( 'redirect' => 'no' )
+                                       );
+                                       $newLink = Linker::linkKnown( $newSubpage );
                                        $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
+                                       ++$count;
+                                       if( $count >= $wgMaximumMovedPages ) {
+                                               $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $this->getLanguage()->formatNum( $wgMaximumMovedPages ) );
+                                               break;
+                                       }
                                } else {
-                                       $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
-                                       $newLink = $skin->makeLinkObj( $newSubpage );
+                                       $oldLink = Linker::linkKnown( $oldSubpage );
+                                       $newLink = Linker::link( $newSubpage );
                                        $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
                                }
                        }
 
-                       ++$count;
-                       if( $count >= $wgMaximumMovedPages ) {
-                               $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) );
-                               break;
-                       }
                }
 
                if( $extraOutput !== array() ) {
-                       $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
+                       $out->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
                }
 
                # Deal with watches (we don't watch subpages)
-               if( $this->watch ) {
-                       $wgUser->addWatch( $ot );
-                       $wgUser->addWatch( $nt );
+               if( $this->watch && $user->isLoggedIn() ) {
+                       $user->addWatch( $ot );
+                       $user->addWatch( $nt );
                } else {
-                       $wgUser->removeWatch( $ot );
-                       $wgUser->removeWatch( $nt );
+                       $user->removeWatch( $ot );
+                       $user->removeWatch( $nt );
                }
-       }
 
-       function showLogFragment( $title, &$out ) {
-               $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'move' ) ) );
-               LogEventsList::showLogExtract( $out, 'move', $title->getPrefixedText() );
+               # Re-clear the file redirect cache, which may have been polluted by
+               # parsing in messages above. See CR r56745.
+               # @todo FIXME: Needs a more robust solution inside FileRepo.
+               if( $ot->getNamespace() == NS_FILE ) {
+                       RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect( $ot );
+               }
        }
 
-       function showSubpages( $title, $out ) {
-               global $wgUser;
+       function showLogFragment( $title ) {
+               $out = $this->getOutput();
+               $out->addHTML( Xml::element( 'h2', null, LogPage::logName( 'move' ) ) );
+               LogEventsList::showLogExtract( $out, 'move', $title );
+       }
 
+       function showSubpages( $title ) {
                if( !MWNamespace::hasSubpages( $title->getNamespace() ) )
                        return;
 
-               $out->wrapWikiMsg( '== $1 ==', 'movesubpage' );
                $subpages = $title->getSubpages();
+               $count = $subpages instanceof TitleArray ? $subpages->count() : 0;
+
+               $out = $this->getOutput();
+               $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
 
                # No subpages.
-               if ( !( $subpages instanceof TitleArray ) || $subpages->count() == 0 ) {
+               if ( $count == 0 ) {
                        $out->addWikiMsg( 'movenosubpage' );
                        return;
                }
 
-               $skin = $wgUser->getSkin();
+               $out->addWikiMsg( 'movesubpagetext', $this->getLanguage()->formatNum( $count ) );
                $out->addHTML( "<ul>\n" );
 
                foreach( $subpages as $subpage ) {
-                       $link = $skin->link( $subpage );
-                       if ( $subpage->isRedirect() )
-                               $link = '<div class="allpagesredirect">' . $link . '</div>' ;
-
+                       $link = Linker::link( $subpage );
                        $out->addHTML( "<li>$link</li>\n" );
                }
                $out->addHTML( "</ul>\n" );
        }
 }
-