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; # 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->watch
= $wgRequest->getCheck( 'wpWatch' );
87 * @param mixed $err Error message. May either be a string message name or
88 * array message name and parameters, like the second argument to
89 * OutputPage::wrapWikiMsg().
91 function showForm( $err ) {
92 global $wgOut, $wgUser, $wgContLang, $wgFixDoubleRedirects;
94 $skin = $wgUser->getSkin();
96 $oldTitleLink = $skin->link( $this->oldTitle
);
98 $wgOut->setPagetitle( wfMsg( 'move-page', $this->oldTitle
->getPrefixedText() ) );
99 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
101 $newTitle = $this->newTitle
;
104 # Show the current title as a default
105 # when the form is first opened.
106 $newTitle = $this->oldTitle
;
110 # If a title was supplied, probably from the move log revert
111 # link, check for validity. We can then show some diagnostic
112 # information and save a click.
113 $newerr = $this->oldTitle
->isValidMoveOperation( $newTitle );
120 if ( !empty($err) && $err[0] == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
121 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
122 $movepagebtn = wfMsg( 'delete_and_move' );
123 $submitVar = 'wpDeleteAndMove';
127 <td class='mw-input'>" .
128 Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
133 $wgOut->addWikiMsg( 'movepagetext' );
134 $movepagebtn = wfMsg( 'movepagebtn' );
135 $submitVar = 'wpMove';
139 $oldTalk = $this->oldTitle
->getTalkPage();
140 $considerTalk = ( !$this->oldTitle
->isTalkPage() && $oldTalk->exists() );
142 $dbr = wfGetDB( DB_SLAVE
);
143 if ( $wgFixDoubleRedirects ) {
144 $hasRedirects = $dbr->selectField( 'redirect', '1',
146 'rd_namespace' => $this->oldTitle
->getNamespace(),
147 'rd_title' => $this->oldTitle
->getDBkey(),
150 $hasRedirects = false;
153 if ( $considerTalk ) {
154 $wgOut->addWikiMsg( 'movepagetalktext' );
157 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
158 $token = htmlspecialchars( $wgUser->editToken() );
160 if ( !empty($err) ) {
161 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
162 if( $err[0] == 'hookaborted' ) {
164 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
165 $wgOut->addHTML( $errMsg );
167 $wgOut->wrapWikiMsg( '<p><strong class="error">$1</strong></p>', $err );
171 if ( $this->oldTitle
->isProtected( 'move' ) ) {
172 # Is the title semi-protected?
173 if ( $this->oldTitle
->isSemiProtected( 'move' ) ) {
174 $noticeMsg = 'semiprotectedpagemovewarning';
175 $classes[] = 'mw-textarea-sprotected';
177 # Then it must be protected based on static groups (regular)
178 $noticeMsg = 'protectedpagemovewarning';
179 $classes[] = 'mw-textarea-protected';
181 $wgOut->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
182 $wgOut->addWikiMsg( $noticeMsg );
183 LogEventsList
::showLogExtract( $wgOut, 'protect', $this->oldTitle
->getPrefixedText(), '', array( 'lim' => 1 ) );
184 $wgOut->addHTML( "</div>\n" );
188 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
189 Xml
::openElement( 'fieldset' ) .
190 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
191 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
193 <td class='mw-label'>" .
194 wfMsgHtml( 'movearticle' ) .
196 <td class='mw-input'>
197 <strong>{$oldTitleLink}</strong>
201 <td class='mw-label'>" .
202 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
204 <td class='mw-input'>" .
205 Xml
::input( 'wpNewTitle', 40, $wgContLang->recodeForEdit( $newTitle->getPrefixedText() ), array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
206 Xml
::hidden( 'wpOldTitle', $this->oldTitle
->getPrefixedText() ) .
210 <td class='mw-label'>" .
211 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
213 <td class='mw-input'>" .
214 Xml
::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason
) ) .
219 if( $considerTalk ) {
223 <td class='mw-input'>" .
224 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
230 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
234 <td class='mw-input' >" .
235 Xml
::checkLabel( wfMsg( 'move-leave-redirect' ), 'wpLeaveRedirect',
236 'wpLeaveRedirect', $this->leaveRedirect
) .
242 if ( $hasRedirects ) {
246 <td class='mw-input' >" .
247 Xml
::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects',
248 'wpFixRedirects', $this->fixRedirects
) .
254 if( ($this->oldTitle
->hasSubpages() ||
$this->oldTitle
->getTalkPage()->hasSubpages())
255 && $this->oldTitle
->userCan( 'move-subpages' ) )
257 global $wgMaximumMovedPages, $wgLang;
262 <td class=\"mw-input\">" .
265 # Don't check the box if we only have talk subpages to
266 # move and we aren't moving the talk page.
267 $this->moveSubpages
&& ($this->oldTitle
->hasSubpages() ||
$this->moveTalk
),
268 array( 'id' => 'wpMovesubpages' )
270 Xml
::tags( 'label', array( 'for' => 'wpMovesubpages' ),
272 ( $this->oldTitle
->hasSubpages()
274 : 'move-talk-subpages' ),
275 array( 'parseinline' ),
276 $wgLang->formatNum( $wgMaximumMovedPages ),
277 # $2 to allow use of PLURAL in message.
286 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' )
287 ||
$this->oldTitle
->userIsWatching();
291 <td class='mw-input'>" .
292 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
298 <td class='mw-submit'>" .
299 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
302 Xml
::closeElement( 'table' ) .
303 Xml
::hidden( 'wpEditToken', $token ) .
304 Xml
::closeElement( 'fieldset' ) .
305 Xml
::closeElement( 'form' ) .
309 $this->showLogFragment( $this->oldTitle
, $wgOut );
310 $this->showSubpages( $this->oldTitle
, $wgOut );
314 function doSubmit() {
315 global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
316 global $wgFixDoubleRedirects;
318 if ( $wgUser->pingLimiter( 'move' ) ) {
319 $wgOut->rateLimited();
323 $ot = $this->oldTitle
;
324 $nt = $this->newTitle
;
326 # Delete to make way if requested
327 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
328 $article = new Article( $nt );
330 # Disallow deletions of big articles
331 $bigHistory = $article->isBigDeletion();
332 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
333 global $wgLang, $wgDeleteRevisionsLimit;
334 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
338 // Delete an associated image if there is
339 $file = wfLocalFile( $nt );
340 if( $file->exists() ) {
341 $file->delete( wfMsgForContent( 'delete_and_move_reason' ), false );
344 // This may output an error message and exit
345 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
348 # don't allow moving to pages with # in
349 if ( !$nt ||
$nt->getFragment() != '' ) {
350 $this->showForm( 'badtitletext' );
354 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
355 $createRedirect = $this->leaveRedirect
;
357 $createRedirect = true;
360 # Do the actual move. First remember the old ID for later reference,
361 # so that we don't get the ID of the redirect.
362 $oldId = $ot->getArticleId();
363 $error = $ot->moveTo( $nt, true, $this->reason
, $createRedirect );
364 if ( $error !== true ) {
365 # FIXME: show all the errors in a list, not just the first one
366 $this->showForm( reset( $error ) );
370 if ( $wgFixDoubleRedirects && $this->fixRedirects
) {
371 DoubleRedirectJob
::fixRedirects( 'move', $ot, $nt );
374 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
376 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
378 $oldUrl = $ot->getFullUrl( 'redirect=no' );
379 $newUrl = $nt->getFullUrl();
380 $oldText = $ot->getPrefixedText();
381 $newText = $nt->getPrefixedText();
382 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
383 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
385 $msgName = $createRedirect ?
'movepage-moved-redirect' : 'movepage-moved-noredirect';
386 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
387 $wgOut->addWikiMsg( $msgName );
389 # Now we move extra pages we've been asked to move: subpages and talk
390 # pages. First, if the old page or the new page is a talk page, we
391 # can't move any talk pages: cancel that.
392 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
393 $this->moveTalk
= false;
396 if( !$ot->userCan( 'move-subpages' ) ) {
397 $this->moveSubpages
= false;
400 # Next make a list of id's. This might be marginally less efficient
401 # than a more direct method, but this is not a highly performance-cri-
402 # tical code path and readable code is more important here.
404 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
405 # 4 might get confused. If so, consider rewriting as a UNION.
407 # If the target namespace doesn't allow subpages, moving with subpages
408 # would mean that you couldn't move them back in one operation, which
409 # is bad. FIXME: A specific error message should be given in this
412 // FIXME: Use Title::moveSubpages() here
413 $dbr = wfGetDB( DB_MASTER
);
414 if( $this->moveSubpages
&& (
415 MWNamespace
::hasSubpages( $nt->getNamespace() ) ||
(
417 MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() )
421 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
422 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
424 $conds['page_namespace'] = array();
425 if( MWNamespace
::hasSubpages( $nt->getNamespace() ) ) {
426 $conds['page_namespace'] []= $ot->getNamespace();
428 if( $this->moveTalk
&& MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
429 $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
431 } elseif( $this->moveTalk
) {
433 'page_namespace' => $ot->getTalkPage()->getNamespace(),
434 'page_title' => $ot->getDBkey()
441 $extraPages = array();
442 if( !is_null( $conds ) ) {
443 $extraPages = TitleArray
::newFromResult(
444 $dbr->select( 'page',
445 array( 'page_id', 'page_namespace', 'page_title' ),
452 $extraOutput = array();
453 $skin = $wgUser->getSkin();
455 foreach( $extraPages as $oldSubpage ) {
456 if( $oldSubpage->getArticleId() == $oldId ) {
457 # Already did this one.
461 $newPageName = preg_replace(
462 '#^'.preg_quote( $ot->getDBkey(), '#' ).'#',
464 $oldSubpage->getDBkey()
466 if( $oldSubpage->isTalkPage() ) {
467 $newNs = $nt->getTalkPage()->getNamespace();
469 $newNs = $nt->getSubjectPage()->getNamespace();
471 # Bug 14385: we need makeTitleSafe because the new page names may
472 # be longer than 255 characters.
473 $newSubpage = Title
::makeTitleSafe( $newNs, $newPageName );
475 $oldLink = $skin->linkKnown( $oldSubpage );
476 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
477 htmlspecialchars(Title
::makeName( $newNs, $newPageName )));
481 # This was copy-pasted from Renameuser, bleh.
482 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
483 $link = $skin->linkKnown( $newSubpage );
484 $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
486 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason
, $createRedirect );
487 if( $success === true ) {
488 if ( $this->fixRedirects
) {
489 DoubleRedirectJob
::fixRedirects( 'move', $oldSubpage, $newSubpage );
491 $oldLink = $skin->linkKnown(
495 array( 'redirect' => 'no' )
497 $newLink = $skin->linkKnown( $newSubpage );
498 $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
500 if( $count >= $wgMaximumMovedPages ) {
501 $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) );
505 $oldLink = $skin->linkKnown( $oldSubpage );
506 $newLink = $skin->link( $newSubpage );
507 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
513 if( $extraOutput !== array() ) {
514 $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
517 # Deal with watches (we don't watch subpages)
519 $wgUser->addWatch( $ot );
520 $wgUser->addWatch( $nt );
522 $wgUser->removeWatch( $ot );
523 $wgUser->removeWatch( $nt );
527 function showLogFragment( $title, &$out ) {
528 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
529 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );
532 function showSubpages( $title, $out ) {
533 global $wgUser, $wgLang;
535 if( !MWNamespace
::hasSubpages( $title->getNamespace() ) )
538 $subpages = $title->getSubpages();
539 $count = $subpages instanceof TitleArray ?
$subpages->count() : 0;
541 $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
545 $out->addWikiMsg( 'movenosubpage' );
549 $out->addWikiMsg( 'movesubpagetext', $wgLang->formatNum( $count ) );
550 $skin = $wgUser->getSkin();
551 $out->addHTML( "<ul>\n" );
553 foreach( $subpages as $subpage ) {
554 $link = $skin->link( $subpage );
555 $out->addHTML( "<li>$link</li>\n" );
557 $out->addHTML( "</ul>\n" );