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