4 * @addtogroup SpecialPage
10 function wfSpecialMovepage( $par = null ) {
11 global $wgUser, $wgOut, $wgRequest, $action;
14 if ( !$wgUser->isAllowed( 'move' ) ) {
15 $wgOut->showErrorPage( 'movenologin', 'movenologintext' );
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 ) {
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 $confirmText = wfMsgHtml( 'delete_and_move_confirm' );
109 $submitVar = 'wpDeleteAndMove';
113 <input type='checkbox' name='wpConfirm' id='wpConfirm' value=\"true\" />
115 <td align='$start'><label for='wpConfirm'>{$confirmText}</label></td>
119 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
120 $movepagebtn = wfMsgHtml( 'movepagebtn' );
121 $submitVar = 'wpMove';
125 $oldTalk = $ot->getTalkPage();
126 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
128 if ( $considerTalk ) {
129 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
132 $movearticle = wfMsgHtml( 'movearticle' );
133 $newtitle = wfMsgHtml( 'newtitle' );
134 $movetalk = wfMsgHtml( 'movetalk' );
135 $movereason = wfMsgHtml( 'movereason' );
137 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
138 $action = $titleObj->escapeLocalURL( 'action=submit' );
139 $token = htmlspecialchars( $wgUser->editToken() );
142 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
143 $wgOut->addWikiText( '<p class="error">' . wfMsg($err) . "</p>\n" );
146 $moveTalkChecked = $this->moveTalk ?
' checked="checked"' : '';
149 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
152 <td align='$end'>{$movearticle}:</td>
153 <td align='$start'><strong>{$oldTitle}</strong></td>
156 <td align='$end'><label for='wpNewTitle'>{$newtitle}:</label></td>
158 <input type='text' size='40' name='wpNewTitle' id='wpNewTitle' value=\"{$encNewTitle}\" />
159 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
163 <td align='$end' valign='top'><br /><label for='wpReason'>{$movereason}:</label></td>
164 <td align='$start' valign='top'><br />
165 <textarea cols='60' rows='2' name='wpReason' id='wpReason'>{$encReason}</textarea>
169 if ( $considerTalk ) {
173 <input type='checkbox' id=\"wpMovetalk\" name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
175 <td><label for=\"wpMovetalk\">{$movetalk}</label></td>
179 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' ) ||
$ot->userIsWatching();
181 $watch .= "<td align=\"$end\">" . Xml
::check( 'wpWatch', $watchChecked, array( 'id' => 'watch' ) ) . '</td>';
182 $watch .= '<td>' . Xml
::label( wfMsg( 'move-watch' ), 'watch' ) . '</td>';
184 $wgOut->addHtml( $watch );
191 <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
195 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
198 $this->showLogFragment( $ot, $wgOut );
202 function doSubmit() {
203 global $wgOut, $wgUser, $wgRequest;
205 if ( $wgUser->pingLimiter( 'move' ) ) {
206 $wgOut->rateLimited();
210 # Variables beginning with 'o' for old article 'n' for new article
212 $ot = Title
::newFromText( $this->oldTitle
);
213 $nt = Title
::newFromText( $this->newTitle
);
215 # Delete to make way if requested
216 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
217 $article = new Article( $nt );
218 // This may output an error message and exit
219 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
222 # don't allow moving to pages with # in
223 if ( !$nt ||
$nt->getFragment() != '' ) {
224 $this->showForm( 'badtitletext' );
228 $error = $ot->moveTo( $nt, true, $this->reason
);
229 if ( $error !== true ) {
230 $this->showForm( $error );
234 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
236 # Move the talk page if relevant, if it exists, and if we've been told to
237 $ott = $ot->getTalkPage();
238 if( $ott->exists() ) {
239 if( $this->moveTalk
&& !$ot->isTalkPage() && !$nt->isTalkPage() ) {
240 $ntt = $nt->getTalkPage();
243 $error = $ott->moveTo( $ntt, true, $this->reason
);
244 if ( $error === true ) {
246 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) ) ;
251 # Stay silent on the subject of talk.
255 $talkmoved = 'notalkpage';
260 $wgUser->addWatch( $ot );
261 $wgUser->addWatch( $nt );
263 $wgUser->removeWatch( $ot );
264 $wgUser->removeWatch( $nt );
267 # Give back result to user.
268 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
269 $success = $titleObj->getFullURL(
270 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
271 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
272 '&talkmoved='.$talkmoved );
274 $wgOut->redirect( $success );
277 function showSuccess() {
278 global $wgOut, $wgRequest, $wgRawHtml;
280 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
281 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
283 $oldText = wfEscapeWikiText( $wgRequest->getVal('oldtitle') );
284 $newText = wfEscapeWikiText( $wgRequest->getVal('newtitle') );
285 $talkmoved = $wgRequest->getVal('talkmoved');
287 $text = wfMsg( 'pagemovedtext', $oldText, $newText );
289 $allowHTML = $wgRawHtml;
291 $wgOut->addWikiText( $text );
292 $wgRawHtml = $allowHTML;
294 if ( $talkmoved == 1 ) {
295 $wgOut->addWikiText( wfMsg( 'talkpagemoved' ) );
296 } elseif( 'articleexists' == $talkmoved ) {
297 $wgOut->addWikiText( wfMsg( 'talkexists' ) );
299 $oldTitle = Title
::newFromText( $oldText );
300 if ( isset( $oldTitle ) && !$oldTitle->isTalkPage() && $talkmoved != 'notalkpage' ) {
301 $wgOut->addWikiText( wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) );
306 function showLogFragment( $title, &$out ) {
307 $out->addHtml( wfElement( 'h2', NULL, LogPage
::logName( 'move' ) ) );
308 $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) );
309 $viewer = new LogViewer( new LogReader( $request ) );
310 $viewer->showList( $out );