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
49 var $moveTalk, $deleteAndMove;
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 );
57 $this->deleteAndMove
= $wgRequest->getBool( 'wpDeleteAndMove' );
60 function showForm( $err ) {
61 global $wgOut, $wgUser, $wgLang;
63 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
65 if ( $this->oldTitle
== '' ) {
66 $wgOut->errorpage( 'notargettitle', 'notargettext' );
70 $ot = Title
::newFromURL( $this->oldTitle
);
71 $oldTitle = $ot->getPrefixedText();
73 $encOldTitle = htmlspecialchars( $this->oldTitle
);
74 if( $this->newTitle
== '' ) {
75 # Show the current title as a default
76 # when the form is first opened.
77 $encNewTitle = $oldTitle;
80 $nt = Title
::newFromURL( $this->newTitle
);
82 # If a title was supplied, probably from the move log revert
83 # link, check for validity. We can then show some diagnostic
84 # information and save a click.
85 $newerr = $ot->isValidMoveOperation( $nt );
86 if( is_string( $newerr ) ) {
91 $encNewTitle = htmlspecialchars( $this->newTitle
);
93 $encReason = htmlspecialchars( $this->reason
);
95 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
96 $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
97 $movepagebtn = wfMsg( 'delete_and_move' );
98 $submitVar = 'wpDeleteAndMove';
101 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
102 $movepagebtn = wfMsg( 'movepagebtn' );
103 $submitVar = 'wpMove';
106 if ( !$ot->isTalkPage() ) {
107 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
110 $movearticle = wfMsg( 'movearticle' );
111 $newtitle = wfMsg( 'newtitle' );
112 $movetalk = wfMsg( 'movetalk' );
113 $movereason = wfMsg( 'movereason' );
115 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
116 $action = $titleObj->escapeLocalURL( 'action=submit' );
117 $token = htmlspecialchars( $wgUser->editToken() );
120 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
121 $wgOut->addHTML( '<p class="error">' . wfMsg($err) . "</p>\n" );
124 $moveTalkChecked = $this->moveTalk ?
' checked="checked"' : '';
127 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
130 <td align='right'>{$movearticle}:</td>
131 <td align='left'><strong>{$oldTitle}</strong></td>
134 <td align='right'>{$newtitle}:</td>
136 <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
137 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
141 <td align='right'>{$movereason}:</td>
143 <input type='text' size=40 name=\"wpReason\" value=\"{$encReason}\" />
147 if ( ! $ot->isTalkPage() ) {
151 <input type='checkbox' name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
160 <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
164 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
169 function doSubmit() {
170 global $wgOut, $wgUser, $wgLang;
171 global $wgDeferredUpdateList, $wgMessageCache;
172 global $wgUseSquid, $wgRequest;
173 $fname = "MovePageForm::doSubmit";
175 # Variables beginning with 'o' for old article 'n' for new article
177 $ot = Title
::newFromText( $this->oldTitle
);
178 $nt = Title
::newFromText( $this->newTitle
);
180 # Delete to make way if requested
181 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
182 $article = new Article( $nt );
183 // This may output an error message and exit
184 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
187 # don't allow moving to pages with # in
188 if ( !$nt ||
$nt->getFragment() != '' ) {
189 $this->showForm( 'badtitletext' );
193 $error = $ot->moveTo( $nt, true, $this->reason
);
194 if ( $error !== true ) {
195 $this->showForm( $error );
199 # Update counters if the article got moved into or out of NS_MAIN namespace
200 $ons = $ot->getNamespace();
201 $nns = $nt->getNamespace();
203 # moved out of article namespace?
204 if ( $ons == NS_MAIN
and $nns != NS_MAIN
) {
205 $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
207 # moved into article namespace?
208 elseif ( $ons != NS_MAIN
and $nns == NS_MAIN
) {
209 $u = new SiteStatsUpdate( 0, 1, +
1 ); # not viewed, edited, adding
213 if ( $u !== false ) {
214 # save it for later update
215 array_push( $wgDeferredUpdateList, $u );
220 # (1) the checkbox says to,
221 # (2) the namespaces are not themselves talk namespaces, and of course
223 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
224 ( ! Namespace::isTalk( $ons ) ) &&
225 ( ! Namespace::isTalk( $nns ) ) ) {
227 # get old talk page namespace
228 $ons = Namespace::getTalk( $ons );
229 # get new talk page namespace
230 $nns = Namespace::getTalk( $nns );
232 # make talk page title objects
233 $ott = Title
::makeTitle( $ons, $ot->getDBkey() );
234 $ntt = Title
::makeTitle( $nns, $nt->getDBkey() );
237 $error = $ott->moveTo( $ntt, true, $this->reason
);
238 if ( $error === true ) {
245 # Give back result to user.
246 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
247 $success = $titleObj->getFullURL(
248 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
249 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
250 '&talkmoved='.$talkmoved );
252 $wgOut->redirect( $success );
255 function showSuccess() {
256 global $wgOut, $wgRequest, $wgRawHtml;
258 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
259 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
260 $oldtitle = $wgRequest->getVal('oldtitle');
261 $newtitle = $wgRequest->getVal('newtitle');
262 $talkmoved = $wgRequest->getVal('talkmoved');
264 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
266 # Temporarily disable raw html wikitext option out of XSS paranoia
267 $marchingantofdoom = $wgRawHtml;
269 $wgOut->addWikiText( $text );
270 $wgRawHtml = $marchingantofdoom;
272 if ( $talkmoved == 1 ) {
273 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
274 } elseif( 'articleexists' == $talkmoved ) {
275 $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
277 $ot = Title
::newFromURL( $oldtitle );
278 if ( ! $ot->isTalkPage() ) {
279 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );