10 function wfSpecialMovepage( $par = null ) {
11 global $wgUser, $wgOut, $wgRequest, $action;
13 # Check for database lock
15 $wgOut->readOnlyPage();
19 $target = isset( $par ) ?
$par : $wgRequest->getVal( 'target' );
21 // Yes, the use of getVal() and getText() is wanted, see bug 20365
22 $oldTitleText = $wgRequest->getVal( 'wpOldTitle', $target );
23 $newTitleText = $wgRequest->getText( 'wpNewTitle' );
25 $oldTitle = Title
::newFromText( $oldTitleText );
26 $newTitle = Title
::newFromText( $newTitleText );
28 if( is_null( $oldTitle ) ) {
29 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
32 if( !$oldTitle->exists() ) {
33 $wgOut->showErrorPage( 'nopagetitle', 'nopagetext' );
38 $permErrors = $oldTitle->getUserPermissionsErrors( 'move', $wgUser );
39 if( !empty( $permErrors ) ) {
40 $wgOut->showPermissionsErrorPage( $permErrors );
44 $form = new MovePageForm( $oldTitle, $newTitle );
46 if ( 'submit' == $action && $wgRequest->wasPosted()
47 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
50 $form->showForm( '' );
55 * HTML form for Special:Movepage
56 * @ingroup SpecialPage
59 var $oldTitle, $newTitle; # Objects
60 var $reason; # Text input
61 var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect, $moveOverShared; # Checks
63 private $watch = false;
65 function __construct( $oldTitle, $newTitle ) {
67 $target = isset($par) ?
$par : $wgRequest->getVal( 'target' );
68 $this->oldTitle
= $oldTitle;
69 $this->newTitle
= $newTitle;
70 $this->reason
= $wgRequest->getText( 'wpReason' );
71 if ( $wgRequest->wasPosted() ) {
72 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', false );
73 $this->fixRedirects
= $wgRequest->getBool( 'wpFixRedirects', false );
74 $this->leaveRedirect
= $wgRequest->getBool( 'wpLeaveRedirect', false );
76 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', true );
77 $this->fixRedirects
= $wgRequest->getBool( 'wpFixRedirects', true );
78 $this->leaveRedirect
= $wgRequest->getBool( 'wpLeaveRedirect', true );
80 $this->moveSubpages
= $wgRequest->getBool( 'wpMovesubpages', false );
81 $this->deleteAndMove
= $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
82 $this->moveOverShared
= $wgRequest->getBool( 'wpMoveOverSharedFile', false );
83 $this->watch
= $wgRequest->getCheck( 'wpWatch' );
88 * @param mixed $err Error message. May either be a string message name or
89 * array message name and parameters, like the second argument to
90 * OutputPage::wrapWikiMsg().
92 function showForm( $err ) {
93 global $wgOut, $wgUser, $wgContLang, $wgFixDoubleRedirects;
95 $skin = $wgUser->getSkin();
97 $oldTitleLink = $skin->link( $this->oldTitle
);
99 $wgOut->setPagetitle( wfMsg( 'move-page', $this->oldTitle
->getPrefixedText() ) );
100 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
102 $newTitle = $this->newTitle
;
105 # Show the current title as a default
106 # when the form is first opened.
107 $newTitle = $this->oldTitle
;
111 # If a title was supplied, probably from the move log revert
112 # link, check for validity. We can then show some diagnostic
113 # information and save a click.
114 $newerr = $this->oldTitle
->isValidMoveOperation( $newTitle );
121 if ( !empty($err) && $err[0] == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
122 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
123 $movepagebtn = wfMsg( 'delete_and_move' );
124 $submitVar = 'wpDeleteAndMove';
128 <td class='mw-input'>" .
129 Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
134 $wgOut->addWikiMsg( 'movepagetext' );
135 $movepagebtn = wfMsg( 'movepagebtn' );
136 $submitVar = 'wpMove';
140 if ( !empty($err) && $err[0] == 'file-exists-sharedrepo' && $wgUser->isAllowed( 'reupload-shared' ) ) {
141 $wgOut->addWikiMsg( 'move-over-sharedrepo', $newTitle->getPrefixedText() );
142 $submitVar = 'wpMoveOverSharedFile';
146 $oldTalk = $this->oldTitle
->getTalkPage();
147 $considerTalk = ( !$this->oldTitle
->isTalkPage() && $oldTalk->exists() );
149 $dbr = wfGetDB( DB_SLAVE
);
150 if ( $wgFixDoubleRedirects ) {
151 $hasRedirects = $dbr->selectField( 'redirect', '1',
153 'rd_namespace' => $this->oldTitle
->getNamespace(),
154 'rd_title' => $this->oldTitle
->getDBkey(),
157 $hasRedirects = false;
160 if ( $considerTalk ) {
161 $wgOut->addWikiMsg( 'movepagetalktext' );
164 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
165 $token = htmlspecialchars( $wgUser->editToken() );
167 if ( !empty($err) ) {
168 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
169 if( $err[0] == 'hookaborted' ) {
171 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
172 $wgOut->addHTML( $errMsg );
174 $wgOut->wrapWikiMsg( '<p><strong class="error">$1</strong></p>', $err );
178 if ( $this->oldTitle
->isProtected( 'move' ) ) {
179 # Is the title semi-protected?
180 if ( $this->oldTitle
->isSemiProtected( 'move' ) ) {
181 $noticeMsg = 'semiprotectedpagemovewarning';
182 $classes[] = 'mw-textarea-sprotected';
184 # Then it must be protected based on static groups (regular)
185 $noticeMsg = 'protectedpagemovewarning';
186 $classes[] = 'mw-textarea-protected';
188 $wgOut->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
189 $wgOut->addWikiMsg( $noticeMsg );
190 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->oldTitle
->getPrefixedText(), '', array( 'lim' => 1 ) );
191 $wgOut->addHTML( "</div>\n" );
195 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
196 Xml
::openElement( 'fieldset' ) .
197 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
198 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
200 <td class='mw-label'>" .
201 wfMsgHtml( 'movearticle' ) .
203 <td class='mw-input'>
204 <strong>{$oldTitleLink}</strong>
208 <td class='mw-label'>" .
209 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
211 <td class='mw-input'>" .
212 Xml
::input( 'wpNewTitle', 40, $wgContLang->recodeForEdit( $newTitle->getPrefixedText() ), array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
213 Xml
::hidden( 'wpOldTitle', $this->oldTitle
->getPrefixedText() ) .
217 <td class='mw-label'>" .
218 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
220 <td class='mw-input'>" .
221 Xml
::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason
) ) .
226 if( $considerTalk ) {
230 <td class='mw-input'>" .
231 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
237 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
241 <td class='mw-input' >" .
242 Xml
::checkLabel( wfMsg( 'move-leave-redirect' ), 'wpLeaveRedirect',
243 'wpLeaveRedirect', $this->leaveRedirect
) .
249 if ( $hasRedirects ) {
253 <td class='mw-input' >" .
254 Xml
::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects',
255 'wpFixRedirects', $this->fixRedirects
) .
261 if( ($this->oldTitle
->hasSubpages() ||
$this->oldTitle
->getTalkPage()->hasSubpages())
262 && $this->oldTitle
->userCan( 'move-subpages' ) )
264 global $wgMaximumMovedPages, $wgLang;
269 <td class=\"mw-input\">" .
272 # Don't check the box if we only have talk subpages to
273 # move and we aren't moving the talk page.
274 $this->moveSubpages
&& ($this->oldTitle
->hasSubpages() ||
$this->moveTalk
),
275 array( 'id' => 'wpMovesubpages' )
277 Xml
::tags( 'label', array( 'for' => 'wpMovesubpages' ),
279 ( $this->oldTitle
->hasSubpages()
281 : 'move-talk-subpages' ),
282 array( 'parseinline' ),
283 $wgLang->formatNum( $wgMaximumMovedPages ),
284 # $2 to allow use of PLURAL in message.
293 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' )
294 ||
$this->oldTitle
->userIsWatching();
298 <td class='mw-input'>" .
299 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
305 <td class='mw-submit'>" .
306 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
309 Xml
::closeElement( 'table' ) .
310 Xml
::hidden( 'wpEditToken', $token ) .
311 Xml
::closeElement( 'fieldset' ) .
312 Xml
::closeElement( 'form' ) .
316 $this->showLogFragment( $this->oldTitle
, $wgOut );
317 $this->showSubpages( $this->oldTitle
, $wgOut );
321 function doSubmit() {
322 global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
323 global $wgFixDoubleRedirects;
325 if ( $wgUser->pingLimiter( 'move' ) ) {
326 $wgOut->rateLimited();
330 $ot = $this->oldTitle
;
331 $nt = $this->newTitle
;
333 # Delete to make way if requested
334 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
335 $article = new Article( $nt );
337 # Disallow deletions of big articles
338 $bigHistory = $article->isBigDeletion();
339 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
340 global $wgLang, $wgDeleteRevisionsLimit;
341 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
345 // Delete an associated image if there is
346 $file = wfLocalFile( $nt );
347 if( $file->exists() ) {
348 $file->delete( wfMsgForContent( 'delete_and_move_reason' ), false );
351 // This may output an error message and exit
352 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
355 # don't allow moving to pages with # in
356 if ( !$nt ||
$nt->getFragment() != '' ) {
357 $this->showForm( 'badtitletext' );
361 # Show a warning if the target file exists on a shared repo
362 if ( $nt->getNamespace() == NS_FILE
363 && !( $this->moveOverShared
&& $wgUser->isAllowed( 'reupload-shared' ) )
364 && !RepoGroup
::singleton()->getLocalRepo()->findFile( $nt )
365 && wfFindFile( $nt ) )
367 $this->showForm( array('file-exists-sharedrepo') );
372 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
373 $createRedirect = $this->leaveRedirect
;
375 $createRedirect = true;
378 # Do the actual move.
379 $error = $ot->moveTo( $nt, true, $this->reason
, $createRedirect );
380 if ( $error !== true ) {
381 # FIXME: show all the errors in a list, not just the first one
382 $this->showForm( reset( $error ) );
386 if ( $wgFixDoubleRedirects && $this->fixRedirects
) {
387 DoubleRedirectJob
::fixRedirects( 'move', $ot, $nt );
390 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
392 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
394 $oldUrl = $ot->getFullUrl( 'redirect=no' );
395 $newUrl = $nt->getFullUrl();
396 $oldText = $ot->getPrefixedText();
397 $newText = $nt->getPrefixedText();
398 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
399 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
401 $msgName = $createRedirect ?
'movepage-moved-redirect' : 'movepage-moved-noredirect';
402 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
403 $wgOut->addWikiMsg( $msgName );
405 # Now we move extra pages we've been asked to move: subpages and talk
406 # pages. First, if the old page or the new page is a talk page, we
407 # can't move any talk pages: cancel that.
408 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
409 $this->moveTalk
= false;
412 if( !$ot->userCan( 'move-subpages' ) ) {
413 $this->moveSubpages
= false;
416 # Next make a list of id's. This might be marginally less efficient
417 # than a more direct method, but this is not a highly performance-cri-
418 # tical code path and readable code is more important here.
420 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
421 # 4 might get confused. If so, consider rewriting as a UNION.
423 # If the target namespace doesn't allow subpages, moving with subpages
424 # would mean that you couldn't move them back in one operation, which
425 # is bad. FIXME: A specific error message should be given in this
428 // FIXME: Use Title::moveSubpages() here
429 $dbr = wfGetDB( DB_MASTER
);
430 if( $this->moveSubpages
&& (
431 MWNamespace
::hasSubpages( $nt->getNamespace() ) ||
(
433 MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() )
437 'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
438 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
440 $conds['page_namespace'] = array();
441 if( MWNamespace
::hasSubpages( $nt->getNamespace() ) ) {
442 $conds['page_namespace'] []= $ot->getNamespace();
444 if( $this->moveTalk
&& MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
445 $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
447 } elseif( $this->moveTalk
) {
449 'page_namespace' => $ot->getTalkPage()->getNamespace(),
450 'page_title' => $ot->getDBkey()
457 $extraPages = array();
458 if( !is_null( $conds ) ) {
459 $extraPages = TitleArray
::newFromResult(
460 $dbr->select( 'page',
461 array( 'page_id', 'page_namespace', 'page_title' ),
468 $extraOutput = array();
469 $skin = $wgUser->getSkin();
471 foreach( $extraPages as $oldSubpage ) {
472 if( $ot->equals( $oldSubpage ) ) {
473 # Already did this one.
477 $newPageName = preg_replace(
478 '#^'.preg_quote( $ot->getDBkey(), '#' ).'#',
479 str_replace( '\\', '\\\\', $nt->getDBkey() ), # bug 21234
480 $oldSubpage->getDBkey()
482 if( $oldSubpage->isTalkPage() ) {
483 $newNs = $nt->getTalkPage()->getNamespace();
485 $newNs = $nt->getSubjectPage()->getNamespace();
487 # Bug 14385: we need makeTitleSafe because the new page names may
488 # be longer than 255 characters.
489 $newSubpage = Title
::makeTitleSafe( $newNs, $newPageName );
491 $oldLink = $skin->linkKnown( $oldSubpage );
492 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
493 htmlspecialchars(Title
::makeName( $newNs, $newPageName )));
497 # This was copy-pasted from Renameuser, bleh.
498 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
499 $link = $skin->linkKnown( $newSubpage );
500 $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
502 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason
, $createRedirect );
503 if( $success === true ) {
504 if ( $this->fixRedirects
) {
505 DoubleRedirectJob
::fixRedirects( 'move', $oldSubpage, $newSubpage );
507 $oldLink = $skin->linkKnown(
511 array( 'redirect' => 'no' )
513 $newLink = $skin->linkKnown( $newSubpage );
514 $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
516 if( $count >= $wgMaximumMovedPages ) {
517 $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) );
521 $oldLink = $skin->linkKnown( $oldSubpage );
522 $newLink = $skin->link( $newSubpage );
523 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
529 if( $extraOutput !== array() ) {
530 $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
533 # Deal with watches (we don't watch subpages)
535 $wgUser->addWatch( $ot );
536 $wgUser->addWatch( $nt );
538 $wgUser->removeWatch( $ot );
539 $wgUser->removeWatch( $nt );
543 function showLogFragment( $title, &$out ) {
544 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
545 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );
548 function showSubpages( $title, $out ) {
549 global $wgUser, $wgLang;
551 if( !MWNamespace
::hasSubpages( $title->getNamespace() ) )
554 $subpages = $title->getSubpages();
555 $count = $subpages instanceof TitleArray ?
$subpages->count() : 0;
557 $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
561 $out->addWikiMsg( 'movenosubpage' );
565 $out->addWikiMsg( 'movesubpagetext', $wgLang->formatNum( $count ) );
566 $skin = $wgUser->getSkin();
567 $out->addHTML( "<ul>\n" );
569 foreach( $subpages as $subpage ) {
570 $link = $skin->link( $subpage );
571 $out->addHTML( "<li>$link</li>\n" );
573 $out->addHTML( "</ul>\n" );