8addbd62edc97b8bc2769c883e59cf2b6fd7bf0c
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";
142 $errMsg = '<p><strong class="error">' . wfMsgWikiHtml( $err ) . "</strong></p>\n";
144 $wgOut->addHTML( $errMsg );
147 $moveTalkChecked = $this->moveTalk ?
' checked="checked"' : '';
150 Xml
::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
151 Xml
::openElement( 'fieldset' ) .
152 Xml
::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
153 Xml
::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
156 wfMsgHtml( 'movearticle' ) .
159 <strong>{$oldTitleLink}</strong>
164 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
166 <td align='$start'>" .
167 Xml
::input( 'wpNewTitle', 40, $newTitle, array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
168 Xml
::hidden( 'wpOldTitle', $oldTitle ) .
172 <td align='$end' valign='top'><br />" .
173 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
175 <td align='$start' valign='top'><br />" .
176 Xml
::openElement( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ) ) .
177 htmlspecialchars( $this->reason
) .
178 Xml
::closeElement( 'textarea' ) .
183 if ( $considerTalk ) {
188 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $moveTalkChecked ) .
194 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' ) ||
$ot->userIsWatching();
199 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
205 <td align='$start'>" .
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 );
236 // This may output an error message and exit
237 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
240 # don't allow moving to pages with # in
241 if ( !$nt ||
$nt->getFragment() != '' ) {
242 $this->showForm( 'badtitletext' );
247 if( !wfRunHooks( 'AbortMove', array( $ot, $nt, $wgUser, &$hookErr ) ) ) {
248 $this->showForm( 'hookaborted', $hookErr );
252 $error = $ot->moveTo( $nt, true, $this->reason
);
253 if ( $error !== true ) {
254 $this->showForm( $error );
258 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
260 # Move the talk page if relevant, if it exists, and if we've been told to
261 $ott = $ot->getTalkPage();
262 if( $ott->exists() ) {
263 if( $this->moveTalk
&& !$ot->isTalkPage() && !$nt->isTalkPage() ) {
264 $ntt = $nt->getTalkPage();
267 $error = $ott->moveTo( $ntt, true, $this->reason
);
268 if ( $error === true ) {
270 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) );
275 # Stay silent on the subject of talk.
279 $talkmoved = 'notalkpage';
284 $wgUser->addWatch( $ot );
285 $wgUser->addWatch( $nt );
287 $wgUser->removeWatch( $ot );
288 $wgUser->removeWatch( $nt );
291 # Give back result to user.
292 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
293 $success = $titleObj->getFullURL(
294 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
295 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
296 '&talkmoved='.$talkmoved );
298 $wgOut->redirect( $success );
301 function showSuccess() {
302 global $wgOut, $wgRequest, $wgUser;
304 $old = Title
::newFromText( $wgRequest->getVal( 'oldtitle' ) );
305 $new = Title
::newFromText( $wgRequest->getVal( 'newtitle' ) );
307 if( is_null( $old ) ||
is_null( $new ) ) {
308 throw new ErrorPageError( 'badtitle', 'badtitletext' );
311 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
313 $talkmoved = $wgRequest->getVal( 'talkmoved' );
314 $oldUrl = $old->getFullUrl( 'redirect=no' );
315 $newUrl = $new->getFullUrl();
316 $oldText = $old->getPrefixedText();
317 $newText = $new->getPrefixedText();
318 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
319 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
321 $s = wfMsgNoTrans( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
323 if ( $talkmoved == 1 ) {
324 $s .= "\n\n" . wfMsgNoTrans( 'talkpagemoved' );
325 } elseif( 'articleexists' == $talkmoved ) {
326 $s .= "\n\n" . wfMsgNoTrans( 'talkexists' );
328 if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
329 $s .= "\n\n" . wfMsgNoTrans( 'talkpagenotmoved', wfMsgNoTrans( $talkmoved ) );
332 $wgOut->addWikiText( $s );
335 function showLogFragment( $title, &$out ) {
336 $out->addHTML( Xml
::element( 'h2', NULL, LogPage
::logName( 'move' ) ) );
337 $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) );
338 $viewer = new LogViewer( new LogReader( $request ) );
339 $viewer->showList( $out );