Changing comments layout preparing for generated documentation with Phpdocumentor
[lhc/web/wiklou.git] / includes / SpecialMovepage.php
1 <?php
2 /**
3 *
4 */
5
6 /**
7 *
8 */
9 require_once( "LinksUpdate.php" );
10
11 /**
12 * Constructor
13 */
14 function wfSpecialMovepage() {
15 global $wgUser, $wgOut, $wgRequest, $action, $wgOnlySysopMayMove;
16
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;
21 }
22 # We don't move protected pages
23 if ( wfReadOnly() ) {
24 $wgOut->readOnlyPage();
25 return;
26 }
27
28 $f = new MovePageForm();
29
30 if ( 'success' == $action ) { $f->showSuccess(); }
31 else if ( 'submit' == $action && $wgRequest->wasPosted() ) { $f->doSubmit(); }
32 else { $f->showForm( '' ); }
33 }
34
35 /**
36 *
37 */
38 class MovePageForm {
39 var $oldTitle, $newTitle; # Text input
40
41 function MovePageForm() {
42 global $wgRequest;
43 $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
44 $this->newTitle = $wgRequest->getText( 'wpNewTitle' );
45 }
46
47 function showForm( $err ) {
48 global $wgOut, $wgUser, $wgLang;
49
50 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
51
52 if ( empty( $this->oldTitle ) ) {
53 $wgOut->errorpage( 'notargettitle', 'notargettext' );
54 return;
55 }
56
57 $encOldTitle = htmlspecialchars( $this->oldTitle );
58 $encNewTitle = htmlspecialchars( $this->newTitle );
59 $ot = Title::newFromURL( $this->oldTitle );
60 $ott = $ot->getPrefixedText();
61
62 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
63 if ( ! Namespace::isTalk( $ot->getNamespace() ) ) {
64 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
65 }
66
67 $ma = wfMsg( 'movearticle' );
68 $newt = wfMsg( 'newtitle' );
69 $mpb = wfMsg( 'movepagebtn' );
70 $movetalk = wfMsg( 'movetalk' );
71
72 $titleObj = Title::makeTitle( NS_SPECIAL, 'Movepage' );
73 $action = $titleObj->escapeLocalURL( 'action=submit' );
74
75 if ( $err != '' ) {
76 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
77 $wgOut->addHTML( '<p class="error">'.$err."</p>\n" );
78 }
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>" );
93
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>" );
102 }
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" );
112
113 }
114
115 function doSubmit() {
116 global $wgOut, $wgUser, $wgLang;
117 global $wgDeferredUpdateList, $wgMessageCache;
118 global $wgUseSquid, $wgRequest;
119 $fname = "MovePageForm::doSubmit";
120
121 # Variables beginning with 'o' for old article 'n' for new article
122
123 # Attempt to move the article
124
125 $ot = Title::newFromText( $this->oldTitle );
126 $nt = Title::newFromText( $this->newTitle );
127
128 $error = $ot->moveTo( $nt );
129 if ( $error !== true ) {
130 $this->showForm( wfMsg( $error ) );
131 return;
132 }
133
134 # Update counters if the article got moved into or out of NS_MAIN namespace
135 $ons = $ot->getNamespace();
136 $nns = $nt->getNamespace();
137
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
141 }
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;
147 }
148 if ( $u !== false ) {
149 # save it for later update
150 array_push( $wgDeferredUpdateList, $u );
151 unset($u);
152 }
153
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.
158
159 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
160 ( ! Namespace::isTalk( $ons ) ) &&
161 ( ! Namespace::isTalk( $nns ) ) ) {
162
163 # get old talk page namespace
164 $ons = Namespace::getTalk( $ons );
165 # get new talk page namespace
166 $nns = Namespace::getTalk( $nns );
167
168 # make talk page title objects
169 $ott = Title::makeTitle( $ons, $ot->getDBkey() );
170 $ntt = Title::makeTitle( $nns, $nt->getDBkey() );
171
172 # Attempt the move
173 $error = $ott->moveTo( $ntt );
174 if ( $error === true ) {
175 $talkmoved = 1;
176 } else {
177 $talkmoved = $error;
178 }
179 }
180
181 # Give back result to user.
182
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 );
188
189 $wgOut->redirect( $success );
190 }
191
192 function showSuccess() {
193 global $wgOut, $wgUser, $wgRequest;
194
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');
200
201 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
202 $wgOut->addWikiText( $text );
203
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" );
212 }
213 }
214 }
215 }
216 ?>