* double quotes to single quotes
[mediawiki.git] / includes / SpecialMovepage.php
blobe40d89864c66953a0e19d0c417a4b00021e4b2dc
1 <?php
2 /**
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
8 /**
11 require_once( "LinksUpdate.php" );
13 /**
14 * Constructor
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" );
22 return;
24 # We don't move protected pages
25 if ( wfReadOnly() ) {
26 $wgOut->readOnlyPage();
27 return;
30 $f = new MovePageForm();
32 if ( 'success' == $action ) { $f->showSuccess(); }
33 else if ( 'submit' == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
34 else { $f->showForm( '' ); }
37 /**
39 * @package MediaWiki
40 * @subpackage SpecialPage
42 class MovePageForm {
43 var $oldTitle, $newTitle; # Text input
45 function MovePageForm() {
46 global $wgRequest;
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 ( empty( $this->oldTitle ) ) {
57 $wgOut->errorpage( 'notargettitle', 'notargettext' );
58 return;
61 $encOldTitle = htmlspecialchars( $this->oldTitle );
62 $encNewTitle = htmlspecialchars( $this->newTitle );
63 $ot = Title::newFromURL( $this->oldTitle );
64 $ott = $ot->getPrefixedText();
66 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
67 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
68 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
71 $ma = wfMsg( 'movearticle' );
72 $newt = wfMsg( 'newtitle' );
73 $mpb = wfMsg( 'movepagebtn' );
74 $movetalk = wfMsg( 'movetalk' );
76 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
77 $action = $titleObj->escapeLocalURL( 'action=submit' );
79 if ( $err != '' ) {
80 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
81 $wgOut->addHTML( '<p class="error">'.$err."</p>\n" );
83 $wgOut->addHTML( "
84 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
85 <table border='0'>
86 <tr>
87 <td align='right'>{$ma}:</td>
88 <td align='left'><strong>{$ott}</strong></td>
89 </tr>
90 <tr>
91 <td align='right'>{$newt}:</td>
92 <td align='left'>
93 <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
94 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
95 </td>
96 </tr>" );
98 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
99 $wgOut->addHTML( "
100 <tr>
101 <td align='right'>
102 <input type='checkbox' name=\"wpMovetalk\" checked='checked' value=\"1\" />
103 </td>
104 <td>{$movetalk}</td>
105 </tr>" );
107 $wgOut->addHTML( "
108 <tr>
109 <td>&nbsp;</td>
110 <td align='left'>
111 <input type='submit' name=\"wpMove\" value=\"{$mpb}\" />
112 </td>
113 </tr>
114 </table>
115 </form>\n" );
119 function doSubmit() {
120 global $wgOut, $wgUser, $wgLang;
121 global $wgDeferredUpdateList, $wgMessageCache;
122 global $wgUseSquid, $wgRequest;
123 $fname = "MovePageForm::doSubmit";
125 # Variables beginning with 'o' for old article 'n' for new article
127 # Attempt to move the article
129 $ot = Title::newFromText( $this->oldTitle );
130 $nt = Title::newFromText( $this->newTitle );
132 $error = $ot->moveTo( $nt );
133 if ( $error !== true ) {
134 $this->showForm( wfMsg( $error ) );
135 return;
138 # Update counters if the article got moved into or out of NS_MAIN namespace
139 $ons = $ot->getNamespace();
140 $nns = $nt->getNamespace();
142 # moved out of article namespace?
143 if ( $ons == NS_MAIN and $nns != NS_MAIN ) {
144 $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
146 # moved into article namespace?
147 elseif ( $ons != NS_MAIN and $nns == NS_MAIN ) {
148 $u = new SiteStatsUpdate( 0, 1, +1 ); # not viewed, edited, adding
149 } else {
150 $u = false;
152 if ( $u !== false ) {
153 # save it for later update
154 array_push( $wgDeferredUpdateList, $u );
155 unset($u);
158 # Move talk page if
159 # (1) the checkbox says to,
160 # (2) the namespaces are not themselves talk namespaces, and of course
161 # (3) it exists.
163 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
164 ( ! Namespace::isTalk( $ons ) ) &&
165 ( ! Namespace::isTalk( $nns ) ) ) {
167 # get old talk page namespace
168 $ons = Namespace::getTalk( $ons );
169 # get new talk page namespace
170 $nns = Namespace::getTalk( $nns );
172 # make talk page title objects
173 $ott = Title::makeTitle( $ons, $ot->getDBkey() );
174 $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
176 # Attempt the move
177 $error = $ott->moveTo( $ntt );
178 if ( $error === true ) {
179 $talkmoved = 1;
180 } else {
181 $talkmoved = $error;
185 # Give back result to user.
187 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
188 $success = $titleObj->getFullURL(
189 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
190 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
191 '&talkmoved='.$talkmoved );
193 $wgOut->redirect( $success );
196 function showSuccess() {
197 global $wgOut, $wgUser, $wgRequest;
199 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
200 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
201 $oldtitle = $wgRequest->getVal('oldtitle');
202 $newtitle = $wgRequest->getVal('newtitle');
203 $talkmoved = $wgRequest->getVal('talkmoved');
205 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
206 $wgOut->addWikiText( $text );
208 if ( $talkmoved == 1 ) {
209 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
210 } elseif( 'articleexists' == $talkmoved ) {
211 $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
212 } else {
213 $ot = Title::newFromURL( $oldtitle );
214 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
215 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );