Fix bug 2642 : watchdetails message using HTML instead of wiki syntax. Patch by zigge...
[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 = wfMsgHtml( 'delete_and_move' );
99 $submitVar = 'wpDeleteAndMove';
100 $err = '';
101 } else {
102 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
103 $movepagebtn = wfMsgHtml( 'movepagebtn' );
104 $submitVar = 'wpMove';
105 }
106
107 if ( !$ot->isTalkPage() ) {
108 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
109 }
110
111 $movearticle = wfMsgHtml( 'movearticle' );
112 $newtitle = wfMsgHtml( 'newtitle' );
113 $movetalk = wfMsgHtml( 'movetalk' );
114 $movereason = wfMsgHtml( '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->addWikiText( '<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 # Move talk page if
206 # (1) the checkbox says to,
207 # (2) the namespaces are not themselves talk namespaces, and of course
208 # (3) it exists.
209 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
210 ( ! Namespace::isTalk( $ons ) ) &&
211 ( ! Namespace::isTalk( $nns ) ) ) {
212
213 # get old talk page namespace
214 $ons = Namespace::getTalk( $ons );
215 # get new talk page namespace
216 $nns = Namespace::getTalk( $nns );
217
218 # make talk page title objects
219 $ott = Title::makeTitle( $ons, $ot->getDBkey() );
220 $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
221
222 # Attempt the move
223 $error = $ott->moveTo( $ntt, true, $this->reason );
224 if ( $error === true ) {
225 $talkmoved = 1;
226 } else {
227 $talkmoved = $error;
228 }
229 } else {
230 # Stay silent on the subject of talk.
231 $talkmoved = '';
232 }
233
234 # Give back result to user.
235 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
236 $success = $titleObj->getFullURL(
237 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
238 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
239 '&talkmoved='.$talkmoved );
240
241 $wgOut->redirect( $success );
242 }
243
244 function showSuccess() {
245 global $wgOut, $wgRequest, $wgRawHtml;
246
247 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
248 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
249 $oldtitle = $wgRequest->getVal('oldtitle');
250 $newtitle = $wgRequest->getVal('newtitle');
251 $talkmoved = $wgRequest->getVal('talkmoved');
252
253 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
254
255 # Temporarily disable raw html wikitext option out of XSS paranoia
256 $marchingantofdoom = $wgRawHtml;
257 $wgRawHtml = false;
258 $wgOut->addWikiText( $text );
259 $wgRawHtml = $marchingantofdoom;
260
261 if ( $talkmoved == 1 ) {
262 $wgOut->addWikiText( wfMsg( 'talkpagemoved' ) );
263 } elseif( 'articleexists' == $talkmoved ) {
264 $wgOut->addWikiText( wfMsg( 'talkexists' ) );
265 } else {
266 $ot = Title::newFromURL( $oldtitle );
267 if ( ! $ot->isTalkPage() ) {
268 $wgOut->addWikiText( wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) );
269 }
270 }
271 }
272 }
273 ?>