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 $sk = $wgUser->getSkin();
82 $oldTitleLink = $sk->makeLinkObj( $ot );
83 $oldTitle = $ot->getPrefixedText();
85 $encOldTitle = htmlspecialchars( $oldTitle );
86 if( $this->newTitle
== '' ) {
87 # Show the current title as a default
88 # when the form is first opened.
89 $newTitle = $oldTitle;
90 $encNewTitle = $encOldTitle;
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
;
105 $encNewTitle = htmlspecialchars( $newTitle );
107 $encReason = htmlspecialchars( $this->reason
);
109 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
110 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle );
111 $movepagebtn = wfMsgHtml( 'delete_and_move' );
112 $submitVar = 'wpDeleteAndMove';
115 <td></td><td>" . Xml
::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) . "</td>
119 $wgOut->addWikiMsg( 'movepagetext' );
120 $movepagebtn = wfMsgHtml( 'movepagebtn' );
121 $submitVar = 'wpMove';
125 $oldTalk = $ot->getTalkPage();
126 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
128 if ( $considerTalk ) {
129 $wgOut->addWikiMsg( 'movepagetalktext' );
132 $movearticle = wfMsgHtml( 'movearticle' );
133 $newtitle = wfMsgHtml( 'newtitle' );
134 $movereason = wfMsgHtml( 'movereason' );
136 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
137 $action = $titleObj->escapeLocalURL( 'action=submit' );
138 $token = htmlspecialchars( $wgUser->editToken() );
141 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
143 if( $err == 'hookaborted' ) {
144 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
146 $errMsg = '<p><strong class="error">' . wfMsgWikiHtml( $err ) . "</strong></p>\n";
148 $wgOut->addHTML( $errMsg );
151 $moveTalkChecked = $this->moveTalk ?
' checked="checked"' : '';
154 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
157 <td align='$end'>{$movearticle}</td>
158 <td align='$start'><strong>{$oldTitleLink}</strong></td>
161 <td align='$end'><label for='wpNewTitle'>{$newtitle}</label></td>
163 <input type='text' size='40' name='wpNewTitle' id='wpNewTitle' value=\"{$encNewTitle}\" />
164 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
168 <td align='$end' valign='top'><br /><label for='wpReason'>{$movereason}</label></td>
169 <td align='$start' valign='top'><br />
170 <textarea cols='60' rows='2' name='wpReason' id='wpReason'>{$encReason}</textarea>
174 if ( $considerTalk ) {
177 <td></td><td>" . Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $moveTalkChecked ) . "</td>
181 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' ) ||
$ot->userIsWatching();
183 $watch .= '<td></td><td>' . Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) . '</td>';
185 $wgOut->addHtml( $watch );
192 <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
196 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
199 $this->showLogFragment( $ot, $wgOut );
203 function doSubmit() {
204 global $wgOut, $wgUser, $wgRequest;
206 if ( $wgUser->pingLimiter( 'move' ) ) {
207 $wgOut->rateLimited();
211 # Variables beginning with 'o' for old article 'n' for new article
213 $ot = Title
::newFromText( $this->oldTitle
);
214 $nt = Title
::newFromText( $this->newTitle
);
216 # Delete to make way if requested
217 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
218 $article = new Article( $nt );
219 // This may output an error message and exit
220 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
223 # don't allow moving to pages with # in
224 if ( !$nt ||
$nt->getFragment() != '' ) {
225 $this->showForm( 'badtitletext' );
230 if( !wfRunHooks( 'AbortMove', array( $ot, $nt, $wgUser, &$hookErr ) ) ) {
231 $this->showForm( 'hookaborted', $hookErr );
235 $error = $ot->moveTo( $nt, true, $this->reason
);
236 if ( $error !== true ) {
237 $this->showForm( $error );
241 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
243 # Move the talk page if relevant, if it exists, and if we've been told to
244 $ott = $ot->getTalkPage();
245 if( $ott->exists() ) {
246 if( $this->moveTalk
&& !$ot->isTalkPage() && !$nt->isTalkPage() ) {
247 $ntt = $nt->getTalkPage();
250 $error = $ott->moveTo( $ntt, true, $this->reason
);
251 if ( $error === true ) {
253 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) ) ;
258 # Stay silent on the subject of talk.
262 $talkmoved = 'notalkpage';
267 $wgUser->addWatch( $ot );
268 $wgUser->addWatch( $nt );
270 $wgUser->removeWatch( $ot );
271 $wgUser->removeWatch( $nt );
274 # Give back result to user.
275 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
276 $success = $titleObj->getFullURL(
277 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
278 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
279 '&talkmoved='.$talkmoved );
281 $wgOut->redirect( $success );
284 function showSuccess() {
285 global $wgOut, $wgRequest, $wgUser;
287 $old = Title
::newFromText( $wgRequest->getVal( 'oldtitle' ) );
288 $new = Title
::newFromText( $wgRequest->getVal( 'newtitle' ) );
290 if( is_null( $old ) ||
is_null( $new ) ) {
291 throw new ErrorPageError( 'badtitle', 'badtitletext' );
294 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
295 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
297 $talkmoved = $wgRequest->getVal( 'talkmoved' );
298 $oldUrl = $old->getFullUrl( 'redirect=no' );
299 $newUrl = $new->getFullUrl();
300 $oldText = $old->getPrefixedText();
301 $newText = $new->getPrefixedText();
302 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
303 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
305 $s = wfMsgNoTrans( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
307 if ( $talkmoved == 1 ) {
308 $s .= "\n\n" . wfMsgNoTrans( 'talkpagemoved' );
309 } elseif( 'articleexists' == $talkmoved ) {
310 $s .= "\n\n" . wfMsgNoTrans( 'talkexists' );
312 if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
313 $s .= "\n\n" . wfMsgNoTrans( 'talkpagenotmoved', wfMsgNoTrans( $talkmoved ) );
316 $wgOut->addWikiText( $s );
319 function showLogFragment( $title, &$out ) {
320 $out->addHtml( wfElement( 'h2', NULL, LogPage
::logName( 'move' ) ) );
321 $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) );
322 $viewer = new LogViewer( new LogReader( $request ) );
323 $viewer->showList( $out );