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