fix synxtax
[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 $start = $wgContLang->isRTL() ? 'right' : 'left';
72 $end = $wgContLang->isRTL() ? 'left' : 'right';
73
74 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
75
76 $ot = Title::newFromURL( $this->oldTitle );
77 if( is_null( $ot ) ) {
78 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
79 return;
80 }
81 $sk = $wgUser->getSkin();
82 $oldTitleLink = $sk->makeLinkObj( $ot );
83 $oldTitle = $ot->getPrefixedText();
84
85 $encOldTitle = htmlspecialchars( $oldTitle );
86 if( $this->newTitle == '' ) {
87 # Show the current title as a default
88 # when the form is first opened.
89 $encNewTitle = $encOldTitle;
90 } else {
91 if( $err == '' ) {
92 $nt = Title::newFromURL( $this->newTitle );
93 if( $nt ) {
94 # If a title was supplied, probably from the move log revert
95 # link, check for validity. We can then show some diagnostic
96 # information and save a click.
97 $newerr = $ot->isValidMoveOperation( $nt );
98 if( is_string( $newerr ) ) {
99 $err = $newerr;
100 }
101 }
102 }
103 $encNewTitle = htmlspecialchars( $this->newTitle );
104 }
105 $encReason = htmlspecialchars( $this->reason );
106
107 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
108 $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
109 $movepagebtn = wfMsgHtml( 'delete_and_move' );
110 $submitVar = 'wpDeleteAndMove';
111 $confirm = "
112 <tr>
113 <td></td><td>" . Xml::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) . "</td>
114 </tr>";
115 $err = '';
116 } else {
117 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
118 $movepagebtn = wfMsgHtml( 'movepagebtn' );
119 $submitVar = 'wpMove';
120 $confirm = false;
121 }
122
123 $oldTalk = $ot->getTalkPage();
124 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
125
126 if ( $considerTalk ) {
127 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
128 }
129
130 $movearticle = wfMsgHtml( 'movearticle' );
131 $newtitle = wfMsgHtml( 'newtitle' );
132 $movereason = wfMsgHtml( 'movereason' );
133
134 $titleObj = SpecialPage::getTitleFor( 'Movepage' );
135 $action = $titleObj->escapeLocalURL( 'action=submit' );
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 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
153 <table border='0'>
154 <tr>
155 <td align='$end'>{$movearticle}</td>
156 <td align='$start'><strong>{$oldTitleLink}</strong></td>
157 </tr>
158 <tr>
159 <td align='$end'><label for='wpNewTitle'>{$newtitle}</label></td>
160 <td align='$start'>
161 <input type='text' size='40' name='wpNewTitle' id='wpNewTitle' value=\"{$encNewTitle}\" />
162 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
163 </td>
164 </tr>
165 <tr>
166 <td align='$end' valign='top'><br /><label for='wpReason'>{$movereason}</label></td>
167 <td align='$start' valign='top'><br />
168 <textarea cols='60' rows='2' name='wpReason' id='wpReason'>{$encReason}</textarea>
169 </td>
170 </tr>" );
171
172 if ( $considerTalk ) {
173 $wgOut->addHTML( "
174 <tr>
175 <td></td><td>" . Xml::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $moveTalkChecked ) . "</td>
176 </tr>" );
177 }
178
179 $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) || $ot->userIsWatching();
180 $watch = '<tr>';
181 $watch .= '<td></td><td>' . Xml::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) . '</td>';
182 $watch .= '</tr>';
183 $wgOut->addHtml( $watch );
184
185 $wgOut->addHTML( "
186 {$confirm}
187 <tr>
188 <td>&nbsp;</td>
189 <td align='$start'>
190 <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
191 </td>
192 </tr>
193 </table>
194 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
195 </form>\n" );
196
197 $this->showLogFragment( $ot, $wgOut );
198
199 }
200
201 function doSubmit() {
202 global $wgOut, $wgUser, $wgRequest;
203
204 if ( $wgUser->pingLimiter( 'move' ) ) {
205 $wgOut->rateLimited();
206 return;
207 }
208
209 # Variables beginning with 'o' for old article 'n' for new article
210
211 $ot = Title::newFromText( $this->oldTitle );
212 $nt = Title::newFromText( $this->newTitle );
213
214 # Delete to make way if requested
215 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) {
216 $article = new Article( $nt );
217 // This may output an error message and exit
218 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
219 }
220
221 # don't allow moving to pages with # in
222 if ( !$nt || $nt->getFragment() != '' ) {
223 $this->showForm( 'badtitletext' );
224 return;
225 }
226
227 $hookErr = null;
228 if( !wfRunHooks( 'AbortMove', array( $ot, $nt, $wgUser, &$hookErr ) ) ) {
229 $this->showForm( 'hookaborted', $hookErr );
230 return;
231 }
232
233 $error = $ot->moveTo( $nt, true, $this->reason );
234 if ( $error !== true ) {
235 $this->showForm( $error );
236 return;
237 }
238
239 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
240
241 # Move the talk page if relevant, if it exists, and if we've been told to
242 $ott = $ot->getTalkPage();
243 if( $ott->exists() ) {
244 if( $this->moveTalk && !$ot->isTalkPage() && !$nt->isTalkPage() ) {
245 $ntt = $nt->getTalkPage();
246
247 # Attempt the move
248 $error = $ott->moveTo( $ntt, true, $this->reason );
249 if ( $error === true ) {
250 $talkmoved = 1;
251 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) ) ;
252 } else {
253 $talkmoved = $error;
254 }
255 } else {
256 # Stay silent on the subject of talk.
257 $talkmoved = '';
258 }
259 } else {
260 $talkmoved = 'notalkpage';
261 }
262
263 # Deal with watches
264 if( $this->watch ) {
265 $wgUser->addWatch( $ot );
266 $wgUser->addWatch( $nt );
267 } else {
268 $wgUser->removeWatch( $ot );
269 $wgUser->removeWatch( $nt );
270 }
271
272 # Give back result to user.
273 $titleObj = SpecialPage::getTitleFor( 'Movepage' );
274 $success = $titleObj->getFullURL(
275 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
276 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
277 '&talkmoved='.$talkmoved );
278
279 $wgOut->redirect( $success );
280 }
281
282 function showSuccess() {
283 global $wgOut, $wgRequest, $wgUser;
284
285 $old = Title::newFromText( $wgRequest->getVal( 'oldtitle' ) );
286 $new = Title::newFromText( $wgRequest->getVal( 'newtitle' ) );
287
288 if( is_null( $old ) || is_null( $new ) ) {
289 throw new ErrorPageError( 'badtitle', 'badtitletext' );
290 }
291
292 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
293 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
294
295 $talkmoved = $wgRequest->getVal( 'talkmoved' );
296 $oldUrl = $old->getFullUrl( 'redirect=no' );
297 $newUrl = $new->getFullURl();
298 $oldText = wfEscapeWikiText( $old->getPrefixedText() );
299 $newText = wfEscapeWikiText( $new->getPrefixedText() );
300 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
301 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
302
303 $s = wfMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
304
305 if ( $talkmoved == 1 ) {
306 $s .= "\n\n" . wfMsg( 'talkpagemoved' );
307 } elseif( 'articleexists' == $talkmoved ) {
308 $s .= "\n\n" . wfMsg( 'talkexists' );
309 } else {
310 if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
311 $s .= "\n\n" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) );
312 }
313 }
314 $wgOut->addWikiText( $s );
315 }
316
317 function showLogFragment( $title, &$out ) {
318 $out->addHtml( wfElement( 'h2', NULL, LogPage::logName( 'move' ) ) );
319 $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) );
320 $viewer = new LogViewer( new LogReader( $request ) );
321 $viewer->showList( $out );
322 }
323
324 }
325