removed crippled enotif code from checkPassword(), this is roughly how it was in...
[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 # Variables beginning with 'o' for old article 'n' for new article
177
178 $ot = Title::newFromText( $this->oldTitle );
179 $nt = Title::newFromText( $this->newTitle );
180
181 # Delete to make way if requested
182 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) {
183 $article = new Article( $nt );
184 // This may output an error message and exit
185 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
186 }
187
188 # don't allow moving to pages with # in
189 if ( !$nt || $nt->getFragment() != '' ) {
190 $this->showForm( 'badtitletext' );
191 return;
192 }
193
194 $error = $ot->moveTo( $nt, true, $this->reason );
195 if ( $error !== true ) {
196 $this->showForm( $error );
197 return;
198 }
199
200 # Update counters if the article got moved into or out of NS_MAIN namespace
201 $ons = $ot->getNamespace();
202 $nns = $nt->getNamespace();
203
204 # moved out of article namespace?
205 if ( $ons == NS_MAIN and $nns != NS_MAIN ) {
206 $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
207 }
208 # moved into article namespace?
209 elseif ( $ons != NS_MAIN and $nns == NS_MAIN ) {
210 $u = new SiteStatsUpdate( 0, 1, +1 ); # not viewed, edited, adding
211 } else {
212 $u = false;
213 }
214 if ( $u !== false ) {
215 # save it for later update
216 array_push( $wgDeferredUpdateList, $u );
217 unset($u);
218 }
219
220 # Move talk page if
221 # (1) the checkbox says to,
222 # (2) the namespaces are not themselves talk namespaces, and of course
223 # (3) it exists.
224 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
225 ( ! Namespace::isTalk( $ons ) ) &&
226 ( ! Namespace::isTalk( $nns ) ) ) {
227
228 # get old talk page namespace
229 $ons = Namespace::getTalk( $ons );
230 # get new talk page namespace
231 $nns = Namespace::getTalk( $nns );
232
233 # make talk page title objects
234 $ott = Title::makeTitle( $ons, $ot->getDBkey() );
235 $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
236
237 # Attempt the move
238 $error = $ott->moveTo( $ntt, true, $this->reason );
239 if ( $error === true ) {
240 $talkmoved = 1;
241 } else {
242 $talkmoved = $error;
243 }
244 } else {
245 # Stay silent on the subject of talk.
246 $talkmoved = '';
247 }
248
249 # Give back result to user.
250 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
251 $success = $titleObj->getFullURL(
252 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
253 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
254 '&talkmoved='.$talkmoved );
255
256 $wgOut->redirect( $success );
257 }
258
259 function showSuccess() {
260 global $wgOut, $wgRequest, $wgRawHtml;
261
262 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
263 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
264 $oldtitle = $wgRequest->getVal('oldtitle');
265 $newtitle = $wgRequest->getVal('newtitle');
266 $talkmoved = $wgRequest->getVal('talkmoved');
267
268 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
269
270 # Temporarily disable raw html wikitext option out of XSS paranoia
271 $marchingantofdoom = $wgRawHtml;
272 $wgRawHtml = false;
273 $wgOut->addWikiText( $text );
274 $wgRawHtml = $marchingantofdoom;
275
276 if ( $talkmoved == 1 ) {
277 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
278 } elseif( 'articleexists' == $talkmoved ) {
279 $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
280 } else {
281 $ot = Title::newFromURL( $oldtitle );
282 if ( ! $ot->isTalkPage() ) {
283 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );
284 }
285 }
286 }
287 }
288 ?>