Pass the two titles in plain text as (unused per default) parameters $3 and $4 to...
[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 $submitVar = 'wpDeleteAndMove';
109 $confirm = "
110 <tr>
111 <td></td><td>" . Xml::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) . "</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 $movereason = wfMsgHtml( 'movereason' );
131
132 $titleObj = SpecialPage::getTitleFor( 'Movepage' );
133 $action = $titleObj->escapeLocalURL( 'action=submit' );
134 $token = htmlspecialchars( $wgUser->editToken() );
135
136 if ( $err != '' ) {
137 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
138 $wgOut->addWikiText( '<p class="error">' . wfMsg($err) . "</p>\n" );
139 }
140
141 $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
142
143 $wgOut->addHTML( "
144 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
145 <table border='0'>
146 <tr>
147 <td align='$end'>{$movearticle}</td>
148 <td align='$start'><strong>{$oldTitle}</strong></td>
149 </tr>
150 <tr>
151 <td align='$end'><label for='wpNewTitle'>{$newtitle}</label></td>
152 <td align='$start'>
153 <input type='text' size='40' name='wpNewTitle' id='wpNewTitle' value=\"{$encNewTitle}\" />
154 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
155 </td>
156 </tr>
157 <tr>
158 <td align='$end' valign='top'><br /><label for='wpReason'>{$movereason}</label></td>
159 <td align='$start' valign='top'><br />
160 <textarea cols='60' rows='2' name='wpReason' id='wpReason'>{$encReason}</textarea>
161 </td>
162 </tr>" );
163
164 if ( $considerTalk ) {
165 $wgOut->addHTML( "
166 <tr>
167 <td></td><td>" . Xml::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $moveTalkChecked ) . "</td>
168 </tr>" );
169 }
170
171 $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) || $ot->userIsWatching();
172 $watch = '<tr>';
173 $watch .= '<td></td><td>' . Xml::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) . '</td>';
174 $watch .= '</tr>';
175 $wgOut->addHtml( $watch );
176
177 $wgOut->addHTML( "
178 {$confirm}
179 <tr>
180 <td>&nbsp;</td>
181 <td align='$start'>
182 <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
183 </td>
184 </tr>
185 </table>
186 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
187 </form>\n" );
188
189 $this->showLogFragment( $ot, $wgOut );
190
191 }
192
193 function doSubmit() {
194 global $wgOut, $wgUser, $wgRequest;
195
196 if ( $wgUser->pingLimiter( 'move' ) ) {
197 $wgOut->rateLimited();
198 return;
199 }
200
201 # Variables beginning with 'o' for old article 'n' for new article
202
203 $ot = Title::newFromText( $this->oldTitle );
204 $nt = Title::newFromText( $this->newTitle );
205
206 # Delete to make way if requested
207 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) {
208 $article = new Article( $nt );
209 // This may output an error message and exit
210 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
211 }
212
213 # don't allow moving to pages with # in
214 if ( !$nt || $nt->getFragment() != '' ) {
215 $this->showForm( 'badtitletext' );
216 return;
217 }
218
219 $error = $ot->moveTo( $nt, true, $this->reason );
220 if ( $error !== true ) {
221 $this->showForm( $error );
222 return;
223 }
224
225 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
226
227 # Move the talk page if relevant, if it exists, and if we've been told to
228 $ott = $ot->getTalkPage();
229 if( $ott->exists() ) {
230 if( $this->moveTalk && !$ot->isTalkPage() && !$nt->isTalkPage() ) {
231 $ntt = $nt->getTalkPage();
232
233 # Attempt the move
234 $error = $ott->moveTo( $ntt, true, $this->reason );
235 if ( $error === true ) {
236 $talkmoved = 1;
237 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) ) ;
238 } else {
239 $talkmoved = $error;
240 }
241 } else {
242 # Stay silent on the subject of talk.
243 $talkmoved = '';
244 }
245 } else {
246 $talkmoved = 'notalkpage';
247 }
248
249 # Deal with watches
250 if( $this->watch ) {
251 $wgUser->addWatch( $ot );
252 $wgUser->addWatch( $nt );
253 } else {
254 $wgUser->removeWatch( $ot );
255 $wgUser->removeWatch( $nt );
256 }
257
258 # Give back result to user.
259 $titleObj = SpecialPage::getTitleFor( 'Movepage' );
260 $success = $titleObj->getFullURL(
261 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
262 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
263 '&talkmoved='.$talkmoved );
264
265 $wgOut->redirect( $success );
266 }
267
268 function showSuccess() {
269 global $wgOut, $wgRequest, $wgUser, $wgRawHtml;
270
271 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
272 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
273
274 $old = Title::newFromText( $wgRequest->getText( 'oldtitle' ) );
275 $new = Title::newFromText( $wgRequest->getText( 'newtitle' ) );
276 $talkmoved = $wgRequest->getVal( 'talkmoved' );
277
278 $olink = $wgUser->getSkin()->makeKnownLinkObj( $old, '', 'redirect=no' );
279 $nlink = $wgUser->getSkin()->makeKnownLinkObj( $new );
280
281 $wgOut->addHtml( wfMsgExt( 'movepage-moved', array( 'parseinline', 'replaceafter' ),
282 $olink, $nlink, $old->getPrefixedText(), $new->getPrefixedText() ) );
283
284 if ( $talkmoved == 1 ) {
285 $wgOut->addWikiText( wfMsg( 'talkpagemoved' ) );
286 } elseif( 'articleexists' == $talkmoved ) {
287 $wgOut->addWikiText( wfMsg( 'talkexists' ) );
288 } else {
289 if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
290 $wgOut->addWikiText( wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) );
291 }
292 }
293 }
294
295 function showLogFragment( $title, &$out ) {
296 $out->addHtml( wfElement( 'h2', NULL, LogPage::logName( 'move' ) ) );
297 $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) );
298 $viewer = new LogViewer( new LogReader( $request ) );
299 $viewer->showList( $out );
300 }
301
302 }
303 ?>