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 $start = $wgContLang->isRTL() ?
'right' : 'left';
72 $end = $wgContLang->isRTL() ?
'left' : 'right';
74 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
76 $ot = Title
::newFromURL( $this->oldTitle
);
77 if( is_null( $ot ) ) {
78 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
81 $oldTitle = $ot->getPrefixedText();
83 $encOldTitle = htmlspecialchars( $oldTitle );
84 if( $this->newTitle
== '' ) {
85 # Show the current title as a default
86 # when the form is first opened.
87 $encNewTitle = $encOldTitle;
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 $encNewTitle = htmlspecialchars( $this->newTitle
);
103 $encReason = htmlspecialchars( $this->reason
);
105 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
106 $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
107 $movepagebtn = wfMsgHtml( 'delete_and_move' );
108 $submitVar = 'wpDeleteAndMove';
111 <td></td><td>" . Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) . "</td>
115 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
116 $movepagebtn = wfMsgHtml( 'movepagebtn' );
117 $submitVar = 'wpMove';
121 $oldTalk = $ot->getTalkPage();
122 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
124 if ( $considerTalk ) {
125 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
128 $movearticle = wfMsgHtml( 'movearticle' );
129 $newtitle = wfMsgHtml( 'newtitle' );
130 $movereason = wfMsgHtml( 'movereason' );
132 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
133 $action = $titleObj->escapeLocalURL( 'action=submit' );
134 $token = htmlspecialchars( $wgUser->editToken() );
137 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
139 if( $err == 'hookaborted' ) {
142 $errMsg = '<p class="error">' . wfMsgWikiHtml( $err ) . "</p>\n";
144 $wgOut->addHTML( $errMsg );
147 $moveTalkChecked = $this->moveTalk ?
' checked="checked"' : '';
150 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
153 <td align='$end'>{$movearticle}</td>
154 <td align='$start'><strong>{$oldTitle}</strong></td>
157 <td align='$end'><label for='wpNewTitle'>{$newtitle}</label></td>
159 <input type='text' size='40' name='wpNewTitle' id='wpNewTitle' value=\"{$encNewTitle}\" />
160 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
164 <td align='$end' valign='top'><br /><label for='wpReason'>{$movereason}</label></td>
165 <td align='$start' valign='top'><br />
166 <textarea cols='60' rows='2' name='wpReason' id='wpReason'>{$encReason}</textarea>
170 if ( $considerTalk ) {
173 <td></td><td>" . Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $moveTalkChecked ) . "</td>
177 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' ) ||
$ot->userIsWatching();
179 $watch .= '<td></td><td>' . Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) . '</td>';
181 $wgOut->addHtml( $watch );
188 <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
192 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
195 $this->showLogFragment( $ot, $wgOut );
199 function doSubmit() {
200 global $wgOut, $wgUser, $wgRequest;
202 if ( $wgUser->pingLimiter( 'move' ) ) {
203 $wgOut->rateLimited();
207 # Variables beginning with 'o' for old article 'n' for new article
209 $ot = Title
::newFromText( $this->oldTitle
);
210 $nt = Title
::newFromText( $this->newTitle
);
212 # Delete to make way if requested
213 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
214 $article = new Article( $nt );
215 // This may output an error message and exit
216 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
219 # don't allow moving to pages with # in
220 if ( !$nt ||
$nt->getFragment() != '' ) {
221 $this->showForm( 'badtitletext' );
226 if( !wfRunHooks( 'AbortMove', array( $ot, $nt, $wgUser, &$hookErr ) ) ) {
227 $this->showForm( 'hookaborted', $hookErr );
231 $error = $ot->moveTo( $nt, true, $this->reason
);
232 if ( $error !== true ) {
233 $this->showForm( $error );
237 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
239 # Move the talk page if relevant, if it exists, and if we've been told to
240 $ott = $ot->getTalkPage();
241 if( $ott->exists() ) {
242 if( $this->moveTalk
&& !$ot->isTalkPage() && !$nt->isTalkPage() ) {
243 $ntt = $nt->getTalkPage();
246 $error = $ott->moveTo( $ntt, true, $this->reason
);
247 if ( $error === true ) {
249 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) ) ;
254 # Stay silent on the subject of talk.
258 $talkmoved = 'notalkpage';
263 $wgUser->addWatch( $ot );
264 $wgUser->addWatch( $nt );
266 $wgUser->removeWatch( $ot );
267 $wgUser->removeWatch( $nt );
270 # Give back result to user.
271 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
272 $success = $titleObj->getFullURL(
273 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
274 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
275 '&talkmoved='.$talkmoved );
277 $wgOut->redirect( $success );
280 function showSuccess() {
281 global $wgOut, $wgRequest, $wgUser;
283 $old = Title
::newFromText( $wgRequest->getVal( 'oldtitle' ) );
284 $new = Title
::newFromText( $wgRequest->getVal( 'newtitle' ) );
286 if( is_null( $old ) ||
is_null( $new ) ) {
287 throw new ErrorPageError( 'badtitle', 'badtitletext' );
290 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
291 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
293 $talkmoved = $wgRequest->getVal( 'talkmoved' );
294 $oldUrl = $old->getFullUrl( 'redirect=no' );
295 $newUrl = $new->getFullURl();
296 $oldText = wfEscapeWikiText( $old->getPrefixedText() );
297 $newText = wfEscapeWikiText( $new->getPrefixedText() );
298 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
299 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
301 $s = wfMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
303 if ( $talkmoved == 1 ) {
304 $s .= "\n\n" . wfMsg( 'talkpagemoved' );
305 } elseif( 'articleexists' == $talkmoved ) {
306 $s .= "\n\n" . wfMsg( 'talkexists' );
308 if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
309 $s .= "\n\n" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) );
312 $wgOut->addWikiText( $s );
315 function showLogFragment( $title, &$out ) {
316 $out->addHtml( wfElement( 'h2', NULL, LogPage
::logName( 'move' ) ) );
317 $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) );
318 $viewer = new LogViewer( new LogReader( $request ) );
319 $viewer->showList( $out );