8fcf33a93f9db707f572873d9faae28b773be140
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->makeLinkObj( $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 );
170 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
171 Xml
::openElement( 'fieldset' ) .
172 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
173 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
175 <td class='mw-label'>" .
176 wfMsgHtml( 'movearticle' ) .
178 <td class='mw-input'>
179 <strong>{$oldTitleLink}</strong>
183 <td class='mw-label'>" .
184 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
186 <td class='mw-input'>" .
187 Xml
::input( 'wpNewTitle', 40, $newTitle->getPrefixedText(), array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
188 Xml
::hidden( 'wpOldTitle', $this->oldTitle
->getPrefixedText() ) .
192 <td class='mw-label'>" .
193 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
195 <td class='mw-input'>" .
196 Xml
::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason
) ) .
201 if( $considerTalk ) {
205 <td class='mw-input'>" .
206 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
212 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
216 <td class='mw-input' >" .
217 Xml
::checkLabel( wfMsg( 'move-leave-redirect' ), 'wpLeaveRedirect',
218 'wpLeaveRedirect', $this->leaveRedirect
) .
224 if ( $hasRedirects ) {
228 <td class='mw-input' >" .
229 Xml
::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects',
230 'wpFixRedirects', $this->fixRedirects
) .
236 if( ($this->oldTitle
->hasSubpages() ||
$this->oldTitle
->getTalkPage()->hasSubpages())
237 && $this->oldTitle
->userCan( 'move-subpages' ) )
239 global $wgMaximumMovedPages, $wgLang;
244 <td class=\"mw-input\">" .
245 Xml
::checkLabel( wfMsgExt(
246 ( $this->oldTitle
->hasSubpages()
248 : 'move-talk-subpages' ),
250 $wgLang->formatNum( $wgMaximumMovedPages ),
251 # $2 to allow use of PLURAL in message.
254 'wpMovesubpages', 'wpMovesubpages',
255 # Don't check the box if we only have talk subpages to
256 # move and we aren't moving the talk page.
257 $this->moveSubpages
&& ($this->oldTitle
->hasSubpages() ||
$this->moveTalk
)
264 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' )
265 ||
$this->oldTitle
->userIsWatching();
269 <td class='mw-input'>" .
270 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
276 <td class='mw-submit'>" .
277 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
280 Xml
::closeElement( 'table' ) .
281 Xml
::hidden( 'wpEditToken', $token ) .
282 Xml
::closeElement( 'fieldset' ) .
283 Xml
::closeElement( 'form' ) .
287 $this->showLogFragment( $this->oldTitle
, $wgOut );
288 $this->showSubpages( $this->oldTitle
, $wgOut );
292 function doSubmit() {
293 global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
294 global $wgFixDoubleRedirects;
296 if ( $wgUser->pingLimiter( 'move' ) ) {
297 $wgOut->rateLimited();
301 $ot = $this->oldTitle
;
302 $nt = $this->newTitle
;
304 # Delete to make way if requested
305 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
306 $article = new Article( $nt );
308 # Disallow deletions of big articles
309 $bigHistory = $article->isBigDeletion();
310 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
311 global $wgLang, $wgDeleteRevisionsLimit;
312 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
316 // Delete an associated image if there is
317 $file = wfLocalFile( $nt );
318 if( $file->exists() ) {
319 $file->delete( wfMsgForContent( 'delete_and_move_reason' ), false );
322 // This may output an error message and exit
323 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
326 # don't allow moving to pages with # in
327 if ( !$nt ||
$nt->getFragment() != '' ) {
328 $this->showForm( 'badtitletext' );
332 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
333 $createRedirect = $this->leaveRedirect
;
335 $createRedirect = true;
338 $error = $ot->moveTo( $nt, true, $this->reason
, $createRedirect );
339 if ( $error !== true ) {
340 # FIXME: show all the errors in a list, not just the first one
341 $this->showForm( reset( $error ) );
345 if ( $wgFixDoubleRedirects && $this->fixRedirects
) {
346 DoubleRedirectJob
::fixRedirects( 'move', $ot, $nt );
349 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
351 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
353 $oldUrl = $ot->getFullUrl( 'redirect=no' );
354 $newUrl = $nt->getFullUrl();
355 $oldText = $ot->getPrefixedText();
356 $newText = $nt->getPrefixedText();
357 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
358 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
360 $msgName = $createRedirect ?
'movepage-moved-redirect' : 'movepage-moved-noredirect';
361 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
362 $wgOut->addWikiMsg( $msgName );
364 # Now we move extra pages we've been asked to move: subpages and talk
365 # pages. First, if the old page or the new page is a talk page, we
366 # can't move any talk pages: cancel that.
367 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
368 $this->moveTalk
= false;
371 if( !$ot->userCan( 'move-subpages' ) ) {
372 $this->moveSubpages
= false;
375 # Next make a list of id's. This might be marginally less efficient
376 # than a more direct method, but this is not a highly performance-cri-
377 # tical code path and readable code is more important here.
379 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
380 # 4 might get confused. If so, consider rewriting as a UNION.
382 # If the target namespace doesn't allow subpages, moving with subpages
383 # would mean that you couldn't move them back in one operation, which
384 # is bad. FIXME: A specific error message should be given in this
387 // FIXME: Use Title::moveSubpages() here
388 $dbr = wfGetDB( DB_MASTER
);
389 if( $this->moveSubpages
&& (
390 MWNamespace
::hasSubpages( $nt->getNamespace() ) ||
(
392 MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() )
396 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
397 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
399 $conds['page_namespace'] = array();
400 if( MWNamespace
::hasSubpages( $nt->getNamespace() ) ) {
401 $conds['page_namespace'] []= $ot->getNamespace();
403 if( $this->moveTalk
&& MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
404 $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
406 } elseif( $this->moveTalk
) {
408 'page_namespace' => $ot->getTalkPage()->getNamespace(),
409 'page_title' => $ot->getDBKey()
416 $extraPages = array();
417 if( !is_null( $conds ) ) {
418 $extraPages = TitleArray
::newFromResult(
419 $dbr->select( 'page',
420 array( 'page_id', 'page_namespace', 'page_title' ),
427 $extraOutput = array();
428 $skin = $wgUser->getSkin();
430 foreach( $extraPages as $oldSubpage ) {
431 if( $oldSubpage->getArticleId() == $ot->getArticleId() ) {
432 # Already did this one.
436 $newPageName = preg_replace(
437 '#^'.preg_quote( $ot->getDBKey(), '#' ).'#',
439 $oldSubpage->getDBKey()
441 if( $oldSubpage->isTalkPage() ) {
442 $newNs = $nt->getTalkPage()->getNamespace();
444 $newNs = $nt->getSubjectPage()->getNamespace();
446 # Bug 14385: we need makeTitleSafe because the new page names may
447 # be longer than 255 characters.
448 $newSubpage = Title
::makeTitleSafe( $newNs, $newPageName );
450 $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
451 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
452 htmlspecialchars(Title
::makeName( $newNs, $newPageName )));
456 # This was copy-pasted from Renameuser, bleh.
457 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
458 $link = $skin->makeKnownLinkObj( $newSubpage );
459 $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
461 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason
, $createRedirect );
462 if( $success === true ) {
463 if ( $this->fixRedirects
) {
464 DoubleRedirectJob
::fixRedirects( 'move', $oldSubpage, $newSubpage );
466 $oldLink = $skin->makeKnownLinkObj( $oldSubpage, '', 'redirect=no' );
467 $newLink = $skin->makeKnownLinkObj( $newSubpage );
468 $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
470 $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
471 $newLink = $skin->makeLinkObj( $newSubpage );
472 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
477 if( $count >= $wgMaximumMovedPages ) {
478 $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) );
483 if( $extraOutput !== array() ) {
484 $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
487 # Deal with watches (we don't watch subpages)
489 $wgUser->addWatch( $ot );
490 $wgUser->addWatch( $nt );
492 $wgUser->removeWatch( $ot );
493 $wgUser->removeWatch( $nt );
497 function showLogFragment( $title, &$out ) {
498 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
499 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );
502 function showSubpages( $title, $out ) {
503 global $wgUser, $wgLang;
505 if( !MWNamespace
::hasSubpages( $title->getNamespace() ) )
508 $subpages = $title->getSubpages();
509 $count = $subpages instanceof TitleArray ?
$subpages->count() : 0;
511 $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
515 $out->addWikiMsg( 'movenosubpage' );
519 $out->addWikiMsg( 'movesubpagetext', $wgLang->formatNum( $count ) );
520 $skin = $wgUser->getSkin();
521 $out->addHTML( "<ul>\n" );
523 foreach( $subpages as $subpage ) {
524 $link = $skin->link( $subpage );
525 $out->addHTML( "<li>$link</li>\n" );
527 $out->addHTML( "</ul>\n" );