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 );
70 $this->fixRedirects
= $wgRequest->getBool( 'wpFixRedirects', false );
72 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', true );
73 $this->fixRedirects
= $wgRequest->getBool( 'wpFixRedirects', true );
75 $this->moveSubpages
= $wgRequest->getBool( 'wpMovesubpages', false );
76 $this->deleteAndMove
= $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
77 $this->watch
= $wgRequest->getCheck( 'wpWatch' );
80 function showForm( $err, $hookErr = '' ) {
81 global $wgOut, $wgUser;
83 $skin = $wgUser->getSkin();
85 $oldTitleLink = $skin->makeLinkObj( $this->oldTitle
);
86 $oldTitle = $this->oldTitle
->getPrefixedText();
88 $wgOut->setPagetitle( wfMsg( 'move-page', $oldTitle ) );
89 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
91 if( $this->newTitle
== '' ) {
92 # Show the current title as a default
93 # when the form is first opened.
94 $newTitle = $oldTitle;
97 $nt = Title
::newFromURL( $this->newTitle
);
99 # If a title was supplied, probably from the move log revert
100 # link, check for validity. We can then show some diagnostic
101 # information and save a click.
102 $newerr = $this->oldTitle
->isValidMoveOperation( $nt );
103 if( is_string( $newerr ) ) {
108 $newTitle = $this->newTitle
;
111 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
112 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle );
113 $movepagebtn = wfMsg( 'delete_and_move' );
114 $submitVar = 'wpDeleteAndMove';
118 <td class='mw-input'>" .
119 Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
124 $wgOut->addWikiMsg( 'movepagetext' );
125 $movepagebtn = wfMsg( 'movepagebtn' );
126 $submitVar = 'wpMove';
130 $oldTalk = $this->oldTitle
->getTalkPage();
131 $considerTalk = ( !$this->oldTitle
->isTalkPage() && $oldTalk->exists() );
133 $dbr = wfGetDB( DB_SLAVE
);
134 $hasRedirects = $dbr->selectField( 'redirect', '1',
136 'rd_namespace' => $this->oldTitle
->getNamespace(),
137 'rd_title' => $this->oldTitle
->getDBkey(),
140 if ( $considerTalk ) {
141 $wgOut->addWikiMsg( 'movepagetalktext' );
144 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
145 $token = htmlspecialchars( $wgUser->editToken() );
148 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
149 if( $err == 'hookaborted' ) {
150 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
151 $wgOut->addHTML( $errMsg );
153 $wgOut->wrapWikiMsg( '<p><strong class="error">$1</strong></p>', $err );
158 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
159 Xml
::openElement( 'fieldset' ) .
160 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
161 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
163 <td class='mw-label'>" .
164 wfMsgHtml( 'movearticle' ) .
166 <td class='mw-input'>
167 <strong>{$oldTitleLink}</strong>
171 <td class='mw-label'>" .
172 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
174 <td class='mw-input'>" .
175 Xml
::input( 'wpNewTitle', 40, $newTitle, array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
176 Xml
::hidden( 'wpOldTitle', $oldTitle ) .
180 <td class='mw-label'>" .
181 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
183 <td class='mw-input'>" .
184 Xml
::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason
) ) .
189 if( $considerTalk ) {
193 <td class='mw-input'>" .
194 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
200 if ( $hasRedirects ) {
204 <td class='mw-input' >" .
205 Xml
::checkLabel( wfMsg( 'fix-double-redirects' ), 'wpFixRedirects',
206 'wpFixRedirects', $this->fixRedirects
) .
212 if( ($this->oldTitle
->hasSubpages() ||
$this->oldTitle
->getTalkPage()->hasSubpages())
213 && $this->oldTitle
->userCan( 'move-subpages' ) ) {
217 <td class=\"mw-input\">" .
218 Xml
::checkLabel( wfMsgHtml(
219 $this->oldTitle
->hasSubpages()
221 : 'move-talk-subpages'
223 'wpMovesubpages', 'wpMovesubpages',
224 # Don't check the box if we only have talk subpages to
225 # move and we aren't moving the talk page.
226 $this->moveSubpages
&& ($this->oldTitle
->hasSubpages() ||
$this->moveTalk
)
233 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' )
234 ||
$this->oldTitle
->userIsWatching();
238 <td class='mw-input'>" .
239 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
245 <td class='mw-submit'>" .
246 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
249 Xml
::closeElement( 'table' ) .
250 Xml
::hidden( 'wpEditToken', $token ) .
251 Xml
::closeElement( 'fieldset' ) .
252 Xml
::closeElement( 'form' ) .
256 $this->showLogFragment( $this->oldTitle
, $wgOut );
260 function doSubmit() {
261 global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
263 if ( $wgUser->pingLimiter( 'move' ) ) {
264 $wgOut->rateLimited();
268 $ot = $this->oldTitle
;
269 $nt = $this->newTitle
;
271 # Delete to make way if requested
272 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
273 $article = new Article( $nt );
275 # Disallow deletions of big articles
276 $bigHistory = $article->isBigDeletion();
277 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
278 global $wgLang, $wgDeleteRevisionsLimit;
279 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
283 // This may output an error message and exit
284 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
287 # don't allow moving to pages with # in
288 if ( !$nt ||
$nt->getFragment() != '' ) {
289 $this->showForm( 'badtitletext' );
293 $error = $ot->moveTo( $nt, true, $this->reason
);
294 if ( $error !== true ) {
295 # FIXME: showForm() should handle multiple errors
296 call_user_func_array(array($this, 'showForm'), $error[0]);
300 if ( $this->fixRedirects
) {
301 DoubleRedirectJob
::fixRedirects( 'move', $ot, $nt );
304 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
306 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
308 $oldUrl = $ot->getFullUrl( 'redirect=no' );
309 $newUrl = $nt->getFullUrl();
310 $oldText = $ot->getPrefixedText();
311 $newText = $nt->getPrefixedText();
312 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
313 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
315 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
317 # Now we move extra pages we've been asked to move: subpages and talk
318 # pages. First, if the old page or the new page is a talk page, we
319 # can't move any talk pages: cancel that.
320 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
321 $this->moveTalk
= false;
324 if( !$ot->userCan( 'move-subpages' ) ) {
325 $this->moveSubpages
= false;
328 # Next make a list of id's. This might be marginally less efficient
329 # than a more direct method, but this is not a highly performance-cri-
330 # tical code path and readable code is more important here.
332 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
333 # 4 might get confused. If so, consider rewriting as a UNION.
335 # If the target namespace doesn't allow subpages, moving with subpages
336 # would mean that you couldn't move them back in one operation, which
337 # is bad. FIXME: A specific error message should be given in this
339 $dbr = wfGetDB( DB_MASTER
);
340 if( $this->moveSubpages
&& (
341 MWNamespace
::hasSubpages( $nt->getNamespace() ) ||
(
343 MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() )
347 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
348 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
350 $conds['page_namespace'] = array();
351 if( MWNamespace
::hasSubpages( $nt->getNamespace() ) ) {
352 $conds['page_namespace'] []= $ot->getNamespace();
354 if( $this->moveTalk
&& MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
355 $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
357 } elseif( $this->moveTalk
) {
359 'page_namespace' => $ot->getTalkPage()->getNamespace(),
360 'page_title' => $ot->getDBKey()
367 $extraPages = array();
368 if( !is_null( $conds ) ) {
369 $extraPages = TitleArray
::newFromResult(
370 $dbr->select( 'page',
371 array( 'page_id', 'page_namespace', 'page_title' ),
378 $extraOutput = array();
379 $skin = $wgUser->getSkin();
381 foreach( $extraPages as $oldSubpage ) {
382 if( $oldSubpage->getArticleId() == $ot->getArticleId() ) {
383 # Already did this one.
387 $newPageName = preg_replace(
388 '#^'.preg_quote( $ot->getDBKey(), '#' ).'#',
390 $oldSubpage->getDBKey()
392 if( $oldSubpage->isTalkPage() ) {
393 $newNs = $nt->getTalkPage()->getNamespace();
395 $newNs = $nt->getSubjectPage()->getNamespace();
397 # Bug 14385: we need makeTitleSafe because the new page names may
398 # be longer than 255 characters.
399 $newSubpage = Title
::makeTitleSafe( $newNs, $newPageName );
401 $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
402 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
403 htmlspecialchars(Title
::makeName( $newNs, $newPageName )));
407 # This was copy-pasted from Renameuser, bleh.
408 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
409 $link = $skin->makeKnownLinkObj( $newSubpage );
410 $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
412 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason
);
413 if( $success === true ) {
414 if ( $this->fixRedirects
) {
415 DoubleRedirectJob
::fixRedirects( 'move', $oldSubpage, $newSubpage );
417 $oldLink = $skin->makeKnownLinkObj( $oldSubpage, '', 'redirect=no' );
418 $newLink = $skin->makeKnownLinkObj( $newSubpage );
419 $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
421 $oldLink = $skin->makeKnownLinkObj( $oldSubpage );
422 $newLink = $skin->makeLinkObj( $newSubpage );
423 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
428 if( $count >= $wgMaximumMovedPages ) {
429 $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) );
434 if( $extraOutput !== array() ) {
435 $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
438 # Deal with watches (we don't watch subpages)
440 $wgUser->addWatch( $ot );
441 $wgUser->addWatch( $nt );
443 $wgUser->removeWatch( $ot );
444 $wgUser->removeWatch( $nt );
448 function showLogFragment( $title, &$out ) {
449 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
450 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );