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' );
20 $oldTitleText = $wgRequest->getText( 'wpOldTitle', $target );
21 $newTitleText = $wgRequest->getText( 'wpNewTitle' );
23 $oldTitle = Title
::newFromText( $oldTitleText );
24 $newTitle = Title
::newFromText( $newTitleText );
26 if( is_null( $oldTitle ) ) {
27 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
30 if( !$oldTitle->exists() ) {
31 $wgOut->showErrorPage( 'nopagetitle', 'nopagetext' );
36 $permErrors = $oldTitle->getUserPermissionsErrors( 'move', $wgUser );
37 if( !empty( $permErrors ) ) {
38 $wgOut->showPermissionsErrorPage( $permErrors );
42 $form = new MovePageForm( $oldTitle, $newTitle );
44 if ( 'submit' == $action && $wgRequest->wasPosted()
45 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
48 $form->showForm( '' );
53 * HTML form for Special:Movepage
54 * @ingroup SpecialPage
57 var $oldTitle, $newTitle; # Objects
58 var $reason; # Text input
59 var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect; # Checks
61 private $watch = false;
63 function __construct( $oldTitle, $newTitle ) {
65 $target = isset($par) ?
$par : $wgRequest->getVal( 'target' );
66 $this->oldTitle
= $oldTitle;
67 $this->newTitle
= $newTitle;
68 $this->reason
= $wgRequest->getText( 'wpReason' );
69 if ( $wgRequest->wasPosted() ) {
70 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', false );
71 $this->fixRedirects
= $wgRequest->getBool( 'wpFixRedirects', false );
72 $this->leaveRedirect
= $wgRequest->getBool( 'wpLeaveRedirect', false );
74 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', true );
75 $this->fixRedirects
= $wgRequest->getBool( 'wpFixRedirects', true );
76 $this->leaveRedirect
= $wgRequest->getBool( 'wpLeaveRedirect', true );
78 $this->moveSubpages
= $wgRequest->getBool( 'wpMovesubpages', false );
79 $this->deleteAndMove
= $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
80 $this->watch
= $wgRequest->getCheck( 'wpWatch' );
85 * @param mixed $err Error message. May either be a string message name or
86 * array message name and parameters, like the second argument to
87 * OutputPage::wrapWikiMsg().
89 function showForm( $err ) {
90 global $wgOut, $wgUser, $wgFixDoubleRedirects;
92 $skin = $wgUser->getSkin();
94 $oldTitleLink = $skin->link( $this->oldTitle
);
96 $wgOut->setPagetitle( wfMsg( 'move-page', $this->oldTitle
->getPrefixedText() ) );
97 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
99 $newTitle = $this->newTitle
;
102 # Show the current title as a default
103 # when the form is first opened.
104 $newTitle = $this->oldTitle
;
108 # If a title was supplied, probably from the move log revert
109 # link, check for validity. We can then show some diagnostic
110 # information and save a click.
111 $newerr = $this->oldTitle
->isValidMoveOperation( $newTitle );
118 if ( !empty($err) && $err[0] == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
119 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
120 $movepagebtn = wfMsg( 'delete_and_move' );
121 $submitVar = 'wpDeleteAndMove';
125 <td class='mw-input'>" .
126 Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
131 $wgOut->addWikiMsg( 'movepagetext' );
132 $movepagebtn = wfMsg( 'movepagebtn' );
133 $submitVar = 'wpMove';
137 $oldTalk = $this->oldTitle
->getTalkPage();
138 $considerTalk = ( !$this->oldTitle
->isTalkPage() && $oldTalk->exists() );
140 $dbr = wfGetDB( DB_SLAVE
);
141 if ( $wgFixDoubleRedirects ) {
142 $hasRedirects = $dbr->selectField( 'redirect', '1',
144 'rd_namespace' => $this->oldTitle
->getNamespace(),
145 'rd_title' => $this->oldTitle
->getDBkey(),
148 $hasRedirects = false;
151 if ( $considerTalk ) {
152 $wgOut->addWikiMsg( 'movepagetalktext' );
155 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
156 $token = htmlspecialchars( $wgUser->editToken() );
158 if ( !empty($err) ) {
159 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
160 if( $err[0] == 'hookaborted' ) {
162 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
163 $wgOut->addHTML( $errMsg );
165 $wgOut->wrapWikiMsg( '<p><strong class="error">$1</strong></p>', $err );
169 if ( $this->oldTitle
->isProtected( 'move' ) ) {
170 # Is the title semi-protected?
171 if ( $this->oldTitle
->isSemiProtected( 'move' ) ) {
172 $noticeMsg = 'semiprotectedpagemovewarning';
173 $classes[] = 'mw-textarea-sprotected';
175 # Then it must be protected based on static groups (regular)
176 $noticeMsg = 'protectedpagemovewarning';
177 $classes[] = 'mw-textarea-protected';
179 $wgOut->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
180 $wgOut->addWikiMsg( $noticeMsg );
181 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->oldTitle
->getPrefixedText(), '', 1 );
182 $wgOut->addHTML( "</div>\n" );
186 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
187 Xml
::openElement( 'fieldset' ) .
188 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
189 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
191 <td class='mw-label'>" .
192 wfMsgHtml( 'movearticle' ) .
194 <td class='mw-input'>
195 <strong>{$oldTitleLink}</strong>
199 <td class='mw-label'>" .
200 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
202 <td class='mw-input'>" .
203 Xml
::input( 'wpNewTitle', 40, $newTitle->getPrefixedText(), array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
204 Xml
::hidden( 'wpOldTitle', $this->oldTitle
->getPrefixedText() ) .
208 <td class='mw-label'>" .
209 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
211 <td class='mw-input'>" .
212 Xml
::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason
) ) .
217 if( $considerTalk ) {
221 <td class='mw-input'>" .
222 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
228 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
232 <td class='mw-input' >" .
233 Xml
::checkLabel( wfMsg( 'move-leave-redirect' ), 'wpLeaveRedirect',
234 'wpLeaveRedirect', $this->leaveRedirect
) .
240 if ( $hasRedirects ) {
244 <td class='mw-input' >" .
245 Xml
::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects',
246 'wpFixRedirects', $this->fixRedirects
) .
252 if( ($this->oldTitle
->hasSubpages() ||
$this->oldTitle
->getTalkPage()->hasSubpages())
253 && $this->oldTitle
->userCan( 'move-subpages' ) )
255 global $wgMaximumMovedPages, $wgLang;
260 <td class=\"mw-input\">" .
261 Xml
::checkLabel( wfMsgExt(
262 ( $this->oldTitle
->hasSubpages()
264 : 'move-talk-subpages' ),
266 $wgLang->formatNum( $wgMaximumMovedPages ),
267 # $2 to allow use of PLURAL in message.
270 'wpMovesubpages', 'wpMovesubpages',
271 # Don't check the box if we only have talk subpages to
272 # move and we aren't moving the talk page.
273 $this->moveSubpages
&& ($this->oldTitle
->hasSubpages() ||
$this->moveTalk
)
280 # Check the watch checkbox in case the watch parameter was given in the
281 # request, the preferences say so, or either the old or new title is
283 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' )
284 ||
$this->oldTitle
->userIsWatching() ||
$this->newTitle
->userIsWatching();
288 <td class='mw-input'>" .
289 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
295 <td class='mw-submit'>" .
296 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
299 Xml
::closeElement( 'table' ) .
300 Xml
::hidden( 'wpEditToken', $token ) .
301 Xml
::closeElement( 'fieldset' ) .
302 Xml
::closeElement( 'form' ) .
306 $this->showLogFragment( $this->oldTitle
, $wgOut );
307 $this->showSubpages( $this->oldTitle
, $wgOut );
311 function doSubmit() {
312 global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
313 global $wgFixDoubleRedirects;
315 if ( $wgUser->pingLimiter( 'move' ) ) {
316 $wgOut->rateLimited();
320 $ot = $this->oldTitle
;
321 $nt = $this->newTitle
;
323 # Delete to make way if requested
324 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
325 $article = new Article( $nt );
327 # Disallow deletions of big articles
328 $bigHistory = $article->isBigDeletion();
329 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
330 global $wgLang, $wgDeleteRevisionsLimit;
331 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
335 // Delete an associated image if there is
336 $file = wfLocalFile( $nt );
337 if( $file->exists() ) {
338 $file->delete( wfMsgForContent( 'delete_and_move_reason' ), false );
341 // This may output an error message and exit
342 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
345 # don't allow moving to pages with # in
346 if ( !$nt ||
$nt->getFragment() != '' ) {
347 $this->showForm( 'badtitletext' );
351 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
352 $createRedirect = $this->leaveRedirect
;
354 $createRedirect = true;
357 $error = $ot->moveTo( $nt, true, $this->reason
, $createRedirect );
358 if ( $error !== true ) {
359 # FIXME: show all the errors in a list, not just the first one
360 $this->showForm( reset( $error ) );
364 if ( $wgFixDoubleRedirects && $this->fixRedirects
) {
365 DoubleRedirectJob
::fixRedirects( 'move', $ot, $nt );
368 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
370 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
372 $oldUrl = $ot->getFullUrl( 'redirect=no' );
373 $newUrl = $nt->getFullUrl();
374 $oldText = $ot->getPrefixedText();
375 $newText = $nt->getPrefixedText();
376 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
377 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
379 $msgName = $createRedirect ?
'movepage-moved-redirect' : 'movepage-moved-noredirect';
380 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
381 $wgOut->addWikiMsg( $msgName );
383 # Now we move extra pages we've been asked to move: subpages and talk
384 # pages. First, if the old page or the new page is a talk page, we
385 # can't move any talk pages: cancel that.
386 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
387 $this->moveTalk
= false;
390 if( !$ot->userCan( 'move-subpages' ) ) {
391 $this->moveSubpages
= false;
394 # Next make a list of id's. This might be marginally less efficient
395 # than a more direct method, but this is not a highly performance-cri-
396 # tical code path and readable code is more important here.
398 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
399 # 4 might get confused. If so, consider rewriting as a UNION.
401 # If the target namespace doesn't allow subpages, moving with subpages
402 # would mean that you couldn't move them back in one operation, which
403 # is bad. FIXME: A specific error message should be given in this
406 // FIXME: Use Title::moveSubpages() here
407 $dbr = wfGetDB( DB_MASTER
);
408 if( $this->moveSubpages
&& (
409 MWNamespace
::hasSubpages( $nt->getNamespace() ) ||
(
411 MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() )
415 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
416 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
418 $conds['page_namespace'] = array();
419 if( MWNamespace
::hasSubpages( $nt->getNamespace() ) ) {
420 $conds['page_namespace'] []= $ot->getNamespace();
422 if( $this->moveTalk
&& MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
423 $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
425 } elseif( $this->moveTalk
) {
427 'page_namespace' => $ot->getTalkPage()->getNamespace(),
428 'page_title' => $ot->getDBkey()
435 $extraPages = array();
436 if( !is_null( $conds ) ) {
437 $extraPages = TitleArray
::newFromResult(
438 $dbr->select( 'page',
439 array( 'page_id', 'page_namespace', 'page_title' ),
446 $extraOutput = array();
447 $skin = $wgUser->getSkin();
449 foreach( $extraPages as $oldSubpage ) {
450 if( $oldSubpage->getArticleId() == $ot->getArticleId() ) {
451 # Already did this one.
455 $newPageName = preg_replace(
456 '#^'.preg_quote( $ot->getDBkey(), '#' ).'#',
458 $oldSubpage->getDBkey()
460 if( $oldSubpage->isTalkPage() ) {
461 $newNs = $nt->getTalkPage()->getNamespace();
463 $newNs = $nt->getSubjectPage()->getNamespace();
465 # Bug 14385: we need makeTitleSafe because the new page names may
466 # be longer than 255 characters.
467 $newSubpage = Title
::makeTitleSafe( $newNs, $newPageName );
469 $oldLink = $skin->linkKnown( $oldSubpage );
470 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
471 htmlspecialchars(Title
::makeName( $newNs, $newPageName )));
475 # This was copy-pasted from Renameuser, bleh.
476 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
477 $link = $skin->linkKnown( $newSubpage );
478 $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
480 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason
, $createRedirect );
481 if( $success === true ) {
482 if ( $this->fixRedirects
) {
483 DoubleRedirectJob
::fixRedirects( 'move', $oldSubpage, $newSubpage );
485 $oldLink = $skin->linkKnown(
489 array( 'redirect' => 'no' )
491 $newLink = $skin->linkKnown( $newSubpage );
492 $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
494 $oldLink = $skin->linkKnown( $oldSubpage );
495 $newLink = $skin->link( $newSubpage );
496 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
501 if( $count >= $wgMaximumMovedPages ) {
502 $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) );
507 if( $extraOutput !== array() ) {
508 $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
511 # Deal with watches (we don't watch subpages)
513 $wgUser->addWatch( $ot );
514 $wgUser->addWatch( $nt );
516 $wgUser->removeWatch( $ot );
517 $wgUser->removeWatch( $nt );
521 function showLogFragment( $title, &$out ) {
522 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
523 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );
526 function showSubpages( $title, $out ) {
527 global $wgUser, $wgLang;
529 if( !MWNamespace
::hasSubpages( $title->getNamespace() ) )
532 $subpages = $title->getSubpages();
533 $count = $subpages instanceof TitleArray ?
$subpages->count() : 0;
535 $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
539 $out->addWikiMsg( 'movenosubpage' );
543 $out->addWikiMsg( 'movesubpagetext', $wgLang->formatNum( $count ) );
544 $skin = $wgUser->getSkin();
545 $out->addHTML( "<ul>\n" );
547 foreach( $subpages as $subpage ) {
548 $link = $skin->link( $subpage );
549 $out->addHTML( "<li>$link</li>\n" );
551 $out->addHTML( "</ul>\n" );