4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
22 * @ingroup SpecialPage
28 function wfSpecialMovepage( $par = null ) {
29 global $wgUser, $wgOut, $wgRequest;
31 # Check for database lock
33 $wgOut->readOnlyPage();
37 $target = isset( $par ) ?
$par : $wgRequest->getVal( 'target' );
39 // Yes, the use of getVal() and getText() is wanted, see bug 20365
40 $oldTitleText = $wgRequest->getVal( 'wpOldTitle', $target );
41 $newTitleText = $wgRequest->getText( 'wpNewTitle' );
43 $oldTitle = Title
::newFromText( $oldTitleText );
44 $newTitle = Title
::newFromText( $newTitleText );
46 if( is_null( $oldTitle ) ) {
47 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
50 if( !$oldTitle->exists() ) {
51 $wgOut->showErrorPage( 'nopagetitle', 'nopagetext' );
56 $permErrors = $oldTitle->getUserPermissionsErrors( 'move', $wgUser );
57 if( !empty( $permErrors ) ) {
58 $wgOut->showPermissionsErrorPage( $permErrors );
62 $form = new MovePageForm( $oldTitle, $newTitle );
64 if ( 'submit' == $wgRequest->getVal( 'action' ) && $wgRequest->wasPosted()
65 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
68 $form->showForm( '' );
73 * HTML form for Special:Movepage
74 * @ingroup SpecialPage
77 var $oldTitle, $newTitle; # Objects
78 var $reason; # Text input
79 var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect, $moveOverShared; # Checks
81 private $watch = false;
83 function __construct( $oldTitle, $newTitle ) {
84 global $wgRequest, $wgUser;
85 $target = isset($par) ?
$par : $wgRequest->getVal( 'target' );
86 $this->oldTitle
= $oldTitle;
87 $this->newTitle
= $newTitle;
88 $this->reason
= $wgRequest->getText( 'wpReason' );
89 if ( $wgRequest->wasPosted() ) {
90 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', false );
91 $this->fixRedirects
= $wgRequest->getBool( 'wpFixRedirects', false );
92 $this->leaveRedirect
= $wgRequest->getBool( 'wpLeaveRedirect', false );
94 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', true );
95 $this->fixRedirects
= $wgRequest->getBool( 'wpFixRedirects', true );
96 $this->leaveRedirect
= $wgRequest->getBool( 'wpLeaveRedirect', true );
98 $this->moveSubpages
= $wgRequest->getBool( 'wpMovesubpages', false );
99 $this->deleteAndMove
= $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
100 $this->moveOverShared
= $wgRequest->getBool( 'wpMoveOverSharedFile', false );
101 $this->watch
= $wgRequest->getCheck( 'wpWatch' ) && $wgUser->isLoggedIn();
107 * @param $err Mixed: error message. May either be a string message name or
108 * array message name and parameters, like the second argument to
109 * OutputPage::wrapWikiMsg().
111 function showForm( $err ) {
112 global $wgOut, $wgUser, $wgContLang, $wgFixDoubleRedirects;
114 $skin = $wgUser->getSkin();
116 $oldTitleLink = $skin->link( $this->oldTitle
);
118 $wgOut->setPagetitle( wfMsg( 'move-page', $this->oldTitle
->getPrefixedText() ) );
119 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
121 $newTitle = $this->newTitle
;
124 # Show the current title as a default
125 # when the form is first opened.
126 $newTitle = $this->oldTitle
;
130 # If a title was supplied, probably from the move log revert
131 # link, check for validity. We can then show some diagnostic
132 # information and save a click.
133 $newerr = $this->oldTitle
->isValidMoveOperation( $newTitle );
140 if ( !empty($err) && $err[0] == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
141 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
142 $movepagebtn = wfMsg( 'delete_and_move' );
143 $submitVar = 'wpDeleteAndMove';
147 <td class='mw-input'>" .
148 Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
153 if ($this->oldTitle
->getNamespace() == NS_USER
&& !$this->oldTitle
->isSubpage() ) {
154 $wgOut->wrapWikiMsg( "<div class=\"error mw-moveuserpage-warning\">\n$1\n</div>", 'moveuserpage-warning' );
156 $wgOut->addWikiMsg( 'movepagetext' );
157 $movepagebtn = wfMsg( 'movepagebtn' );
158 $submitVar = 'wpMove';
162 if ( !empty($err) && $err[0] == 'file-exists-sharedrepo' && $wgUser->isAllowed( 'reupload-shared' ) ) {
163 $wgOut->addWikiMsg( 'move-over-sharedrepo', $newTitle->getPrefixedText() );
164 $submitVar = 'wpMoveOverSharedFile';
168 $oldTalk = $this->oldTitle
->getTalkPage();
169 $considerTalk = ( !$this->oldTitle
->isTalkPage() && $oldTalk->exists() );
171 $dbr = wfGetDB( DB_SLAVE
);
172 if ( $wgFixDoubleRedirects ) {
173 $hasRedirects = $dbr->selectField( 'redirect', '1',
175 'rd_namespace' => $this->oldTitle
->getNamespace(),
176 'rd_title' => $this->oldTitle
->getDBkey(),
179 $hasRedirects = false;
182 if ( $considerTalk ) {
183 $wgOut->addWikiMsg( 'movepagetalktext' );
186 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
187 $token = htmlspecialchars( $wgUser->editToken() );
189 if ( !empty($err) ) {
190 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
191 if( $err[0] == 'hookaborted' ) {
193 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
194 $wgOut->addHTML( $errMsg );
196 $wgOut->wrapWikiMsg( "<p><strong class=\"error\">\n$1\n</strong></p>", $err );
200 if ( $this->oldTitle
->isProtected( 'move' ) ) {
201 # Is the title semi-protected?
202 if ( $this->oldTitle
->isSemiProtected( 'move' ) ) {
203 $noticeMsg = 'semiprotectedpagemovewarning';
204 $classes[] = 'mw-textarea-sprotected';
206 # Then it must be protected based on static groups (regular)
207 $noticeMsg = 'protectedpagemovewarning';
208 $classes[] = 'mw-textarea-protected';
210 $wgOut->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
211 $wgOut->addWikiMsg( $noticeMsg );
212 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->oldTitle
->getPrefixedText(), '', array( 'lim' => 1 ) );
213 $wgOut->addHTML( "</div>\n" );
217 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
218 Xml
::openElement( 'fieldset' ) .
219 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
220 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
222 <td class='mw-label'>" .
223 wfMsgHtml( 'movearticle' ) .
225 <td class='mw-input'>
226 <strong>{$oldTitleLink}</strong>
230 <td class='mw-label'>" .
231 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
233 <td class='mw-input'>" .
234 Xml
::input( 'wpNewTitle', 40, $wgContLang->recodeForEdit( $newTitle->getPrefixedText() ), array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
235 Xml
::hidden( 'wpOldTitle', $this->oldTitle
->getPrefixedText() ) .
239 <td class='mw-label'>" .
240 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
242 <td class='mw-input'>" .
243 Html
::element( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2,
244 'maxlength' => 200 ), $this->reason
) .
249 if( $considerTalk ) {
253 <td class='mw-input'>" .
254 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
260 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
264 <td class='mw-input' >" .
265 Xml
::checkLabel( wfMsg( 'move-leave-redirect' ), 'wpLeaveRedirect',
266 'wpLeaveRedirect', $this->leaveRedirect
) .
272 if ( $hasRedirects ) {
276 <td class='mw-input' >" .
277 Xml
::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects',
278 'wpFixRedirects', $this->fixRedirects
) .
284 if( ($this->oldTitle
->hasSubpages() ||
$this->oldTitle
->getTalkPage()->hasSubpages())
285 && $this->oldTitle
->userCan( 'move-subpages' ) )
287 global $wgMaximumMovedPages, $wgLang;
292 <td class=\"mw-input\">" .
295 # Don't check the box if we only have talk subpages to
296 # move and we aren't moving the talk page.
297 $this->moveSubpages
&& ($this->oldTitle
->hasSubpages() ||
$this->moveTalk
),
298 array( 'id' => 'wpMovesubpages' )
300 Xml
::tags( 'label', array( 'for' => 'wpMovesubpages' ),
302 ( $this->oldTitle
->hasSubpages()
304 : 'move-talk-subpages' ),
305 array( 'parseinline' ),
306 $wgLang->formatNum( $wgMaximumMovedPages ),
307 # $2 to allow use of PLURAL in message.
316 $watchChecked = $wgUser->isLoggedIn() && ($this->watch ||
$wgUser->getBoolOption( 'watchmoves' )
317 ||
$this->oldTitle
->userIsWatching());
318 # Don't allow watching if user is not logged in
319 if( $wgUser->isLoggedIn() ) {
323 <td class='mw-input'>" .
324 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
333 <td class='mw-submit'>" .
334 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
337 Xml
::closeElement( 'table' ) .
338 Xml
::hidden( 'wpEditToken', $token ) .
339 Xml
::closeElement( 'fieldset' ) .
340 Xml
::closeElement( 'form' ) .
344 $this->showLogFragment( $this->oldTitle
, $wgOut );
345 $this->showSubpages( $this->oldTitle
, $wgOut );
349 function doSubmit() {
350 global $wgOut, $wgUser, $wgMaximumMovedPages, $wgLang;
351 global $wgFixDoubleRedirects;
353 if ( $wgUser->pingLimiter( 'move' ) ) {
354 $wgOut->rateLimited();
358 $ot = $this->oldTitle
;
359 $nt = $this->newTitle
;
361 # Delete to make way if requested
362 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
363 $article = new Article( $nt );
365 # Disallow deletions of big articles
366 $bigHistory = $article->isBigDeletion();
367 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
368 global $wgDeleteRevisionsLimit;
369 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
373 // Delete an associated image if there is
374 $file = wfLocalFile( $nt );
375 if( $file->exists() ) {
376 $file->delete( wfMsgForContent( 'delete_and_move_reason' ), false );
379 // This may output an error message and exit
380 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
383 # don't allow moving to pages with # in
384 if ( !$nt ||
$nt->getFragment() != '' ) {
385 $this->showForm( 'badtitletext' );
389 # Show a warning if the target file exists on a shared repo
390 if ( $nt->getNamespace() == NS_FILE
391 && !( $this->moveOverShared
&& $wgUser->isAllowed( 'reupload-shared' ) )
392 && !RepoGroup
::singleton()->getLocalRepo()->findFile( $nt )
393 && wfFindFile( $nt ) )
395 $this->showForm( array('file-exists-sharedrepo') );
400 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
401 $createRedirect = $this->leaveRedirect
;
403 $createRedirect = true;
406 # Do the actual move.
407 $error = $ot->moveTo( $nt, true, $this->reason
, $createRedirect );
408 if ( $error !== true ) {
409 # FIXME: show all the errors in a list, not just the first one
410 $this->showForm( reset( $error ) );
414 if ( $wgFixDoubleRedirects && $this->fixRedirects
) {
415 DoubleRedirectJob
::fixRedirects( 'move', $ot, $nt );
418 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
420 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
422 $oldUrl = $ot->getFullUrl( 'redirect=no' );
423 $newUrl = $nt->getFullUrl();
424 $oldText = $ot->getPrefixedText();
425 $newText = $nt->getPrefixedText();
426 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
427 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
429 $msgName = $createRedirect ?
'movepage-moved-redirect' : 'movepage-moved-noredirect';
430 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
431 $wgOut->addWikiMsg( $msgName );
433 # Now we move extra pages we've been asked to move: subpages and talk
434 # pages. First, if the old page or the new page is a talk page, we
435 # can't move any talk pages: cancel that.
436 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
437 $this->moveTalk
= false;
440 if( !$ot->userCan( 'move-subpages' ) ) {
441 $this->moveSubpages
= false;
444 # Next make a list of id's. This might be marginally less efficient
445 # than a more direct method, but this is not a highly performance-cri-
446 # tical code path and readable code is more important here.
448 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
449 # 4 might get confused. If so, consider rewriting as a UNION.
451 # If the target namespace doesn't allow subpages, moving with subpages
452 # would mean that you couldn't move them back in one operation, which
453 # is bad. FIXME: A specific error message should be given in this
456 // FIXME: Use Title::moveSubpages() here
457 $dbr = wfGetDB( DB_MASTER
);
458 if( $this->moveSubpages
&& (
459 MWNamespace
::hasSubpages( $nt->getNamespace() ) ||
(
461 MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() )
465 'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
466 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
468 $conds['page_namespace'] = array();
469 if( MWNamespace
::hasSubpages( $nt->getNamespace() ) ) {
470 $conds['page_namespace'] []= $ot->getNamespace();
472 if( $this->moveTalk
&& MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
473 $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
475 } elseif( $this->moveTalk
) {
477 'page_namespace' => $ot->getTalkPage()->getNamespace(),
478 'page_title' => $ot->getDBkey()
485 $extraPages = array();
486 if( !is_null( $conds ) ) {
487 $extraPages = TitleArray
::newFromResult(
488 $dbr->select( 'page',
489 array( 'page_id', 'page_namespace', 'page_title' ),
496 $extraOutput = array();
497 $skin = $wgUser->getSkin();
499 foreach( $extraPages as $oldSubpage ) {
500 if( $ot->equals( $oldSubpage ) ) {
501 # Already did this one.
505 $newPageName = preg_replace(
506 '#^'.preg_quote( $ot->getDBkey(), '#' ).'#',
507 StringUtils
::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
508 $oldSubpage->getDBkey()
510 if( $oldSubpage->isTalkPage() ) {
511 $newNs = $nt->getTalkPage()->getNamespace();
513 $newNs = $nt->getSubjectPage()->getNamespace();
515 # Bug 14385: we need makeTitleSafe because the new page names may
516 # be longer than 255 characters.
517 $newSubpage = Title
::makeTitleSafe( $newNs, $newPageName );
519 $oldLink = $skin->linkKnown( $oldSubpage );
520 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
521 htmlspecialchars(Title
::makeName( $newNs, $newPageName )));
525 # This was copy-pasted from Renameuser, bleh.
526 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
527 $link = $skin->linkKnown( $newSubpage );
528 $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
530 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason
, $createRedirect );
531 if( $success === true ) {
532 if ( $this->fixRedirects
) {
533 DoubleRedirectJob
::fixRedirects( 'move', $oldSubpage, $newSubpage );
535 $oldLink = $skin->linkKnown(
539 array( 'redirect' => 'no' )
541 $newLink = $skin->linkKnown( $newSubpage );
542 $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
544 if( $count >= $wgMaximumMovedPages ) {
545 $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) );
549 $oldLink = $skin->linkKnown( $oldSubpage );
550 $newLink = $skin->link( $newSubpage );
551 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
557 if( $extraOutput !== array() ) {
558 $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
561 # Deal with watches (we don't watch subpages)
562 if( $this->watch
&& $wgUser->isLoggedIn() ) {
563 $wgUser->addWatch( $ot );
564 $wgUser->addWatch( $nt );
566 $wgUser->removeWatch( $ot );
567 $wgUser->removeWatch( $nt );
570 # Re-clear the file redirect cache, which may have been polluted by
571 # parsing in messages above. See CR r56745.
572 # FIXME: needs a more robust solution inside FileRepo.
573 if( $ot->getNamespace() == NS_FILE
) {
574 RepoGroup
::singleton()->getLocalRepo()->invalidateImageRedirect( $ot );
578 function showLogFragment( $title, &$out ) {
579 $out->addHTML( Xml
::element( 'h2', null, LogPage
::logName( 'move' ) ) );
580 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );
583 function showSubpages( $title, $out ) {
584 global $wgUser, $wgLang;
586 if( !MWNamespace
::hasSubpages( $title->getNamespace() ) )
589 $subpages = $title->getSubpages();
590 $count = $subpages instanceof TitleArray ?
$subpages->count() : 0;
592 $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
596 $out->addWikiMsg( 'movenosubpage' );
600 $out->addWikiMsg( 'movesubpagetext', $wgLang->formatNum( $count ) );
601 $skin = $wgUser->getSkin();
602 $out->addHTML( "<ul>\n" );
604 foreach( $subpages as $subpage ) {
605 $link = $skin->link( $subpage );
606 $out->addHTML( "<li>$link</li>\n" );
608 $out->addHTML( "</ul>\n" );