Rights log changes:
[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->showErrorPage( "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->showErrorPage( '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 $oldTalk = $ot->getTalkPage();
111 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
112
113 if ( $considerTalk ) {
114 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
115 }
116
117 $movearticle = wfMsgHtml( 'movearticle' );
118 $newtitle = wfMsgHtml( 'newtitle' );
119 $movetalk = wfMsgHtml( 'movetalk' );
120 $movereason = wfMsgHtml( 'movereason' );
121
122 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
123 $action = $titleObj->escapeLocalURL( 'action=submit' );
124 $token = htmlspecialchars( $wgUser->editToken() );
125
126 if ( $err != '' ) {
127 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
128 $wgOut->addWikiText( '<p class="error">' . wfMsg($err) . "</p>\n" );
129 }
130
131 $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
132
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>" );
153
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>" );
162 }
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" );
174
175 }
176
177 function doSubmit() {
178 global $wgOut, $wgUser, $wgRequest;
179 $fname = "MovePageForm::doSubmit";
180
181 if ( $wgUser->pingLimiter( 'move' ) ) {
182 $wgOut->rateLimited();
183 return;
184 }
185
186 # Variables beginning with 'o' for old article 'n' for new article
187
188 $ot = Title::newFromText( $this->oldTitle );
189 $nt = Title::newFromText( $this->newTitle );
190
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' ) );
196 }
197
198 # don't allow moving to pages with # in
199 if ( !$nt || $nt->getFragment() != '' ) {
200 $this->showForm( 'badtitletext' );
201 return;
202 }
203
204 $error = $ot->moveTo( $nt, true, $this->reason );
205 if ( $error !== true ) {
206 $this->showForm( $error );
207 return;
208 }
209
210 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
211
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();
217
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;
225 }
226 } else {
227 # Stay silent on the subject of talk.
228 $talkmoved = '';
229 }
230 } else {
231 $talkmoved = 'notalkpage';
232 }
233
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 );
240
241 $wgOut->redirect( $success );
242 }
243
244 function showSuccess() {
245 global $wgOut, $wgRequest, $wgRawHtml;
246
247 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
248 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
249
250 $oldText = $wgRequest->getVal('oldtitle');
251 $newText = $wgRequest->getVal('newtitle');
252 $talkmoved = $wgRequest->getVal('talkmoved');
253
254 $text = wfMsg( 'pagemovedtext', $oldText, $newText );
255
256 $allowHTML = $wgRawHtml;
257 $wgRawHtml = false;
258 $wgOut->addWikiText( $text );
259 $wgRawHtml = $allowHTML;
260
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 ) ) );
269 }
270 }
271 }
272 }
273 ?>