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;
79 $nt = Title
::newFromURL( $this->newTitle
);
81 // Check if it's valid
82 if ( !$nt->isValidMoveTarget( $ot ) ) {
83 $err = 'articleexists';
85 $encNewTitle = htmlspecialchars( $this->newTitle
);
87 $encNewTitle = $oldTitle;
90 $encReason = htmlspecialchars( $this->reason
);
92 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
93 $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
94 $movepagebtn = wfMsg( 'delete_and_move' );
95 $submitVar = 'wpDeleteAndMove';
98 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
99 $movepagebtn = wfMsg( 'movepagebtn' );
100 $submitVar = 'wpMove';
103 if ( !$ot->isTalkPage() ) {
104 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
107 $movearticle = wfMsg( 'movearticle' );
108 $newtitle = wfMsg( 'newtitle' );
109 $movetalk = wfMsg( 'movetalk' );
110 $movereason = wfMsg( 'movereason' );
112 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
113 $action = $titleObj->escapeLocalURL( 'action=submit' );
114 $token = htmlspecialchars( $wgUser->editToken() );
117 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
118 $wgOut->addHTML( '<p class="error">' . wfMsg($err) . "</p>\n" );
121 $moveTalkChecked = $this->moveTalk ?
' checked="checked"' : '';
124 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
127 <td align='right'>{$movearticle}:</td>
128 <td align='left'><strong>{$oldTitle}</strong></td>
131 <td align='right'>{$newtitle}:</td>
133 <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
134 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
138 <td align='right'>{$movereason}:</td>
140 <input type='text' size=40 name=\"wpReason\" value=\"{$encReason}\" />
144 if ( ! $ot->isTalkPage() ) {
148 <input type='checkbox' name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
157 <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
161 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
166 function doSubmit() {
167 global $wgOut, $wgUser, $wgLang;
168 global $wgDeferredUpdateList, $wgMessageCache;
169 global $wgUseSquid, $wgRequest;
170 $fname = "MovePageForm::doSubmit";
172 # Variables beginning with 'o' for old article 'n' for new article
174 $ot = Title
::newFromText( $this->oldTitle
);
175 $nt = Title
::newFromText( $this->newTitle
);
177 # Delete to make way if requested
178 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
179 $article = new Article( $nt );
180 // This may output an error message and exit
181 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
184 # don't allow moving to pages with # in
185 if ( !$nt ||
$nt->getFragment() != '' ) {
186 $this->showForm( 'badtitletext' );
190 $error = $ot->moveTo( $nt, true, $this->reason
);
191 if ( $error !== true ) {
192 $this->showForm( $error );
196 # Update counters if the article got moved into or out of NS_MAIN namespace
197 $ons = $ot->getNamespace();
198 $nns = $nt->getNamespace();
200 # moved out of article namespace?
201 if ( $ons == NS_MAIN
and $nns != NS_MAIN
) {
202 $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
204 # moved into article namespace?
205 elseif ( $ons != NS_MAIN
and $nns == NS_MAIN
) {
206 $u = new SiteStatsUpdate( 0, 1, +
1 ); # not viewed, edited, adding
210 if ( $u !== false ) {
211 # save it for later update
212 array_push( $wgDeferredUpdateList, $u );
217 # (1) the checkbox says to,
218 # (2) the namespaces are not themselves talk namespaces, and of course
220 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
221 ( ! Namespace::isTalk( $ons ) ) &&
222 ( ! Namespace::isTalk( $nns ) ) ) {
224 # get old talk page namespace
225 $ons = Namespace::getTalk( $ons );
226 # get new talk page namespace
227 $nns = Namespace::getTalk( $nns );
229 # make talk page title objects
230 $ott = Title
::makeTitle( $ons, $ot->getDBkey() );
231 $ntt = Title
::makeTitle( $nns, $nt->getDBkey() );
234 $error = $ott->moveTo( $ntt, true, $this->reason
);
235 if ( $error === true ) {
242 # Give back result to user.
243 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
244 $success = $titleObj->getFullURL(
245 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
246 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
247 '&talkmoved='.$talkmoved );
249 $wgOut->redirect( $success );
252 function showSuccess() {
253 global $wgOut, $wgRequest, $wgRawHtml;
255 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
256 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
257 $oldtitle = $wgRequest->getVal('oldtitle');
258 $newtitle = $wgRequest->getVal('newtitle');
259 $talkmoved = $wgRequest->getVal('talkmoved');
261 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
263 # Temporarily disable raw html wikitext option out of XSS paranoia
264 $marchingantofdoom = $wgRawHtml;
266 $wgOut->addWikiText( $text );
267 $wgRawHtml = $marchingantofdoom;
269 if ( $talkmoved == 1 ) {
270 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
271 } elseif( 'articleexists' == $talkmoved ) {
272 $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
274 $ot = Title
::newFromURL( $oldtitle );
275 if ( ! $ot->isTalkPage() ) {
276 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );