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' );
77 $sk = $wgUser->getSkin();
79 $oldTitleLink = $sk->makeLinkObj( $ot );
80 $oldTitle = $ot->getPrefixedText();
82 $wgOut->setPagetitle( wfMsg( 'move-page', $oldTitle ) );
83 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
85 if( $this->newTitle
== '' ) {
86 # Show the current title as a default
87 # when the form is first opened.
88 $newTitle = $oldTitle;
91 $nt = Title
::newFromURL( $this->newTitle
);
93 # If a title was supplied, probably from the move log revert
94 # link, check for validity. We can then show some diagnostic
95 # information and save a click.
96 $newerr = $ot->isValidMoveOperation( $nt );
97 if( is_string( $newerr ) ) {
102 $newTitle = $this->newTitle
;
105 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
106 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle );
107 $movepagebtn = wfMsg( 'delete_and_move' );
108 $submitVar = 'wpDeleteAndMove';
112 <td class='mw-input'>" .
113 Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
118 $wgOut->addWikiMsg( 'movepagetext' );
119 $movepagebtn = wfMsg( 'movepagebtn' );
120 $submitVar = 'wpMove';
124 $oldTalk = $ot->getTalkPage();
125 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
127 if ( $considerTalk ) {
128 $wgOut->addWikiMsg( 'movepagetalktext' );
131 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
132 $token = htmlspecialchars( $wgUser->editToken() );
135 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
137 if( $err == 'hookaborted' ) {
138 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
139 } else if (is_array($err)) {
140 $errMsg = '<p><strong class="error">' . call_user_func_array( 'wfMsgWikiHtml', $err ) . "</strong></p>\n";
142 $errMsg = '<p><strong class="error">' . wfMsgWikiHtml( $err ) . "</strong></p>\n";
144 $wgOut->addHTML( $errMsg );
148 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
149 Xml
::openElement( 'fieldset' ) .
150 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
151 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
153 <td class='mw-label'>" .
154 wfMsgHtml( 'movearticle' ) .
156 <td class='mw-input'>
157 <strong>{$oldTitleLink}</strong>
161 <td class='mw-label'>" .
162 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
164 <td class='mw-input'>" .
165 Xml
::input( 'wpNewTitle', 40, $newTitle, array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
166 Xml
::hidden( 'wpOldTitle', $oldTitle ) .
170 <td class='mw-label'>" .
171 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
173 <td class='mw-input'>" .
174 Xml
::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason
) ) .
179 if ( $considerTalk ) {
183 <td class='mw-input'>" .
184 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk
) .
190 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' ) ||
$ot->userIsWatching();
194 <td class='mw-input'>" .
195 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
201 <td class='mw-submit'>" .
202 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
205 Xml
::closeElement( 'table' ) .
206 Xml
::hidden( 'wpEditToken', $token ) .
207 Xml
::closeElement( 'fieldset' ) .
208 Xml
::closeElement( 'form' ) .
212 $this->showLogFragment( $ot, $wgOut );
216 function doSubmit() {
217 global $wgOut, $wgUser, $wgRequest;
219 if ( $wgUser->pingLimiter( 'move' ) ) {
220 $wgOut->rateLimited();
224 # Variables beginning with 'o' for old article 'n' for new article
226 $ot = Title
::newFromText( $this->oldTitle
);
227 $nt = Title
::newFromText( $this->newTitle
);
229 # Delete to make way if requested
230 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
231 $article = new Article( $nt );
233 # Disallow deletions of big articles
234 $bigHistory = $article->isBigDeletion();
235 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
236 global $wgLang, $wgDeleteRevisionsLimit;
237 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
241 // This may output an error message and exit
242 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
245 # don't allow moving to pages with # in
246 if ( !$nt ||
$nt->getFragment() != '' ) {
247 $this->showForm( 'badtitletext' );
252 if( !wfRunHooks( 'AbortMove', array( $ot, $nt, $wgUser, &$hookErr ) ) ) {
253 $this->showForm( 'hookaborted', $hookErr );
257 $error = $ot->moveTo( $nt, true, $this->reason
);
258 if ( $error !== true ) {
259 $this->showForm( $error );
263 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
265 # Move the talk page if relevant, if it exists, and if we've been told to
266 $ott = $ot->getTalkPage();
267 if( $ott->exists() ) {
268 if( $this->moveTalk
&& !$ot->isTalkPage() && !$nt->isTalkPage() ) {
269 $ntt = $nt->getTalkPage();
272 $error = $ott->moveTo( $ntt, true, $this->reason
);
273 if ( $error === true ) {
275 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) );
280 # Stay silent on the subject of talk.
284 $talkmoved = 'notalkpage';
289 $wgUser->addWatch( $ot );
290 $wgUser->addWatch( $nt );
292 $wgUser->removeWatch( $ot );
293 $wgUser->removeWatch( $nt );
296 # Give back result to user.
297 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
298 $success = $titleObj->getFullURL(
299 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
300 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
301 '&talkmoved='.$talkmoved );
303 $wgOut->redirect( $success );
306 function showSuccess() {
307 global $wgOut, $wgRequest, $wgUser;
309 $old = Title
::newFromText( $wgRequest->getVal( 'oldtitle' ) );
310 $new = Title
::newFromText( $wgRequest->getVal( 'newtitle' ) );
312 if( is_null( $old ) ||
is_null( $new ) ) {
313 throw new ErrorPageError( 'badtitle', 'badtitletext' );
316 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
318 $talkmoved = $wgRequest->getVal( 'talkmoved' );
319 $oldUrl = $old->getFullUrl( 'redirect=no' );
320 $newUrl = $new->getFullUrl();
321 $oldText = $old->getPrefixedText();
322 $newText = $new->getPrefixedText();
323 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
324 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
326 $s = wfMsgNoTrans( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
328 if ( $talkmoved == 1 ) {
329 $s .= "\n\n" . wfMsgNoTrans( 'talkpagemoved' );
330 } elseif( 'articleexists' == $talkmoved ) {
331 $s .= "\n\n" . wfMsgNoTrans( 'talkexists' );
333 if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
334 $s .= "\n\n" . wfMsgNoTrans( 'talkpagenotmoved', wfMsgNoTrans( $talkmoved ) );
337 $wgOut->addWikiText( $s );
340 function showLogFragment( $title, &$out ) {
341 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
342 LogEventsList
::showLogExtract( $out, 'move', $title->getPrefixedText() );