5 * @subpackage SpecialPage
11 require_once( "LinksUpdate.php" );
16 function wfSpecialMovepage( $par = null ) {
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( $par );
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( $par ) {
53 $target = isset($par) ?
$par : $wgRequest->getVal( 'target' );
54 $this->oldTitle
= $wgRequest->getText( 'wpOldTitle', $target );
55 $this->newTitle
= $wgRequest->getText( 'wpNewTitle' );
56 $this->reason
= $wgRequest->getText( 'wpReason' );
57 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', true );
58 $this->deleteAndMove
= $wgRequest->getBool( 'wpDeleteAndMove' );
61 function showForm( $err ) {
62 global $wgOut, $wgUser, $wgLang;
64 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
66 $ot = Title
::newFromURL( $this->oldTitle
);
67 if( is_null( $ot ) ) {
68 $wgOut->errorpage( 'notargettitle', 'notargettext' );
71 $oldTitle = $ot->getPrefixedText();
73 $encOldTitle = htmlspecialchars( $oldTitle );
74 if( $this->newTitle
== '' ) {
75 # Show the current title as a default
76 # when the form is first opened.
77 $encNewTitle = $encOldTitle;
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 = wfMsgHtml( 'delete_and_move' );
98 $submitVar = 'wpDeleteAndMove';
101 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
102 $movepagebtn = wfMsgHtml( 'movepagebtn' );
103 $submitVar = 'wpMove';
106 if ( !$ot->isTalkPage() ) {
107 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
110 $movearticle = wfMsgHtml( 'movearticle' );
111 $newtitle = wfMsgHtml( 'newtitle' );
112 $movetalk = wfMsgHtml( 'movetalk' );
113 $movereason = wfMsgHtml( '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->addWikiText( '<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' valign='top'><br />{$movereason}:</td>
142 <td align='left' valign='top'><br />
143 <textarea type='text' cols='60' rows='2' name=\"wpReason\" value=\"{$encReason}\"></textarea>
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 if ( $wgUser->pingLimiter( 'move' ) ) {
176 $wgOut->rateLimited();
180 # Variables beginning with 'o' for old article 'n' for new article
182 $ot = Title
::newFromText( $this->oldTitle
);
183 $nt = Title
::newFromText( $this->newTitle
);
185 # Delete to make way if requested
186 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
187 $article = new Article( $nt );
188 // This may output an error message and exit
189 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
192 # don't allow moving to pages with # in
193 if ( !$nt ||
$nt->getFragment() != '' ) {
194 $this->showForm( 'badtitletext' );
198 $error = $ot->moveTo( $nt, true, $this->reason
);
199 if ( $error !== true ) {
200 $this->showForm( $error );
205 # (1) the checkbox says to,
206 # (2) the namespaces are not themselves talk namespaces, and of course
208 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
209 !$ot->isTalkPage() &&
210 !$nt->isTalkPage() ) {
212 $ott = $ot->getTalkPage();
213 $ntt = $nt->getTalkPage();
216 $error = $ott->moveTo( $ntt, true, $this->reason
);
217 if ( $error === true ) {
223 # Stay silent on the subject of talk.
227 # Give back result to user.
228 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
229 $success = $titleObj->getFullURL(
230 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
231 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
232 '&talkmoved='.$talkmoved );
234 $wgOut->redirect( $success );
237 function showSuccess() {
238 global $wgOut, $wgRequest, $wgRawHtml;
240 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
241 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
242 $oldtitle = $wgRequest->getVal('oldtitle');
243 $newtitle = $wgRequest->getVal('newtitle');
244 $talkmoved = $wgRequest->getVal('talkmoved');
246 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
248 # Temporarily disable raw html wikitext option out of XSS paranoia
249 $marchingantofdoom = $wgRawHtml;
251 $wgOut->addWikiText( $text );
252 $wgRawHtml = $marchingantofdoom;
254 if ( $talkmoved == 1 ) {
255 $wgOut->addWikiText( wfMsg( 'talkpagemoved' ) );
256 } elseif( 'articleexists' == $talkmoved ) {
257 $wgOut->addWikiText( wfMsg( 'talkexists' ) );
259 $ot = Title
::newFromURL( $oldtitle );
260 if ( ! $ot->isTalkPage() ) {
261 $wgOut->addWikiText( wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) );