De-cruftification continues.
[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; # Text input
49
50 function MovePageForm() {
51 global $wgRequest;
52 $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
53 $this->newTitle = $wgRequest->getText( 'wpNewTitle' );
54 }
55
56 function showForm( $err ) {
57 global $wgOut, $wgUser, $wgLang;
58
59 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
60
61 if ( $this->oldTitle == '' ) {
62 $wgOut->errorpage( 'notargettitle', 'notargettext' );
63 return;
64 }
65
66 $ot = Title::newFromURL( $this->oldTitle );
67 $ott = $ot->getPrefixedText();
68
69 $encOldTitle = htmlspecialchars( $this->oldTitle );
70 if( $this->newTitle == '' ) {
71 # Show the current title as a default
72 # when the form is first opened.
73 $encNewTitle = $ott;
74 } else {
75 $encNewTitle = htmlspecialchars( $this->newTitle );
76 }
77
78 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
79 if ( !$ot->isTalkPage() ) {
80 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
81 }
82
83 $ma = wfMsg( 'movearticle' );
84 $newt = wfMsg( 'newtitle' );
85 $mpb = wfMsg( 'movepagebtn' );
86 $movetalk = wfMsg( 'movetalk' );
87
88 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
89 $action = $titleObj->escapeLocalURL( 'action=submit' );
90 $token = htmlspecialchars( $wgUser->editToken() );
91
92 if ( $err != '' ) {
93 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
94 $wgOut->addHTML( '<p class="error">'.$err."</p>\n" );
95 }
96 $wgOut->addHTML( "
97 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
98 <table border='0'>
99 <tr>
100 <td align='right'>{$ma}:</td>
101 <td align='left'><strong>{$ott}</strong></td>
102 </tr>
103 <tr>
104 <td align='right'>{$newt}:</td>
105 <td align='left'>
106 <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
107 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
108 </td>
109 </tr>" );
110
111 if ( ! $ot->isTalkPage() ) {
112 $wgOut->addHTML( "
113 <tr>
114 <td align='right'>
115 <input type='checkbox' name=\"wpMovetalk\" checked='checked' value=\"1\" />
116 </td>
117 <td>{$movetalk}</td>
118 </tr>" );
119 }
120 $wgOut->addHTML( "
121 <tr>
122 <td>&nbsp;</td>
123 <td align='left'>
124 <input type='submit' name=\"wpMove\" value=\"{$mpb}\" />
125 </td>
126 </tr>
127 </table>
128 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
129 </form>\n" );
130
131 }
132
133 function doSubmit() {
134 global $wgOut, $wgUser, $wgLang;
135 global $wgDeferredUpdateList, $wgMessageCache;
136 global $wgUseSquid, $wgRequest;
137 $fname = "MovePageForm::doSubmit";
138
139 # Variables beginning with 'o' for old article 'n' for new article
140
141 # Attempt to move the article
142 $ot = Title::newFromText( $this->oldTitle );
143 $nt = Title::newFromText( $this->newTitle );
144
145 # don't allow moving to pages with # in
146 if ( !$nt || $nt->getFragment() != '' ) {
147 $this->showForm( wfMsg( "badtitletext" ) );
148 return;
149 }
150
151 $error = $ot->moveTo( $nt );
152 if ( $error !== true ) {
153 $this->showForm( wfMsg( $error ) );
154 return;
155 }
156
157 # Update counters if the article got moved into or out of NS_MAIN namespace
158 $ons = $ot->getNamespace();
159 $nns = $nt->getNamespace();
160
161 # moved out of article namespace?
162 if ( $ons == NS_MAIN and $nns != NS_MAIN ) {
163 $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
164 }
165 # moved into article namespace?
166 elseif ( $ons != NS_MAIN and $nns == NS_MAIN ) {
167 $u = new SiteStatsUpdate( 0, 1, +1 ); # not viewed, edited, adding
168 } else {
169 $u = false;
170 }
171 if ( $u !== false ) {
172 # save it for later update
173 array_push( $wgDeferredUpdateList, $u );
174 unset($u);
175 }
176
177 # Move talk page if
178 # (1) the checkbox says to,
179 # (2) the namespaces are not themselves talk namespaces, and of course
180 # (3) it exists.
181 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
182 ( ! Namespace::isTalk( $ons ) ) &&
183 ( ! Namespace::isTalk( $nns ) ) ) {
184
185 # get old talk page namespace
186 $ons = Namespace::getTalk( $ons );
187 # get new talk page namespace
188 $nns = Namespace::getTalk( $nns );
189
190 # make talk page title objects
191 $ott = Title::makeTitle( $ons, $ot->getDBkey() );
192 $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
193
194 # Attempt the move
195 $error = $ott->moveTo( $ntt );
196 if ( $error === true ) {
197 $talkmoved = 1;
198 } else {
199 $talkmoved = $error;
200 }
201 }
202
203 # Give back result to user.
204 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
205 $success = $titleObj->getFullURL(
206 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
207 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
208 '&talkmoved='.$talkmoved );
209
210 $wgOut->redirect( $success );
211 }
212
213 function showSuccess() {
214 global $wgOut, $wgRequest, $wgRawHtml;
215
216 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
217 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
218 $oldtitle = $wgRequest->getVal('oldtitle');
219 $newtitle = $wgRequest->getVal('newtitle');
220 $talkmoved = $wgRequest->getVal('talkmoved');
221
222 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
223
224 # Temporarily disable raw html wikitext option out of XSS paranoia
225 $marchingantofdoom = $wgRawHtml;
226 $wgRawHtml = false;
227 $wgOut->addWikiText( $text );
228 $wgRawHtml = $marchingantofdoom;
229
230 if ( $talkmoved == 1 ) {
231 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
232 } elseif( 'articleexists' == $talkmoved ) {
233 $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
234 } else {
235 $ot = Title::newFromURL( $oldtitle );
236 if ( ! $ot->isTalkPage() ) {
237 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );
238 }
239 }
240 }
241 }
242 ?>