Link to docs/magicword.txt
[lhc/web/wiklou.git] / includes / SpecialMovepage.php
1 <?php
2 /**
3 *
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 * Constructor
9 */
10 function wfSpecialMovepage( $par = null ) {
11 global $wgUser, $wgOut, $wgRequest, $action;
12
13 # Check rights
14 if ( !$wgUser->isAllowed( 'move' ) ) {
15 $wgOut->showPermissionsErrorPage( array( $wgUser->isAnon() ? 'movenologintext' : 'movenotallowed' ) );
16 return;
17 }
18
19 # Don't allow blocked users to move pages
20 if ( $wgUser->isBlocked() ) {
21 $wgOut->blockedPage();
22 return;
23 }
24
25 # Check for database lock
26 if ( wfReadOnly() ) {
27 $wgOut->readOnlyPage();
28 return;
29 }
30
31 $f = new MovePageForm( $par );
32
33 if ( 'success' == $action ) {
34 $f->showSuccess();
35 } else if ( 'submit' == $action && $wgRequest->wasPosted()
36 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
37 $f->doSubmit();
38 } else {
39 $f->showForm( '' );
40 }
41 }
42
43 /**
44 * HTML form for Special:Movepage
45 * @addtogroup SpecialPage
46 */
47 class MovePageForm {
48 var $oldTitle, $newTitle, $reason; # Text input
49 var $moveTalk, $deleteAndMove;
50
51 private $watch = false;
52
53 function MovePageForm( $par ) {
54 global $wgRequest;
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 );
61 } else {
62 $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
63 }
64 $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
65 $this->watch = $wgRequest->getCheck( 'wpWatch' );
66 }
67
68 function showForm( $err, $hookErr = '' ) {
69 global $wgOut, $wgUser, $wgContLang;
70
71 $ot = Title::newFromURL( $this->oldTitle );
72 if( is_null( $ot ) ) {
73 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
74 return;
75 }
76
77 $start = $wgContLang->isRTL() ? 'right' : 'left';
78 $end = $wgContLang->isRTL() ? 'left' : 'right';
79 $sk = $wgUser->getSkin();
80
81 $oldTitleLink = $sk->makeLinkObj( $ot );
82 $oldTitle = $ot->getPrefixedText();
83
84 $wgOut->setPagetitle( wfMsg( 'move-page', $oldTitle ) );
85 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
86
87 if( $this->newTitle == '' ) {
88 # Show the current title as a default
89 # when the form is first opened.
90 $newTitle = $oldTitle;
91 $encNewTitle = htmlspecialchars( $oldTitle );
92 } else {
93 if( $err == '' ) {
94 $nt = Title::newFromURL( $this->newTitle );
95 if( $nt ) {
96 # If a title was supplied, probably from the move log revert
97 # link, check for validity. We can then show some diagnostic
98 # information and save a click.
99 $newerr = $ot->isValidMoveOperation( $nt );
100 if( is_string( $newerr ) ) {
101 $err = $newerr;
102 }
103 }
104 }
105 $newTitle = $this->newTitle;
106 $encNewTitle = htmlspecialchars( $newTitle );
107 }
108
109 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
110 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle );
111 $movepagebtn = wfMsg( 'delete_and_move' );
112 $submitVar = 'wpDeleteAndMove';
113 $confirm = "
114 <tr>
115 <td></td>
116 <td>" .
117 Xml::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
118 "</td>
119 </tr>";
120 $err = '';
121 } else {
122 $wgOut->addWikiMsg( 'movepagetext' );
123 $movepagebtn = wfMsg( 'movepagebtn' );
124 $submitVar = 'wpMove';
125 $confirm = false;
126 }
127
128 $oldTalk = $ot->getTalkPage();
129 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
130
131 if ( $considerTalk ) {
132 $wgOut->addWikiMsg( 'movepagetalktext' );
133 }
134
135 $titleObj = SpecialPage::getTitleFor( 'Movepage' );
136 $token = htmlspecialchars( $wgUser->editToken() );
137
138 if ( $err != '' ) {
139 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
140 $errMsg = "";
141 if( $err == 'hookaborted' ) {
142 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
143 } else {
144 $errMsg = '<p><strong class="error">' . wfMsgWikiHtml( $err ) . "</strong></p>\n";
145 }
146 $wgOut->addHTML( $errMsg );
147 }
148
149 $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
150
151 $wgOut->addHTML(
152 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
153 Xml::openElement( 'fieldset' ) .
154 Xml::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
155 Xml::openElement( 'table', array( 'border' => '0' ) ) .
156 "<tr>
157 <td align='$end'>" .
158 wfMsgHtml( 'movearticle' ) .
159 "</td>
160 <td align='$start'>
161 <strong>{$oldTitleLink}</strong>
162 </td>
163 </tr>
164 <tr>
165 <td align='$end'>" .
166 Xml::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
167 "</td>
168 <td align='$start'>" .
169 Xml::input( 'wpNewTitle', 40, $this->newTitle, array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
170 Xml::hidden( 'wpOldTitle', $oldTitle ) .
171 "</td>
172 </tr>
173 <tr>
174 <td align='$end' valign='top'><br />" .
175 Xml::label( wfMsg( 'movereason' ), 'wpReason' ) .
176 "</td>
177 <td align='$start' valign='top'><br />" .
178 Xml::openElement( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ) ) .
179 htmlspecialchars( $this->reason ) .
180 Xml::closeElement( 'textarea' ) .
181 "</td>
182 </tr>"
183 );
184
185 if ( $considerTalk ) {
186 $wgOut->addHTML( "
187 <tr>
188 <td></td>
189 <td>" .
190 Xml::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $moveTalkChecked ) .
191 "</td>
192 </tr>"
193 );
194 }
195
196 $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) || $ot->userIsWatching();
197 $wgOut->addHTML( "
198 <tr>
199 <td></td>
200 <td>" .
201 Xml::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
202 "</td>
203 </tr>
204 {$confirm}
205 <tr>
206 <td>&nbsp;</td>
207 <td align='$start'>" .
208 Xml::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
209 "</td>
210 </tr>" .
211 Xml::closeElement( 'table' ) .
212 Xml::hidden( 'wpEditToken', $token ) .
213 Xml::closeElement( 'fieldset' ) .
214 Xml::closeElement( 'form' ) .
215 "\n"
216 );
217
218 $this->showLogFragment( $ot, $wgOut );
219
220 }
221
222 function doSubmit() {
223 global $wgOut, $wgUser, $wgRequest;
224
225 if ( $wgUser->pingLimiter( 'move' ) ) {
226 $wgOut->rateLimited();
227 return;
228 }
229
230 # Variables beginning with 'o' for old article 'n' for new article
231
232 $ot = Title::newFromText( $this->oldTitle );
233 $nt = Title::newFromText( $this->newTitle );
234
235 # Delete to make way if requested
236 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) {
237 $article = new Article( $nt );
238 // This may output an error message and exit
239 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
240 }
241
242 # don't allow moving to pages with # in
243 if ( !$nt || $nt->getFragment() != '' ) {
244 $this->showForm( 'badtitletext' );
245 return;
246 }
247
248 $hookErr = null;
249 if( !wfRunHooks( 'AbortMove', array( $ot, $nt, $wgUser, &$hookErr ) ) ) {
250 $this->showForm( 'hookaborted', $hookErr );
251 return;
252 }
253
254 $error = $ot->moveTo( $nt, true, $this->reason );
255 if ( $error !== true ) {
256 $this->showForm( $error );
257 return;
258 }
259
260 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
261
262 # Move the talk page if relevant, if it exists, and if we've been told to
263 $ott = $ot->getTalkPage();
264 if( $ott->exists() ) {
265 if( $this->moveTalk && !$ot->isTalkPage() && !$nt->isTalkPage() ) {
266 $ntt = $nt->getTalkPage();
267
268 # Attempt the move
269 $error = $ott->moveTo( $ntt, true, $this->reason );
270 if ( $error === true ) {
271 $talkmoved = 1;
272 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) );
273 } else {
274 $talkmoved = $error;
275 }
276 } else {
277 # Stay silent on the subject of talk.
278 $talkmoved = '';
279 }
280 } else {
281 $talkmoved = 'notalkpage';
282 }
283
284 # Deal with watches
285 if( $this->watch ) {
286 $wgUser->addWatch( $ot );
287 $wgUser->addWatch( $nt );
288 } else {
289 $wgUser->removeWatch( $ot );
290 $wgUser->removeWatch( $nt );
291 }
292
293 # Give back result to user.
294 $titleObj = SpecialPage::getTitleFor( 'Movepage' );
295 $success = $titleObj->getFullURL(
296 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
297 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
298 '&talkmoved='.$talkmoved );
299
300 $wgOut->redirect( $success );
301 }
302
303 function showSuccess() {
304 global $wgOut, $wgRequest, $wgUser;
305
306 $old = Title::newFromText( $wgRequest->getVal( 'oldtitle' ) );
307 $new = Title::newFromText( $wgRequest->getVal( 'newtitle' ) );
308
309 if( is_null( $old ) || is_null( $new ) ) {
310 throw new ErrorPageError( 'badtitle', 'badtitletext' );
311 }
312
313 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
314
315 $talkmoved = $wgRequest->getVal( 'talkmoved' );
316 $oldUrl = $old->getFullUrl( 'redirect=no' );
317 $newUrl = $new->getFullUrl();
318 $oldText = $old->getPrefixedText();
319 $newText = $new->getPrefixedText();
320 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
321 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
322
323 $s = wfMsgNoTrans( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
324
325 if ( $talkmoved == 1 ) {
326 $s .= "\n\n" . wfMsgNoTrans( 'talkpagemoved' );
327 } elseif( 'articleexists' == $talkmoved ) {
328 $s .= "\n\n" . wfMsgNoTrans( 'talkexists' );
329 } else {
330 if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
331 $s .= "\n\n" . wfMsgNoTrans( 'talkpagenotmoved', wfMsgNoTrans( $talkmoved ) );
332 }
333 }
334 $wgOut->addWikiText( $s );
335 }
336
337 function showLogFragment( $title, &$out ) {
338 $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'move' ) ) );
339 $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) );
340 $viewer = new LogViewer( new LogReader( $request ) );
341 $viewer->showList( $out );
342 }
343
344 }