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