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