Localisation updates for core messages from Betawiki (2008-05-11 22:57 CEST)
[mediawiki.git] / includes / SpecialMovepage.php
blob33f043d6992c96222bc7720c180e71a21f6c2dbd
1 <?php
2 /**
4 * @addtogroup SpecialPage
5 */
7 /**
8 * Constructor
9 */
10 function wfSpecialMovepage( $par = null ) {
11 global $wgUser, $wgOut, $wgRequest, $action;
13 # Check rights
14 if ( !$wgUser->isAllowed( 'move' ) ) {
15 $wgOut->showPermissionsErrorPage( array( $wgUser->isAnon() ? 'movenologintext' : 'movenotallowed' ) );
16 return;
19 # Don't allow blocked users to move pages
20 if ( $wgUser->isBlocked() ) {
21 $wgOut->blockedPage();
22 return;
25 # Check for database lock
26 if ( wfReadOnly() ) {
27 $wgOut->readOnlyPage();
28 return;
31 $f = new MovePageForm( $par );
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( '' );
43 /**
44 * HTML form for Special:Movepage
45 * @addtogroup SpecialPage
47 class MovePageForm {
48 var $oldTitle, $newTitle, $reason; # Text input
49 var $moveTalk, $deleteAndMove;
51 private $watch = false;
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 );
64 $this->deleteAndMove = $wgRequest->getBool( 'wpDeleteAndMove' ) && $wgRequest->getBool( 'wpConfirm' );
65 $this->watch = $wgRequest->getCheck( 'wpWatch' );
68 function showForm( $err, $hookErr = '' ) {
69 global $wgOut, $wgUser;
71 $ot = Title::newFromURL( $this->oldTitle );
72 if( is_null( $ot ) ) {
73 $wgOut->showErrorPage( 'notargettitle', 'notargettext' );
74 return;
77 $sk = $wgUser->getSkin();
79 $oldTitleLink = $sk->makeLinkObj( $ot );
80 $oldTitle = $ot->getPrefixedText();
82 $wgOut->setPagetitle( wfMsg( 'move-page', $oldTitle ) );
83 $wgOut->setSubtitle( wfMsg( 'move-page-backlink', $oldTitleLink ) );
85 if( $this->newTitle == '' ) {
86 # Show the current title as a default
87 # when the form is first opened.
88 $newTitle = $oldTitle;
89 } else {
90 if( $err == '' ) {
91 $nt = Title::newFromURL( $this->newTitle );
92 if( $nt ) {
93 # If a title was supplied, probably from the move log revert
94 # link, check for validity. We can then show some diagnostic
95 # information and save a click.
96 $newerr = $ot->isValidMoveOperation( $nt );
97 if( is_string( $newerr ) ) {
98 $err = $newerr;
102 $newTitle = $this->newTitle;
105 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
106 $wgOut->addWikiMsg( 'delete_and_move_text', $newTitle );
107 $movepagebtn = wfMsg( 'delete_and_move' );
108 $submitVar = 'wpDeleteAndMove';
109 $confirm = "
110 <tr>
111 <td></td>
112 <td class='mw-input'>" .
113 Xml::checkLabel( wfMsg( 'delete_and_move_confirm' ), 'wpConfirm', 'wpConfirm' ) .
114 "</td>
115 </tr>";
116 $err = '';
117 } else {
118 $wgOut->addWikiMsg( 'movepagetext' );
119 $movepagebtn = wfMsg( 'movepagebtn' );
120 $submitVar = 'wpMove';
121 $confirm = false;
124 $oldTalk = $ot->getTalkPage();
125 $considerTalk = ( !$ot->isTalkPage() && $oldTalk->exists() );
127 if ( $considerTalk ) {
128 $wgOut->addWikiMsg( 'movepagetalktext' );
131 $titleObj = SpecialPage::getTitleFor( 'Movepage' );
132 $token = htmlspecialchars( $wgUser->editToken() );
134 if ( $err != '' ) {
135 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
136 $errMsg = "";
137 if( $err == 'hookaborted' ) {
138 $errMsg = "<p><strong class=\"error\">$hookErr</strong></p>\n";
139 } else if (is_array($err)) {
140 $errMsg = '<p><strong class="error">' . call_user_func_array( 'wfMsgWikiHtml', $err ) . "</strong></p>\n";
141 } else {
142 $errMsg = '<p><strong class="error">' . wfMsgWikiHtml( $err ) . "</strong></p>\n";
144 $wgOut->addHTML( $errMsg );
147 $wgOut->addHTML(
148 Xml::openElement( 'form', array( 'method' => 'post', 'action' => $titleObj->getLocalURL( 'action=submit' ), 'id' => 'movepage' ) ) .
149 Xml::openElement( 'fieldset' ) .
150 Xml::element( 'legend', null, wfMsg( 'move-page-legend' ) ) .
151 Xml::openElement( 'table', array( 'border' => '0', 'id' => 'mw-movepage-table' ) ) .
152 "<tr>
153 <td class='mw-label'>" .
154 wfMsgHtml( 'movearticle' ) .
155 "</td>
156 <td class='mw-input'>
157 <strong>{$oldTitleLink}</strong>
158 </td>
159 </tr>
160 <tr>
161 <td class='mw-label'>" .
162 Xml::label( wfMsg( 'newtitle' ), 'wpNewTitle' ) .
163 "</td>
164 <td class='mw-input'>" .
165 Xml::input( 'wpNewTitle', 40, $newTitle, array( 'type' => 'text', 'id' => 'wpNewTitle' ) ) .
166 Xml::hidden( 'wpOldTitle', $oldTitle ) .
167 "</td>
168 </tr>
169 <tr>
170 <td class='mw-label'>" .
171 Xml::label( wfMsg( 'movereason' ), 'wpReason' ) .
172 "</td>
173 <td class='mw-input'>" .
174 Xml::tags( 'textarea', array( 'name' => 'wpReason', 'id' => 'wpReason', 'cols' => 60, 'rows' => 2 ), htmlspecialchars( $this->reason ) ) .
175 "</td>
176 </tr>"
179 if ( $considerTalk ) {
180 $wgOut->addHTML( "
181 <tr>
182 <td></td>
183 <td class='mw-input'>" .
184 Xml::checkLabel( wfMsg( 'movetalk' ), 'wpMovetalk', 'wpMovetalk', $this->moveTalk ) .
185 "</td>
186 </tr>"
190 $watchChecked = $this->watch || $wgUser->getBoolOption( 'watchmoves' ) || $ot->userIsWatching();
191 $wgOut->addHTML( "
192 <tr>
193 <td></td>
194 <td class='mw-input'>" .
195 Xml::checkLabel( wfMsg( 'move-watch' ), 'wpWatch', 'watch', $watchChecked ) .
196 "</td>
197 </tr>
198 {$confirm}
199 <tr>
200 <td>&nbsp;</td>
201 <td class='mw-submit'>" .
202 Xml::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
203 "</td>
204 </tr>" .
205 Xml::closeElement( 'table' ) .
206 Xml::hidden( 'wpEditToken', $token ) .
207 Xml::closeElement( 'fieldset' ) .
208 Xml::closeElement( 'form' ) .
209 "\n"
212 $this->showLogFragment( $ot, $wgOut );
216 function doSubmit() {
217 global $wgOut, $wgUser, $wgRequest;
219 if ( $wgUser->pingLimiter( 'move' ) ) {
220 $wgOut->rateLimited();
221 return;
224 # Variables beginning with 'o' for old article 'n' for new article
226 $ot = Title::newFromText( $this->oldTitle );
227 $nt = Title::newFromText( $this->newTitle );
229 # Delete to make way if requested
230 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove ) {
231 $article = new Article( $nt );
233 # Disallow deletions of big articles
234 $bigHistory = $article->isBigDeletion();
235 if( $bigHistory && !$nt->userCan( 'bigdelete' ) ) {
236 global $wgLang, $wgDeleteRevisionsLimit;
237 $this->showForm( array('delete-toobig', $wgLang->formatNum( $wgDeleteRevisionsLimit ) ) );
238 return;
241 // This may output an error message and exit
242 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
245 # don't allow moving to pages with # in
246 if ( !$nt || $nt->getFragment() != '' ) {
247 $this->showForm( 'badtitletext' );
248 return;
251 $hookErr = null;
252 if( !wfRunHooks( 'AbortMove', array( $ot, $nt, $wgUser, &$hookErr ) ) ) {
253 $this->showForm( 'hookaborted', $hookErr );
254 return;
257 $error = $ot->moveTo( $nt, true, $this->reason );
258 if ( $error !== true ) {
259 $this->showForm( $error );
260 return;
263 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ot , &$nt ) ) ;
265 # Move the talk page if relevant, if it exists, and if we've been told to
266 $ott = $ot->getTalkPage();
267 if( $ott->exists() ) {
268 if( $this->moveTalk && !$ot->isTalkPage() && !$nt->isTalkPage() ) {
269 $ntt = $nt->getTalkPage();
271 # Attempt the move
272 $error = $ott->moveTo( $ntt, true, $this->reason );
273 if ( $error === true ) {
274 $talkmoved = 1;
275 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this , &$ott , &$ntt ) );
276 } else {
277 $talkmoved = $error;
279 } else {
280 # Stay silent on the subject of talk.
281 $talkmoved = '';
283 } else {
284 $talkmoved = 'notalkpage';
287 # Deal with watches
288 if( $this->watch ) {
289 $wgUser->addWatch( $ot );
290 $wgUser->addWatch( $nt );
291 } else {
292 $wgUser->removeWatch( $ot );
293 $wgUser->removeWatch( $nt );
296 # Give back result to user.
297 $titleObj = SpecialPage::getTitleFor( 'Movepage' );
298 $success = $titleObj->getFullURL(
299 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
300 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
301 '&talkmoved='.$talkmoved );
303 $wgOut->redirect( $success );
306 function showSuccess() {
307 global $wgOut, $wgRequest, $wgUser;
309 $old = Title::newFromText( $wgRequest->getVal( 'oldtitle' ) );
310 $new = Title::newFromText( $wgRequest->getVal( 'newtitle' ) );
312 if( is_null( $old ) || is_null( $new ) ) {
313 throw new ErrorPageError( 'badtitle', 'badtitletext' );
316 $wgOut->setPagetitle( wfMsg( 'pagemovedsub' ) );
318 $talkmoved = $wgRequest->getVal( 'talkmoved' );
319 $oldUrl = $old->getFullUrl( 'redirect=no' );
320 $newUrl = $new->getFullUrl();
321 $oldText = $old->getPrefixedText();
322 $newText = $new->getPrefixedText();
323 $oldLink = "<span class='plainlinks'>[$oldUrl $oldText]</span>";
324 $newLink = "<span class='plainlinks'>[$newUrl $newText]</span>";
326 $s = wfMsgNoTrans( 'movepage-moved', $oldLink, $newLink, $oldText, $newText );
328 if ( $talkmoved == 1 ) {
329 $s .= "\n\n" . wfMsgNoTrans( 'talkpagemoved' );
330 } elseif( 'articleexists' == $talkmoved ) {
331 $s .= "\n\n" . wfMsgNoTrans( 'talkexists' );
332 } else {
333 if( !$old->isTalkPage() && $talkmoved != 'notalkpage' ) {
334 $s .= "\n\n" . wfMsgNoTrans( 'talkpagenotmoved', wfMsgNoTrans( $talkmoved ) );
337 $wgOut->addWikiText( $s );
340 function showLogFragment( $title, &$out ) {
341 $out->addHTML( Xml::element( 'h2', NULL, LogPage::logName( 'move' ) ) );
342 LogEventsList::showLogExtract( $out, 'move', $title->getPrefixedText() );