Return nothing on empty math tags instead of char encoding
[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;
13
14 # Check rights
15 if ( !$wgUser->isAllowed( 'move' ) ) {
16 $wgOut->showErrorPage( 'movenologin', 'movenologintext' );
17 return;
18 }
19
20 # Don't allow blocked users to move pages
21 if ( $wgUser->isBlocked() ) {
22 $wgOut->blockedPage();
23 return;
24 }
25
26 # Check for database lock
27 if ( wfReadOnly() ) {
28 $wgOut->readOnlyPage();
29 return;
30 }
31
32 $f = new MovePageForm( $par );
33
34 if ( 'success' == $action ) {
35 $f->showSuccess();
36 } else if ( 'submit' == $action && $wgRequest->wasPosted()
37 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
38 $f->doSubmit();
39 } else {
40 $f->showForm( '' );
41 }
42 }
43
44 /**
45 *
46 * @package MediaWiki
47 * @subpackage SpecialPage
48 */
49 class MovePageForm {
50 var $oldTitle, $newTitle, $reason; # Text input
51 var $moveTalk, $deleteAndMove;
52
53 private $watch = false;
54
55 function MovePageForm( $par ) {
56 global $wgRequest;
57 $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
58 $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $target );
59 $this->newTitle = $wgRequest->getText( 'wpNewTitle' );
60 $this->reason = $wgRequest->getText( 'wpReason' );
61 if ( $wgRequest->wasPosted() ) {
62 $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', false );
63 } else {
64 $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
65 }
66 $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
67 $this->watch = $wgRequest->getCheck( 'wpWatch' );
68 }
69
70 function showForm( $err ) {
71 global $wgOut, $wgUser;
72
73 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
74
75 $ot = Title::newFromURL( $this->oldTitle );
76 if( is_null( $ot ) ) {
77 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
78 return;
79 }
80 $oldTitle = $ot->getPrefixedText();
81
82 $encOldTitle = htmlspecialchars( $oldTitle );
83 if( $this->newTitle == '' ) {
84 # Show the current title as a default
85 # when the form is first opened.
86 $encNewTitle = $encOldTitle;
87 } else {
88 if( $err == '' ) {
89 $nt = Title::newFromURL( $this->newTitle );
90 if( $nt ) {
91 # If a title was supplied, probably from the move log revert
92 # link, check for validity. We can then show some diagnostic
93 # information and save a click.
94 $newerr = $ot->isValidMoveOperation( $nt );
95 if( is_string( $newerr ) ) {
96 $err = $newerr;
97 }
98 }
99 }
100 $encNewTitle = htmlspecialchars( $this->newTitle );
101 }
102 $encReason = htmlspecialchars( $this->reason );
103
104 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
105 $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
106 $movepagebtn = wfMsgHtml( 'delete_and_move' );
107 $confirmText = wfMsgHtml( 'delete_and_move_confirm' );
108 $submitVar = 'wpDeleteAndMove';
109 $confirm = "
110 <tr>
111 <td align='right'>
112 <input type='checkbox' name='wpConfirm' id='wpConfirm' value=\"true\" />
113 </td>
114 <td align='left'><label for='wpConfirm'>{$confirmText}</label></td>
115 </tr>";
116 $err = '';
117 } else {
118 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
119 $movepagebtn = wfMsgHtml( 'movepagebtn' );
120 $submitVar = 'wpMove';
121 $confirm = false;
122 }
123
124 $oldTalk = $ot->getTalkPage();
125 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
126
127 if ( $considerTalk ) {
128 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
129 }
130
131 $movearticle = wfMsgHtml( 'movearticle' );
132 $newtitle = wfMsgHtml( 'newtitle' );
133 $movetalk = wfMsgHtml( 'movetalk' );
134 $movereason = wfMsgHtml( 'movereason' );
135
136 $titleObj = SpecialPage::getTitleFor( 'Movepage' );
137 $action = $titleObj->escapeLocalURL( 'action=submit' );
138 $token = htmlspecialchars( $wgUser->editToken() );
139
140 if ( $err != '' ) {
141 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
142 $wgOut->addWikiText( '<p class="error">' . wfMsg($err) . "</p>\n" );
143 }
144
145 $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
146
147 $wgOut->addHTML( "
148 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
149 <table border='0'>
150 <tr>
151 <td align='right'>{$movearticle}:</td>
152 <td align='left'><strong>{$oldTitle}</strong></td>
153 </tr>
154 <tr>
155 <td align='right'><label for='wpNewTitle'>{$newtitle}:</label></td>
156 <td align='left'>
157 <input type='text' size='40' name='wpNewTitle' id='wpNewTitle' value=\"{$encNewTitle}\" />
158 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
159 </td>
160 </tr>
161 <tr>
162 <td align='right' valign='top'><br /><label for='wpReason'>{$movereason}:</label></td>
163 <td align='left' valign='top'><br />
164 <textarea cols='60' rows='2' name='wpReason' id='wpReason'>{$encReason}</textarea>
165 </td>
166 </tr>" );
167
168 if ( $considerTalk ) {
169 $wgOut->addHTML( "
170 <tr>
171 <td align='right'>
172 <input type='checkbox' id=\"wpMovetalk\" name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
173 </td>
174 <td><label for=\"wpMovetalk\">{$movetalk}</label></td>
175 </tr>" );
176 }
177
178 $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) || $ot->userIsWatching();
179 $watch = '<tr>';
180 $watch .= '<td align="right">' . Xml::check( 'wpWatch', $watchChecked, array( 'id' => 'watch' ) ) . '</td>';
181 $watch .= '<td>' . Xml::label( wfMsg( 'move-watch' ), 'watch' ) . '</td>';
182 $watch .= '</tr>';
183 $wgOut->addHtml( $watch );
184
185 $wgOut->addHTML( "
186 {$confirm}
187 <tr>
188 <td>&nbsp;</td>
189 <td align='left'>
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 $error = $ot->moveTo( $nt, true, $this->reason );
228 if ( $error !== true ) {
229 $this->showForm( $error );
230 return;
231 }
232
233 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
234
235 # Move the talk page if relevant, if it exists, and if we've been told to
236 $ott = $ot->getTalkPage();
237 if( $ott->exists() ) {
238 if( $this->moveTalk && !$ot->isTalkPage() && !$nt->isTalkPage() ) {
239 $ntt = $nt->getTalkPage();
240
241 # Attempt the move
242 $error = $ott->moveTo( $ntt, true, $this->reason );
243 if ( $error === true ) {
244 $talkmoved = 1;
245 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) ) ;
246 } else {
247 $talkmoved = $error;
248 }
249 } else {
250 # Stay silent on the subject of talk.
251 $talkmoved = '';
252 }
253 } else {
254 $talkmoved = 'notalkpage';
255 }
256
257 # Deal with watches
258 if( $this->watch ) {
259 $wgUser->addWatch( $ot );
260 $wgUser->addWatch( $nt );
261 } else {
262 $wgUser->removeWatch( $ot );
263 $wgUser->removeWatch( $nt );
264 }
265
266 # Give back result to user.
267 $titleObj = SpecialPage::getTitleFor( 'Movepage' );
268 $success = $titleObj->getFullURL(
269 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
270 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
271 '&talkmoved='.$talkmoved );
272
273 $wgOut->redirect( $success );
274 }
275
276 function showSuccess() {
277 global $wgOut, $wgRequest, $wgRawHtml;
278
279 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
280 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
281
282 $oldText = wfEscapeWikiText( $wgRequest->getVal('oldtitle') );
283 $newText = wfEscapeWikiText( $wgRequest->getVal('newtitle') );
284 $talkmoved = $wgRequest->getVal('talkmoved');
285
286 $text = wfMsg( 'pagemovedtext', $oldText, $newText );
287
288 $allowHTML = $wgRawHtml;
289 $wgRawHtml = false;
290 $wgOut->addWikiText( $text );
291 $wgRawHtml = $allowHTML;
292
293 if ( $talkmoved == 1 ) {
294 $wgOut->addWikiText( wfMsg( 'talkpagemoved' ) );
295 } elseif( 'articleexists' == $talkmoved ) {
296 $wgOut->addWikiText( wfMsg( 'talkexists' ) );
297 } else {
298 $oldTitle = Title::newFromText( $oldText );
299 if ( isset( $oldTitle ) && !$oldTitle->isTalkPage() && $talkmoved != 'notalkpage' ) {
300 $wgOut->addWikiText( wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) );
301 }
302 }
303 }
304
305 function showLogFragment( $title, &$out ) {
306 $out->addHtml( wfElement( 'h2', NULL, LogPage::logName( 'move' ) ) );
307 $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) );
308 $viewer = new LogViewer( new LogReader( $request ) );
309 $viewer->showList( $out );
310 }
311
312 }
313 ?>