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;
91 $encNewTitle = htmlspecialchars( $oldTitle );
94 $nt = Title
::newFromURL( $this->newTitle
);
96 # If a title was supplied, probably from the move log revert
97 # link, check for validity. We can then show some diagnostic
98 # information and save a click.
99 $newerr = $ot->isValidMoveOperation( $nt );
100 if( is_string( $newerr ) ) {
105 $newTitle = $this->newTitle
;
106 $encNewTitle = htmlspecialchars( $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';
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";
144 $errMsg = '<p><strong class="error">' . wfMsgWikiHtml( $err ) . "</strong></p>\n";
146 $wgOut->addHTML( $errMsg );
149 $moveTalkChecked = $this->moveTalk ?
' checked="checked"' : '';
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' ) ) .
158 wfMsgHtml( 'movearticle' ) .
161 <strong>{$oldTitleLink}</strong>
166 Xml
::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
168 <td align='$start'>" .
169 Xml
::input( 'wpNewTitle', 40, $this->newTitle
, array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
170 Xml
::hidden( 'wpOldTitle', $oldTitle ) .
174 <td align='$end' valign='top'><br />" .
175 Xml
::label( wfMsg( 'movereason' ), 'wpReason' ) .
177 <td align='$start' valign='top'><br />" .
178 Xml
::openElement( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ) ) .
179 htmlspecialchars( $this->reason
) .
180 Xml
::closeElement( 'textarea' ) .
185 if ( $considerTalk ) {
190 Xml
::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $moveTalkChecked ) .
196 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' ) ||
$ot->userIsWatching();
201 Xml
::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
207 <td align='$start'>" .
208 Xml
::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
211 Xml
::closeElement( 'table' ) .
212 Xml
::hidden( 'wpEditToken', $token ) .
213 Xml
::closeElement( 'fieldset' ) .
214 Xml
::closeElement( 'form' ) .
218 $this->showLogFragment( $ot, $wgOut );
222 function doSubmit() {
223 global $wgOut, $wgUser, $wgRequest;
225 if ( $wgUser->pingLimiter( 'move' ) ) {
226 $wgOut->rateLimited();
230 # Variables beginning with 'o' for old article 'n' for new article
232 $ot = Title
::newFromText( $this->oldTitle
);
233 $nt = Title
::newFromText( $this->newTitle
);
235 # Delete to make way if requested
236 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
237 $article = new Article( $nt );
238 // This may output an error message and exit
239 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
242 # don't allow moving to pages with # in
243 if ( !$nt ||
$nt->getFragment() != '' ) {
244 $this->showForm( 'badtitletext' );
249 if( !wfRunHooks( 'AbortMove', array( $ot, $nt, $wgUser, &$hookErr ) ) ) {
250 $this->showForm( 'hookaborted', $hookErr );
254 $error = $ot->moveTo( $nt, true, $this->reason
);
255 if ( $error !== true ) {
256 $this->showForm( $error );
260 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
262 # Move the talk page if relevant, if it exists, and if we've been told to
263 $ott = $ot->getTalkPage();
264 if( $ott->exists() ) {
265 if( $this->moveTalk
&& !$ot->isTalkPage() && !$nt->isTalkPage() ) {
266 $ntt = $nt->getTalkPage();
269 $error = $ott->moveTo( $ntt, true, $this->reason
);
270 if ( $error === true ) {
272 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) );
277 # Stay silent on the subject of talk.
281 $talkmoved = 'notalkpage';
286 $wgUser->addWatch( $ot );
287 $wgUser->addWatch( $nt );
289 $wgUser->removeWatch( $ot );
290 $wgUser->removeWatch( $nt );
293 # Give back result to user.
294 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
295 $success = $titleObj->getFullURL(
296 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
297 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
298 '&talkmoved='.$talkmoved );
300 $wgOut->redirect( $success );
303 function showSuccess() {
304 global $wgOut, $wgRequest, $wgUser;
306 $old = Title
::newFromText( $wgRequest->getVal( 'oldtitle' ) );
307 $new = Title
::newFromText( $wgRequest->getVal( 'newtitle' ) );
309 if( is_null( $old ) ||
is_null( $new ) ) {
310 throw new ErrorPageError( 'badtitle', 'badtitletext' );
313 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
315 $talkmoved = $wgRequest->getVal( 'talkmoved' );
316 $oldUrl = $old->getFullUrl( 'redirect=no' );
317 $newUrl = $new->getFullUrl();
318 $oldText = $old->getPrefixedText();
319 $newText = $new->getPrefixedText();
320 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
321 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
323 $s = wfMsgNoTrans( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
325 if ( $talkmoved == 1 ) {
326 $s .= "\n\n" . wfMsgNoTrans( 'talkpagemoved' );
327 } elseif( 'articleexists' == $talkmoved ) {
328 $s .= "\n\n" . wfMsgNoTrans( 'talkexists' );
330 if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
331 $s .= "\n\n" . wfMsgNoTrans( 'talkpagenotmoved', wfMsgNoTrans( $talkmoved ) );
334 $wgOut->addWikiText( $s );
337 function showLogFragment( $title, &$out ) {
338 $out->addHTML( wfElement( 'h2', NULL, LogPage
::logName( 'move' ) ) );
339 $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) );
340 $viewer = new LogViewer( new LogReader( $request ) );
341 $viewer->showList( $out );