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 $oldTitle = $wgRequest->getText( 'wpOldTitle', $target );
21 $newTitle = $wgRequest->getText( 'wpNewTitle' );
23 # Variables beginning with 'o' for old article 'n' for new article
24 $ot = Title
::newFromText( $oldTitle );
25 $nt = Title
::newFromText( $newTitle );
27 if( is_null( $ot ) ) {
28 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
31 if( !$ot->exists() ) {
32 $wgOut->showErrorPage( 'nopagetitle', 'nopagetext' );
37 $permErrors = $ot->getUserPermissionsErrors( 'move', $wgUser );
38 if( !empty( $permErrors ) ) {
39 $wgOut->showPermissionsErrorPage( $permErrors );
43 $f = new MovePageForm( $ot, $nt );
45 if ( 'submit' == $action && $wgRequest->wasPosted()
46 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
54 * HTML form for Special:Movepage
55 * @ingroup SpecialPage
58 var $oldTitle, $newTitle, $reason; # Text input
59 var $moveTalk, $deleteAndMove, $moveSubpages;
61 private $watch = false;
63 function MovePageForm( $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 );
72 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', true );
74 $this->moveSubpages
= $wgRequest->getBool( 'wpMovesubpages', false );
75 $this->deleteAndMove
= $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
76 $this->watch
= $wgRequest->getCheck( 'wpWatch' );
79 function showForm( $err, $hookErr = '' ) {
80 global $wgOut, $wgUser;
82 $ot = $this->oldTitle
;
83 $sk = $wgUser->getSkin();
85 $oldTitleLink = $sk->makeLinkObj( $ot );
86 $oldTitle = $ot->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 = $ot->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 = $ot->getTalkPage();
131 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
133 if ( $considerTalk ) {
134 $wgOut->addWikiMsg( 'movepagetalktext' );
137 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
138 $token = htmlspecialchars( $wgUser->editToken() );
141 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
142 if( $err == 'hookaborted' ) {
143 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
144 $wgOut->addHTML( $errMsg );
146 $wgOut->wrapWikiMsg( '<p><strong class="error">$1</strong></p>', $err );
151 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
152 Xml
::openElement( 'fieldset' ) .
153 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
154 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
156 <td class='mw-label'>" .
157 wfMsgHtml( 'movearticle' ) .
159 <td class='mw-input'>
160 <strong>{$oldTitleLink}</strong>
164 <td class='mw-label'>" .
165 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
167 <td class='mw-input'>" .
168 Xml
::input( 'wpNewTitle', 40, $newTitle, array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
169 Xml
::hidden( 'wpOldTitle', $oldTitle ) .
173 <td class='mw-label'>" .
174 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
176 <td class='mw-input'>" .
177 Xml
::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason
) ) .
182 if( $considerTalk ) {
186 <td class='mw-input'>" .
187 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
193 if( ($ot->hasSubpages() ||
$ot->getTalkPage()->hasSubpages())
194 && $ot->userCan( 'move-subpages' ) ) {
198 <td class=\"mw-input\">" .
199 Xml
::checkLabel( wfMsgHtml(
202 : 'move-talk-subpages'
204 'wpMovesubpages', 'wpMovesubpages',
205 # Don't check the box if we only have talk subpages to
206 # move and we aren't moving the talk page.
207 $this->moveSubpages
&& ($ot->hasSubpages() ||
$this->moveTalk
)
214 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' ) ||
$ot->userIsWatching();
218 <td class='mw-input'>" .
219 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
225 <td class='mw-submit'>" .
226 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
229 Xml
::closeElement( 'table' ) .
230 Xml
::hidden( 'wpEditToken', $token ) .
231 Xml
::closeElement( 'fieldset' ) .
232 Xml
::closeElement( 'form' ) .
236 $this->showLogFragment( $ot, $wgOut );
240 function doSubmit() {
241 global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
243 if ( $wgUser->pingLimiter( 'move' ) ) {
244 $wgOut->rateLimited();
248 $ot = $this->oldTitle
;
249 $nt = $this->newTitle
;
251 # Delete to make way if requested
252 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
253 $article = new Article( $nt );
255 # Disallow deletions of big articles
256 $bigHistory = $article->isBigDeletion();
257 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
258 global $wgLang, $wgDeleteRevisionsLimit;
259 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
263 // This may output an error message and exit
264 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
267 # don't allow moving to pages with # in
268 if ( !$nt ||
$nt->getFragment() != '' ) {
269 $this->showForm( 'badtitletext' );
273 $error = $ot->moveTo( $nt, true, $this->reason
);
274 if ( $error !== true ) {
275 # FIXME: showForm() should handle multiple errors
276 call_user_func_array(array($this, 'showForm'), $error[0]);
280 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
282 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
284 $oldUrl = $ot->getFullUrl( 'redirect=no' );
285 $newUrl = $nt->getFullUrl();
286 $oldText = $ot->getPrefixedText();
287 $newText = $nt->getPrefixedText();
288 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
289 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
291 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
293 # Now we move extra pages we've been asked to move: subpages and talk
294 # pages. First, if the old page or the new page is a talk page, we
295 # can't move any talk pages: cancel that.
296 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
297 $this->moveTalk
= false;
300 if( !$ot->userCan( 'move-subpages' ) ) {
301 $this->moveSubpages
= false;
304 # Next make a list of id's. This might be marginally less efficient
305 # than a more direct method, but this is not a highly performance-cri-
306 # tical code path and readable code is more important here.
308 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
309 # 4 might get confused. If so, consider rewriting as a UNION.
311 # If the target namespace doesn't allow subpages, moving with subpages
312 # would mean that you couldn't move them back in one operation, which
313 # is bad. FIXME: A specific error message should be given in this
315 $dbr = wfGetDB( DB_MASTER
);
316 if( $this->moveSubpages
&& (
317 MWNamespace
::hasSubpages( $nt->getNamespace() ) ||
(
319 MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() )
323 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
324 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
326 $conds['page_namespace'] = array();
327 if( MWNamespace
::hasSubpages( $nt->getNamespace() ) ) {
328 $conds['page_namespace'] []= $ot->getNamespace();
330 if( $this->moveTalk
&& MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
331 $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
333 } elseif( $this->moveTalk
) {
335 'page_namespace' => $ot->getTalkPage()->getNamespace(),
336 'page_title' => $ot->getDBKey()
343 $extrapages = array();
344 if( !is_null( $conds ) ) {
345 $extrapages = $dbr->select( 'page',
346 array( 'page_id', 'page_namespace', 'page_title' ),
352 $extraOutput = array();
353 $skin = $wgUser->getSkin();
355 foreach( $extrapages as $row ) {
356 if( $row->page_id
== $ot->getArticleId() ) {
357 # Already did this one.
361 $oldPage = Title
::newFromRow( $row );
362 $newPageName = preg_replace(
363 '#^'.preg_quote( $ot->getDBKey(), '#' ).'#',
367 if( $oldPage->isTalkPage() ) {
368 $newNs = $nt->getTalkPage()->getNamespace();
370 $newNs = $nt->getSubjectPage()->getNamespace();
372 # Bug 14385: we need makeTitleSafe because the new page names may
373 # be longer than 255 characters.
374 $newPage = Title
::makeTitleSafe( $newNs, $newPageName );
376 $oldLink = $skin->makeKnownLinkObj( $oldPage );
377 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
378 htmlspecialchars(Title
::makeName( $newNs, $newPageName )));
382 # This was copy-pasted from Renameuser, bleh.
383 if ( $newPage->exists() && !$oldPage->isValidMoveTarget( $newPage ) ) {
384 $link = $skin->makeKnownLinkObj( $newPage );
385 $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
387 $success = $oldPage->moveTo( $newPage, true, $this->reason
);
388 if( $success === true ) {
389 $oldLink = $skin->makeKnownLinkObj( $oldPage, '', 'redirect=no' );
390 $newLink = $skin->makeKnownLinkObj( $newPage );
391 $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
393 $oldLink = $skin->makeKnownLinkObj( $oldPage );
394 $newLink = $skin->makeLinkObj( $newPage );
395 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
400 if( $count >= $wgMaximumMovedPages ) {
401 $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) );
406 if( $extraOutput !== array() ) {
407 $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
410 # Deal with watches (we don't watch subpages)
412 $wgUser->addWatch( $ot );
413 $wgUser->addWatch( $nt );
415 $wgUser->removeWatch( $ot );
416 $wgUser->removeWatch( $nt );
420 function showLogFragment( $title, &$out ) {
421 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
422 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );