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