Move page tweaks:
[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 $encOldTitle = htmlspecialchars( $this->oldTitle );
62 if( $this->newTitle == "" ) {
63 # Show the current title as a default
64 # when the form is first opened.
65 $encNewTitle = $encOldTitle;
66 } else {
67 $encNewTitle = htmlspecialchars( $this->newTitle );
68 }
69 $ot = Title::newFromURL( $this->oldTitle );
70 $ott = $ot->getPrefixedText();
71
72 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
73 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
74 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
75 }
76
77 $ma = wfMsg( 'movearticle' );
78 $newt = wfMsg( 'newtitle' );
79 $mpb = wfMsg( 'movepagebtn' );
80 $movetalk = wfMsg( 'movetalk' );
81
82 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
83 $action = $titleObj->escapeLocalURL( 'action=submit' );
84
85 if ( $err != '' ) {
86 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
87 $wgOut->addHTML( '<p class="error">'.$err."</p>\n" );
88 }
89 $wgOut->addHTML( "
90 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
91 <table border='0'>
92 <tr>
93 <td align='right'>{$ma}:</td>
94 <td align='left'><strong>{$ott}</strong></td>
95 </tr>
96 <tr>
97 <td align='right'>{$newt}:</td>
98 <td align='left'>
99 <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
100 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
101 </td>
102 </tr>" );
103
104 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
105 $wgOut->addHTML( "
106 <tr>
107 <td align='right'>
108 <input type='checkbox' name=\"wpMovetalk\" checked='checked' value=\"1\" />
109 </td>
110 <td>{$movetalk}</td>
111 </tr>" );
112 }
113 $wgOut->addHTML( "
114 <tr>
115 <td>&nbsp;</td>
116 <td align='left'>
117 <input type='submit' name=\"wpMove\" value=\"{$mpb}\" />
118 </td>
119 </tr>
120 </table>
121 </form>\n" );
122
123 }
124
125 function doSubmit() {
126 global $wgOut, $wgUser, $wgLang;
127 global $wgDeferredUpdateList, $wgMessageCache;
128 global $wgUseSquid, $wgRequest;
129 $fname = "MovePageForm::doSubmit";
130
131 # Variables beginning with 'o' for old article 'n' for new article
132
133 # Attempt to move the article
134
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
175 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
176 ( ! Namespace::isTalk( $ons ) ) &&
177 ( ! Namespace::isTalk( $nns ) ) ) {
178
179 # get old talk page namespace
180 $ons = Namespace::getTalk( $ons );
181 # get new talk page namespace
182 $nns = Namespace::getTalk( $nns );
183
184 # make talk page title objects
185 $ott = Title::makeTitle( $ons, $ot->getDBkey() );
186 $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
187
188 # Attempt the move
189 $error = $ott->moveTo( $ntt );
190 if ( $error === true ) {
191 $talkmoved = 1;
192 } else {
193 $talkmoved = $error;
194 }
195 }
196
197 # Give back result to user.
198
199 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
200 $success = $titleObj->getFullURL(
201 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
202 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
203 '&talkmoved='.$talkmoved );
204
205 $wgOut->redirect( $success );
206 }
207
208 function showSuccess() {
209 global $wgOut, $wgUser, $wgRequest, $wgRawHtml;
210
211 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
212 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
213 $oldtitle = $wgRequest->getVal('oldtitle');
214 $newtitle = $wgRequest->getVal('newtitle');
215 $talkmoved = $wgRequest->getVal('talkmoved');
216
217 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
218
219 # Temporarily disable raw html wikitext option out of XSS paranoia
220 $marchingantofdoom = $wgRawHtml;
221 $wgRawHtml = false;
222 $wgOut->addWikiText( $text );
223 $wgRawHtml = $marchingantofdoom;
224
225 if ( $talkmoved == 1 ) {
226 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
227 } elseif( 'articleexists' == $talkmoved ) {
228 $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
229 } else {
230 $ot = Title::newFromURL( $oldtitle );
231 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
232 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );
233 }
234 }
235 }
236 }
237 ?>