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' );
83 function showForm( $err ) {
84 global $wgOut, $wgUser, $wgFixDoubleRedirects;
86 $skin = $wgUser->getSkin();
88 $oldTitleLink = $skin->makeLinkObj( $this->oldTitle
);
90 $wgOut->setPagetitle( wfMsg( 'move-page', $this->oldTitle
->getPrefixedText() ) );
91 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
93 $newTitle = $this->newTitle
;
96 # Show the current title as a default
97 # when the form is first opened.
98 $newTitle = $this->oldTitle
;
100 // WTF is this doing, passing title *object* to newFromUrl()??
103 $nt = Title::newFromURL( $this->newTitle );
105 # If a title was supplied, probably from the move log revert
106 # link, check for validity. We can then show some diagnostic
107 # information and save a click.
108 $newerr = $this->oldTitle->isValidMoveOperation( $nt );
109 if( is_string( $newerr ) ) {
116 if ( !empty($err) && $err[0] == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
117 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
118 $movepagebtn = wfMsg( 'delete_and_move' );
119 $submitVar = 'wpDeleteAndMove';
123 <td class='mw-input'>" .
124 Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
129 $wgOut->addWikiMsg( 'movepagetext' );
130 $movepagebtn = wfMsg( 'movepagebtn' );
131 $submitVar = 'wpMove';
135 $oldTalk = $this->oldTitle
->getTalkPage();
136 $considerTalk = ( !$this->oldTitle
->isTalkPage() && $oldTalk->exists() );
138 $dbr = wfGetDB( DB_SLAVE
);
139 if ( $wgFixDoubleRedirects ) {
140 $hasRedirects = $dbr->selectField( 'redirect', '1',
142 'rd_namespace' => $this->oldTitle
->getNamespace(),
143 'rd_title' => $this->oldTitle
->getDBkey(),
146 $hasRedirects = false;
149 if ( $considerTalk ) {
150 $wgOut->addWikiMsg( 'movepagetalktext' );
153 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
154 $token = htmlspecialchars( $wgUser->editToken() );
156 if ( !empty($err) ) {
157 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
158 if( $err[0] == 'hookaborted' ) {
160 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
161 $wgOut->addHTML( $errMsg );
163 $wgOut->wrapWikiMsg( '<p><strong class="error">$1</strong></p>', $err );
168 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
169 Xml
::openElement( 'fieldset' ) .
170 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
171 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
173 <td class='mw-label'>" .
174 wfMsgHtml( 'movearticle' ) .
176 <td class='mw-input'>
177 <strong>{$oldTitleLink}</strong>
181 <td class='mw-label'>" .
182 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
184 <td class='mw-input'>" .
185 Xml
::input( 'wpNewTitle', 40, $newTitle->getPrefixedText(), array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
186 Xml
::hidden( 'wpOldTitle', $this->oldTitle
->getPrefixedText() ) .
190 <td class='mw-label'>" .
191 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
193 <td class='mw-input'>" .
194 Xml
::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason
) ) .
199 if( $considerTalk ) {
203 <td class='mw-input'>" .
204 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
210 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
214 <td class='mw-input' >" .
215 Xml
::checkLabel( wfMsg( 'move-leave-redirect' ), 'wpLeaveRedirect',
216 'wpLeaveRedirect', $this->leaveRedirect
) .
222 if ( $hasRedirects ) {
226 <td class='mw-input' >" .
227 Xml
::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects',
228 'wpFixRedirects', $this->fixRedirects
) .
234 if( ($this->oldTitle
->hasSubpages() ||
$this->oldTitle
->getTalkPage()->hasSubpages())
235 && $this->oldTitle
->userCan( 'move-subpages' ) ) {
239 <td class=\"mw-input\">" .
240 Xml
::checkLabel( wfMsg(
241 $this->oldTitle
->hasSubpages()
243 : 'move-talk-subpages'
245 'wpMovesubpages', 'wpMovesubpages',
246 # Don't check the box if we only have talk subpages to
247 # move and we aren't moving the talk page.
248 $this->moveSubpages
&& ($this->oldTitle
->hasSubpages() ||
$this->moveTalk
)
255 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' )
256 ||
$this->oldTitle
->userIsWatching();
260 <td class='mw-input'>" .
261 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
267 <td class='mw-submit'>" .
268 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
271 Xml
::closeElement( 'table' ) .
272 Xml
::hidden( 'wpEditToken', $token ) .
273 Xml
::closeElement( 'fieldset' ) .
274 Xml
::closeElement( 'form' ) .
278 $this->showLogFragment( $this->oldTitle
, $wgOut );
282 function doSubmit() {
283 global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
284 global $wgFixDoubleRedirects;
286 if ( $wgUser->pingLimiter( 'move' ) ) {
287 $wgOut->rateLimited();
291 $ot = $this->oldTitle
;
292 $nt = $this->newTitle
;
294 # Delete to make way if requested
295 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
296 $article = new Article( $nt );
298 # Disallow deletions of big articles
299 $bigHistory = $article->isBigDeletion();
300 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
301 global $wgLang, $wgDeleteRevisionsLimit;
302 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
306 // This may output an error message and exit
307 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
310 # don't allow moving to pages with # in
311 if ( !$nt ||
$nt->getFragment() != '' ) {
312 $this->showForm( 'badtitletext' );
316 if ( $wgUser->isAllowed( 'suppressredirect' ) ) {
317 $createRedirect = $this->leaveRedirect
;
319 $createRedirect = true;
322 $error = $ot->moveTo( $nt, true, $this->reason
, $createRedirect );
323 if ( $error !== true ) {
324 call_user_func_array( array($this, 'showForm'), $error );
328 if ( $wgFixDoubleRedirects && $this->fixRedirects
) {
329 DoubleRedirectJob
::fixRedirects( 'move', $ot, $nt );
332 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
334 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
336 $oldUrl = $ot->getFullUrl( 'redirect=no' );
337 $newUrl = $nt->getFullUrl();
338 $oldText = $ot->getPrefixedText();
339 $newText = $nt->getPrefixedText();
340 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
341 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
343 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
345 # Now we move extra pages we've been asked to move: subpages and talk
346 # pages. First, if the old page or the new page is a talk page, we
347 # can't move any talk pages: cancel that.
348 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
349 $this->moveTalk
= false;
352 if( !$ot->userCan( 'move-subpages' ) ) {
353 $this->moveSubpages
= false;
356 # Next make a list of id's. This might be marginally less efficient
357 # than a more direct method, but this is not a highly performance-cri-
358 # tical code path and readable code is more important here.
360 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
361 # 4 might get confused. If so, consider rewriting as a UNION.
363 # If the target namespace doesn't allow subpages, moving with subpages
364 # would mean that you couldn't move them back in one operation, which
365 # is bad. FIXME: A specific error message should be given in this
367 $dbr = wfGetDB( DB_MASTER
);
368 if( $this->moveSubpages
&& (
369 MWNamespace
::hasSubpages( $nt->getNamespace() ) ||
(
371 MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() )
375 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
376 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
378 $conds['page_namespace'] = array();
379 if( MWNamespace
::hasSubpages( $nt->getNamespace() ) ) {
380 $conds['page_namespace'] []= $ot->getNamespace();
382 if( $this->moveTalk
&& MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
383 $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
385 } elseif( $this->moveTalk
) {
387 'page_namespace' => $ot->getTalkPage()->getNamespace(),
388 'page_title' => $ot->getDBKey()
395 $extraPages = array();
396 if( !is_null( $conds ) ) {
397 $extraPages = TitleArray
::newFromResult(
398 $dbr->select( 'page',
399 array( 'page_id', 'page_namespace', 'page_title' ),
406 $extraOutput = array();
407 $skin = $wgUser->getSkin();
409 foreach( $extraPages as $oldSubpage ) {
410 if( $oldSubpage->getArticleId() == $ot->getArticleId() ) {
411 # Already did this one.
415 $newPageName = preg_replace(
416 '#^'.preg_quote( $ot->getDBKey(), '#' ).'#',
418 $oldSubpage->getDBKey()
420 if( $oldSubpage->isTalkPage() ) {
421 $newNs = $nt->getTalkPage()->getNamespace();
423 $newNs = $nt->getSubjectPage()->getNamespace();
425 # Bug 14385: we need makeTitleSafe because the new page names may
426 # be longer than 255 characters.
427 $newSubpage = Title
::makeTitleSafe( $newNs, $newPageName );
429 $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
430 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
431 htmlspecialchars(Title
::makeName( $newNs, $newPageName )));
435 # This was copy-pasted from Renameuser, bleh.
436 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
437 $link = $skin->makeKnownLinkObj( $newSubpage );
438 $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
440 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason
);
441 if( $success === true ) {
442 if ( $this->fixRedirects
) {
443 DoubleRedirectJob
::fixRedirects( 'move', $oldSubpage, $newSubpage );
445 $oldLink = $skin->makeKnownLinkObj( $oldSubpage, '', 'redirect=no' );
446 $newLink = $skin->makeKnownLinkObj( $newSubpage );
447 $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
449 $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
450 $newLink = $skin->makeLinkObj( $newSubpage );
451 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
456 if( $count >= $wgMaximumMovedPages ) {
457 $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) );
462 if( $extraOutput !== array() ) {
463 $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
466 # Deal with watches (we don't watch subpages)
468 $wgUser->addWatch( $ot );
469 $wgUser->addWatch( $nt );
471 $wgUser->removeWatch( $ot );
472 $wgUser->removeWatch( $nt );
476 function showLogFragment( $title, &$out ) {
477 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
478 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );