Some documentation. Let's talk about it in wikitech-l.
[mediawiki.git] / includes / SpecialMovepage.php
blob4fc6435591be21170729db6b3a8ea117963514ee
1 <?php
2 /**
4 */
6 /**
8 */
9 require_once( "LinksUpdate.php" );
11 /**
12 * Constructor
14 function wfSpecialMovepage() {
15 global $wgUser, $wgOut, $wgRequest, $action, $wgOnlySysopMayMove;
17 # check rights. We don't want newbies to move pages to prevents possible attack
18 if ( 0 == $wgUser->getID() or $wgUser->isBlocked() or ($wgOnlySysopMayMove and $wgUser->isNewbie())) {
19 $wgOut->errorpage( "movenologin", "movenologintext" );
20 return;
22 # We don't move protected pages
23 if ( wfReadOnly() ) {
24 $wgOut->readOnlyPage();
25 return;
28 $f = new MovePageForm();
30 if ( 'success' == $action ) { $f->showSuccess(); }
31 else if ( 'submit' == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
32 else { $f->showForm( '' ); }
35 /**
38 class MovePageForm {
39 var $oldTitle, $newTitle; # Text input
41 function MovePageForm() {
42 global $wgRequest;
43 $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
44 $this->newTitle = $wgRequest->getText( 'wpNewTitle' );
47 function showForm( $err ) {
48 global $wgOut, $wgUser, $wgLang;
50 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
52 if ( empty( $this->oldTitle ) ) {
53 $wgOut->errorpage( 'notargettitle', 'notargettext' );
54 return;
57 $encOldTitle = htmlspecialchars( $this->oldTitle );
58 $encNewTitle = htmlspecialchars( $this->newTitle );
59 $ot = Title::newFromURL( $this->oldTitle );
60 $ott = $ot->getPrefixedText();
62 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
63 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
64 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
67 $ma = wfMsg( 'movearticle' );
68 $newt = wfMsg( 'newtitle' );
69 $mpb = wfMsg( 'movepagebtn' );
70 $movetalk = wfMsg( 'movetalk' );
72 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
73 $action = $titleObj->escapeLocalURL( 'action=submit' );
75 if ( $err != '' ) {
76 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
77 $wgOut->addHTML( '<p class="error">'.$err."</p>\n" );
79 $wgOut->addHTML( "
80 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
81 <table border='0'>
82 <tr>
83 <td align='right'>{$ma}:</td>
84 <td align='left'><strong>{$ott}</strong></td>
85 </tr>
86 <tr>
87 <td align='right'>{$newt}:</td>
88 <td align='left'>
89 <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
90 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
91 </td>
92 </tr>" );
94 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
95 $wgOut->addHTML( "
96 <tr>
97 <td align='right'>
98 <input type='checkbox' name=\"wpMovetalk\" checked='checked' value=\"1\" />
99 </td>
100 <td>{$movetalk}</td>
101 </tr>" );
103 $wgOut->addHTML( "
104 <tr>
105 <td>&nbsp;</td>
106 <td align='left'>
107 <input type='submit' name=\"wpMove\" value=\"{$mpb}\" />
108 </td>
109 </tr>
110 </table>
111 </form>\n" );
115 function doSubmit() {
116 global $wgOut, $wgUser, $wgLang;
117 global $wgDeferredUpdateList, $wgMessageCache;
118 global $wgUseSquid, $wgRequest;
119 $fname = "MovePageForm::doSubmit";
121 # Variables beginning with 'o' for old article 'n' for new article
123 # Attempt to move the article
125 $ot = Title::newFromText( $this->oldTitle );
126 $nt = Title::newFromText( $this->newTitle );
128 $error = $ot->moveTo( $nt );
129 if ( $error !== true ) {
130 $this->showForm( wfMsg( $error ) );
131 return;
134 # Update counters if the article got moved into or out of NS_MAIN namespace
135 $ons = $ot->getNamespace();
136 $nns = $nt->getNamespace();
138 # moved out of article namespace?
139 if ( $ons == NS_MAIN and $nns != NS_MAIN ) {
140 $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
142 # moved into article namespace?
143 elseif ( $ons != NS_MAIN and $nns == NS_MAIN ) {
144 $u = new SiteStatsUpdate( 0, 1, +1 ); # not viewed, edited, adding
145 } else {
146 $u = false;
148 if ( $u !== false ) {
149 # save it for later update
150 array_push( $wgDeferredUpdateList, $u );
151 unset($u);
154 # Move talk page if
155 # (1) the checkbox says to,
156 # (2) the namespaces are not themselves talk namespaces, and of course
157 # (3) it exists.
159 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
160 ( ! Namespace::isTalk( $ons ) ) &&
161 ( ! Namespace::isTalk( $nns ) ) ) {
163 # get old talk page namespace
164 $ons = Namespace::getTalk( $ons );
165 # get new talk page namespace
166 $nns = Namespace::getTalk( $nns );
168 # make talk page title objects
169 $ott = Title::makeTitle( $ons, $ot->getDBkey() );
170 $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
172 # Attempt the move
173 $error = $ott->moveTo( $ntt );
174 if ( $error === true ) {
175 $talkmoved = 1;
176 } else {
177 $talkmoved = $error;
181 # Give back result to user.
183 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
184 $success = $titleObj->getFullURL(
185 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
186 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
187 '&talkmoved='.$talkmoved );
189 $wgOut->redirect( $success );
192 function showSuccess() {
193 global $wgOut, $wgUser, $wgRequest;
195 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
196 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
197 $oldtitle = $wgRequest->getVal('oldtitle');
198 $newtitle = $wgRequest->getVal('newtitle');
199 $talkmoved = $wgRequest->getVal('talkmoved');
201 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
202 $wgOut->addWikiText( $text );
204 if ( $talkmoved == 1 ) {
205 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
206 } elseif( 'articleexists' == $talkmoved ) {
207 $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
208 } else {
209 $ot = Title::newFromURL( $oldtitle );
210 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
211 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );