Split files and classes in different packages for phpdocumentor. I probably changed...
[lhc/web/wiklou.git] / includes / SpecialMovepage.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 require_once( "LinksUpdate.php" );
12
13 /**
14 * Constructor
15 */
16 function wfSpecialMovepage() {
17 global $wgUser, $wgOut, $wgRequest, $action, $wgOnlySysopMayMove;
18
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;
23 }
24 # We don't move protected pages
25 if ( wfReadOnly() ) {
26 $wgOut->readOnlyPage();
27 return;
28 }
29
30 $f = new MovePageForm();
31
32 if ( 'success' == $action ) { $f->showSuccess(); }
33 else if ( 'submit' == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
34 else { $f->showForm( '' ); }
35 }
36
37 /**
38 *
39 * @package MediaWiki
40 * @subpackage SpecialPage
41 */
42 class MovePageForm {
43 var $oldTitle, $newTitle; # Text input
44
45 function MovePageForm() {
46 global $wgRequest;
47 $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
48 $this->newTitle = $wgRequest->getText( 'wpNewTitle' );
49 }
50
51 function showForm( $err ) {
52 global $wgOut, $wgUser, $wgLang;
53
54 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
55
56 if ( empty( $this->oldTitle ) ) {
57 $wgOut->errorpage( 'notargettitle', 'notargettext' );
58 return;
59 }
60
61 $encOldTitle = htmlspecialchars( $this->oldTitle );
62 $encNewTitle = htmlspecialchars( $this->newTitle );
63 $ot = Title::newFromURL( $this->oldTitle );
64 $ott = $ot->getPrefixedText();
65
66 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
67 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
68 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
69 }
70
71 $ma = wfMsg( 'movearticle' );
72 $newt = wfMsg( 'newtitle' );
73 $mpb = wfMsg( 'movepagebtn' );
74 $movetalk = wfMsg( 'movetalk' );
75
76 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
77 $action = $titleObj->escapeLocalURL( 'action=submit' );
78
79 if ( $err != '' ) {
80 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
81 $wgOut->addHTML( '<p class="error">'.$err."</p>\n" );
82 }
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>" );
97
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>" );
106 }
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" );
116
117 }
118
119 function doSubmit() {
120 global $wgOut, $wgUser, $wgLang;
121 global $wgDeferredUpdateList, $wgMessageCache;
122 global $wgUseSquid, $wgRequest;
123 $fname = "MovePageForm::doSubmit";
124
125 # Variables beginning with 'o' for old article 'n' for new article
126
127 # Attempt to move the article
128
129 $ot = Title::newFromText( $this->oldTitle );
130 $nt = Title::newFromText( $this->newTitle );
131
132 $error = $ot->moveTo( $nt );
133 if ( $error !== true ) {
134 $this->showForm( wfMsg( $error ) );
135 return;
136 }
137
138 # Update counters if the article got moved into or out of NS_MAIN namespace
139 $ons = $ot->getNamespace();
140 $nns = $nt->getNamespace();
141
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
145 }
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;
151 }
152 if ( $u !== false ) {
153 # save it for later update
154 array_push( $wgDeferredUpdateList, $u );
155 unset($u);
156 }
157
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.
162
163 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
164 ( ! Namespace::isTalk( $ons ) ) &&
165 ( ! Namespace::isTalk( $nns ) ) ) {
166
167 # get old talk page namespace
168 $ons = Namespace::getTalk( $ons );
169 # get new talk page namespace
170 $nns = Namespace::getTalk( $nns );
171
172 # make talk page title objects
173 $ott = Title::makeTitle( $ons, $ot->getDBkey() );
174 $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
175
176 # Attempt the move
177 $error = $ott->moveTo( $ntt );
178 if ( $error === true ) {
179 $talkmoved = 1;
180 } else {
181 $talkmoved = $error;
182 }
183 }
184
185 # Give back result to user.
186
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 );
192
193 $wgOut->redirect( $success );
194 }
195
196 function showSuccess() {
197 global $wgOut, $wgUser, $wgRequest;
198
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');
204
205 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
206 $wgOut->addWikiText( $text );
207
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" );
216 }
217 }
218 }
219 }
220 ?>