becf7985aa2ded9896500884b3edef72085ff091
4 * @addtogroup SpecialPage
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 * @addtogroup 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, $wgNamespacesWithSubpages;
70 $ot = Title
::newFromURL( $this->oldTitle
);
71 if( is_null( $ot ) ) {
72 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
76 $sk = $wgUser->getSkin();
78 $oldTitleLink = $sk->makeLinkObj( $ot );
79 $oldTitle = $ot->getPrefixedText();
81 $wgOut->setPagetitle( wfMsg( 'move-page', $oldTitle ) );
82 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
84 if( $this->newTitle
== '' ) {
85 # Show the current title as a default
86 # when the form is first opened.
87 $newTitle = $oldTitle;
90 $nt = Title
::newFromURL( $this->newTitle
);
92 # If a title was supplied, probably from the move log revert
93 # link, check for validity. We can then show some diagnostic
94 # information and save a click.
95 $newerr = $ot->isValidMoveOperation( $nt );
96 if( is_string( $newerr ) ) {
101 $newTitle = $this->newTitle
;
104 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
105 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle );
106 $movepagebtn = wfMsg( 'delete_and_move' );
107 $submitVar = 'wpDeleteAndMove';
111 <td class='mw-input'>" .
112 Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
117 $wgOut->addWikiMsg( 'movepagetext' );
118 $movepagebtn = wfMsg( 'movepagebtn' );
119 $submitVar = 'wpMove';
123 $oldTalk = $ot->getTalkPage();
124 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
126 if ( $considerTalk ) {
127 $wgOut->addWikiMsg( 'movepagetalktext' );
130 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
131 $token = htmlspecialchars( $wgUser->editToken() );
134 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
136 if( $err == 'hookaborted' ) {
137 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
138 } else if (is_array($err)) {
139 $errMsg = '<p><strong class="error">' . call_user_func_array( 'wfMsgWikiHtml', $err ) . "</strong></p>\n";
141 $errMsg = '<p><strong class="error">' . wfMsgWikiHtml( $err ) . "</strong></p>\n";
143 $wgOut->addHTML( $errMsg );
147 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
148 Xml
::openElement( 'fieldset' ) .
149 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
150 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
152 <td class='mw-label'>" .
153 wfMsgHtml( 'movearticle' ) .
155 <td class='mw-input'>
156 <strong>{$oldTitleLink}</strong>
160 <td class='mw-label'>" .
161 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
163 <td class='mw-input'>" .
164 Xml
::input( 'wpNewTitle', 40, $newTitle, array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
165 Xml
::hidden( 'wpOldTitle', $oldTitle ) .
169 <td class='mw-label'>" .
170 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
172 <td class='mw-input'>" .
173 Xml
::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason
) ) .
178 if( $considerTalk ) {
182 <td class='mw-input'>" .
183 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk',
184 'wpMovetalk', $this->moveTalk ?
' checked="checked"' : '').
190 if( isset( $wgNamespacesWithSubpages[$ot->getNamespace()] ) ) {
194 <td class=\"mw-input\">" .
195 Xml
::checkLabel( wfMsgHtml( 'move-subpages' ),
196 'wpMovesubpages', 'wpMovesubpages',
197 $this->moveSubpages ?
' checked="checked"' : '' ) .
203 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' ) ||
$ot->userIsWatching();
207 <td class='mw-input'>" .
208 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
214 <td class='mw-submit'>" .
215 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
218 Xml
::closeElement( 'table' ) .
219 Xml
::hidden( 'wpEditToken', $token ) .
220 Xml
::closeElement( 'fieldset' ) .
221 Xml
::closeElement( 'form' ) .
225 $this->showLogFragment( $ot, $wgOut );
229 function doSubmit() {
230 global $wgOut, $wgUser, $wgRequest;
232 if ( $wgUser->pingLimiter( 'move' ) ) {
233 $wgOut->rateLimited();
237 # Variables beginning with 'o' for old article 'n' for new article
239 $ot = Title
::newFromText( $this->oldTitle
);
240 $nt = Title
::newFromText( $this->newTitle
);
242 # Delete to make way if requested
243 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
244 $article = new Article( $nt );
246 # Disallow deletions of big articles
247 $bigHistory = $article->isBigDeletion();
248 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
249 global $wgLang, $wgDeleteRevisionsLimit;
250 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
254 // This may output an error message and exit
255 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
258 # don't allow moving to pages with # in
259 if ( !$nt ||
$nt->getFragment() != '' ) {
260 $this->showForm( 'badtitletext' );
265 if( !wfRunHooks( 'AbortMove', array( $ot, $nt, $wgUser, &$hookErr ) ) ) {
266 $this->showForm( 'hookaborted', $hookErr );
270 $error = $ot->moveTo( $nt, true, $this->reason
);
271 if ( $error !== true ) {
272 $this->showForm( $error );
276 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
278 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
280 $oldUrl = $ot->getFullUrl( 'redirect=no' );
281 $newUrl = $nt->getFullUrl();
282 $oldText = $ot->getPrefixedText();
283 $newText = $nt->getPrefixedText();
284 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
285 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
287 $wgOut->addWikiMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
289 # Now we move extra pages we've been asked to move: subpages and talk
290 # pages. First, if the old page or the new page is a talk page, we
291 # can't move any talk pages: cancel that.
292 if( $ot->isTalkPage() ||
$nt->isTalkPage() ) {
293 $this->moveTalk
= false;
296 # Next make a list of id's. This might be marginally less efficient
297 # than a more direct method, but this is not a highly performance-cri-
298 # tical code path and readable code is more important here.
300 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
301 # 4 might get confused. If so, consider rewriting as a UNION.
302 $dbr = wfGetDB( DB_SLAVE
);
303 if( $this->moveSubpages
) {
305 'page_title LIKE '.$dbr->addQuotes( $dbr->escapeLike( $ot->getDBkey() ) . '/%' )
306 .' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
308 if( $this->moveTalk
) {
309 $conds['page_namespace'] = array( $ot->getNamespace(),
310 MWNamespace
::getTalk($ot->getNamespace()) );
312 $conds['page_namespace'] = $ot->getNamespace();
315 if( $this->moveTalk
) {
317 'page_namespace' => MWNamespace
::getTalk($ot->getNamespace()),
318 'page_title' => $ot->getDBKey()
325 $extrapages = $dbr->select(
327 array( 'page_id', 'page_namespace', 'page_title' ),
333 $skin =& $wgUser->getSkin();
334 foreach( $extrapages as $row ) {
335 if( $row->page_id
== $ot->getArticleId() ) {
336 # Already did this one.
340 $oldPage = Title
::newFromRow( $row );
341 $newPageName = preg_replace(
342 '#^'.preg_quote( $ot->getDBKey(), '#' ).'#',
346 # The following line is an atrocious hack. Kill it.
347 $newNs = $nt->getNamespace() +
($oldPage->getNamespace() & 1);
348 $newPage = Title
::makeTitle( $newNs, $newPageName );
350 # This was copy-pasted from Renameuser, bleh.
351 if ( $newPage->exists() && !$oldPage->isValidMoveTarget( $newPage ) ) {
352 $link = $skin->makeKnownLinkObj( $newPage );
353 $extraOutput .= '<li>' . wfMsgHtml( 'movepage-page-exists', $link ) . '</li>';
355 $success = $oldPage->moveTo( $newPage, true, $this->reason
);
356 if( $success === true ) {
357 $oldLink = $skin->makeKnownLinkObj( $oldPage, '', 'redirect=no' );
358 $newLink = $skin->makeKnownLinkObj( $newPage );
359 $extraOutput .= '<li>' . wfMsgHtml( 'movepage-page-moved', $oldLink, $newLink ) . '</li>';
361 $oldLink = $skin->makeKnownLinkObj( $oldPage );
362 $newLink = $skin->makeLinkObj( $newPage );
363 $extraOutput .= '<li>' . wfMsgHtml( 'movepage-page-unmoved', $oldLink, $newLink ) . '</li>';
368 if( $extraOutput !== '' ) {
369 $wgOut->addHTML( "<ul>$extraOutput</ul>" );
374 $wgUser->addWatch( $ot );
375 $wgUser->addWatch( $nt );
377 $wgUser->removeWatch( $ot );
378 $wgUser->removeWatch( $nt );
382 function showLogFragment( $title, &$out ) {
383 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
384 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );