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, $reason; # Text input
58 var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects;
60 private $watch = false;
62 function MovePageForm( $oldTitle, $newTitle ) {
64 $target = isset($par) ?
$par : $wgRequest->getVal( 'target' );
65 $this->oldTitle
= $oldTitle;
66 $this->newTitle
= $newTitle;
67 $this->reason
= $wgRequest->getText( 'wpReason' );
68 if ( $wgRequest->wasPosted() ) {
69 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', false );
71 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', true );
73 $this->moveSubpages
= $wgRequest->getBool( 'wpMovesubpages', false );
74 $this->deleteAndMove
= $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
75 $this->fixRedirects
= $wgRequest->getBool( 'wpFixRedirects', true );
76 $this->watch
= $wgRequest->getCheck( 'wpWatch' );
79 function showForm( $err, $hookErr = '' ) {
80 global $wgOut, $wgUser;
82 $skin = $wgUser->getSkin();
84 $oldTitleLink = $skin->makeLinkObj( $this->oldTitle
);
85 $oldTitle = $this->oldTitle
->getPrefixedText();
87 $wgOut->setPagetitle( wfMsg( 'move-page', $oldTitle ) );
88 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
90 if( $this->newTitle
== '' ) {
91 # Show the current title as a default
92 # when the form is first opened.
93 $newTitle = $oldTitle;
96 $nt = Title
::newFromURL( $this->newTitle
);
98 # If a title was supplied, probably from the move log revert
99 # link, check for validity. We can then show some diagnostic
100 # information and save a click.
101 $newerr = $this->oldTitle
->isValidMoveOperation( $nt );
102 if( is_string( $newerr ) ) {
107 $newTitle = $this->newTitle
;
110 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
111 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle );
112 $movepagebtn = wfMsg( 'delete_and_move' );
113 $submitVar = 'wpDeleteAndMove';
117 <td class='mw-input'>" .
118 Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
123 $wgOut->addWikiMsg( 'movepagetext' );
124 $movepagebtn = wfMsg( 'movepagebtn' );
125 $submitVar = 'wpMove';
129 $oldTalk = $this->oldTitle
->getTalkPage();
130 $considerTalk = ( !$this->oldTitle
->isTalkPage() && $oldTalk->exists() );
132 $dbr = wfGetDB( DB_SLAVE
);
133 $hasRedirects = $dbr->selectField( 'redirect', '1',
135 'rd_namespace' => $this->oldTitle
->getNamespace(),
136 'rd_title' => $this->oldTitle
->getDBkey(),
139 if ( $considerTalk ) {
140 $wgOut->addWikiMsg( 'movepagetalktext' );
143 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
144 $token = htmlspecialchars( $wgUser->editToken() );
147 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
148 if( $err == 'hookaborted' ) {
149 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
150 $wgOut->addHTML( $errMsg );
152 $wgOut->wrapWikiMsg( '<p><strong class="error">$1</strong></p>', $err );
157 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
158 Xml
::openElement( 'fieldset' ) .
159 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
160 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
162 <td class='mw-label'>" .
163 wfMsgHtml( 'movearticle' ) .
165 <td class='mw-input'>
166 <strong>{$oldTitleLink}</strong>
170 <td class='mw-label'>" .
171 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
173 <td class='mw-input'>" .
174 Xml
::input( 'wpNewTitle', 40, $newTitle, array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
175 Xml
::hidden( 'wpOldTitle', $oldTitle ) .
179 <td class='mw-label'>" .
180 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
182 <td class='mw-input'>" .
183 Xml
::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason
) ) .
188 if( $considerTalk ) {
192 <td class='mw-input'>" .
193 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
199 if ( $hasRedirects ) {
203 <td class='mw-input' >" .
204 Xml
::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects',
205 'wpFixRedirects', $this->fixRedirects
) .
211 if( ($this->oldTitle
->hasSubpages() ||
$this->oldTitle
->getTalkPage()->hasSubpages())
212 && $this->oldTitle
->userCan( 'move-subpages' ) ) {
216 <td class=\"mw-input\">" .
217 Xml
::checkLabel( wfMsgHtml(
218 $this->oldTitle
->hasSubpages()
220 : 'move-talk-subpages'
222 'wpMovesubpages', 'wpMovesubpages',
223 # Don't check the box if we only have talk subpages to
224 # move and we aren't moving the talk page.
225 $this->moveSubpages
&& ($this->oldTitle
->hasSubpages() ||
$this->moveTalk
)
232 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' )
233 ||
$this->oldTitle
->userIsWatching();
237 <td class='mw-input'>" .
238 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
244 <td class='mw-submit'>" .
245 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
248 Xml
::closeElement( 'table' ) .
249 Xml
::hidden( 'wpEditToken', $token ) .
250 Xml
::closeElement( 'fieldset' ) .
251 Xml
::closeElement( 'form' ) .
255 $this->showLogFragment( $this->oldTitle
, $wgOut );
259 function doSubmit() {
260 global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
262 if ( $wgUser->pingLimiter( 'move' ) ) {
263 $wgOut->rateLimited();
267 $ot = $this->oldTitle
;
268 $nt = $this->newTitle
;
270 # Delete to make way if requested
271 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
272 $article = new Article( $nt );
274 # Disallow deletions of big articles
275 $bigHistory = $article->isBigDeletion();
276 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
277 global $wgLang, $wgDeleteRevisionsLimit;
278 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
282 // This may output an error message and exit
283 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
286 # don't allow moving to pages with # in
287 if ( !$nt ||
$nt->getFragment() != '' ) {
288 $this->showForm( 'badtitletext' );
292 $error = $ot->moveTo( $nt, true, $this->reason
);
293 if ( $error !== true ) {
294 # FIXME: showForm() should handle multiple errors
295 call_user_func_array(array($this, 'showForm'), $error[0]);
299 if ( $this->fixRedirects
) {
300 DoubleRedirectJob
::fixRedirects( 'move', $ot, $nt );
303 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
305 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
307 $oldUrl = $ot->getFullUrl( 'redirect=no' );
308 $newUrl = $nt->getFullUrl();
309 $oldText = $ot->getPrefixedText();
310 $newText = $nt->getPrefixedText();
311 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
312 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
314 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
316 # Now we move extra pages we've been asked to move: subpages and talk
317 # pages. First, if the old page or the new page is a talk page, we
318 # can't move any talk pages: cancel that.
319 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
320 $this->moveTalk
= false;
323 if( !$ot->userCan( 'move-subpages' ) ) {
324 $this->moveSubpages
= false;
327 # Next make a list of id's. This might be marginally less efficient
328 # than a more direct method, but this is not a highly performance-cri-
329 # tical code path and readable code is more important here.
331 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
332 # 4 might get confused. If so, consider rewriting as a UNION.
334 # If the target namespace doesn't allow subpages, moving with subpages
335 # would mean that you couldn't move them back in one operation, which
336 # is bad. FIXME: A specific error message should be given in this
338 $dbr = wfGetDB( DB_MASTER
);
339 if( $this->moveSubpages
&& (
340 MWNamespace
::hasSubpages( $nt->getNamespace() ) ||
(
342 MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() )
346 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
347 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
349 $conds['page_namespace'] = array();
350 if( MWNamespace
::hasSubpages( $nt->getNamespace() ) ) {
351 $conds['page_namespace'] []= $ot->getNamespace();
353 if( $this->moveTalk
&& MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
354 $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
356 } elseif( $this->moveTalk
) {
358 'page_namespace' => $ot->getTalkPage()->getNamespace(),
359 'page_title' => $ot->getDBKey()
366 $extraPages = array();
367 if( !is_null( $conds ) ) {
368 $extraPages = TitleArray
::newFromResult(
369 $dbr->select( 'page',
370 array( 'page_id', 'page_namespace', 'page_title' ),
377 $extraOutput = array();
378 $skin = $wgUser->getSkin();
380 foreach( $extraPages as $oldSubpage ) {
381 if( $oldSubpage->getArticleId() == $ot->getArticleId() ) {
382 # Already did this one.
386 $newPageName = preg_replace(
387 '#^'.preg_quote( $ot->getDBKey(), '#' ).'#',
389 $oldSubpage->getDBKey()
391 if( $oldSubpage->isTalkPage() ) {
392 $newNs = $nt->getTalkPage()->getNamespace();
394 $newNs = $nt->getSubjectPage()->getNamespace();
396 # Bug 14385: we need makeTitleSafe because the new page names may
397 # be longer than 255 characters.
398 $newSubpage = Title
::makeTitleSafe( $newNs, $newPageName );
400 $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
401 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
402 htmlspecialchars(Title
::makeName( $newNs, $newPageName )));
406 # This was copy-pasted from Renameuser, bleh.
407 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
408 $link = $skin->makeKnownLinkObj( $newSubpage );
409 $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
411 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason
);
412 if( $success === true ) {
413 if ( $this->fixRedirects
) {
414 DoubleRedirectJob
::fixRedirects( 'move', $oldSubpage, $newSubpage );
416 $oldLink = $skin->makeKnownLinkObj( $oldSubpage, '', 'redirect=no' );
417 $newLink = $skin->makeKnownLinkObj( $newSubpage );
418 $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
420 $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
421 $newLink = $skin->makeLinkObj( $newSubpage );
422 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
427 if( $count >= $wgMaximumMovedPages ) {
428 $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) );
433 if( $extraOutput !== array() ) {
434 $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
437 # Deal with watches (we don't watch subpages)
439 $wgUser->addWatch( $ot );
440 $wgUser->addWatch( $nt );
442 $wgUser->removeWatch( $ot );
443 $wgUser->removeWatch( $nt );
447 function showLogFragment( $title, &$out ) {
448 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
449 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );