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