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