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