Fix #1130 : special:movepage not showing actual title but encoded one.
[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
136 $ot = Title::newFromText( $this->oldTitle );
137 $nt = Title::newFromText( $this->newTitle );
138
139 # don't allow moving to pages with # in
140 if ( !$nt || $nt->getFragment() != '' ) {
141 $this->showForm( wfMsg( "badtitletext" ) );
142 return;
143 }
144
145 $error = $ot->moveTo( $nt );
146 if ( $error !== true ) {
147 $this->showForm( wfMsg( $error ) );
148 return;
149 }
150
151 # Update counters if the article got moved into or out of NS_MAIN namespace
152 $ons = $ot->getNamespace();
153 $nns = $nt->getNamespace();
154
155 # moved out of article namespace?
156 if ( $ons == NS_MAIN and $nns != NS_MAIN ) {
157 $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
158 }
159 # moved into article namespace?
160 elseif ( $ons != NS_MAIN and $nns == NS_MAIN ) {
161 $u = new SiteStatsUpdate( 0, 1, +1 ); # not viewed, edited, adding
162 } else {
163 $u = false;
164 }
165 if ( $u !== false ) {
166 # save it for later update
167 array_push( $wgDeferredUpdateList, $u );
168 unset($u);
169 }
170
171 # Move talk page if
172 # (1) the checkbox says to,
173 # (2) the namespaces are not themselves talk namespaces, and of course
174 # (3) it exists.
175
176 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
177 ( ! Namespace::isTalk( $ons ) ) &&
178 ( ! Namespace::isTalk( $nns ) ) ) {
179
180 # get old talk page namespace
181 $ons = Namespace::getTalk( $ons );
182 # get new talk page namespace
183 $nns = Namespace::getTalk( $nns );
184
185 # make talk page title objects
186 $ott = Title::makeTitle( $ons, $ot->getDBkey() );
187 $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
188
189 # Attempt the move
190 $error = $ott->moveTo( $ntt );
191 if ( $error === true ) {
192 $talkmoved = 1;
193 } else {
194 $talkmoved = $error;
195 }
196 }
197
198 # Give back result to user.
199
200 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
201 $success = $titleObj->getFullURL(
202 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
203 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
204 '&talkmoved='.$talkmoved );
205
206 $wgOut->redirect( $success );
207 }
208
209 function showSuccess() {
210 global $wgOut, $wgUser, $wgRequest, $wgRawHtml;
211
212 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
213 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
214 $oldtitle = $wgRequest->getVal('oldtitle');
215 $newtitle = $wgRequest->getVal('newtitle');
216 $talkmoved = $wgRequest->getVal('talkmoved');
217
218 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
219
220 # Temporarily disable raw html wikitext option out of XSS paranoia
221 $marchingantofdoom = $wgRawHtml;
222 $wgRawHtml = false;
223 $wgOut->addWikiText( $text );
224 $wgRawHtml = $marchingantofdoom;
225
226 if ( $talkmoved == 1 ) {
227 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
228 } elseif( 'articleexists' == $talkmoved ) {
229 $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
230 } else {
231 $ot = Title::newFromURL( $oldtitle );
232 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
233 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );
234 }
235 }
236 }
237 }
238 ?>