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;
71 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
73 $ot = Title
::newFromURL( $this->oldTitle
);
74 if( is_null( $ot ) ) {
75 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
78 $oldTitle = $ot->getPrefixedText();
80 $encOldTitle = htmlspecialchars( $oldTitle );
81 if( $this->newTitle
== '' ) {
82 # Show the current title as a default
83 # when the form is first opened.
84 $encNewTitle = $encOldTitle;
87 $nt = Title
::newFromURL( $this->newTitle
);
89 # If a title was supplied, probably from the move log revert
90 # link, check for validity. We can then show some diagnostic
91 # information and save a click.
92 $newerr = $ot->isValidMoveOperation( $nt );
93 if( is_string( $newerr ) ) {
98 $encNewTitle = htmlspecialchars( $this->newTitle
);
100 $encReason = htmlspecialchars( $this->reason
);
102 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
103 $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
104 $movepagebtn = wfMsgHtml( 'delete_and_move' );
105 $confirmText = wfMsgHtml( 'delete_and_move_confirm' );
106 $submitVar = 'wpDeleteAndMove';
110 <input type='checkbox' name='wpConfirm' id='wpConfirm' value=\"true\" />
112 <td align='left'><label for='wpConfirm'>{$confirmText}</label></td>
116 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
117 $movepagebtn = wfMsgHtml( 'movepagebtn' );
118 $submitVar = 'wpMove';
122 $oldTalk = $ot->getTalkPage();
123 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
125 if ( $considerTalk ) {
126 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
129 $movearticle = wfMsgHtml( 'movearticle' );
130 $newtitle = wfMsgHtml( 'newtitle' );
131 $movetalk = wfMsgHtml( 'movetalk' );
132 $movereason = wfMsgHtml( 'movereason' );
134 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
135 $action = $titleObj->escapeLocalURL( 'action=submit' );
136 $token = htmlspecialchars( $wgUser->editToken() );
139 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
140 $wgOut->addWikiText( '<p class="error">' . wfMsg($err) . "</p>\n" );
143 $moveTalkChecked = $this->moveTalk ?
' checked="checked"' : '';
146 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
149 <td align='right'>{$movearticle}:</td>
150 <td align='left'><strong>{$oldTitle}</strong></td>
153 <td align='right'><label for='wpNewTitle'>{$newtitle}:</label></td>
155 <input type='text' size='40' name='wpNewTitle' id='wpNewTitle' value=\"{$encNewTitle}\" />
156 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
160 <td align='right' valign='top'><br /><label for='wpReason'>{$movereason}:</label></td>
161 <td align='left' valign='top'><br />
162 <textarea cols='60' rows='2' name='wpReason' id='wpReason'>{$encReason}</textarea>
166 if ( $considerTalk ) {
170 <input type='checkbox' id=\"wpMovetalk\" name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
172 <td><label for=\"wpMovetalk\">{$movetalk}</label></td>
176 $watchChecked = $this->watch ||
$wgUser->getBoolOption( 'watchmoves' ) ||
$ot->userIsWatching();
178 $watch .= '<td align="right">' . Xml
::check( 'wpWatch', $watchChecked, array( 'id' => 'watch' ) ) . '</td>';
179 $watch .= '<td>' . Xml
::label( wfMsg( 'move-watch' ), 'watch' ) . '</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' );
225 $error = $ot->moveTo( $nt, true, $this->reason
);
226 if ( $error !== true ) {
227 $this->showForm( $error );
231 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
233 # Move the talk page if relevant, if it exists, and if we've been told to
234 $ott = $ot->getTalkPage();
235 if( $ott->exists() ) {
236 if( $this->moveTalk
&& !$ot->isTalkPage() && !$nt->isTalkPage() ) {
237 $ntt = $nt->getTalkPage();
240 $error = $ott->moveTo( $ntt, true, $this->reason
);
241 if ( $error === true ) {
243 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) ) ;
248 # Stay silent on the subject of talk.
252 $talkmoved = 'notalkpage';
257 $wgUser->addWatch( $ot );
258 $wgUser->addWatch( $nt );
260 $wgUser->removeWatch( $ot );
261 $wgUser->removeWatch( $nt );
264 # Give back result to user.
265 $titleObj = SpecialPage
::getTitleFor( 'Movepage' );
266 $success = $titleObj->getFullURL(
267 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
268 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
269 '&talkmoved='.$talkmoved );
271 $wgOut->redirect( $success );
274 function showSuccess() {
275 global $wgOut, $wgRequest, $wgRawHtml;
277 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
278 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
280 $oldText = wfEscapeWikiText( $wgRequest->getVal('oldtitle') );
281 $newText = wfEscapeWikiText( $wgRequest->getVal('newtitle') );
282 $talkmoved = $wgRequest->getVal('talkmoved');
284 $text = wfMsg( 'pagemovedtext', $oldText, $newText );
286 $allowHTML = $wgRawHtml;
288 $wgOut->addWikiText( $text );
289 $wgRawHtml = $allowHTML;
291 if ( $talkmoved == 1 ) {
292 $wgOut->addWikiText( wfMsg( 'talkpagemoved' ) );
293 } elseif( 'articleexists' == $talkmoved ) {
294 $wgOut->addWikiText( wfMsg( 'talkexists' ) );
296 $oldTitle = Title
::newFromText( $oldText );
297 if ( isset( $oldTitle ) && !$oldTitle->isTalkPage() && $talkmoved != 'notalkpage' ) {
298 $wgOut->addWikiText( wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) );
303 function showLogFragment( $title, &$out ) {
304 $out->addHtml( wfElement( 'h2', NULL, LogPage
::logName( 'move' ) ) );
305 $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) );
306 $viewer = new LogViewer( new LogReader( $request ) );
307 $viewer->showList( $out );