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