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 ) {
66 global $wgRequest, $wgUser;
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' ) && $wgUser->isLoggedIn();
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 if ($this->oldTitle
->getNamespace() == NS_USER
&& !$this->oldTitle
->isSubpage() ) {
135 $wgOut->wrapWikiMsg( "<div class=\"error mw-moveuserpage-warning\">\n$1\n</div>", 'moveuserpage-warning' );
137 $wgOut->addWikiMsg( 'movepagetext' );
138 $movepagebtn = wfMsg( 'movepagebtn' );
139 $submitVar = 'wpMove';
143 if ( !empty($err) && $err[0] == 'file-exists-sharedrepo' && $wgUser->isAllowed( 'reupload-shared' ) ) {
144 $wgOut->addWikiMsg( 'move-over-sharedrepo', $newTitle->getPrefixedText() );
145 $submitVar = 'wpMoveOverSharedFile';
149 $oldTalk = $this->oldTitle
->getTalkPage();
150 $considerTalk = ( !$this->oldTitle
->isTalkPage() && $oldTalk->exists() );
152 $dbr = wfGetDB( DB_SLAVE
);
153 if ( $wgFixDoubleRedirects ) {
154 $hasRedirects = $dbr->selectField( 'redirect', '1',
156 'rd_namespace' => $this->oldTitle
->getNamespace(),
157 'rd_title' => $this->oldTitle
->getDBkey(),
160 $hasRedirects = false;
163 if ( $considerTalk ) {
164 $wgOut->addWikiMsg( 'movepagetalktext' );
167 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
168 $token = htmlspecialchars( $wgUser->editToken() );
170 if ( !empty($err) ) {
171 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
172 if( $err[0] == 'hookaborted' ) {
174 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
175 $wgOut->addHTML( $errMsg );
177 $wgOut->wrapWikiMsg( '<p><strong class="error">$1</strong></p>', $err );
181 if ( $this->oldTitle
->isProtected( 'move' ) ) {
182 # Is the title semi-protected?
183 if ( $this->oldTitle
->isSemiProtected( 'move' ) ) {
184 $noticeMsg = 'semiprotectedpagemovewarning';
185 $classes[] = 'mw-textarea-sprotected';
187 # Then it must be protected based on static groups (regular)
188 $noticeMsg = 'protectedpagemovewarning';
189 $classes[] = 'mw-textarea-protected';
191 $wgOut->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
192 $wgOut->addWikiMsg( $noticeMsg );
193 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->oldTitle
->getPrefixedText(), '', array( 'lim' => 1 ) );
194 $wgOut->addHTML( "</div>\n" );
198 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
199 Xml
::openElement( 'fieldset' ) .
200 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
201 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
203 <td class='mw-label'>" .
204 wfMsgHtml( 'movearticle' ) .
206 <td class='mw-input'>
207 <strong>{$oldTitleLink}</strong>
211 <td class='mw-label'>" .
212 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
214 <td class='mw-input'>" .
215 Xml
::input( 'wpNewTitle', 40, $wgContLang->recodeForEdit( $newTitle->getPrefixedText() ), array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
216 Xml
::hidden( 'wpOldTitle', $this->oldTitle
->getPrefixedText() ) .
220 <td class='mw-label'>" .
221 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
223 <td class='mw-input'>" .
224 Html
::element( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2,
225 'maxlength' => 200 ), $this->reason
) .
230 if( $considerTalk ) {
234 <td class='mw-input'>" .
235 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
241 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
245 <td class='mw-input' >" .
246 Xml
::checkLabel( wfMsg( 'move-leave-redirect' ), 'wpLeaveRedirect',
247 'wpLeaveRedirect', $this->leaveRedirect
) .
253 if ( $hasRedirects ) {
257 <td class='mw-input' >" .
258 Xml
::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects',
259 'wpFixRedirects', $this->fixRedirects
) .
265 if( ($this->oldTitle
->hasSubpages() ||
$this->oldTitle
->getTalkPage()->hasSubpages())
266 && $this->oldTitle
->userCan( 'move-subpages' ) )
268 global $wgMaximumMovedPages, $wgLang;
273 <td class=\"mw-input\">" .
276 # Don't check the box if we only have talk subpages to
277 # move and we aren't moving the talk page.
278 $this->moveSubpages
&& ($this->oldTitle
->hasSubpages() ||
$this->moveTalk
),
279 array( 'id' => 'wpMovesubpages' )
281 Xml
::tags( 'label', array( 'for' => 'wpMovesubpages' ),
283 ( $this->oldTitle
->hasSubpages()
285 : 'move-talk-subpages' ),
286 array( 'parseinline' ),
287 $wgLang->formatNum( $wgMaximumMovedPages ),
288 # $2 to allow use of PLURAL in message.
297 $watchChecked = $wgUser->isLoggedIn() && ($this->watch ||
$wgUser->getBoolOption( 'watchmoves' )
298 ||
$this->oldTitle
->userIsWatching());
299 # Don't allow watching if user is not logged in
300 if( $wgUser->isLoggedIn() ) {
304 <td class='mw-input'>" .
305 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
314 <td class='mw-submit'>" .
315 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
318 Xml
::closeElement( 'table' ) .
319 Xml
::hidden( 'wpEditToken', $token ) .
320 Xml
::closeElement( 'fieldset' ) .
321 Xml
::closeElement( 'form' ) .
325 $this->showLogFragment( $this->oldTitle
, $wgOut );
326 $this->showSubpages( $this->oldTitle
, $wgOut );
330 function doSubmit() {
331 global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
332 global $wgFixDoubleRedirects;
334 if ( $wgUser->pingLimiter( 'move' ) ) {
335 $wgOut->rateLimited();
339 $ot = $this->oldTitle
;
340 $nt = $this->newTitle
;
342 # Delete to make way if requested
343 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
344 $article = new Article( $nt );
346 # Disallow deletions of big articles
347 $bigHistory = $article->isBigDeletion();
348 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
349 global $wgLang, $wgDeleteRevisionsLimit;
350 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
354 // Delete an associated image if there is
355 $file = wfLocalFile( $nt );
356 if( $file->exists() ) {
357 $file->delete( wfMsgForContent( 'delete_and_move_reason' ), false );
360 // This may output an error message and exit
361 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
364 # don't allow moving to pages with # in
365 if ( !$nt ||
$nt->getFragment() != '' ) {
366 $this->showForm( 'badtitletext' );
370 # Show a warning if the target file exists on a shared repo
371 if ( $nt->getNamespace() == NS_FILE
372 && !( $this->moveOverShared
&& $wgUser->isAllowed( 'reupload-shared' ) )
373 && !RepoGroup
::singleton()->getLocalRepo()->findFile( $nt )
374 && wfFindFile( $nt ) )
376 $this->showForm( array('file-exists-sharedrepo') );
381 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
382 $createRedirect = $this->leaveRedirect
;
384 $createRedirect = true;
387 # Do the actual move.
388 $error = $ot->moveTo( $nt, true, $this->reason
, $createRedirect );
389 if ( $error !== true ) {
390 # FIXME: show all the errors in a list, not just the first one
391 $this->showForm( reset( $error ) );
395 if ( $wgFixDoubleRedirects && $this->fixRedirects
) {
396 DoubleRedirectJob
::fixRedirects( 'move', $ot, $nt );
399 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
401 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
403 $oldUrl = $ot->getFullUrl( 'redirect=no' );
404 $newUrl = $nt->getFullUrl();
405 $oldText = $ot->getPrefixedText();
406 $newText = $nt->getPrefixedText();
407 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
408 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
410 $msgName = $createRedirect ?
'movepage-moved-redirect' : 'movepage-moved-noredirect';
411 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
412 $wgOut->addWikiMsg( $msgName );
414 # Now we move extra pages we've been asked to move: subpages and talk
415 # pages. First, if the old page or the new page is a talk page, we
416 # can't move any talk pages: cancel that.
417 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
418 $this->moveTalk
= false;
421 if( !$ot->userCan( 'move-subpages' ) ) {
422 $this->moveSubpages
= false;
425 # Next make a list of id's. This might be marginally less efficient
426 # than a more direct method, but this is not a highly performance-cri-
427 # tical code path and readable code is more important here.
429 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
430 # 4 might get confused. If so, consider rewriting as a UNION.
432 # If the target namespace doesn't allow subpages, moving with subpages
433 # would mean that you couldn't move them back in one operation, which
434 # is bad. FIXME: A specific error message should be given in this
437 // FIXME: Use Title::moveSubpages() here
438 $dbr = wfGetDB( DB_MASTER
);
439 if( $this->moveSubpages
&& (
440 MWNamespace
::hasSubpages( $nt->getNamespace() ) ||
(
442 MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() )
446 'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
447 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
449 $conds['page_namespace'] = array();
450 if( MWNamespace
::hasSubpages( $nt->getNamespace() ) ) {
451 $conds['page_namespace'] []= $ot->getNamespace();
453 if( $this->moveTalk
&& MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
454 $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
456 } elseif( $this->moveTalk
) {
458 'page_namespace' => $ot->getTalkPage()->getNamespace(),
459 'page_title' => $ot->getDBkey()
466 $extraPages = array();
467 if( !is_null( $conds ) ) {
468 $extraPages = TitleArray
::newFromResult(
469 $dbr->select( 'page',
470 array( 'page_id', 'page_namespace', 'page_title' ),
477 $extraOutput = array();
478 $skin = $wgUser->getSkin();
480 foreach( $extraPages as $oldSubpage ) {
481 if( $ot->equals( $oldSubpage ) ) {
482 # Already did this one.
486 $newPageName = preg_replace(
487 '#^'.preg_quote( $ot->getDBkey(), '#' ).'#',
488 StringUtils
::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
489 $oldSubpage->getDBkey()
491 if( $oldSubpage->isTalkPage() ) {
492 $newNs = $nt->getTalkPage()->getNamespace();
494 $newNs = $nt->getSubjectPage()->getNamespace();
496 # Bug 14385: we need makeTitleSafe because the new page names may
497 # be longer than 255 characters.
498 $newSubpage = Title
::makeTitleSafe( $newNs, $newPageName );
500 $oldLink = $skin->linkKnown( $oldSubpage );
501 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
502 htmlspecialchars(Title
::makeName( $newNs, $newPageName )));
506 # This was copy-pasted from Renameuser, bleh.
507 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
508 $link = $skin->linkKnown( $newSubpage );
509 $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
511 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason
, $createRedirect );
512 if( $success === true ) {
513 if ( $this->fixRedirects
) {
514 DoubleRedirectJob
::fixRedirects( 'move', $oldSubpage, $newSubpage );
516 $oldLink = $skin->linkKnown(
520 array( 'redirect' => 'no' )
522 $newLink = $skin->linkKnown( $newSubpage );
523 $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
525 if( $count >= $wgMaximumMovedPages ) {
526 $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) );
530 $oldLink = $skin->linkKnown( $oldSubpage );
531 $newLink = $skin->link( $newSubpage );
532 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
538 if( $extraOutput !== array() ) {
539 $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
542 # Deal with watches (we don't watch subpages)
543 if( $this->watch
&& $wgUser->isLoggedIn() ) {
544 $wgUser->addWatch( $ot );
545 $wgUser->addWatch( $nt );
547 $wgUser->removeWatch( $ot );
548 $wgUser->removeWatch( $nt );
551 # Re-clear the file redirect cache, which may have been polluted by
552 # parsing in messages above. See CR r56745.
553 # FIXME: needs a more robust solution inside FileRepo.
554 if( $ot->getNamespace() == NS_FILE
) {
555 RepoGroup
::singleton()->getLocalRepo()->invalidateImageRedirect( $ot );
559 function showLogFragment( $title, &$out ) {
560 $out->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'move' ) ) );
561 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );
564 function showSubpages( $title, $out ) {
565 global $wgUser, $wgLang;
567 if( !MWNamespace
::hasSubpages( $title->getNamespace() ) )
570 $subpages = $title->getSubpages();
571 $count = $subpages instanceof TitleArray ?
$subpages->count() : 0;
573 $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
577 $out->addWikiMsg( 'movenosubpage' );
581 $out->addWikiMsg( 'movesubpagetext', $wgLang->formatNum( $count ) );
582 $skin = $wgUser->getSkin();
583 $out->addHTML( "<ul>\n" );
585 foreach( $subpages as $subpage ) {
586 $link = $skin->link( $subpage );
587 $out->addHTML( "<li>$link</li>\n" );
589 $out->addHTML( "</ul>\n" );