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;
71 $ot = Title
::newFromURL( $this->oldTitle
);
72 if( is_null( $ot ) ) {
73 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
76 if( !$ot->exists() ) {
77 $wgOut->showErrorPage( 'nopagetitle', 'nopagetext' );
81 $sk = $wgUser->getSkin();
83 $oldTitleLink = $sk->makeLinkObj( $ot );
84 $oldTitle = $ot->getPrefixedText();
86 $wgOut->setPagetitle( wfMsg( 'move-page', $oldTitle ) );
87 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
89 if( $this->newTitle
== '' ) {
90 # Show the current title as a default
91 # when the form is first opened.
92 $newTitle = $oldTitle;
95 $nt = Title
::newFromURL( $this->newTitle
);
97 # If a title was supplied, probably from the move log revert
98 # link, check for validity. We can then show some diagnostic
99 # information and save a click.
100 $newerr = $ot->isValidMoveOperation( $nt );
101 if( is_string( $newerr ) ) {
106 $newTitle = $this->newTitle
;
109 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
110 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle );
111 $movepagebtn = wfMsg( 'delete_and_move' );
112 $submitVar = 'wpDeleteAndMove';
116 <td class='mw-input'>" .
117 Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
122 $wgOut->addWikiMsg( 'movepagetext' );
123 $movepagebtn = wfMsg( 'movepagebtn' );
124 $submitVar = 'wpMove';
128 $oldTalk = $ot->getTalkPage();
129 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
131 if ( $considerTalk ) {
132 $wgOut->addWikiMsg( 'movepagetalktext' );
135 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
136 $token = htmlspecialchars( $wgUser->editToken() );
139 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
141 if( $err == 'hookaborted' ) {
142 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
143 } else if (is_array($err)) {
144 $errMsg = '<p><strong class="error">' . call_user_func_array( 'wfMsgWikiHtml', $err ) . "</strong></p>\n";
146 $errMsg = '<p><strong class="error">' . wfMsgWikiHtml( $err ) . "</strong></p>\n";
148 $wgOut->addHTML( $errMsg );
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' ) ) .
157 <td class='mw-label'>" .
158 wfMsgHtml( 'movearticle' ) .
160 <td class='mw-input'>
161 <strong>{$oldTitleLink}</strong>
165 <td class='mw-label'>" .
166 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
168 <td class='mw-input'>" .
169 Xml
::input( 'wpNewTitle', 40, $newTitle, array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
170 Xml
::hidden( 'wpOldTitle', $oldTitle ) .
174 <td class='mw-label'>" .
175 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
177 <td class='mw-input'>" .
178 Xml
::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason
) ) .
183 if ( $considerTalk ) {
187 <td class='mw-input'>" .
188 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
194 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' ) ||
$ot->userIsWatching();
198 <td class='mw-input'>" .
199 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
205 <td class='mw-submit'>" .
206 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
209 Xml
::closeElement( 'table' ) .
210 Xml
::hidden( 'wpEditToken', $token ) .
211 Xml
::closeElement( 'fieldset' ) .
212 Xml
::closeElement( 'form' ) .
216 $this->showLogFragment( $ot, $wgOut );
220 function doSubmit() {
221 global $wgOut, $wgUser, $wgRequest;
223 if ( $wgUser->pingLimiter( 'move' ) ) {
224 $wgOut->rateLimited();
228 # Variables beginning with 'o' for old article 'n' for new article
230 $ot = Title
::newFromText( $this->oldTitle
);
231 $nt = Title
::newFromText( $this->newTitle
);
233 # Delete to make way if requested
234 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
235 $article = new Article( $nt );
237 # Disallow deletions of big articles
238 $bigHistory = $article->isBigDeletion();
239 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
240 global $wgLang, $wgDeleteRevisionsLimit;
241 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
245 // This may output an error message and exit
246 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
249 # don't allow moving to pages with # in
250 if ( !$nt ||
$nt->getFragment() != '' ) {
251 $this->showForm( 'badtitletext' );
256 if( !wfRunHooks( 'AbortMove', array( $ot, $nt, $wgUser, &$hookErr ) ) ) {
257 $this->showForm( 'hookaborted', $hookErr );
261 $error = $ot->moveTo( $nt, true, $this->reason
);
262 if ( $error !== true ) {
263 $this->showForm( $error );
267 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
269 # Move the talk page if relevant, if it exists, and if we've been told to
270 $ott = $ot->getTalkPage();
271 if( $ott->exists() ) {
272 if( $this->moveTalk
&& !$ot->isTalkPage() && !$nt->isTalkPage() ) {
273 $ntt = $nt->getTalkPage();
276 $error = $ott->moveTo( $ntt, true, $this->reason
);
277 if ( $error === true ) {
279 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) );
284 # Stay silent on the subject of talk.
288 $talkmoved = 'notalkpage';
293 $wgUser->addWatch( $ot );
294 $wgUser->addWatch( $nt );
296 $wgUser->removeWatch( $ot );
297 $wgUser->removeWatch( $nt );
300 # Give back result to user.
301 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
302 $success = $titleObj->getFullURL(
303 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
304 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
305 '&talkmoved='.$talkmoved );
307 $wgOut->redirect( $success );
310 function showSuccess() {
311 global $wgOut, $wgRequest, $wgUser;
313 $old = Title
::newFromText( $wgRequest->getVal( 'oldtitle' ) );
314 $new = Title
::newFromText( $wgRequest->getVal( 'newtitle' ) );
316 if( is_null( $old ) ||
is_null( $new ) ) {
317 throw new ErrorPageError( 'badtitle', 'badtitletext' );
320 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
322 $talkmoved = $wgRequest->getVal( 'talkmoved' );
323 $oldUrl = $old->getFullUrl( 'redirect=no' );
324 $newUrl = $new->getFullUrl();
325 $oldText = $old->getPrefixedText();
326 $newText = $new->getPrefixedText();
327 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
328 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
330 $s = wfMsgNoTrans( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
332 if ( $talkmoved == 1 ) {
333 $s .= "\n\n" . wfMsgNoTrans( 'talkpagemoved' );
334 } elseif( 'articleexists' == $talkmoved ) {
335 $s .= "\n\n" . wfMsgNoTrans( 'talkexists' );
337 if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
338 $s .= "\n\n" . wfMsgNoTrans( 'talkpagenotmoved', wfMsgNoTrans( $talkmoved ) );
341 $wgOut->addWikiText( $s );
344 function showLogFragment( $title, &$out ) {
345 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
346 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );