* Further work on rev_deleted; changed to a bitfield with several data-hiding
[lhc/web/wiklou.git] / includes / SpecialMovepage.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * Constructor
10 */
11 function wfSpecialMovepage( $par = null ) {
12 global $wgUser, $wgOut, $wgRequest, $action, $wgOnlySysopMayMove;
13
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;
18 }
19 # We don't move protected pages
20 if ( wfReadOnly() ) {
21 $wgOut->readOnlyPage();
22 return;
23 }
24
25 $f = new MovePageForm( $par );
26
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( '' );
34 }
35 }
36
37 /**
38 *
39 * @package MediaWiki
40 * @subpackage SpecialPage
41 */
42 class MovePageForm {
43 var $oldTitle, $newTitle, $reason; # Text input
44 var $moveTalk, $deleteAndMove;
45
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' );
54 }
55
56 function showForm( $err ) {
57 global $wgOut, $wgUser;
58
59 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
60
61 $ot = Title::newFromURL( $this->oldTitle );
62 if( is_null( $ot ) ) {
63 $wgOut->errorpage( 'notargettitle', 'notargettext' );
64 return;
65 }
66 $oldTitle = $ot->getPrefixedText();
67
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;
83 }
84 }
85 }
86 $encNewTitle = htmlspecialchars( $this->newTitle );
87 }
88 $encReason = htmlspecialchars( $this->reason );
89
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;
108 }
109
110 if ( !$ot->isTalkPage() ) {
111 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
112 }
113
114 $movearticle = wfMsgHtml( 'movearticle' );
115 $newtitle = wfMsgHtml( 'newtitle' );
116 $movetalk = wfMsgHtml( 'movetalk' );
117 $movereason = wfMsgHtml( 'movereason' );
118
119 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
120 $action = $titleObj->escapeLocalURL( 'action=submit' );
121 $token = htmlspecialchars( $wgUser->editToken() );
122
123 if ( $err != '' ) {
124 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
125 $wgOut->addWikiText( '<p class="error">' . wfMsg($err) . "</p>\n" );
126 }
127
128 $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
129
130 $wgOut->addHTML( "
131 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
132 <table border='0'>
133 <tr>
134 <td align='right'>{$movearticle}:</td>
135 <td align='left'><strong>{$oldTitle}</strong></td>
136 </tr>
137 <tr>
138 <td align='right'><label for='wpNewTitle'>{$newtitle}:</label></td>
139 <td align='left'>
140 <input type='text' size='40' name='wpNewTitle' id='wpNewTitle' value=\"{$encNewTitle}\" />
141 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
142 </td>
143 </tr>
144 <tr>
145 <td align='right' valign='top'><br /><label for='wpReason'>{$movereason}:</label></td>
146 <td align='left' valign='top'><br />
147 <textarea cols='60' rows='2' name='wpReason' id='wpReason'>{$encReason}</textarea>
148 </td>
149 </tr>" );
150
151 if ( ! $ot->isTalkPage() ) {
152 $wgOut->addHTML( "
153 <tr>
154 <td align='right'>
155 <input type='checkbox' id=\"wpMovetalk\" name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
156 </td>
157 <td><label for=\"wpMovetalk\">{$movetalk}</label></td>
158 </tr>" );
159 }
160 $wgOut->addHTML( "
161 {$confirm}
162 <tr>
163 <td>&nbsp;</td>
164 <td align='left'>
165 <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
166 </td>
167 </tr>
168 </table>
169 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
170 </form>\n" );
171
172 }
173
174 function doSubmit() {
175 global $wgOut, $wgUser, $wgRequest;
176 $fname = "MovePageForm::doSubmit";
177
178 if ( $wgUser->pingLimiter( 'move' ) ) {
179 $wgOut->rateLimited();
180 return;
181 }
182
183 # Variables beginning with 'o' for old article 'n' for new article
184
185 $ot = Title::newFromText( $this->oldTitle );
186 $nt = Title::newFromText( $this->newTitle );
187
188 # Delete to make way if requested
189 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) {
190 $article = new Article( $nt );
191 // This may output an error message and exit
192 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
193 }
194
195 # don't allow moving to pages with # in
196 if ( !$nt || $nt->getFragment() != '' ) {
197 $this->showForm( 'badtitletext' );
198 return;
199 }
200
201 $error = $ot->moveTo( $nt, true, $this->reason );
202 if ( $error !== true ) {
203 $this->showForm( $error );
204 return;
205 }
206
207 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
208
209 # Move talk page if
210 # (1) the checkbox says to,
211 # (2) the namespaces are not themselves talk namespaces, and of course
212 # (3) it exists.
213 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
214 !$ot->isTalkPage() &&
215 !$nt->isTalkPage() ) {
216
217 $ott = $ot->getTalkPage();
218 $ntt = $nt->getTalkPage();
219
220 # Attempt the move
221 $error = $ott->moveTo( $ntt, true, $this->reason );
222 if ( $error === true ) {
223 $talkmoved = 1;
224 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) ) ;
225 } else {
226 $talkmoved = $error;
227 }
228 } else {
229 # Stay silent on the subject of talk.
230 $talkmoved = '';
231 }
232
233 # Give back result to user.
234 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
235 $success = $titleObj->getFullURL(
236 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
237 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
238 '&talkmoved='.$talkmoved );
239
240 $wgOut->redirect( $success );
241 }
242
243 function showSuccess() {
244 global $wgOut, $wgRequest, $wgRawHtml;
245
246 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
247 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
248
249 $oldText = $wgRequest->getVal('oldtitle');
250 $newText = $wgRequest->getVal('newtitle');
251 $talkmoved = $wgRequest->getVal('talkmoved');
252
253 $text = wfMsg( 'pagemovedtext', $oldText, $newText );
254
255 $allowHTML = $wgRawHtml;
256 $wgRawHtml = false;
257 $wgOut->addWikiText( $text );
258 $wgRawHtml = $allowHTML;
259
260 if ( $talkmoved == 1 ) {
261 $wgOut->addWikiText( wfMsg( 'talkpagemoved' ) );
262 } elseif( 'articleexists' == $talkmoved ) {
263 $wgOut->addWikiText( wfMsg( 'talkexists' ) );
264 } else {
265 $oldTitle = Title::newFromText( $oldText );
266 if ( !$oldTitle->isTalkPage() ) {
267 $wgOut->addWikiText( wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) );
268 }
269 }
270 }
271 }
272 ?>