]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/SpecialMovepage.php
MediaWiki 1.11.0
[autoinstalls/mediawiki.git] / includes / SpecialMovepage.php
1 <?php
2 /**
3  *
4  * @addtogroup SpecialPage
5  */
6
7 /**
8  * Constructor
9  */
10 function wfSpecialMovepage( $par = null ) {
11         global $wgUser, $wgOut, $wgRequest, $action;
12
13         # Check rights
14         if ( !$wgUser->isAllowed( 'move' ) ) {
15                 $wgOut->showPermissionsErrorPage( array( $wgUser->isAnon() ? 'movenologintext' : 'movenotallowed' ) );
16                 return;
17         }
18
19         # Don't allow blocked users to move pages
20         if ( $wgUser->isBlocked() ) {
21                 $wgOut->blockedPage();
22                 return;
23         }
24
25         # Check for database lock
26         if ( wfReadOnly() ) {
27                 $wgOut->readOnlyPage();
28                 return;
29         }
30
31         $f = new MovePageForm( $par );
32
33         if ( 'success' == $action ) {
34                 $f->showSuccess();
35         } else if ( 'submit' == $action && $wgRequest->wasPosted()
36                 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
37                 $f->doSubmit();
38         } else {
39                 $f->showForm( '' );
40         }
41 }
42
43 /**
44  * HTML form for Special:Movepage
45  * @addtogroup SpecialPage
46  */
47 class MovePageForm {
48         var $oldTitle, $newTitle, $reason; # Text input
49         var $moveTalk, $deleteAndMove;
50         
51         private $watch = false;
52
53         function MovePageForm( $par ) {
54                 global $wgRequest;
55                 $target = isset($par) ? $par : $wgRequest->getVal( 'target' );
56                 $this->oldTitle = $wgRequest->getText( 'wpOldTitle', $target );
57                 $this->newTitle = $wgRequest->getText( 'wpNewTitle' );
58                 $this->reason = $wgRequest->getText( 'wpReason' );
59                 if ( $wgRequest->wasPosted() ) {
60                         $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', false );
61                 } else {
62                         $this->moveTalk = $wgRequest->getBool( 'wpMovetalk', true );
63                 }
64                 $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
65                 $this->watch = $wgRequest->getCheck( 'wpWatch' );
66         }
67
68         function showForm( $err ) {
69                 global $wgOut, $wgUser, $wgContLang;
70                 
71                 $start = $wgContLang->isRTL() ? 'right' : 'left';
72                 $end = $wgContLang->isRTL() ? 'left' : 'right';
73
74                 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
75
76                 $ot = Title::newFromURL( $this->oldTitle );
77                 if( is_null( $ot ) ) {
78                         $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
79                         return;
80                 }
81                 $oldTitle = $ot->getPrefixedText();
82
83                 $encOldTitle = htmlspecialchars( $oldTitle );
84                 if( $this->newTitle == '' ) {
85                         # Show the current title as a default
86                         # when the form is first opened.
87                         $encNewTitle = $encOldTitle;
88                 } else {
89                         if( $err == '' ) {
90                                 $nt = Title::newFromURL( $this->newTitle );
91                                 if( $nt ) {
92                                         # If a title was supplied, probably from the move log revert
93                                         # link, check for validity. We can then show some diagnostic
94                                         # information and save a click.
95                                         $newerr = $ot->isValidMoveOperation( $nt );
96                                         if( is_string( $newerr ) ) {
97                                                 $err = $newerr;
98                                         }
99                                 }
100                         }
101                         $encNewTitle = htmlspecialchars( $this->newTitle );
102                 }
103                 $encReason = htmlspecialchars( $this->reason );
104
105                 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
106                         $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
107                         $movepagebtn = wfMsgHtml( 'delete_and_move' );
108                         $submitVar = 'wpDeleteAndMove';
109                         $confirm = "
110                                 <tr>
111                                         <td></td><td>" . Xml::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) . "</td>
112                                 </tr>";
113                         $err = '';
114                 } else {
115                         $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
116                         $movepagebtn = wfMsgHtml( 'movepagebtn' );
117                         $submitVar = 'wpMove';
118                         $confirm = false;
119                 }
120
121                 $oldTalk = $ot->getTalkPage();
122                 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
123
124                 if ( $considerTalk ) {
125                         $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
126                 }
127
128                 $movearticle = wfMsgHtml( 'movearticle' );
129                 $newtitle = wfMsgHtml( 'newtitle' );
130                 $movereason = wfMsgHtml( 'movereason' );
131
132                 $titleObj = SpecialPage::getTitleFor( 'Movepage' );
133                 $action = $titleObj->escapeLocalURL( 'action=submit' );
134                 $token = htmlspecialchars( $wgUser->editToken() );
135
136                 if ( $err != '' ) {
137                         $wgOut->setSubtitle( wfMsg( 'formerror' ) );
138                         $wgOut->addWikiText( '<p class="error">' . wfMsg($err) . "</p>\n" );
139                 }
140
141                 $moveTalkChecked = $this->moveTalk ? ' checked="checked"' : '';
142
143                 $wgOut->addHTML( "
144 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
145         <table border='0'>
146                 <tr>
147                         <td align='$end'>{$movearticle}</td>
148                         <td align='$start'><strong>{$oldTitle}</strong></td>
149                 </tr>
150                 <tr>
151                         <td align='$end'><label for='wpNewTitle'>{$newtitle}</label></td>
152                         <td align='$start'>
153                                 <input type='text' size='40' name='wpNewTitle' id='wpNewTitle' value=\"{$encNewTitle}\" />
154                                 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
155                         </td>
156                 </tr>
157                 <tr>
158                         <td align='$end' valign='top'><br /><label for='wpReason'>{$movereason}</label></td>
159                         <td align='$start' valign='top'><br />
160                                 <textarea cols='60' rows='2' name='wpReason' id='wpReason'>{$encReason}</textarea>
161                         </td>
162                 </tr>" );
163
164                 if ( $considerTalk ) {
165                         $wgOut->addHTML( "
166                 <tr>
167                         <td></td><td>" . Xml::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $moveTalkChecked ) . "</td>
168                 </tr>" );
169                 }
170
171                 $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) || $ot->userIsWatching();
172                 $watch  = '<tr>';
173                 $watch .= '<td></td><td>' . Xml::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) . '</td>';
174                 $watch .= '</tr>';
175                 $wgOut->addHtml( $watch );
176
177                 $wgOut->addHTML( "
178                 {$confirm}
179                 <tr>
180                         <td>&nbsp;</td>
181                         <td align='$start'>
182                                 <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
183                         </td>
184                 </tr>
185         </table>
186         <input type='hidden' name='wpEditToken' value=\"{$token}\" />
187 </form>\n" );
188
189         $this->showLogFragment( $ot, $wgOut );
190
191         }
192
193         function doSubmit() {
194                 global $wgOut, $wgUser, $wgRequest;
195
196                 if ( $wgUser->pingLimiter( 'move' ) ) {
197                         $wgOut->rateLimited();
198                         return;
199                 }
200
201                 # Variables beginning with 'o' for old article 'n' for new article
202
203                 $ot = Title::newFromText( $this->oldTitle );
204                 $nt = Title::newFromText( $this->newTitle );
205
206                 # Delete to make way if requested
207                 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) {
208                         $article = new Article( $nt );
209                         // This may output an error message and exit
210                         $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
211                 }
212
213                 # don't allow moving to pages with # in
214                 if ( !$nt || $nt->getFragment() != '' ) {
215                         $this->showForm( 'badtitletext' );
216                         return;
217                 }
218
219                 $error = $ot->moveTo( $nt, true, $this->reason );
220                 if ( $error !== true ) {
221                         $this->showForm( $error );
222                         return;
223                 }
224
225                 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
226
227                 # Move the talk page if relevant, if it exists, and if we've been told to
228                 $ott = $ot->getTalkPage();
229                 if( $ott->exists() ) {
230                         if( $this->moveTalk && !$ot->isTalkPage() && !$nt->isTalkPage() ) {
231                                 $ntt = $nt->getTalkPage();
232         
233                                 # Attempt the move
234                                 $error = $ott->moveTo( $ntt, true, $this->reason );
235                                 if ( $error === true ) {
236                                         $talkmoved = 1;
237                                         wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) )       ;
238                                 } else {
239                                         $talkmoved = $error;
240                                 }
241                         } else {
242                                 # Stay silent on the subject of talk.
243                                 $talkmoved = '';
244                         }
245                 } else {
246                         $talkmoved = 'notalkpage';
247                 }
248                 
249                 # Deal with watches
250                 if( $this->watch ) {
251                         $wgUser->addWatch( $ot );
252                         $wgUser->addWatch( $nt );
253                 } else {
254                         $wgUser->removeWatch( $ot );
255                         $wgUser->removeWatch( $nt );
256                 }
257
258                 # Give back result to user.
259                 $titleObj = SpecialPage::getTitleFor( 'Movepage' );
260                 $success = $titleObj->getFullURL(
261                   'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
262                   '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
263                   '&talkmoved='.$talkmoved );
264
265                 $wgOut->redirect( $success );
266         }
267
268         function showSuccess() {
269                 global $wgOut, $wgRequest, $wgUser;
270                 
271                 $old = Title::newFromText( $wgRequest->getVal( 'oldtitle' ) );
272                 $new = Title::newFromText( $wgRequest->getVal( 'newtitle' ) );
273                 
274                 if( is_null( $old ) || is_null( $new ) ) {
275                         throw new ErrorPageError( 'badtitle', 'badtitletext' );
276                 }
277                 
278                 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
279                 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
280
281                 $talkmoved = $wgRequest->getVal( 'talkmoved' );
282                 $oldUrl = $old->getFullUrl( 'redirect=no' );
283                 $newUrl = $new->getFullURl();
284                 $oldText = $old->getPrefixedText();
285                 $newText = $new->getPrefixedText();
286                 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
287                 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
288
289                 $s = wfMsg( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
290
291                 if ( $talkmoved == 1 ) {
292                         $s .= "\n\n" . wfMsg( 'talkpagemoved' );
293                 } elseif( 'articleexists' == $talkmoved ) {
294                         $s .= "\n\n" . wfMsg( 'talkexists' );
295                 } else {
296                         if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
297                                 $s .= "\n\n" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) );
298                         }
299                 }
300                 $wgOut->addWikiText( $s );
301         }
302         
303         function showLogFragment( $title, &$out ) {
304                 $out->addHtml( wfElement( 'h2', NULL, LogPage::logName( 'move' ) ) );
305                 $request = new FauxRequest( array( 'page' => $title->getPrefixedText(), 'type' => 'move' ) );
306                 $viewer = new LogViewer( new LogReader( $request ) );
307                 $viewer->showList( $out );
308         }
309         
310 }
311