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