39e5fac049014ee9f09a27feada34303fcf7982e
[lhc/web/wiklou.git] / includes / SpecialMovepage.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 require_once( "LinksUpdate.php" );
12
13 /**
14 * Constructor
15 */
16 function wfSpecialMovepage( $par = null ) {
17 global $wgUser, $wgOut, $wgRequest, $action, $wgOnlySysopMayMove;
18
19 # check rights. We don't want newbies to move pages to prevents possible attack
20 if ( $wgUser->isAnon() or $wgUser->isBlocked() or ($wgOnlySysopMayMove and $wgUser->isNewbie())) {
21 $wgOut->errorpage( "movenologin", "movenologintext" );
22 return;
23 }
24 # We don't move protected pages
25 if ( wfReadOnly() ) {
26 $wgOut->readOnlyPage();
27 return;
28 }
29
30 $f = new MovePageForm( $par );
31
32 if ( 'success' == $action ) {
33 $f->showSuccess();
34 } else if ( 'submit' == $action && $wgRequest->wasPosted()
35 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
36 $f->doSubmit();
37 } else {
38 $f->showForm( '' );
39 }
40 }
41
42 /**
43 *
44 * @package MediaWiki
45 * @subpackage SpecialPage
46 */
47 class MovePageForm {
48 var $oldTitle, $newTitle, $reason; # Text input
49 var $moveTalk, $deleteAndMove;
50
51 function MovePageForm( $par ) {
52 global $wgRequest;
53 $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
54 $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $target );
55 $this->newTitle = $wgRequest->getText( 'wpNewTitle' );
56 $this->reason = $wgRequest->getText( 'wpReason' );
57 $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
58 $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' );
59 }
60
61 function showForm( $err ) {
62 global $wgOut, $wgUser, $wgLang;
63
64 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
65
66 if ( $this->oldTitle == '' ) {
67 $wgOut->errorpage( 'notargettitle', 'notargettext' );
68 return;
69 }
70
71 $ot = Title::newFromURL( $this->oldTitle );
72 $oldTitle = $ot->getPrefixedText();
73
74 $encOldTitle = htmlspecialchars( $this->oldTitle );
75 if( $this->newTitle == '' ) {
76 # Show the current title as a default
77 # when the form is first opened.
78 $encNewTitle = $oldTitle;
79 } else {
80 if( $err == '' ) {
81 $nt = Title::newFromURL( $this->newTitle );
82 if( $nt ) {
83 # If a title was supplied, probably from the move log revert
84 # link, check for validity. We can then show some diagnostic
85 # information and save a click.
86 $newerr = $ot->isValidMoveOperation( $nt );
87 if( is_string( $newerr ) ) {
88 $err = $newerr;
89 }
90 }
91 }
92 $encNewTitle = htmlspecialchars( $this->newTitle );
93 }
94 $encReason = htmlspecialchars( $this->reason );
95
96 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
97 $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
98 $movepagebtn = wfMsg( 'delete_and_move' );
99 $submitVar = 'wpDeleteAndMove';
100 $err = '';
101 } else {
102 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
103 $movepagebtn = wfMsg( 'movepagebtn' );
104 $submitVar = 'wpMove';
105 }
106
107 if ( !$ot->isTalkPage() ) {
108 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
109 }
110
111 $movearticle = wfMsg( 'movearticle' );
112 $newtitle = wfMsg( 'newtitle' );
113 $movetalk = wfMsg( 'movetalk' );
114 $movereason = wfMsg( 'movereason' );
115
116 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
117 $action = $titleObj->escapeLocalURL( 'action=submit' );
118 $token = htmlspecialchars( $wgUser->editToken() );
119
120 if ( $err != '' ) {
121 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
122 $wgOut->addHTML( '<p class="error">' . wfMsg($err) . "</p>\n" );
123 }
124
125 $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
126
127 $wgOut->addHTML( "
128 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
129 <table border='0'>
130 <tr>
131 <td align='right'>{$movearticle}:</td>
132 <td align='left'><strong>{$oldTitle}</strong></td>
133 </tr>
134 <tr>
135 <td align='right'>{$newtitle}:</td>
136 <td align='left'>
137 <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
138 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
139 </td>
140 </tr>
141 <tr>
142 <td align='right'>{$movereason}:</td>
143 <td align='left'>
144 <input type='text' size='40' name=\"wpReason\" value=\"{$encReason}\" />
145 </td>
146 </tr>" );
147
148 if ( ! $ot->isTalkPage() ) {
149 $wgOut->addHTML( "
150 <tr>
151 <td align='right'>
152 <input type='checkbox' name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
153 </td>
154 <td>{$movetalk}</td>
155 </tr>" );
156 }
157 $wgOut->addHTML( "
158 <tr>
159 <td>&nbsp;</td>
160 <td align='left'>
161 <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
162 </td>
163 </tr>
164 </table>
165 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
166 </form>\n" );
167
168 }
169
170 function doSubmit() {
171 global $wgOut, $wgUser, $wgLang;
172 global $wgDeferredUpdateList, $wgMessageCache;
173 global $wgUseSquid, $wgRequest;
174 $fname = "MovePageForm::doSubmit";
175
176 if ( $wgUser->pingLimiter( 'move' ) ) {
177 $wgOut->rateLimited();
178 return;
179 }
180
181 # Variables beginning with 'o' for old article 'n' for new article
182
183 $ot = Title::newFromText( $this->oldTitle );
184 $nt = Title::newFromText( $this->newTitle );
185
186 # Delete to make way if requested
187 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) {
188 $article = new Article( $nt );
189 // This may output an error message and exit
190 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
191 }
192
193 # don't allow moving to pages with # in
194 if ( !$nt || $nt->getFragment() != '' ) {
195 $this->showForm( 'badtitletext' );
196 return;
197 }
198
199 $error = $ot->moveTo( $nt, true, $this->reason );
200 if ( $error !== true ) {
201 $this->showForm( $error );
202 return;
203 }
204
205 # Update counters if the article got moved into or out of NS_MAIN namespace
206 $ons = $ot->getNamespace();
207 $nns = $nt->getNamespace();
208
209 # moved out of article namespace?
210 if ( $ons == NS_MAIN and $nns != NS_MAIN ) {
211 $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
212 }
213 # moved into article namespace?
214 elseif ( $ons != NS_MAIN and $nns == NS_MAIN ) {
215 $u = new SiteStatsUpdate( 0, 1, +1 ); # not viewed, edited, adding
216 } else {
217 $u = false;
218 }
219 if ( $u !== false ) {
220 # save it for later update
221 array_push( $wgDeferredUpdateList, $u );
222 unset($u);
223 }
224
225 # Move talk page if
226 # (1) the checkbox says to,
227 # (2) the namespaces are not themselves talk namespaces, and of course
228 # (3) it exists.
229 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
230 ( ! Namespace::isTalk( $ons ) ) &&
231 ( ! Namespace::isTalk( $nns ) ) ) {
232
233 # get old talk page namespace
234 $ons = Namespace::getTalk( $ons );
235 # get new talk page namespace
236 $nns = Namespace::getTalk( $nns );
237
238 # make talk page title objects
239 $ott = Title::makeTitle( $ons, $ot->getDBkey() );
240 $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
241
242 # Attempt the move
243 $error = $ott->moveTo( $ntt, true, $this->reason );
244 if ( $error === true ) {
245 $talkmoved = 1;
246 } else {
247 $talkmoved = $error;
248 }
249 } else {
250 # Stay silent on the subject of talk.
251 $talkmoved = '';
252 }
253
254 # Give back result to user.
255 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
256 $success = $titleObj->getFullURL(
257 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
258 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
259 '&talkmoved='.$talkmoved );
260
261 $wgOut->redirect( $success );
262 }
263
264 function showSuccess() {
265 global $wgOut, $wgRequest, $wgRawHtml;
266
267 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
268 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
269 $oldtitle = $wgRequest->getVal('oldtitle');
270 $newtitle = $wgRequest->getVal('newtitle');
271 $talkmoved = $wgRequest->getVal('talkmoved');
272
273 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
274
275 # Temporarily disable raw html wikitext option out of XSS paranoia
276 $marchingantofdoom = $wgRawHtml;
277 $wgRawHtml = false;
278 $wgOut->addWikiText( $text );
279 $wgRawHtml = $marchingantofdoom;
280
281 if ( $talkmoved == 1 ) {
282 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
283 } elseif( 'articleexists' == $talkmoved ) {
284 $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
285 } else {
286 $ot = Title::newFromURL( $oldtitle );
287 if ( ! $ot->isTalkPage() ) {
288 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );
289 }
290 }
291 }
292 }
293 ?>