MediaWiki  REL1_23
SpecialMovepage.php
Go to the documentation of this file.
00001 <?php
00029 class MovePageForm extends UnlistedSpecialPage {
00034     var $oldTitle, $newTitle;
00035     // Text input
00036     var $reason;
00037     // Checks
00038     var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect, $moveOverShared;
00039 
00040     private $watch = false;
00041 
00042     public function __construct() {
00043         parent::__construct( 'Movepage' );
00044     }
00045 
00046     public function execute( $par ) {
00047         $this->checkReadOnly();
00048 
00049         $this->setHeaders();
00050         $this->outputHeader();
00051 
00052         $request = $this->getRequest();
00053         $target = !is_null( $par ) ? $par : $request->getVal( 'target' );
00054 
00055         // Yes, the use of getVal() and getText() is wanted, see bug 20365
00056 
00057         $oldTitleText = $request->getVal( 'wpOldTitle', $target );
00058         $this->oldTitle = Title::newFromText( $oldTitleText );
00059 
00060         if ( is_null( $this->oldTitle ) ) {
00061             throw new ErrorPageError( 'notargettitle', 'notargettext' );
00062         }
00063         if ( !$this->oldTitle->exists() ) {
00064             throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
00065         }
00066 
00067         $newTitleTextMain = $request->getText( 'wpNewTitleMain' );
00068         $newTitleTextNs = $request->getInt( 'wpNewTitleNs', $this->oldTitle->getNamespace() );
00069         // Backwards compatibility for forms submitting here from other sources
00070         // which is more common than it should be..
00071         $newTitleText_bc = $request->getText( 'wpNewTitle' );
00072         $this->newTitle = strlen( $newTitleText_bc ) > 0
00073             ? Title::newFromText( $newTitleText_bc )
00074             : Title::makeTitleSafe( $newTitleTextNs, $newTitleTextMain );
00075 
00076         $user = $this->getUser();
00077 
00078         # Check rights
00079         $permErrors = $this->oldTitle->getUserPermissionsErrors( 'move', $user );
00080         if ( count( $permErrors ) ) {
00081             // Auto-block user's IP if the account was "hard" blocked
00082             $user->spreadAnyEditBlock();
00083             throw new PermissionsError( 'move', $permErrors );
00084         }
00085 
00086         $def = !$request->wasPosted();
00087 
00088         $this->reason = $request->getText( 'wpReason' );
00089         $this->moveTalk = $request->getBool( 'wpMovetalk', $def );
00090         $this->fixRedirects = $request->getBool( 'wpFixRedirects', $def );
00091         $this->leaveRedirect = $request->getBool( 'wpLeaveRedirect', $def );
00092         $this->moveSubpages = $request->getBool( 'wpMovesubpages', false );
00093         $this->deleteAndMove = $request->getBool( 'wpDeleteAndMove' ) && $request->getBool( 'wpConfirm' );
00094         $this->moveOverShared = $request->getBool( 'wpMoveOverSharedFile', false );
00095         $this->watch = $request->getCheck( 'wpWatch' ) && $user->isLoggedIn();
00096 
00097         if ( 'submit' == $request->getVal( 'action' ) && $request->wasPosted()
00098             && $user->matchEditToken( $request->getVal( 'wpEditToken' ) )
00099         ) {
00100             $this->doSubmit();
00101         } else {
00102             $this->showForm( array() );
00103         }
00104     }
00105 
00113     function showForm( $err ) {
00114         global $wgContLang, $wgFixDoubleRedirects, $wgMaximumMovedPages;
00115 
00116         $this->getSkin()->setRelevantTitle( $this->oldTitle );
00117 
00118         $oldTitleLink = Linker::link( $this->oldTitle );
00119 
00120         $out = $this->getOutput();
00121         $out->setPageTitle( $this->msg( 'move-page', $this->oldTitle->getPrefixedText() ) );
00122         $out->addModules( 'mediawiki.special.movePage' );
00123 
00124         $newTitle = $this->newTitle;
00125 
00126         if ( !$newTitle ) {
00127             # Show the current title as a default
00128             # when the form is first opened.
00129             $newTitle = $this->oldTitle;
00130         } elseif ( !count( $err ) ) {
00131             # If a title was supplied, probably from the move log revert
00132             # link, check for validity. We can then show some diagnostic
00133             # information and save a click.
00134             $newerr = $this->oldTitle->isValidMoveOperation( $newTitle );
00135             if ( is_array( $newerr ) ) {
00136                 $err = $newerr;
00137             }
00138         }
00139 
00140         $user = $this->getUser();
00141 
00142         if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists'
00143             && $newTitle->quickUserCan( 'delete', $user )
00144         ) {
00145             $out->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
00146             $movepagebtn = $this->msg( 'delete_and_move' )->text();
00147             $submitVar = 'wpDeleteAndMove';
00148             $confirm = "
00149                 <tr>
00150                     <td></td>
00151                     <td class='mw-input'>" .
00152                 Xml::checkLabel(
00153                     $this->msg( 'delete_and_move_confirm' )->text(),
00154                     'wpConfirm',
00155                     'wpConfirm'
00156                 ) .
00157                 "</td>
00158                 </tr>";
00159             $err = array();
00160         } else {
00161             if ( $this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) {
00162                 $out->wrapWikiMsg(
00163                     "<div class=\"error mw-moveuserpage-warning\">\n$1\n</div>",
00164                     'moveuserpage-warning'
00165                 );
00166             }
00167 
00168             $out->addWikiMsg( $wgFixDoubleRedirects ?
00169                 'movepagetext' :
00170                 'movepagetext-noredirectfixer'
00171             );
00172             $movepagebtn = $this->msg( 'movepagebtn' )->text();
00173             $submitVar = 'wpMove';
00174             $confirm = false;
00175         }
00176 
00177         if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'file-exists-sharedrepo'
00178             && $user->isAllowed( 'reupload-shared' )
00179         ) {
00180             $out->addWikiMsg( 'move-over-sharedrepo', $newTitle->getPrefixedText() );
00181             $submitVar = 'wpMoveOverSharedFile';
00182             $err = array();
00183         }
00184 
00185         $oldTalk = $this->oldTitle->getTalkPage();
00186         $oldTitleSubpages = $this->oldTitle->hasSubpages();
00187         $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
00188 
00189         $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
00190             !count( $this->oldTitle->getUserPermissionsErrors( 'move-subpages', $user ) );
00191 
00192         # We also want to be able to move assoc. subpage talk-pages even if base page
00193         # has no associated talk page, so || with $oldTitleTalkSubpages.
00194         $considerTalk = !$this->oldTitle->isTalkPage() &&
00195             ( $oldTalk->exists()
00196                 || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
00197 
00198         $dbr = wfGetDB( DB_SLAVE );
00199         if ( $wgFixDoubleRedirects ) {
00200             $hasRedirects = $dbr->selectField( 'redirect', '1',
00201                 array(
00202                     'rd_namespace' => $this->oldTitle->getNamespace(),
00203                     'rd_title' => $this->oldTitle->getDBkey(),
00204                 ), __METHOD__ );
00205         } else {
00206             $hasRedirects = false;
00207         }
00208 
00209         if ( $considerTalk ) {
00210             $out->addWikiMsg( 'movepagetalktext' );
00211         }
00212 
00213         if ( count( $err ) ) {
00214             $out->addHTML( "<div class='error'>\n" );
00215             $action_desc = $this->msg( 'action-move' )->plain();
00216             $out->addWikiMsg( 'permissionserrorstext-withaction', count( $err ), $action_desc );
00217 
00218             if ( count( $err ) == 1 ) {
00219                 $errMsg = $err[0];
00220                 $errMsgName = array_shift( $errMsg );
00221 
00222                 if ( $errMsgName == 'hookaborted' ) {
00223                     $out->addHTML( "<p>{$errMsg[0]}</p>\n" );
00224                 } else {
00225                     $out->addWikiMsgArray( $errMsgName, $errMsg );
00226                 }
00227             } else {
00228                 $errStr = array();
00229 
00230                 foreach ( $err as $errMsg ) {
00231                     if ( $errMsg[0] == 'hookaborted' ) {
00232                         $errStr[] = $errMsg[1];
00233                     } else {
00234                         $errMsgName = array_shift( $errMsg );
00235                         $errStr[] = $this->msg( $errMsgName, $errMsg )->parse();
00236                     }
00237                 }
00238 
00239                 $out->addHTML( '<ul><li>' . implode( "</li>\n<li>", $errStr ) . "</li></ul>\n" );
00240             }
00241             $out->addHTML( "</div>\n" );
00242         }
00243 
00244         if ( $this->oldTitle->isProtected( 'move' ) ) {
00245             # Is the title semi-protected?
00246             if ( $this->oldTitle->isSemiProtected( 'move' ) ) {
00247                 $noticeMsg = 'semiprotectedpagemovewarning';
00248                 $classes[] = 'mw-textarea-sprotected';
00249             } else {
00250                 # Then it must be protected based on static groups (regular)
00251                 $noticeMsg = 'protectedpagemovewarning';
00252                 $classes[] = 'mw-textarea-protected';
00253             }
00254             $out->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
00255             $out->addWikiMsg( $noticeMsg );
00256             LogEventsList::showLogExtract(
00257                 $out,
00258                 'protect',
00259                 $this->oldTitle,
00260                 '',
00261                 array( 'lim' => 1 )
00262             );
00263             $out->addHTML( "</div>\n" );
00264         }
00265 
00266         // Byte limit (not string length limit) for wpReason and wpNewTitleMain
00267         // is enforced in the mediawiki.special.movePage module
00268 
00269         $immovableNamespaces = array();
00270 
00271         foreach ( array_keys( $this->getLanguage()->getNamespaces() ) as $nsId ) {
00272             if ( !MWNamespace::isMovable( $nsId ) ) {
00273                 $immovableNamespaces[] = $nsId;
00274             }
00275         }
00276 
00277         $handler = ContentHandler::getForTitle( $this->oldTitle );
00278 
00279         $out->addHTML(
00280             Xml::openElement(
00281                 'form',
00282                 array(
00283                     'method' => 'post',
00284                     'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ),
00285                     'id' => 'movepage'
00286                 )
00287             ) .
00288                 Xml::openElement( 'fieldset' ) .
00289                 Xml::element( 'legend', null, $this->msg( 'move-page-legend' )->text() ) .
00290                 Xml::openElement( 'table', array( 'id' => 'mw-movepage-table' ) ) .
00291                 "<tr>
00292                 <td class='mw-label'>" .
00293                 $this->msg( 'movearticle' )->escaped() .
00294                 "</td>
00295                 <td class='mw-input'>
00296                     <strong>{$oldTitleLink}</strong>
00297                 </td>
00298             </tr>
00299             <tr>
00300                 <td class='mw-label'>" .
00301                 Xml::label( $this->msg( 'newtitle' )->text(), 'wpNewTitleMain' ) .
00302                 "</td>
00303                 <td class='mw-input'>" .
00304                 Html::namespaceSelector(
00305                     array(
00306                         'selected' => $newTitle->getNamespace(),
00307                         'exclude' => $immovableNamespaces
00308                     ),
00309                     array( 'name' => 'wpNewTitleNs', 'id' => 'wpNewTitleNs' )
00310                 ) .
00311                 Xml::input(
00312                     'wpNewTitleMain',
00313                     60,
00314                     $wgContLang->recodeForEdit( $newTitle->getText() ),
00315                     array(
00316                         'type' => 'text',
00317                         'id' => 'wpNewTitleMain',
00318                         'maxlength' => 255
00319                     )
00320                 ) .
00321                 Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
00322                 "</td>
00323             </tr>
00324             <tr>
00325                 <td class='mw-label'>" .
00326                 Xml::label( $this->msg( 'movereason' )->text(), 'wpReason' ) .
00327                 "</td>
00328                 <td class='mw-input'>" .
00329                     Xml::input( 'wpReason', 60, $this->reason, array(
00330                         'type' => 'text',
00331                         'id' => 'wpReason',
00332                         'maxlength' => 200,
00333                     ) ) .
00334                 "</td>
00335             </tr>"
00336         );
00337 
00338         if ( $considerTalk ) {
00339             $out->addHTML( "
00340                 <tr>
00341                     <td></td>
00342                     <td class='mw-input'>" .
00343                     Xml::checkLabel(
00344                         $this->msg( 'movetalk' )->text(),
00345                         'wpMovetalk',
00346                         'wpMovetalk',
00347                         $this->moveTalk
00348                     ) .
00349                     "</td>
00350                 </tr>"
00351             );
00352         }
00353 
00354         if ( $user->isAllowed( 'suppressredirect' ) ) {
00355             if ( $handler->supportsRedirects() ) {
00356                 $isChecked = $this->leaveRedirect;
00357                 $options = array();
00358             } else {
00359                 $isChecked = false;
00360                 $options = array(
00361                     'disabled' => 'disabled'
00362                 );
00363             }
00364             $out->addHTML( "
00365                 <tr>
00366                     <td></td>
00367                     <td class='mw-input' >" .
00368                     Xml::checkLabel(
00369                         $this->msg( 'move-leave-redirect' )->text(),
00370                         'wpLeaveRedirect',
00371                         'wpLeaveRedirect',
00372                         $isChecked,
00373                         $options
00374                     ) .
00375                     "</td>
00376                 </tr>"
00377             );
00378         }
00379 
00380         if ( $hasRedirects ) {
00381             $out->addHTML( "
00382                 <tr>
00383                     <td></td>
00384                     <td class='mw-input' >" .
00385                     Xml::checkLabel(
00386                         $this->msg( 'fix-double-redirects' )->text(),
00387                         'wpFixRedirects',
00388                         'wpFixRedirects',
00389                         $this->fixRedirects
00390                     ) .
00391                     "</td>
00392                 </tr>"
00393             );
00394         }
00395 
00396         if ( $canMoveSubpage ) {
00397             $out->addHTML( "
00398                 <tr>
00399                     <td></td>
00400                     <td class=\"mw-input\">" .
00401                     Xml::check(
00402                         'wpMovesubpages',
00403                         # Don't check the box if we only have talk subpages to
00404                         # move and we aren't moving the talk page.
00405                         $this->moveSubpages && ( $this->oldTitle->hasSubpages() || $this->moveTalk ),
00406                         array( 'id' => 'wpMovesubpages' )
00407                     ) . '&#160;' .
00408                     Xml::tags( 'label', array( 'for' => 'wpMovesubpages' ),
00409                         $this->msg(
00410                             ( $this->oldTitle->hasSubpages()
00411                                 ? 'move-subpages'
00412                                 : 'move-talk-subpages' )
00413                         )->numParams( $wgMaximumMovedPages )->params( $wgMaximumMovedPages )->parse()
00414                     ) .
00415                     "</td>
00416                 </tr>"
00417             );
00418         }
00419 
00420         $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption( 'watchmoves' )
00421             || $user->isWatched( $this->oldTitle ) );
00422         # Don't allow watching if user is not logged in
00423         if ( $user->isLoggedIn() ) {
00424             $out->addHTML( "
00425             <tr>
00426                 <td></td>
00427                 <td class='mw-input'>" .
00428                 Xml::checkLabel(
00429                     $this->msg( 'move-watch' )->text(),
00430                     'wpWatch',
00431                     'watch',
00432                     $watchChecked
00433                 ) .
00434                 "</td>
00435             </tr>" );
00436         }
00437 
00438         $out->addHTML( "
00439                 {$confirm}
00440             <tr>
00441                 <td>&#160;</td>
00442                 <td class='mw-submit'>" .
00443                 Xml::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
00444                 "</td>
00445             </tr>" .
00446                 Xml::closeElement( 'table' ) .
00447                 Html::hidden( 'wpEditToken', $user->getEditToken() ) .
00448                 Xml::closeElement( 'fieldset' ) .
00449                 Xml::closeElement( 'form' ) .
00450                 "\n"
00451         );
00452 
00453         $this->showLogFragment( $this->oldTitle );
00454         $this->showSubpages( $this->oldTitle );
00455     }
00456 
00457     function doSubmit() {
00458         global $wgMaximumMovedPages, $wgFixDoubleRedirects;
00459 
00460         $user = $this->getUser();
00461 
00462         if ( $user->pingLimiter( 'move' ) ) {
00463             throw new ThrottledError;
00464         }
00465 
00466         $ot = $this->oldTitle;
00467         $nt = $this->newTitle;
00468 
00469         # don't allow moving to pages with # in
00470         if ( !$nt || $nt->hasFragment() ) {
00471             $this->showForm( array( array( 'badtitletext' ) ) );
00472 
00473             return;
00474         }
00475 
00476         # Show a warning if the target file exists on a shared repo
00477         if ( $nt->getNamespace() == NS_FILE
00478             && !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) )
00479             && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt )
00480             && wfFindFile( $nt )
00481         ) {
00482             $this->showForm( array( array( 'file-exists-sharedrepo' ) ) );
00483 
00484             return;
00485         }
00486 
00487         # Delete to make way if requested
00488         if ( $this->deleteAndMove ) {
00489             $permErrors = $nt->getUserPermissionsErrors( 'delete', $user );
00490             if ( count( $permErrors ) ) {
00491                 # Only show the first error
00492                 $this->showForm( $permErrors );
00493 
00494                 return;
00495             }
00496 
00497             $reason = $this->msg( 'delete_and_move_reason', $ot )->inContentLanguage()->text();
00498 
00499             // Delete an associated image if there is
00500             if ( $nt->getNamespace() == NS_FILE ) {
00501                 $file = wfLocalFile( $nt );
00502                 if ( $file->exists() ) {
00503                     $file->delete( $reason, false );
00504                 }
00505             }
00506 
00507             $error = ''; // passed by ref
00508             $page = WikiPage::factory( $nt );
00509             $deleteStatus = $page->doDeleteArticleReal( $reason, false, 0, true, $error, $user );
00510             if ( !$deleteStatus->isGood() ) {
00511                 $this->showForm( $deleteStatus->getErrorsArray() );
00512 
00513                 return;
00514             }
00515         }
00516 
00517         $handler = ContentHandler::getForTitle( $ot );
00518 
00519         if ( !$handler->supportsRedirects() ) {
00520             $createRedirect = false;
00521         } elseif ( $user->isAllowed( 'suppressredirect' ) ) {
00522             $createRedirect = $this->leaveRedirect;
00523         } else {
00524             $createRedirect = true;
00525         }
00526 
00527         # Do the actual move.
00528         $error = $ot->moveTo( $nt, true, $this->reason, $createRedirect );
00529         if ( $error !== true ) {
00530             $this->showForm( $error );
00531 
00532             return;
00533         }
00534 
00535         if ( $wgFixDoubleRedirects && $this->fixRedirects ) {
00536             DoubleRedirectJob::fixRedirects( 'move', $ot, $nt );
00537         }
00538 
00539         $out = $this->getOutput();
00540         $out->setPageTitle( $this->msg( 'pagemovedsub' ) );
00541 
00542         $oldLink = Linker::link(
00543             $ot,
00544             null,
00545             array(),
00546             array( 'redirect' => 'no' )
00547         );
00548         $newLink = Linker::linkKnown( $nt );
00549         $oldText = $ot->getPrefixedText();
00550         $newText = $nt->getPrefixedText();
00551 
00552         if ( $ot->exists() ) {
00553             //NOTE: we assume that if the old title exists, it's because it was re-created as
00554             // a redirect to the new title. This is not safe, but what we did before was
00555             // even worse: we just determined whether a redirect should have been created,
00556             // and reported that it was created if it should have, without any checks.
00557             // Also note that isRedirect() is unreliable because of bug 37209.
00558             $msgName = 'movepage-moved-redirect';
00559         } else {
00560             $msgName = 'movepage-moved-noredirect';
00561         }
00562 
00563         $out->addHTML( $this->msg( 'movepage-moved' )->rawParams( $oldLink,
00564             $newLink )->params( $oldText, $newText )->parseAsBlock() );
00565         $out->addWikiMsg( $msgName );
00566 
00567         wfRunHooks( 'SpecialMovepageAfterMove', array( &$this, &$ot, &$nt ) );
00568 
00569         # Now we move extra pages we've been asked to move: subpages and talk
00570         # pages.  First, if the old page or the new page is a talk page, we
00571         # can't move any talk pages: cancel that.
00572         if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
00573             $this->moveTalk = false;
00574         }
00575 
00576         if ( count( $ot->getUserPermissionsErrors( 'move-subpages', $user ) ) ) {
00577             $this->moveSubpages = false;
00578         }
00579 
00580         # Next make a list of id's.  This might be marginally less efficient
00581         # than a more direct method, but this is not a highly performance-cri-
00582         # tical code path and readable code is more important here.
00583         #
00584         # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
00585         # 4 might get confused.  If so, consider rewriting as a UNION.
00586         #
00587         # If the target namespace doesn't allow subpages, moving with subpages
00588         # would mean that you couldn't move them back in one operation, which
00589         # is bad.
00590         # @todo FIXME: A specific error message should be given in this case.
00591 
00592         // @todo FIXME: Use Title::moveSubpages() here
00593         $dbr = wfGetDB( DB_MASTER );
00594         if ( $this->moveSubpages && (
00595             MWNamespace::hasSubpages( $nt->getNamespace() ) || (
00596                 $this->moveTalk
00597                     && MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
00598             )
00599         ) ) {
00600             $conds = array(
00601                 'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
00602                     . ' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
00603             );
00604             $conds['page_namespace'] = array();
00605             if ( MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
00606                 $conds['page_namespace'][] = $ot->getNamespace();
00607             }
00608             if ( $this->moveTalk &&
00609                 MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
00610             ) {
00611                 $conds['page_namespace'][] = $ot->getTalkPage()->getNamespace();
00612             }
00613         } elseif ( $this->moveTalk ) {
00614             $conds = array(
00615                 'page_namespace' => $ot->getTalkPage()->getNamespace(),
00616                 'page_title' => $ot->getDBkey()
00617             );
00618         } else {
00619             # Skip the query
00620             $conds = null;
00621         }
00622 
00623         $extraPages = array();
00624         if ( !is_null( $conds ) ) {
00625             $extraPages = TitleArray::newFromResult(
00626                 $dbr->select( 'page',
00627                     array( 'page_id', 'page_namespace', 'page_title' ),
00628                     $conds,
00629                     __METHOD__
00630                 )
00631             );
00632         }
00633 
00634         $extraOutput = array();
00635         $count = 1;
00636         foreach ( $extraPages as $oldSubpage ) {
00637             if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
00638                 # Already did this one.
00639                 continue;
00640             }
00641 
00642             $newPageName = preg_replace(
00643                 '#^' . preg_quote( $ot->getDBkey(), '#' ) . '#',
00644                 StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
00645                 $oldSubpage->getDBkey()
00646             );
00647 
00648             if ( $oldSubpage->isTalkPage() ) {
00649                 $newNs = $nt->getTalkPage()->getNamespace();
00650             } else {
00651                 $newNs = $nt->getSubjectPage()->getNamespace();
00652             }
00653 
00654             # Bug 14385: we need makeTitleSafe because the new page names may
00655             # be longer than 255 characters.
00656             $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
00657             if ( !$newSubpage ) {
00658                 $oldLink = Linker::linkKnown( $oldSubpage );
00659                 $extraOutput[] = $this->msg( 'movepage-page-unmoved' )->rawParams( $oldLink )
00660                     ->params( Title::makeName( $newNs, $newPageName ) )->escaped();
00661                 continue;
00662             }
00663 
00664             # This was copy-pasted from Renameuser, bleh.
00665             if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
00666                 $link = Linker::linkKnown( $newSubpage );
00667                 $extraOutput[] = $this->msg( 'movepage-page-exists' )->rawParams( $link )->escaped();
00668             } else {
00669                 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason, $createRedirect );
00670 
00671                 if ( $success === true ) {
00672                     if ( $this->fixRedirects ) {
00673                         DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
00674                     }
00675                     $oldLink = Linker::link(
00676                         $oldSubpage,
00677                         null,
00678                         array(),
00679                         array( 'redirect' => 'no' )
00680                     );
00681 
00682                     $newLink = Linker::linkKnown( $newSubpage );
00683                     $extraOutput[] = $this->msg( 'movepage-page-moved' )->rawParams( $oldLink, $newLink )->escaped();
00684                     ++$count;
00685 
00686                     if ( $count >= $wgMaximumMovedPages ) {
00687                         $extraOutput[] = $this->msg( 'movepage-max-pages' )->numParams( $wgMaximumMovedPages )->escaped();
00688                         break;
00689                     }
00690                 } else {
00691                     $oldLink = Linker::linkKnown( $oldSubpage );
00692                     $newLink = Linker::link( $newSubpage );
00693                     $extraOutput[] = $this->msg( 'movepage-page-unmoved' )->rawParams( $oldLink, $newLink )->escaped();
00694                 }
00695             }
00696         }
00697 
00698         if ( $extraOutput !== array() ) {
00699             $out->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
00700         }
00701 
00702         # Deal with watches (we don't watch subpages)
00703         WatchAction::doWatchOrUnwatch( $this->watch, $ot, $user );
00704         WatchAction::doWatchOrUnwatch( $this->watch, $nt, $user );
00705     }
00706 
00707     function showLogFragment( $title ) {
00708         $moveLogPage = new LogPage( 'move' );
00709         $out = $this->getOutput();
00710         $out->addHTML( Xml::element( 'h2', null, $moveLogPage->getName()->text() ) );
00711         LogEventsList::showLogExtract( $out, 'move', $title );
00712     }
00713 
00714     function showSubpages( $title ) {
00715         if ( !MWNamespace::hasSubpages( $title->getNamespace() ) ) {
00716             return;
00717         }
00718 
00719         $subpages = $title->getSubpages();
00720         $count = $subpages instanceof TitleArray ? $subpages->count() : 0;
00721 
00722         $out = $this->getOutput();
00723         $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
00724 
00725         # No subpages.
00726         if ( $count == 0 ) {
00727             $out->addWikiMsg( 'movenosubpage' );
00728 
00729             return;
00730         }
00731 
00732         $out->addWikiMsg( 'movesubpagetext', $this->getLanguage()->formatNum( $count ) );
00733         $out->addHTML( "<ul>\n" );
00734 
00735         foreach ( $subpages as $subpage ) {
00736             $link = Linker::link( $subpage );
00737             $out->addHTML( "<li>$link</li>\n" );
00738         }
00739         $out->addHTML( "</ul>\n" );
00740     }
00741 
00742     protected function getGroupName() {
00743         return 'pagetools';
00744     }
00745 }