redundant file removal
[mediawiki.git] / includes / SpecialMovepage.php
blob4f795c2b81669dff3996dcd5717406963b0c4df7
1 <?php
2 /**
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
8 /**
9 * Constructor
11 function wfSpecialMovepage( $par = null ) {
12 global $wgUser, $wgOut, $wgRequest, $action, $wgOnlySysopMayMove;
14 # check rights. We don't want newbies to move pages to prevents possible attack
15 if ( !$wgUser->isAllowed( 'move' ) or $wgUser->isBlocked() or ($wgOnlySysopMayMove and $wgUser->isNewbie())) {
16 $wgOut->errorpage( "movenologin", "movenologintext" );
17 return;
19 # We don't move protected pages
20 if ( wfReadOnly() ) {
21 $wgOut->readOnlyPage();
22 return;
25 $f = new MovePageForm( $par );
27 if ( 'success' == $action ) {
28 $f->showSuccess();
29 } else if ( 'submit' == $action && $wgRequest->wasPosted()
30 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
31 $f->doSubmit();
32 } else {
33 $f->showForm( '' );
37 /**
39 * @package MediaWiki
40 * @subpackage SpecialPage
42 class MovePageForm {
43 var $oldTitle, $newTitle, $reason; # Text input
44 var $moveTalk, $deleteAndMove;
46 function MovePageForm( $par ) {
47 global $wgRequest;
48 $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
49 $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $target );
50 $this->newTitle = $wgRequest->getText( 'wpNewTitle' );
51 $this->reason = $wgRequest->getText( 'wpReason' );
52 $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
53 $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
56 function showForm( $err ) {
57 global $wgOut, $wgUser;
59 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
61 $ot = Title::newFromURL( $this->oldTitle );
62 if( is_null( $ot ) ) {
63 $wgOut->errorpage( 'notargettitle', 'notargettext' );
64 return;
66 $oldTitle = $ot->getPrefixedText();
68 $encOldTitle = htmlspecialchars( $oldTitle );
69 if( $this->newTitle == '' ) {
70 # Show the current title as a default
71 # when the form is first opened.
72 $encNewTitle = $encOldTitle;
73 } else {
74 if( $err == '' ) {
75 $nt = Title::newFromURL( $this->newTitle );
76 if( $nt ) {
77 # If a title was supplied, probably from the move log revert
78 # link, check for validity. We can then show some diagnostic
79 # information and save a click.
80 $newerr = $ot->isValidMoveOperation( $nt );
81 if( is_string( $newerr ) ) {
82 $err = $newerr;
86 $encNewTitle = htmlspecialchars( $this->newTitle );
88 $encReason = htmlspecialchars( $this->reason );
90 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
91 $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
92 $movepagebtn = wfMsgHtml( 'delete_and_move' );
93 $confirmText = wfMsgHtml( 'delete_and_move_confirm' );
94 $submitVar = 'wpDeleteAndMove';
95 $confirm = "
96 <tr>
97 <td align='right'>
98 <input type='checkbox' name='wpConfirm' id='wpConfirm' value=\"true\" />
99 </td>
100 <td align='left'><label for='wpConfirm'>{$confirmText}</label></td>
101 </tr>";
102 $err = '';
103 } else {
104 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
105 $movepagebtn = wfMsgHtml( 'movepagebtn' );
106 $submitVar = 'wpMove';
107 $confirm = false;
110 $oldTalk = $ot->getTalkPage();
111 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
113 if ( $considerTalk ) {
114 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
117 $movearticle = wfMsgHtml( 'movearticle' );
118 $newtitle = wfMsgHtml( 'newtitle' );
119 $movetalk = wfMsgHtml( 'movetalk' );
120 $movereason = wfMsgHtml( 'movereason' );
122 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
123 $action = $titleObj->escapeLocalURL( 'action=submit' );
124 $token = htmlspecialchars( $wgUser->editToken() );
126 if ( $err != '' ) {
127 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
128 $wgOut->addWikiText( '<p class="error">' . wfMsg($err) . "</p>\n" );
131 $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
133 $wgOut->addHTML( "
134 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
135 <table border='0'>
136 <tr>
137 <td align='right'>{$movearticle}:</td>
138 <td align='left'><strong>{$oldTitle}</strong></td>
139 </tr>
140 <tr>
141 <td align='right'><label for='wpNewTitle'>{$newtitle}:</label></td>
142 <td align='left'>
143 <input type='text' size='40' name='wpNewTitle' id='wpNewTitle' value=\"{$encNewTitle}\" />
144 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
145 </td>
146 </tr>
147 <tr>
148 <td align='right' valign='top'><br /><label for='wpReason'>{$movereason}:</label></td>
149 <td align='left' valign='top'><br />
150 <textarea cols='60' rows='2' name='wpReason' id='wpReason'>{$encReason}</textarea>
151 </td>
152 </tr>" );
154 if ( $considerTalk ) {
155 $wgOut->addHTML( "
156 <tr>
157 <td align='right'>
158 <input type='checkbox' id=\"wpMovetalk\" name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
159 </td>
160 <td><label for=\"wpMovetalk\">{$movetalk}</label></td>
161 </tr>" );
163 $wgOut->addHTML( "
164 {$confirm}
165 <tr>
166 <td>&nbsp;</td>
167 <td align='left'>
168 <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
169 </td>
170 </tr>
171 </table>
172 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
173 </form>\n" );
177 function doSubmit() {
178 global $wgOut, $wgUser, $wgRequest;
179 $fname = "MovePageForm::doSubmit";
181 if ( $wgUser->pingLimiter( 'move' ) ) {
182 $wgOut->rateLimited();
183 return;
186 # Variables beginning with 'o' for old article 'n' for new article
188 $ot = Title::newFromText( $this->oldTitle );
189 $nt = Title::newFromText( $this->newTitle );
191 # Delete to make way if requested
192 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) {
193 $article = new Article( $nt );
194 // This may output an error message and exit
195 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
198 # don't allow moving to pages with # in
199 if ( !$nt || $nt->getFragment() != '' ) {
200 $this->showForm( 'badtitletext' );
201 return;
204 $error = $ot->moveTo( $nt, true, $this->reason );
205 if ( $error !== true ) {
206 $this->showForm( $error );
207 return;
210 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
212 # Move the talk page if relevant, if it exists, and if we've been told to
213 $ott = $ot->getTalkPage();
214 if( $ott->exists() ) {
215 if( $wgRequest->getVal( 'wpMovetalk' ) == 1 && !$ot->isTalkPage() && !$nt->isTalkPage() ) {
216 $ntt = $nt->getTalkPage();
218 # Attempt the move
219 $error = $ott->moveTo( $ntt, true, $this->reason );
220 if ( $error === true ) {
221 $talkmoved = 1;
222 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) ) ;
223 } else {
224 $talkmoved = $error;
226 } else {
227 # Stay silent on the subject of talk.
228 $talkmoved = '';
230 } else {
231 $talkmoved = 'notalkpage';
234 # Give back result to user.
235 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
236 $success = $titleObj->getFullURL(
237 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
238 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
239 '&talkmoved='.$talkmoved );
241 $wgOut->redirect( $success );
244 function showSuccess() {
245 global $wgOut, $wgRequest, $wgRawHtml;
247 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
248 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
250 $oldText = $wgRequest->getVal('oldtitle');
251 $newText = $wgRequest->getVal('newtitle');
252 $talkmoved = $wgRequest->getVal('talkmoved');
254 $text = wfMsg( 'pagemovedtext', $oldText, $newText );
256 $allowHTML = $wgRawHtml;
257 $wgRawHtml = false;
258 $wgOut->addWikiText( $text );
259 $wgRawHtml = $allowHTML;
261 if ( $talkmoved == 1 ) {
262 $wgOut->addWikiText( wfMsg( 'talkpagemoved' ) );
263 } elseif( 'articleexists' == $talkmoved ) {
264 $wgOut->addWikiText( wfMsg( 'talkexists' ) );
265 } else {
266 $oldTitle = Title::newFromText( $oldText );
267 if ( !$oldTitle->isTalkPage() && $talkmoved != 'notalkpage' ) {
268 $wgOut->addWikiText( wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) );