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
50 function MovePageForm() {
52 $this->oldTitle
= $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
53 $this->newTitle
= $wgRequest->getText( 'wpNewTitle' );
54 $this->reason
= $wgRequest->getText( 'wpReason' );
57 function showForm( $err ) {
58 global $wgOut, $wgUser, $wgLang;
60 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
62 if ( $this->oldTitle
== '' ) {
63 $wgOut->errorpage( 'notargettitle', 'notargettext' );
67 $ot = Title
::newFromURL( $this->oldTitle
);
68 $oldTitle = $ot->getPrefixedText();
70 $encOldTitle = htmlspecialchars( $this->oldTitle
);
71 if( $this->newTitle
== '' ) {
72 # Show the current title as a default
73 # when the form is first opened.
74 $encNewTitle = $oldTitle;
76 $encNewTitle = htmlspecialchars( $this->newTitle
);
78 $encReason = htmlspecialchars( $this->reason
);
80 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
81 if ( !$ot->isTalkPage() ) {
82 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
85 $movearticle = wfMsg( 'movearticle' );
86 $newtitle = wfMsg( 'newtitle' );
87 $movepagebtn = wfMsg( 'movepagebtn' );
88 $movetalk = wfMsg( 'movetalk' );
89 $movereason = wfMsg( 'movereason' );
91 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
92 $action = $titleObj->escapeLocalURL( 'action=submit' );
93 $token = htmlspecialchars( $wgUser->editToken() );
96 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
97 $wgOut->addHTML( '<p class="error">'.$err."</p>\n" );
100 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
103 <td align='right'>{$movearticle}:</td>
104 <td align='left'><strong>{$oldTitle}</strong></td>
107 <td align='right'>{$newtitle}:</td>
109 <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
110 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
114 <td align='right'>{$movereason}:</td>
116 <input type='text' size=40 name=\"wpReason\" value=\"{$encReason}\" />
120 if ( ! $ot->isTalkPage() ) {
124 <input type='checkbox' name=\"wpMovetalk\" checked='checked' value=\"1\" />
133 <input type='submit' name=\"wpMove\" value=\"{$movepagebtn}\" />
137 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
142 function doSubmit() {
143 global $wgOut, $wgUser, $wgLang;
144 global $wgDeferredUpdateList, $wgMessageCache;
145 global $wgUseSquid, $wgRequest;
146 $fname = "MovePageForm::doSubmit";
148 # Variables beginning with 'o' for old article 'n' for new article
150 # Attempt to move the article
151 $ot = Title
::newFromText( $this->oldTitle
);
152 $nt = Title
::newFromText( $this->newTitle
);
154 # don't allow moving to pages with # in
155 if ( !$nt ||
$nt->getFragment() != '' ) {
156 $this->showForm( wfMsg( "badtitletext" ) );
160 $error = $ot->moveTo( $nt, true, $this->reason
);
161 if ( $error !== true ) {
162 $this->showForm( wfMsg( $error ) );
166 # Update counters if the article got moved into or out of NS_MAIN namespace
167 $ons = $ot->getNamespace();
168 $nns = $nt->getNamespace();
170 # moved out of article namespace?
171 if ( $ons == NS_MAIN
and $nns != NS_MAIN
) {
172 $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
174 # moved into article namespace?
175 elseif ( $ons != NS_MAIN
and $nns == NS_MAIN
) {
176 $u = new SiteStatsUpdate( 0, 1, +
1 ); # not viewed, edited, adding
180 if ( $u !== false ) {
181 # save it for later update
182 array_push( $wgDeferredUpdateList, $u );
187 # (1) the checkbox says to,
188 # (2) the namespaces are not themselves talk namespaces, and of course
190 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
191 ( ! Namespace::isTalk( $ons ) ) &&
192 ( ! Namespace::isTalk( $nns ) ) ) {
194 # get old talk page namespace
195 $ons = Namespace::getTalk( $ons );
196 # get new talk page namespace
197 $nns = Namespace::getTalk( $nns );
199 # make talk page title objects
200 $ott = Title
::makeTitle( $ons, $ot->getDBkey() );
201 $ntt = Title
::makeTitle( $nns, $nt->getDBkey() );
204 $error = $ott->moveTo( $ntt, true, $this->reason
);
205 if ( $error === true ) {
212 # Give back result to user.
213 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
214 $success = $titleObj->getFullURL(
215 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
216 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
217 '&talkmoved='.$talkmoved );
219 $wgOut->redirect( $success );
222 function showSuccess() {
223 global $wgOut, $wgRequest, $wgRawHtml;
225 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
226 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
227 $oldtitle = $wgRequest->getVal('oldtitle');
228 $newtitle = $wgRequest->getVal('newtitle');
229 $talkmoved = $wgRequest->getVal('talkmoved');
231 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
233 # Temporarily disable raw html wikitext option out of XSS paranoia
234 $marchingantofdoom = $wgRawHtml;
236 $wgOut->addWikiText( $text );
237 $wgRawHtml = $marchingantofdoom;
239 if ( $talkmoved == 1 ) {
240 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
241 } elseif( 'articleexists' == $talkmoved ) {
242 $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
244 $ot = Title
::newFromURL( $oldtitle );
245 if ( ! $ot->isTalkPage() ) {
246 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );