10 function wfSpecialMovepage( $par = null ) {
11 global $wgUser, $wgOut, $wgRequest, $action;
14 if ( !$wgUser->isAllowed( 'move' ) ) {
15 $wgOut->showPermissionsErrorPage( array( $wgUser->isAnon() ?
'movenologintext' : 'movenotallowed' ) );
19 # Don't allow blocked users to move pages
20 if ( $wgUser->isBlocked() ) {
21 $wgOut->blockedPage();
25 # Check for database lock
27 $wgOut->readOnlyPage();
31 $f = new MovePageForm( $par );
33 if ( 'submit' == $action && $wgRequest->wasPosted()
34 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
42 * HTML form for Special:Movepage
43 * @ingroup SpecialPage
46 var $oldTitle, $newTitle, $reason; # Text input
47 var $moveTalk, $deleteAndMove, $moveSubpages;
49 private $watch = false;
51 function MovePageForm( $par ) {
53 $target = isset($par) ?
$par : $wgRequest->getVal( 'target' );
54 $this->oldTitle
= $wgRequest->getText( 'wpOldTitle', $target );
55 $this->newTitle
= $wgRequest->getText( 'wpNewTitle' );
56 $this->reason
= $wgRequest->getText( 'wpReason' );
57 if ( $wgRequest->wasPosted() ) {
58 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', false );
60 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', true );
62 $this->moveSubpages
= $wgRequest->getBool( 'wpMovesubpages', false );
63 $this->deleteAndMove
= $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
64 $this->watch
= $wgRequest->getCheck( 'wpWatch' );
67 function showForm( $err, $hookErr = '' ) {
68 global $wgOut, $wgUser;
70 $ot = Title
::newFromURL( $this->oldTitle
);
71 if( is_null( $ot ) ) {
72 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
75 if( !$ot->exists() ) {
76 $wgOut->showErrorPage( 'nopagetitle', 'nopagetext' );
80 $sk = $wgUser->getSkin();
82 $oldTitleLink = $sk->makeLinkObj( $ot );
83 $oldTitle = $ot->getPrefixedText();
85 $wgOut->setPagetitle( wfMsg( 'move-page', $oldTitle ) );
86 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
88 if( $this->newTitle
== '' ) {
89 # Show the current title as a default
90 # when the form is first opened.
91 $newTitle = $oldTitle;
94 $nt = Title
::newFromURL( $this->newTitle
);
96 # If a title was supplied, probably from the move log revert
97 # link, check for validity. We can then show some diagnostic
98 # information and save a click.
99 $newerr = $ot->isValidMoveOperation( $nt );
100 if( is_string( $newerr ) ) {
105 $newTitle = $this->newTitle
;
108 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
109 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle );
110 $movepagebtn = wfMsg( 'delete_and_move' );
111 $submitVar = 'wpDeleteAndMove';
115 <td class='mw-input'>" .
116 Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
121 $wgOut->addWikiMsg( 'movepagetext' );
122 $movepagebtn = wfMsg( 'movepagebtn' );
123 $submitVar = 'wpMove';
127 $oldTalk = $ot->getTalkPage();
128 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
130 if ( $considerTalk ) {
131 $wgOut->addWikiMsg( 'movepagetalktext' );
134 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
135 $token = htmlspecialchars( $wgUser->editToken() );
138 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
140 if( $err == 'hookaborted' ) {
141 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
142 } else if (is_array($err)) {
143 $errMsg = '<p><strong class="error">' . call_user_func_array( 'wfMsgWikiHtml', $err ) . "</strong></p>\n";
145 $errMsg = '<p><strong class="error">' . wfMsgWikiHtml( $err ) . "</strong></p>\n";
147 $wgOut->addHTML( $errMsg );
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() ) {
197 <td class=\"mw-input\">" .
198 Xml
::checkLabel( wfMsgHtml(
201 : 'move-talk-subpages'
203 'wpMovesubpages', 'wpMovesubpages',
204 # Don't check the box if we only have talk subpages to
205 # move and we aren't moving the talk page.
206 $this->moveSubpages
&& ($ot->hasSubpages() ||
$this->moveTalk
)
213 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' ) ||
$ot->userIsWatching();
217 <td class='mw-input'>" .
218 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
224 <td class='mw-submit'>" .
225 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
228 Xml
::closeElement( 'table' ) .
229 Xml
::hidden( 'wpEditToken', $token ) .
230 Xml
::closeElement( 'fieldset' ) .
231 Xml
::closeElement( 'form' ) .
235 $this->showLogFragment( $ot, $wgOut );
239 function doSubmit() {
240 global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
242 if ( $wgUser->pingLimiter( 'move' ) ) {
243 $wgOut->rateLimited();
247 # Variables beginning with 'o' for old article 'n' for new article
249 $ot = Title
::newFromText( $this->oldTitle
);
250 $nt = Title
::newFromText( $this->newTitle
);
252 # Delete to make way if requested
253 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
254 $article = new Article( $nt );
256 # Disallow deletions of big articles
257 $bigHistory = $article->isBigDeletion();
258 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
259 global $wgLang, $wgDeleteRevisionsLimit;
260 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
264 // This may output an error message and exit
265 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
268 # don't allow moving to pages with # in
269 if ( !$nt ||
$nt->getFragment() != '' ) {
270 $this->showForm( 'badtitletext' );
274 $error = $ot->moveTo( $nt, true, $this->reason
);
275 if ( $error !== true ) {
276 # FIXME: moveTo() can return a string
278 # FIXME: showForm() should handle multiple errors
279 call_user_func_array(array($this, 'showForm'), $error[0]);
281 $this->showForm($error);
285 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
287 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
289 $oldUrl = $ot->getFullUrl( 'redirect=no' );
290 $newUrl = $nt->getFullUrl();
291 $oldText = $ot->getPrefixedText();
292 $newText = $nt->getPrefixedText();
293 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
294 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
296 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
298 # Now we move extra pages we've been asked to move: subpages and talk
299 # pages. First, if the old page or the new page is a talk page, we
300 # can't move any talk pages: cancel that.
301 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
302 $this->moveTalk
= false;
305 # Next make a list of id's. This might be marginally less efficient
306 # than a more direct method, but this is not a highly performance-cri-
307 # tical code path and readable code is more important here.
309 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
310 # 4 might get confused. If so, consider rewriting as a UNION.
312 # If the target namespace doesn't allow subpages, moving with subpages
313 # would mean that you couldn't move them back in one operation, which
314 # is bad. FIXME: A specific error message should be given in this
316 $dbr = wfGetDB( DB_SLAVE
);
317 if( $this->moveSubpages
&& (
318 MWNamespace
::hasSubpages( $nt->getNamespace() ) ||
(
320 MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() )
324 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
325 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
327 $conds['page_namespace'] = array();
328 if( MWNamespace
::hasSubpages( $nt->getNamespace() ) ) {
329 $conds['page_namespace'] []= $ot->getNamespace();
331 if( $this->moveTalk
&& MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
332 $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
334 } elseif( $this->moveTalk
) {
336 'page_namespace' => $ot->getTalkPage()->getNamespace(),
337 'page_title' => $ot->getDBKey()
344 $extrapages = array();
345 if( !is_null( $conds ) ) {
346 $extrapages = $dbr->select( 'page',
347 array( 'page_id', 'page_namespace', 'page_title' ),
353 $extraOutput = array();
354 $skin = $wgUser->getSkin();
356 foreach( $extrapages as $row ) {
357 if( $row->page_id
== $ot->getArticleId() ) {
358 # Already did this one.
362 $oldPage = Title
::newFromRow( $row );
363 $newPageName = preg_replace(
364 '#^'.preg_quote( $ot->getDBKey(), '#' ).'#',
368 # The following line is an atrocious hack. Kill it with fire.
369 $newNs = $nt->getNamespace() +
($oldPage->getNamespace() & 1);
370 $newPage = Title
::makeTitle( $newNs, $newPageName );
372 # This was copy-pasted from Renameuser, bleh.
373 if ( $newPage->exists() && !$oldPage->isValidMoveTarget( $newPage ) ) {
374 $link = $skin->makeKnownLinkObj( $newPage );
375 $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
377 $success = $oldPage->moveTo( $newPage, true, $this->reason
);
378 if( $success === true ) {
379 $oldLink = $skin->makeKnownLinkObj( $oldPage, '', 'redirect=no' );
380 $newLink = $skin->makeKnownLinkObj( $newPage );
381 $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
383 $oldLink = $skin->makeKnownLinkObj( $oldPage );
384 $newLink = $skin->makeLinkObj( $newPage );
385 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
390 if( $count >= $wgMaximumMovedPages ) {
391 $extraOutput []= wfMsgHtml( 'movepage-max-pages', $wgLang->formatNum( $wgMaximumMovedPages ) );
396 if( $extraOutput !== array() ) {
397 $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
400 # Deal with watches (we don't watch subpages)
402 $wgUser->addWatch( $ot );
403 $wgUser->addWatch( $nt );
405 $wgUser->removeWatch( $ot );
406 $wgUser->removeWatch( $nt );
410 function showLogFragment( $title, &$out ) {
411 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
412 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );