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 ( 'success' == $action ) {
35 } else if ( 'submit' == $action && $wgRequest->wasPosted()
36 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
44 * HTML form for Special:Movepage
45 * @addtogroup SpecialPage
48 var $oldTitle, $newTitle, $reason; # Text input
49 var $moveTalk, $deleteAndMove;
51 private $watch = false;
53 function MovePageForm( $par ) {
55 $target = isset($par) ?
$par : $wgRequest->getVal( 'target' );
56 $this->oldTitle
= $wgRequest->getText( 'wpOldTitle', $target );
57 $this->newTitle
= $wgRequest->getText( 'wpNewTitle' );
58 $this->reason
= $wgRequest->getText( 'wpReason' );
59 if ( $wgRequest->wasPosted() ) {
60 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', false );
62 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', true );
64 $this->deleteAndMove
= $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
65 $this->watch
= $wgRequest->getCheck( 'wpWatch' );
68 function showForm( $err, $hookErr = '' ) {
69 global $wgOut, $wgUser, $wgContLang;
71 $ot = Title
::newFromURL( $this->oldTitle
);
72 if( is_null( $ot ) ) {
73 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
77 $start = $wgContLang->isRTL() ?
'right' : 'left';
78 $end = $wgContLang->isRTL() ?
'left' : 'right';
79 $sk = $wgUser->getSkin();
81 $oldTitleLink = $sk->makeLinkObj( $ot );
82 $oldTitle = $ot->getPrefixedText();
84 $wgOut->setPagetitle( wfMsg( 'move-page', $oldTitle ) );
85 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
87 if( $this->newTitle
== '' ) {
88 # Show the current title as a default
89 # when the form is first opened.
90 $newTitle = $oldTitle;
93 $nt = Title
::newFromURL( $this->newTitle
);
95 # If a title was supplied, probably from the move log revert
96 # link, check for validity. We can then show some diagnostic
97 # information and save a click.
98 $newerr = $ot->isValidMoveOperation( $nt );
99 if( is_string( $newerr ) ) {
104 $newTitle = $this->newTitle
;
107 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
108 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle );
109 $movepagebtn = wfMsg( 'delete_and_move' );
110 $submitVar = 'wpDeleteAndMove';
115 Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
120 $wgOut->addWikiMsg( 'movepagetext' );
121 $movepagebtn = wfMsg( 'movepagebtn' );
122 $submitVar = 'wpMove';
126 $oldTalk = $ot->getTalkPage();
127 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
129 if ( $considerTalk ) {
130 $wgOut->addWikiMsg( 'movepagetalktext' );
133 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
134 $token = htmlspecialchars( $wgUser->editToken() );
137 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
139 if( $err == 'hookaborted' ) {
140 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
141 } else if (is_array($err)) {
142 $errMsg = '<p><strong class="error">' . call_user_func_array( 'wfMsgWikiHtml', $err ) . "</strong></p>\n";
144 $errMsg = '<p><strong class="error">' . wfMsgWikiHtml( $err ) . "</strong></p>\n";
146 $wgOut->addHTML( $errMsg );
149 $moveTalkChecked = $this->moveTalk ?
' checked="checked"' : '';
152 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
153 Xml
::openElement( 'fieldset' ) .
154 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
155 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
158 wfMsgHtml( 'movearticle' ) .
161 <strong>{$oldTitleLink}</strong>
166 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
168 <td align='$start'>" .
169 Xml
::input( 'wpNewTitle', 40, $newTitle, array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
170 Xml
::hidden( 'wpOldTitle', $oldTitle ) .
174 <td align='$end' valign='top'><br />" .
175 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
177 <td align='$start' valign='top'><br />" .
178 Xml
::openElement( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ) ) .
179 htmlspecialchars( $this->reason
) .
180 Xml
::closeElement( 'textarea' ) .
185 if ( $considerTalk ) {
190 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $moveTalkChecked ) .
196 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' ) ||
$ot->userIsWatching();
201 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
207 <td align='$start'>" .
208 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
211 Xml
::closeElement( 'table' ) .
212 Xml
::hidden( 'wpEditToken', $token ) .
213 Xml
::closeElement( 'fieldset' ) .
214 Xml
::closeElement( 'form' ) .
218 $this->showLogFragment( $ot, $wgOut );
222 function doSubmit() {
223 global $wgOut, $wgUser, $wgRequest;
225 if ( $wgUser->pingLimiter( 'move' ) ) {
226 $wgOut->rateLimited();
230 # Variables beginning with 'o' for old article 'n' for new article
232 $ot = Title
::newFromText( $this->oldTitle
);
233 $nt = Title
::newFromText( $this->newTitle
);
235 # Delete to make way if requested
236 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
237 $article = new Article( $nt );
239 # Disallow deletions of big articles
240 $bigHistory = $article->isBigDeletion();
241 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
242 global $wgLang, $wgDeleteRevisionsLimit;
243 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
247 // This may output an error message and exit
248 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
251 # don't allow moving to pages with # in
252 if ( !$nt ||
$nt->getFragment() != '' ) {
253 $this->showForm( 'badtitletext' );
258 if( !wfRunHooks( 'AbortMove', array( $ot, $nt, $wgUser, &$hookErr ) ) ) {
259 $this->showForm( 'hookaborted', $hookErr );
263 $error = $ot->moveTo( $nt, true, $this->reason
);
264 if ( $error !== true ) {
265 $this->showForm( $error );
269 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
271 # Move the talk page if relevant, if it exists, and if we've been told to
272 $ott = $ot->getTalkPage();
273 if( $ott->exists() ) {
274 if( $this->moveTalk
&& !$ot->isTalkPage() && !$nt->isTalkPage() ) {
275 $ntt = $nt->getTalkPage();
278 $error = $ott->moveTo( $ntt, true, $this->reason
);
279 if ( $error === true ) {
281 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) );
286 # Stay silent on the subject of talk.
290 $talkmoved = 'notalkpage';
295 $wgUser->addWatch( $ot );
296 $wgUser->addWatch( $nt );
298 $wgUser->removeWatch( $ot );
299 $wgUser->removeWatch( $nt );
302 # Give back result to user.
303 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
304 $success = $titleObj->getFullURL(
305 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
306 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
307 '&talkmoved='.$talkmoved );
309 $wgOut->redirect( $success );
312 function showSuccess() {
313 global $wgOut, $wgRequest, $wgUser;
315 $old = Title
::newFromText( $wgRequest->getVal( 'oldtitle' ) );
316 $new = Title
::newFromText( $wgRequest->getVal( 'newtitle' ) );
318 if( is_null( $old ) ||
is_null( $new ) ) {
319 throw new ErrorPageError( 'badtitle', 'badtitletext' );
322 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
324 $talkmoved = $wgRequest->getVal( 'talkmoved' );
325 $oldUrl = $old->getFullUrl( 'redirect=no' );
326 $newUrl = $new->getFullUrl();
327 $oldText = $old->getPrefixedText();
328 $newText = $new->getPrefixedText();
329 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
330 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
332 $s = wfMsgNoTrans( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
334 if ( $talkmoved == 1 ) {
335 $s .= "\n\n" . wfMsgNoTrans( 'talkpagemoved' );
336 } elseif( 'articleexists' == $talkmoved ) {
337 $s .= "\n\n" . wfMsgNoTrans( 'talkexists' );
339 if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
340 $s .= "\n\n" . wfMsgNoTrans( 'talkpagenotmoved', wfMsgNoTrans( $talkmoved ) );
343 $wgOut->addWikiText( $s );
346 function showLogFragment( $title, &$out ) {
347 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
348 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );