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' ) );
143 if( $err == 'hookaborted' ) {
144 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
145 } else if (is_array($err)) {
146 $errMsg = '<p><strong class="error">' . call_user_func_array( 'wfMsgWikiHtml', $err ) . "</strong></p>\n";
148 $errMsg = '<p><strong class="error">' . wfMsgWikiHtml( $err ) . "</strong></p>\n";
150 $wgOut->addHTML( $errMsg );
154 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
155 Xml
::openElement( 'fieldset' ) .
156 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
157 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
159 <td class='mw-label'>" .
160 wfMsgHtml( 'movearticle' ) .
162 <td class='mw-input'>
163 <strong>{$oldTitleLink}</strong>
167 <td class='mw-label'>" .
168 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
170 <td class='mw-input'>" .
171 Xml
::input( 'wpNewTitle', 40, $newTitle, array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
172 Xml
::hidden( 'wpOldTitle', $oldTitle ) .
176 <td class='mw-label'>" .
177 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
179 <td class='mw-input'>" .
180 Xml
::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason
) ) .
185 if( $considerTalk ) {
189 <td class='mw-input'>" .
190 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
196 if( ($ot->hasSubpages() ||
$ot->getTalkPage()->hasSubpages())
197 && $ot->userCan( 'move-subpages' ) ) {
201 <td class=\"mw-input\">" .
202 Xml
::checkLabel( wfMsgHtml(
205 : 'move-talk-subpages'
207 'wpMovesubpages', 'wpMovesubpages',
208 # Don't check the box if we only have talk subpages to
209 # move and we aren't moving the talk page.
210 $this->moveSubpages
&& ($ot->hasSubpages() ||
$this->moveTalk
)
217 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' ) ||
$ot->userIsWatching();
221 <td class='mw-input'>" .
222 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
228 <td class='mw-submit'>" .
229 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
232 Xml
::closeElement( 'table' ) .
233 Xml
::hidden( 'wpEditToken', $token ) .
234 Xml
::closeElement( 'fieldset' ) .
235 Xml
::closeElement( 'form' ) .
239 $this->showLogFragment( $ot, $wgOut );
243 function doSubmit() {
244 global $wgOut, $wgUser, $wgRequest, $wgMaximumMovedPages, $wgLang;
246 if ( $wgUser->pingLimiter( 'move' ) ) {
247 $wgOut->rateLimited();
251 $ot = $this->oldTitle
;
252 $nt = $this->newTitle
;
254 # Delete to make way if requested
255 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
256 $article = new Article( $nt );
258 # Disallow deletions of big articles
259 $bigHistory = $article->isBigDeletion();
260 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
261 global $wgLang, $wgDeleteRevisionsLimit;
262 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
266 // This may output an error message and exit
267 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
270 # don't allow moving to pages with # in
271 if ( !$nt ||
$nt->getFragment() != '' ) {
272 $this->showForm( 'badtitletext' );
276 $error = $ot->moveTo( $nt, true, $this->reason
);
277 if ( $error !== true ) {
278 # FIXME: showForm() should handle multiple errors
279 call_user_func_array(array($this, 'showForm'), $error[0]);
283 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
285 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
287 $oldUrl = $ot->getFullUrl( 'redirect=no' );
288 $newUrl = $nt->getFullUrl();
289 $oldText = $ot->getPrefixedText();
290 $newText = $nt->getPrefixedText();
291 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
292 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
294 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
296 # Now we move extra pages we've been asked to move: subpages and talk
297 # pages. First, if the old page or the new page is a talk page, we
298 # can't move any talk pages: cancel that.
299 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
300 $this->moveTalk
= false;
303 if( !$ot->userCan( 'move-subpages' ) ) {
304 $this->moveSubpages
= false;
307 # Next make a list of id's. This might be marginally less efficient
308 # than a more direct method, but this is not a highly performance-cri-
309 # tical code path and readable code is more important here.
311 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
312 # 4 might get confused. If so, consider rewriting as a UNION.
314 # If the target namespace doesn't allow subpages, moving with subpages
315 # would mean that you couldn't move them back in one operation, which
316 # is bad. FIXME: A specific error message should be given in this
318 $dbr = wfGetDB( DB_MASTER
);
319 if( $this->moveSubpages
&& (
320 MWNamespace
::hasSubpages( $nt->getNamespace() ) ||
(
322 MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() )
326 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
327 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
329 $conds['page_namespace'] = array();
330 if( MWNamespace
::hasSubpages( $nt->getNamespace() ) ) {
331 $conds['page_namespace'] []= $ot->getNamespace();
333 if( $this->moveTalk
&& MWNamespace
::hasSubpages( $nt->getTalkPage()->getNamespace() ) ) {
334 $conds['page_namespace'] []= $ot->getTalkPage()->getNamespace();
336 } elseif( $this->moveTalk
) {
338 'page_namespace' => $ot->getTalkPage()->getNamespace(),
339 'page_title' => $ot->getDBKey()
346 $extrapages = array();
347 if( !is_null( $conds ) ) {
348 $extrapages = $dbr->select( 'page',
349 array( 'page_id', 'page_namespace', 'page_title' ),
355 $extraOutput = array();
356 $skin = $wgUser->getSkin();
358 foreach( $extrapages as $row ) {
359 if( $row->page_id
== $ot->getArticleId() ) {
360 # Already did this one.
364 $oldPage = Title
::newFromRow( $row );
365 $newPageName = preg_replace(
366 '#^'.preg_quote( $ot->getDBKey(), '#' ).'#',
370 if( $oldPage->isTalkPage() ) {
371 $newNs = $nt->getTalkPage()->getNamespace();
373 $newNs = $nt->getSubjectPage()->getNamespace();
375 # Bug 14385: we need makeTitleSafe because the new page names may
376 # be longer than 255 characters.
377 $newPage = Title
::makeTitleSafe( $newNs, $newPageName );
379 $oldLink = $skin->makeKnownLinkObj( $oldPage );
380 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink,
381 htmlspecialchars(Title
::makeName( $newNs, $newPageName )));
385 # This was copy-pasted from Renameuser, bleh.
386 if ( $newPage->exists() && !$oldPage->isValidMoveTarget( $newPage ) ) {
387 $link = $skin->makeKnownLinkObj( $newPage );
388 $extraOutput []= wfMsgHtml( 'movepage-page-exists', $link );
390 $success = $oldPage->moveTo( $newPage, true, $this->reason
);
391 if( $success === true ) {
392 $oldLink = $skin->makeKnownLinkObj( $oldPage, '', 'redirect=no' );
393 $newLink = $skin->makeKnownLinkObj( $newPage );
394 $extraOutput []= wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink );
396 $oldLink = $skin->makeKnownLinkObj( $oldPage );
397 $newLink = $skin->makeLinkObj( $newPage );
398 $extraOutput []= wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink );
403 if( $count >= $wgMaximumMovedPages ) {
404 $extraOutput []= wfMsgExt( 'movepage-max-pages', array( 'parsemag', 'escape' ), $wgLang->formatNum( $wgMaximumMovedPages ) );
409 if( $extraOutput !== array() ) {
410 $wgOut->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
413 # Deal with watches (we don't watch subpages)
415 $wgUser->addWatch( $ot );
416 $wgUser->addWatch( $nt );
418 $wgUser->removeWatch( $ot );
419 $wgUser->removeWatch( $nt );
423 function showLogFragment( $title, &$out ) {
424 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
425 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );