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; # 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 );
73 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', true );
74 $this->fixRedirects
= $wgRequest->getBool( 'wpFixRedirects', true );
76 $this->moveSubpages
= $wgRequest->getBool( 'wpMovesubpages', false );
77 $this->deleteAndMove
= $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
78 $this->watch
= $wgRequest->getCheck( 'wpWatch' );
81 function showForm( $err ) {
82 global $wgOut, $wgUser;
84 $skin = $wgUser->getSkin();
86 $oldTitleLink = $skin->makeLinkObj( $this->oldTitle
);
88 $wgOut->setPagetitle( wfMsg( 'move-page', $this->oldTitle
->getPrefixedText() ) );
89 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
91 $newTitle = $this->newTitle
;
94 # Show the current title as a default
95 # when the form is first opened.
96 $newTitle = $this->oldTitle
;
98 // WTF is this doing, passing title *object* to newFromUrl()??
101 $nt = Title::newFromURL( $this->newTitle );
103 # If a title was supplied, probably from the move log revert
104 # link, check for validity. We can then show some diagnostic
105 # information and save a click.
106 $newerr = $this->oldTitle->isValidMoveOperation( $nt );
107 if( is_string( $newerr ) ) {
114 if ( !empty($err) && $err[0] == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
115 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
116 $movepagebtn = wfMsg( 'delete_and_move' );
117 $submitVar = 'wpDeleteAndMove';
121 <td class='mw-input'>" .
122 Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
127 $wgOut->addWikiMsg( 'movepagetext' );
128 $movepagebtn = wfMsg( 'movepagebtn' );
129 $submitVar = 'wpMove';
133 $oldTalk = $this->oldTitle
->getTalkPage();
134 $considerTalk = ( !$this->oldTitle
->isTalkPage() && $oldTalk->exists() );
136 $dbr = wfGetDB( DB_SLAVE
);
137 $hasRedirects = $dbr->selectField( 'redirect', '1',
139 'rd_namespace' => $this->oldTitle
->getNamespace(),
140 'rd_title' => $this->oldTitle
->getDBkey(),
143 if ( $considerTalk ) {
144 $wgOut->addWikiMsg( 'movepagetalktext' );
147 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
148 $token = htmlspecialchars( $wgUser->editToken() );
150 if ( !empty($err) ) {
151 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
152 if( $err[0] == 'hookaborted' ) {
154 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
155 $wgOut->addHTML( $errMsg );
157 $wgOut->wrapWikiMsg( '<p><strong class="error">$1</strong></p>', $err );
162 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
163 Xml
::openElement( 'fieldset' ) .
164 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
165 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
167 <td class='mw-label'>" .
168 wfMsgHtml( 'movearticle' ) .
170 <td class='mw-input'>
171 <strong>{$oldTitleLink}</strong>
175 <td class='mw-label'>" .
176 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
178 <td class='mw-input'>" .
179 Xml
::input( 'wpNewTitle', 40, $newTitle->getPrefixedText(), array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
180 Xml
::hidden( 'wpOldTitle', $this->oldTitle
->getPrefixedText() ) .
184 <td class='mw-label'>" .
185 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
187 <td class='mw-input'>" .
188 Xml
::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason
) ) .
193 if( $considerTalk ) {
197 <td class='mw-input'>" .
198 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
204 if ( $hasRedirects ) {
208 <td class='mw-input' >" .
209 Xml
::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects',
210 'wpFixRedirects', $this->fixRedirects
) .
216 if( ($this->oldTitle
->hasSubpages() ||
$this->oldTitle
->getTalkPage()->hasSubpages())
217 && $this->oldTitle
->userCan( 'move-subpages' ) ) {
221 <td class=\"mw-input\">" .
222 Xml
::checkLabel( wfMsg(
223 $this->oldTitle
->hasSubpages()
225 : 'move-talk-subpages'
227 'wpMovesubpages', 'wpMovesubpages',
228 # Don't check the box if we only have talk subpages to
229 # move and we aren't moving the talk page.
230 $this->moveSubpages
&& ($this->oldTitle
->hasSubpages() ||
$this->moveTalk
)
237 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' )
238 ||
$this->oldTitle
->userIsWatching();
242 <td class='mw-input'>" .
243 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
249 <td class='mw-submit'>" .
250 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
253 Xml
::closeElement( 'table' ) .
254 Xml
::hidden( 'wpEditToken', $token ) .
255 Xml
::closeElement( 'fieldset' ) .
256 Xml
::closeElement( 'form' ) .
260 $this->showLogFragment( $this->oldTitle
, $wgOut );
264 function doSubmit() {
265 global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
267 if ( $wgUser->pingLimiter( 'move' ) ) {
268 $wgOut->rateLimited();
272 $ot = $this->oldTitle
;
273 $nt = $this->newTitle
;
275 # Delete to make way if requested
276 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
277 $article = new Article( $nt );
279 # Disallow deletions of big articles
280 $bigHistory = $article->isBigDeletion();
281 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
282 global $wgLang, $wgDeleteRevisionsLimit;
283 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
287 // This may output an error message and exit
288 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
291 # don't allow moving to pages with # in
292 if ( !$nt ||
$nt->getFragment() != '' ) {
293 $this->showForm( 'badtitletext' );
297 $error = $ot->moveTo( $nt, true, $this->reason
);
298 if ( $error !== true ) {
299 call_user_func_array( array($this, 'showForm'), $error );
303 if ( $this->fixRedirects
) {
304 DoubleRedirectJob
::fixRedirects( 'move', $ot, $nt );
307 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
309 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
311 $oldUrl = $ot->getFullUrl( 'redirect=no' );
312 $newUrl = $nt->getFullUrl();
313 $oldText = $ot->getPrefixedText();
314 $newText = $nt->getPrefixedText();
315 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
316 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
318 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
320 # Now we move extra pages we've been asked to move: subpages and talk
321 # pages. First, if the old page or the new page is a talk page, we
322 # can't move any talk pages: cancel that.
323 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
324 $this->moveTalk
= false;
327 if( !$ot->userCan( 'move-subpages' ) ) {
328 $this->moveSubpages
= false;
331 # Next make a list of id's. This might be marginally less efficient
332 # than a more direct method, but this is not a highly performance-cri-
333 # tical code path and readable code is more important here.
335 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
336 # 4 might get confused. If so, consider rewriting as a UNION.
338 # If the target namespace doesn't allow subpages, moving with subpages
339 # would mean that you couldn't move them back in one operation, which
340 # is bad. FIXME: A specific error message should be given in this
342 $dbr = wfGetDB( DB_MASTER
);
343 if( $this->moveSubpages
&& (
344 MWNamespace
::hasSubpages( $nt->getNamespace() ) ||
(
346 MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() )
350 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
351 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
353 $conds['page_namespace'] = array();
354 if( MWNamespace
::hasSubpages( $nt->getNamespace() ) ) {
355 $conds['page_namespace'] []= $ot->getNamespace();
357 if( $this->moveTalk
&& MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
358 $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
360 } elseif( $this->moveTalk
) {
362 'page_namespace' => $ot->getTalkPage()->getNamespace(),
363 'page_title' => $ot->getDBKey()
370 $extraPages = array();
371 if( !is_null( $conds ) ) {
372 $extraPages = TitleArray
::newFromResult(
373 $dbr->select( 'page',
374 array( 'page_id', 'page_namespace', 'page_title' ),
381 $extraOutput = array();
382 $skin = $wgUser->getSkin();
384 foreach( $extraPages as $oldSubpage ) {
385 if( $oldSubpage->getArticleId() == $ot->getArticleId() ) {
386 # Already did this one.
390 $newPageName = preg_replace(
391 '#^'.preg_quote( $ot->getDBKey(), '#' ).'#',
393 $oldSubpage->getDBKey()
395 if( $oldSubpage->isTalkPage() ) {
396 $newNs = $nt->getTalkPage()->getNamespace();
398 $newNs = $nt->getSubjectPage()->getNamespace();
400 # Bug 14385: we need makeTitleSafe because the new page names may
401 # be longer than 255 characters.
402 $newSubpage = Title
::makeTitleSafe( $newNs, $newPageName );
404 $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
405 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
406 htmlspecialchars(Title
::makeName( $newNs, $newPageName )));
410 # This was copy-pasted from Renameuser, bleh.
411 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
412 $link = $skin->makeKnownLinkObj( $newSubpage );
413 $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
415 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason
);
416 if( $success === true ) {
417 if ( $this->fixRedirects
) {
418 DoubleRedirectJob
::fixRedirects( 'move', $oldSubpage, $newSubpage );
420 $oldLink = $skin->makeKnownLinkObj( $oldSubpage, '', 'redirect=no' );
421 $newLink = $skin->makeKnownLinkObj( $newSubpage );
422 $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
424 $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
425 $newLink = $skin->makeLinkObj( $newSubpage );
426 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
431 if( $count >= $wgMaximumMovedPages ) {
432 $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) );
437 if( $extraOutput !== array() ) {
438 $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
441 # Deal with watches (we don't watch subpages)
443 $wgUser->addWatch( $ot );
444 $wgUser->addWatch( $nt );
446 $wgUser->removeWatch( $ot );
447 $wgUser->removeWatch( $nt );
451 function showLogFragment( $title, &$out ) {
452 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
453 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );