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 ( 0 == $wgUser->getID() 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 ) { $f->showSuccess(); }
33 else if ( 'submit' == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
34 else { $f->showForm( '' ); }
40 * @subpackage SpecialPage
43 var $oldTitle, $newTitle; # Text input
45 function MovePageForm() {
47 $this->oldTitle
= $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
48 $this->newTitle
= $wgRequest->getText( 'wpNewTitle' );
51 function showForm( $err ) {
52 global $wgOut, $wgUser, $wgLang;
54 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
56 if ( $this->oldTitle
== '' ) {
57 $wgOut->errorpage( 'notargettitle', 'notargettext' );
61 $ot = Title
::newFromURL( $this->oldTitle
);
62 $ott = $ot->getPrefixedText();
64 $encOldTitle = htmlspecialchars( $this->oldTitle
);
65 if( $this->newTitle
== '' ) {
66 # Show the current title as a default
67 # when the form is first opened.
70 $encNewTitle = htmlspecialchars( $this->newTitle
);
73 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
74 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
75 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
78 $ma = wfMsg( 'movearticle' );
79 $newt = wfMsg( 'newtitle' );
80 $mpb = wfMsg( 'movepagebtn' );
81 $movetalk = wfMsg( 'movetalk' );
83 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
84 $action = $titleObj->escapeLocalURL( 'action=submit' );
87 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
88 $wgOut->addHTML( '<p class="error">'.$err."</p>\n" );
91 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
94 <td align='right'>{$ma}:</td>
95 <td align='left'><strong>{$ott}</strong></td>
98 <td align='right'>{$newt}:</td>
100 <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
101 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
105 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
109 <input type='checkbox' name=\"wpMovetalk\" checked='checked' value=\"1\" />
118 <input type='submit' name=\"wpMove\" value=\"{$mpb}\" />
126 function doSubmit() {
127 global $wgOut, $wgUser, $wgLang;
128 global $wgDeferredUpdateList, $wgMessageCache;
129 global $wgUseSquid, $wgRequest;
130 $fname = "MovePageForm::doSubmit";
132 # Variables beginning with 'o' for old article 'n' for new article
134 # Attempt to move the article
136 $ot = Title
::newFromText( $this->oldTitle
);
137 $nt = Title
::newFromText( $this->newTitle
);
139 # don't allow moving to pages with # in
140 if ( !$nt ||
$nt->getFragment() != '' ) {
141 $this->showForm( wfMsg( "badtitletext" ) );
145 $error = $ot->moveTo( $nt );
146 if ( $error !== true ) {
147 $this->showForm( wfMsg( $error ) );
151 # Update counters if the article got moved into or out of NS_MAIN namespace
152 $ons = $ot->getNamespace();
153 $nns = $nt->getNamespace();
155 # moved out of article namespace?
156 if ( $ons == NS_MAIN
and $nns != NS_MAIN
) {
157 $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
159 # moved into article namespace?
160 elseif ( $ons != NS_MAIN
and $nns == NS_MAIN
) {
161 $u = new SiteStatsUpdate( 0, 1, +
1 ); # not viewed, edited, adding
165 if ( $u !== false ) {
166 # save it for later update
167 array_push( $wgDeferredUpdateList, $u );
172 # (1) the checkbox says to,
173 # (2) the namespaces are not themselves talk namespaces, and of course
176 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
177 ( ! Namespace::isTalk( $ons ) ) &&
178 ( ! Namespace::isTalk( $nns ) ) ) {
180 # get old talk page namespace
181 $ons = Namespace::getTalk( $ons );
182 # get new talk page namespace
183 $nns = Namespace::getTalk( $nns );
185 # make talk page title objects
186 $ott = Title
::makeTitle( $ons, $ot->getDBkey() );
187 $ntt = Title
::makeTitle( $nns, $nt->getDBkey() );
190 $error = $ott->moveTo( $ntt );
191 if ( $error === true ) {
198 # Give back result to user.
200 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
201 $success = $titleObj->getFullURL(
202 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
203 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
204 '&talkmoved='.$talkmoved );
206 $wgOut->redirect( $success );
209 function showSuccess() {
210 global $wgOut, $wgUser, $wgRequest, $wgRawHtml;
212 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
213 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
214 $oldtitle = $wgRequest->getVal('oldtitle');
215 $newtitle = $wgRequest->getVal('newtitle');
216 $talkmoved = $wgRequest->getVal('talkmoved');
218 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
220 # Temporarily disable raw html wikitext option out of XSS paranoia
221 $marchingantofdoom = $wgRawHtml;
223 $wgOut->addWikiText( $text );
224 $wgRawHtml = $marchingantofdoom;
226 if ( $talkmoved == 1 ) {
227 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
228 } elseif( 'articleexists' == $talkmoved ) {
229 $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
231 $ot = Title
::newFromURL( $oldtitle );
232 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
233 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );