5 * @subpackage SpecialPage
11 require_once( "LinksUpdate.php" );
16 function wfSpecialMovepage() {
17 global $wgUser, $wgOut, $wgRequest, $action, $wgOnlySysopMayMove;
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" );
24 # We don't move protected pages
26 $wgOut->readOnlyPage();
30 $f = new MovePageForm();
32 if ( 'success' == $action ) {
34 } else if ( 'submit' == $action && $wgRequest->wasPosted()
35 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
45 * @subpackage SpecialPage
48 var $oldTitle, $newTitle, $reason; # Text input
51 function MovePageForm() {
53 $this->oldTitle
= $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
54 $this->newTitle
= $wgRequest->getText( 'wpNewTitle' );
55 $this->reason
= $wgRequest->getText( 'wpReason' );
56 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', true );
59 function showForm( $err ) {
60 global $wgOut, $wgUser, $wgLang;
62 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
64 if ( $this->oldTitle
== '' ) {
65 $wgOut->errorpage( 'notargettitle', 'notargettext' );
69 $ot = Title
::newFromURL( $this->oldTitle
);
70 $oldTitle = $ot->getPrefixedText();
72 $encOldTitle = htmlspecialchars( $this->oldTitle
);
73 if( $this->newTitle
== '' ) {
74 # Show the current title as a default
75 # when the form is first opened.
76 $encNewTitle = $oldTitle;
78 $encNewTitle = htmlspecialchars( $this->newTitle
);
80 $encReason = htmlspecialchars( $this->reason
);
82 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
83 if ( !$ot->isTalkPage() ) {
84 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
87 $movearticle = wfMsg( 'movearticle' );
88 $newtitle = wfMsg( 'newtitle' );
89 $movepagebtn = wfMsg( 'movepagebtn' );
90 $movetalk = wfMsg( 'movetalk' );
91 $movereason = wfMsg( 'movereason' );
93 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
94 $action = $titleObj->escapeLocalURL( 'action=submit' );
95 $token = htmlspecialchars( $wgUser->editToken() );
98 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
99 $wgOut->addHTML( '<p class="error">'.$err."</p>\n" );
102 if ( $this->moveTalk
) {
103 $moveTalkChecked = " checked='checked'";
105 $moveTalkChecked = '';
109 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
112 <td align='right'>{$movearticle}:</td>
113 <td align='left'><strong>{$oldTitle}</strong></td>
116 <td align='right'>{$newtitle}:</td>
118 <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
119 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
123 <td align='right'>{$movereason}:</td>
125 <input type='text' size=40 name=\"wpReason\" value=\"{$encReason}\" />
129 if ( ! $ot->isTalkPage() ) {
133 <input type='checkbox' name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
142 <input type='submit' name=\"wpMove\" value=\"{$movepagebtn}\" />
146 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
151 function doSubmit() {
152 global $wgOut, $wgUser, $wgLang;
153 global $wgDeferredUpdateList, $wgMessageCache;
154 global $wgUseSquid, $wgRequest;
155 $fname = "MovePageForm::doSubmit";
157 # Variables beginning with 'o' for old article 'n' for new article
159 # Attempt to move the article
160 $ot = Title
::newFromText( $this->oldTitle
);
161 $nt = Title
::newFromText( $this->newTitle
);
163 # don't allow moving to pages with # in
164 if ( !$nt ||
$nt->getFragment() != '' ) {
165 $this->showForm( wfMsg( "badtitletext" ) );
169 $error = $ot->moveTo( $nt, true, $this->reason
);
170 if ( $error !== true ) {
171 $this->showForm( wfMsg( $error ) );
175 # Update counters if the article got moved into or out of NS_MAIN namespace
176 $ons = $ot->getNamespace();
177 $nns = $nt->getNamespace();
179 # moved out of article namespace?
180 if ( $ons == NS_MAIN
and $nns != NS_MAIN
) {
181 $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
183 # moved into article namespace?
184 elseif ( $ons != NS_MAIN
and $nns == NS_MAIN
) {
185 $u = new SiteStatsUpdate( 0, 1, +
1 ); # not viewed, edited, adding
189 if ( $u !== false ) {
190 # save it for later update
191 array_push( $wgDeferredUpdateList, $u );
196 # (1) the checkbox says to,
197 # (2) the namespaces are not themselves talk namespaces, and of course
199 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
200 ( ! Namespace::isTalk( $ons ) ) &&
201 ( ! Namespace::isTalk( $nns ) ) ) {
203 # get old talk page namespace
204 $ons = Namespace::getTalk( $ons );
205 # get new talk page namespace
206 $nns = Namespace::getTalk( $nns );
208 # make talk page title objects
209 $ott = Title
::makeTitle( $ons, $ot->getDBkey() );
210 $ntt = Title
::makeTitle( $nns, $nt->getDBkey() );
213 $error = $ott->moveTo( $ntt, true, $this->reason
);
214 if ( $error === true ) {
221 # Give back result to user.
222 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
223 $success = $titleObj->getFullURL(
224 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
225 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
226 '&talkmoved='.$talkmoved );
228 $wgOut->redirect( $success );
231 function showSuccess() {
232 global $wgOut, $wgRequest, $wgRawHtml;
234 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
235 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
236 $oldtitle = $wgRequest->getVal('oldtitle');
237 $newtitle = $wgRequest->getVal('newtitle');
238 $talkmoved = $wgRequest->getVal('talkmoved');
240 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
242 # Temporarily disable raw html wikitext option out of XSS paranoia
243 $marchingantofdoom = $wgRawHtml;
245 $wgOut->addWikiText( $text );
246 $wgRawHtml = $marchingantofdoom;
248 if ( $talkmoved == 1 ) {
249 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
250 } elseif( 'articleexists' == $talkmoved ) {
251 $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
253 $ot = Title
::newFromURL( $oldtitle );
254 if ( ! $ot->isTalkPage() ) {
255 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );