Allow moving category pages
[lhc/web/wiklou.git] / includes / specials / SpecialMovepage.php
1 <?php
2 /**
3 * Implements Special:Movepage
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * A special page that allows users to change page titles
26 *
27 * @ingroup SpecialPage
28 */
29 class MovePageForm extends UnlistedSpecialPage {
30 /**
31 * Objects
32 * @var Title
33 */
34 var $oldTitle, $newTitle;
35 // Text input
36 var $reason;
37 // Checks
38 var $moveTalk, $deleteAndMove, $moveSubpages, $fixRedirects, $leaveRedirect, $moveOverShared;
39
40 private $watch = false;
41
42 public function __construct() {
43 parent::__construct( 'Movepage' );
44 }
45
46 public function execute( $par ) {
47 $this->checkReadOnly();
48
49 $this->setHeaders();
50 $this->outputHeader();
51
52 $request = $this->getRequest();
53 $target = !is_null( $par ) ? $par : $request->getVal( 'target' );
54
55 // Yes, the use of getVal() and getText() is wanted, see bug 20365
56
57 $oldTitleText = $request->getVal( 'wpOldTitle', $target );
58 $this->oldTitle = Title::newFromText( $oldTitleText );
59
60 if ( is_null( $this->oldTitle ) ) {
61 throw new ErrorPageError( 'notargettitle', 'notargettext' );
62 }
63 if ( !$this->oldTitle->exists() ) {
64 throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
65 }
66
67 $newTitleTextMain = $request->getText( 'wpNewTitleMain' );
68 $newTitleTextNs = $request->getInt( 'wpNewTitleNs', $this->oldTitle->getNamespace() );
69 // Backwards compatibility for forms submitting here from other sources
70 // which is more common than it should be..
71 $newTitleText_bc = $request->getText( 'wpNewTitle' );
72 $this->newTitle = strlen( $newTitleText_bc ) > 0
73 ? Title::newFromText( $newTitleText_bc )
74 : Title::makeTitleSafe( $newTitleTextNs, $newTitleTextMain );
75
76 $user = $this->getUser();
77
78 # Check rights
79 $permErrors = $this->oldTitle->getUserPermissionsErrors( 'move', $user );
80 if ( count( $permErrors ) ) {
81 // Auto-block user's IP if the account was "hard" blocked
82 $user->spreadAnyEditBlock();
83 throw new PermissionsError( 'move', $permErrors );
84 }
85
86 $def = !$request->wasPosted();
87
88 $this->reason = $request->getText( 'wpReason' );
89 $this->moveTalk = $request->getBool( 'wpMovetalk', $def );
90 $this->fixRedirects = $request->getBool( 'wpFixRedirects', $def );
91 $this->leaveRedirect = $request->getBool( 'wpLeaveRedirect', $def );
92 $this->moveSubpages = $request->getBool( 'wpMovesubpages', false );
93 $this->deleteAndMove = $request->getBool( 'wpDeleteAndMove' ) && $request->getBool( 'wpConfirm' );
94 $this->moveOverShared = $request->getBool( 'wpMoveOverSharedFile', false );
95 $this->watch = $request->getCheck( 'wpWatch' ) && $user->isLoggedIn();
96
97 if ( 'submit' == $request->getVal( 'action' ) && $request->wasPosted()
98 && $user->matchEditToken( $request->getVal( 'wpEditToken' ) )
99 ) {
100 $this->doSubmit();
101 } else {
102 $this->showForm( array() );
103 }
104 }
105
106 /**
107 * Show the form
108 *
109 * @param array $err error messages. Each item is an error message.
110 * It may either be a string message name or array message name and
111 * parameters, like the second argument to OutputPage::wrapWikiMsg().
112 */
113 function showForm( $err ) {
114 global $wgContLang, $wgFixDoubleRedirects, $wgMaximumMovedPages;
115
116 $this->getSkin()->setRelevantTitle( $this->oldTitle );
117
118 $oldTitleLink = Linker::link( $this->oldTitle );
119
120 $out = $this->getOutput();
121 $out->setPageTitle( $this->msg( 'move-page', $this->oldTitle->getPrefixedText() ) );
122 $out->addModules( 'mediawiki.special.movePage' );
123
124 $newTitle = $this->newTitle;
125
126 if ( !$newTitle ) {
127 # Show the current title as a default
128 # when the form is first opened.
129 $newTitle = $this->oldTitle;
130 } elseif ( !count( $err ) ) {
131 # If a title was supplied, probably from the move log revert
132 # link, check for validity. We can then show some diagnostic
133 # information and save a click.
134 $newerr = $this->oldTitle->isValidMoveOperation( $newTitle );
135 if ( is_array( $newerr ) ) {
136 $err = $newerr;
137 }
138 }
139
140 $user = $this->getUser();
141
142 if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists'
143 && $newTitle->quickUserCan( 'delete', $user )
144 ) {
145 $out->addWikiMsg( 'delete_and_move_text', $newTitle->getPrefixedText() );
146 $movepagebtn = $this->msg( 'delete_and_move' )->text();
147 $submitVar = 'wpDeleteAndMove';
148 $confirm = "
149 <tr>
150 <td></td>
151 <td class='mw-input'>" .
152 Xml::checkLabel(
153 $this->msg( 'delete_and_move_confirm' )->text(),
154 'wpConfirm',
155 'wpConfirm'
156 ) .
157 "</td>
158 </tr>";
159 $err = array();
160 } else {
161 if ( $this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) {
162 $out->wrapWikiMsg(
163 "<div class=\"error mw-moveuserpage-warning\">\n$1\n</div>",
164 'moveuserpage-warning'
165 );
166 } elseif ( $this->oldTitle->getNamespace() == NS_CATEGORY ) {
167 $out->wrapWikiMsg(
168 "<div class=\"error mw-movecategorypage-warning\">\n$1\n</div>",
169 'movecategorypage-warning'
170 );
171 }
172
173 $out->addWikiMsg( $wgFixDoubleRedirects ?
174 'movepagetext' :
175 'movepagetext-noredirectfixer'
176 );
177 $movepagebtn = $this->msg( 'movepagebtn' )->text();
178 $submitVar = 'wpMove';
179 $confirm = false;
180 }
181
182 if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'file-exists-sharedrepo'
183 && $user->isAllowed( 'reupload-shared' )
184 ) {
185 $out->addWikiMsg( 'move-over-sharedrepo', $newTitle->getPrefixedText() );
186 $submitVar = 'wpMoveOverSharedFile';
187 $err = array();
188 }
189
190 $oldTalk = $this->oldTitle->getTalkPage();
191 $oldTitleSubpages = $this->oldTitle->hasSubpages();
192 $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
193
194 $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
195 !count( $this->oldTitle->getUserPermissionsErrors( 'move-subpages', $user ) );
196
197 # We also want to be able to move assoc. subpage talk-pages even if base page
198 # has no associated talk page, so || with $oldTitleTalkSubpages.
199 $considerTalk = !$this->oldTitle->isTalkPage() &&
200 ( $oldTalk->exists()
201 || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
202
203 $dbr = wfGetDB( DB_SLAVE );
204 if ( $wgFixDoubleRedirects ) {
205 $hasRedirects = $dbr->selectField( 'redirect', '1',
206 array(
207 'rd_namespace' => $this->oldTitle->getNamespace(),
208 'rd_title' => $this->oldTitle->getDBkey(),
209 ), __METHOD__ );
210 } else {
211 $hasRedirects = false;
212 }
213
214 if ( $considerTalk ) {
215 $out->addWikiMsg( 'movepagetalktext' );
216 }
217
218 if ( count( $err ) ) {
219 $out->addHTML( "<div class='error'>\n" );
220 $action_desc = $this->msg( 'action-move' )->plain();
221 $out->addWikiMsg( 'permissionserrorstext-withaction', count( $err ), $action_desc );
222
223 if ( count( $err ) == 1 ) {
224 $errMsg = $err[0];
225 $errMsgName = array_shift( $errMsg );
226
227 if ( $errMsgName == 'hookaborted' ) {
228 $out->addHTML( "<p>{$errMsg[0]}</p>\n" );
229 } else {
230 $out->addWikiMsgArray( $errMsgName, $errMsg );
231 }
232 } else {
233 $errStr = array();
234
235 foreach ( $err as $errMsg ) {
236 if ( $errMsg[0] == 'hookaborted' ) {
237 $errStr[] = $errMsg[1];
238 } else {
239 $errMsgName = array_shift( $errMsg );
240 $errStr[] = $this->msg( $errMsgName, $errMsg )->parse();
241 }
242 }
243
244 $out->addHTML( '<ul><li>' . implode( "</li>\n<li>", $errStr ) . "</li></ul>\n" );
245 }
246 $out->addHTML( "</div>\n" );
247 }
248
249 if ( $this->oldTitle->isProtected( 'move' ) ) {
250 # Is the title semi-protected?
251 if ( $this->oldTitle->isSemiProtected( 'move' ) ) {
252 $noticeMsg = 'semiprotectedpagemovewarning';
253 $classes[] = 'mw-textarea-sprotected';
254 } else {
255 # Then it must be protected based on static groups (regular)
256 $noticeMsg = 'protectedpagemovewarning';
257 $classes[] = 'mw-textarea-protected';
258 }
259 $out->addHTML( "<div class='mw-warning-with-logexcerpt'>\n" );
260 $out->addWikiMsg( $noticeMsg );
261 LogEventsList::showLogExtract(
262 $out,
263 'protect',
264 $this->oldTitle,
265 '',
266 array( 'lim' => 1 )
267 );
268 $out->addHTML( "</div>\n" );
269 }
270
271 // Byte limit (not string length limit) for wpReason and wpNewTitleMain
272 // is enforced in the mediawiki.special.movePage module
273
274 $immovableNamespaces = array();
275
276 foreach ( array_keys( $this->getLanguage()->getNamespaces() ) as $nsId ) {
277 if ( !MWNamespace::isMovable( $nsId ) ) {
278 $immovableNamespaces[] = $nsId;
279 }
280 }
281
282 $handler = ContentHandler::getForTitle( $this->oldTitle );
283
284 $out->addHTML(
285 Xml::openElement(
286 'form',
287 array(
288 'method' => 'post',
289 'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ),
290 'id' => 'movepage'
291 )
292 ) .
293 Xml::openElement( 'fieldset' ) .
294 Xml::element( 'legend', null, $this->msg( 'move-page-legend' )->text() ) .
295 Xml::openElement( 'table', array( 'id' => 'mw-movepage-table' ) ) .
296 "<tr>
297 <td class='mw-label'>" .
298 $this->msg( 'movearticle' )->escaped() .
299 "</td>
300 <td class='mw-input'>
301 <strong>{$oldTitleLink}</strong>
302 </td>
303 </tr>
304 <tr>
305 <td class='mw-label'>" .
306 Xml::label( $this->msg( 'newtitle' )->text(), 'wpNewTitleMain' ) .
307 "</td>
308 <td class='mw-input'>" .
309 Html::namespaceSelector(
310 array(
311 'selected' => $newTitle->getNamespace(),
312 'exclude' => $immovableNamespaces
313 ),
314 array( 'name' => 'wpNewTitleNs', 'id' => 'wpNewTitleNs' )
315 ) .
316 Xml::input(
317 'wpNewTitleMain',
318 60,
319 $wgContLang->recodeForEdit( $newTitle->getText() ),
320 array(
321 'type' => 'text',
322 'id' => 'wpNewTitleMain',
323 'maxlength' => 255
324 )
325 ) .
326 Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
327 "</td>
328 </tr>
329 <tr>
330 <td class='mw-label'>" .
331 Xml::label( $this->msg( 'movereason' )->text(), 'wpReason' ) .
332 "</td>
333 <td class='mw-input'>" .
334 Xml::input( 'wpReason', 60, $this->reason, array(
335 'type' => 'text',
336 'id' => 'wpReason',
337 'maxlength' => 200,
338 ) ) .
339 "</td>
340 </tr>"
341 );
342
343 if ( $considerTalk ) {
344 $out->addHTML( "
345 <tr>
346 <td></td>
347 <td class='mw-input'>" .
348 Xml::checkLabel(
349 $this->msg( 'movetalk' )->text(),
350 'wpMovetalk',
351 'wpMovetalk',
352 $this->moveTalk
353 ) .
354 "</td>
355 </tr>"
356 );
357 }
358
359 if ( $user->isAllowed( 'suppressredirect' ) ) {
360 if ( $handler->supportsRedirects() ) {
361 $isChecked = $this->leaveRedirect;
362 $options = array();
363 } else {
364 $isChecked = false;
365 $options = array(
366 'disabled' => 'disabled'
367 );
368 }
369 $out->addHTML( "
370 <tr>
371 <td></td>
372 <td class='mw-input' >" .
373 Xml::checkLabel(
374 $this->msg( 'move-leave-redirect' )->text(),
375 'wpLeaveRedirect',
376 'wpLeaveRedirect',
377 $isChecked,
378 $options
379 ) .
380 "</td>
381 </tr>"
382 );
383 }
384
385 if ( $hasRedirects ) {
386 $out->addHTML( "
387 <tr>
388 <td></td>
389 <td class='mw-input' >" .
390 Xml::checkLabel(
391 $this->msg( 'fix-double-redirects' )->text(),
392 'wpFixRedirects',
393 'wpFixRedirects',
394 $this->fixRedirects
395 ) .
396 "</td>
397 </tr>"
398 );
399 }
400
401 if ( $canMoveSubpage ) {
402 $out->addHTML( "
403 <tr>
404 <td></td>
405 <td class=\"mw-input\">" .
406 Xml::check(
407 'wpMovesubpages',
408 # Don't check the box if we only have talk subpages to
409 # move and we aren't moving the talk page.
410 $this->moveSubpages && ( $this->oldTitle->hasSubpages() || $this->moveTalk ),
411 array( 'id' => 'wpMovesubpages' )
412 ) . '&#160;' .
413 Xml::tags( 'label', array( 'for' => 'wpMovesubpages' ),
414 $this->msg(
415 ( $this->oldTitle->hasSubpages()
416 ? 'move-subpages'
417 : 'move-talk-subpages' )
418 )->numParams( $wgMaximumMovedPages )->params( $wgMaximumMovedPages )->parse()
419 ) .
420 "</td>
421 </tr>"
422 );
423 }
424
425 $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption( 'watchmoves' )
426 || $user->isWatched( $this->oldTitle ) );
427 # Don't allow watching if user is not logged in
428 if ( $user->isLoggedIn() ) {
429 $out->addHTML( "
430 <tr>
431 <td></td>
432 <td class='mw-input'>" .
433 Xml::checkLabel(
434 $this->msg( 'move-watch' )->text(),
435 'wpWatch',
436 'watch',
437 $watchChecked
438 ) .
439 "</td>
440 </tr>" );
441 }
442
443 $out->addHTML( "
444 {$confirm}
445 <tr>
446 <td>&#160;</td>
447 <td class='mw-submit'>" .
448 Xml::submitButton( $movepagebtn, array( 'name' => $submitVar ) ) .
449 "</td>
450 </tr>" .
451 Xml::closeElement( 'table' ) .
452 Html::hidden( 'wpEditToken', $user->getEditToken() ) .
453 Xml::closeElement( 'fieldset' ) .
454 Xml::closeElement( 'form' ) .
455 "\n"
456 );
457
458 $this->showLogFragment( $this->oldTitle );
459 $this->showSubpages( $this->oldTitle );
460 }
461
462 function doSubmit() {
463 global $wgMaximumMovedPages, $wgFixDoubleRedirects;
464
465 $user = $this->getUser();
466
467 if ( $user->pingLimiter( 'move' ) ) {
468 throw new ThrottledError;
469 }
470
471 $ot = $this->oldTitle;
472 $nt = $this->newTitle;
473
474 # don't allow moving to pages with # in
475 if ( !$nt || $nt->hasFragment() ) {
476 $this->showForm( array( array( 'badtitletext' ) ) );
477
478 return;
479 }
480
481 # Show a warning if the target file exists on a shared repo
482 if ( $nt->getNamespace() == NS_FILE
483 && !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) )
484 && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt )
485 && wfFindFile( $nt )
486 ) {
487 $this->showForm( array( array( 'file-exists-sharedrepo' ) ) );
488
489 return;
490 }
491
492 # Delete to make way if requested
493 if ( $this->deleteAndMove ) {
494 $permErrors = $nt->getUserPermissionsErrors( 'delete', $user );
495 if ( count( $permErrors ) ) {
496 # Only show the first error
497 $this->showForm( $permErrors );
498
499 return;
500 }
501
502 $reason = $this->msg( 'delete_and_move_reason', $ot )->inContentLanguage()->text();
503
504 // Delete an associated image if there is
505 if ( $nt->getNamespace() == NS_FILE ) {
506 $file = wfLocalFile( $nt );
507 if ( $file->exists() ) {
508 $file->delete( $reason, false );
509 }
510 }
511
512 $error = ''; // passed by ref
513 $page = WikiPage::factory( $nt );
514 $deleteStatus = $page->doDeleteArticleReal( $reason, false, 0, true, $error, $user );
515 if ( !$deleteStatus->isGood() ) {
516 $this->showForm( $deleteStatus->getErrorsArray() );
517
518 return;
519 }
520 }
521
522 $handler = ContentHandler::getForTitle( $ot );
523
524 if ( !$handler->supportsRedirects() ) {
525 $createRedirect = false;
526 } elseif ( $user->isAllowed( 'suppressredirect' ) ) {
527 $createRedirect = $this->leaveRedirect;
528 } else {
529 $createRedirect = true;
530 }
531
532 # Do the actual move.
533 $error = $ot->moveTo( $nt, true, $this->reason, $createRedirect );
534 if ( $error !== true ) {
535 $this->showForm( $error );
536
537 return;
538 }
539
540 if ( $wgFixDoubleRedirects && $this->fixRedirects ) {
541 DoubleRedirectJob::fixRedirects( 'move', $ot, $nt );
542 }
543
544 $out = $this->getOutput();
545 $out->setPageTitle( $this->msg( 'pagemovedsub' ) );
546
547 $oldLink = Linker::link(
548 $ot,
549 null,
550 array(),
551 array( 'redirect' => 'no' )
552 );
553 $newLink = Linker::linkKnown( $nt );
554 $oldText = $ot->getPrefixedText();
555 $newText = $nt->getPrefixedText();
556
557 if ( $ot->exists() ) {
558 //NOTE: we assume that if the old title exists, it's because it was re-created as
559 // a redirect to the new title. This is not safe, but what we did before was
560 // even worse: we just determined whether a redirect should have been created,
561 // and reported that it was created if it should have, without any checks.
562 // Also note that isRedirect() is unreliable because of bug 37209.
563 $msgName = 'movepage-moved-redirect';
564 } else {
565 $msgName = 'movepage-moved-noredirect';
566 }
567
568 $out->addHTML( $this->msg( 'movepage-moved' )->rawParams( $oldLink,
569 $newLink )->params( $oldText, $newText )->parseAsBlock() );
570 $out->addWikiMsg( $msgName );
571
572 wfRunHooks( 'SpecialMovepageAfterMove', array( &$this, &$ot, &$nt ) );
573
574 # Now we move extra pages we've been asked to move: subpages and talk
575 # pages. First, if the old page or the new page is a talk page, we
576 # can't move any talk pages: cancel that.
577 if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
578 $this->moveTalk = false;
579 }
580
581 if ( count( $ot->getUserPermissionsErrors( 'move-subpages', $user ) ) ) {
582 $this->moveSubpages = false;
583 }
584
585 # Next make a list of id's. This might be marginally less efficient
586 # than a more direct method, but this is not a highly performance-cri-
587 # tical code path and readable code is more important here.
588 #
589 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
590 # 4 might get confused. If so, consider rewriting as a UNION.
591 #
592 # If the target namespace doesn't allow subpages, moving with subpages
593 # would mean that you couldn't move them back in one operation, which
594 # is bad.
595 # @todo FIXME: A specific error message should be given in this case.
596
597 // @todo FIXME: Use Title::moveSubpages() here
598 $dbr = wfGetDB( DB_MASTER );
599 if ( $this->moveSubpages && (
600 MWNamespace::hasSubpages( $nt->getNamespace() ) || (
601 $this->moveTalk
602 && MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
603 )
604 ) ) {
605 $conds = array(
606 'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
607 . ' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
608 );
609 $conds['page_namespace'] = array();
610 if ( MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
611 $conds['page_namespace'][] = $ot->getNamespace();
612 }
613 if ( $this->moveTalk &&
614 MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
615 ) {
616 $conds['page_namespace'][] = $ot->getTalkPage()->getNamespace();
617 }
618 } elseif ( $this->moveTalk ) {
619 $conds = array(
620 'page_namespace' => $ot->getTalkPage()->getNamespace(),
621 'page_title' => $ot->getDBkey()
622 );
623 } else {
624 # Skip the query
625 $conds = null;
626 }
627
628 $extraPages = array();
629 if ( !is_null( $conds ) ) {
630 $extraPages = TitleArray::newFromResult(
631 $dbr->select( 'page',
632 array( 'page_id', 'page_namespace', 'page_title' ),
633 $conds,
634 __METHOD__
635 )
636 );
637 }
638
639 $extraOutput = array();
640 $count = 1;
641 foreach ( $extraPages as $oldSubpage ) {
642 if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
643 # Already did this one.
644 continue;
645 }
646
647 $newPageName = preg_replace(
648 '#^' . preg_quote( $ot->getDBkey(), '#' ) . '#',
649 StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
650 $oldSubpage->getDBkey()
651 );
652
653 if ( $oldSubpage->isTalkPage() ) {
654 $newNs = $nt->getTalkPage()->getNamespace();
655 } else {
656 $newNs = $nt->getSubjectPage()->getNamespace();
657 }
658
659 # Bug 14385: we need makeTitleSafe because the new page names may
660 # be longer than 255 characters.
661 $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
662 if ( !$newSubpage ) {
663 $oldLink = Linker::linkKnown( $oldSubpage );
664 $extraOutput[] = $this->msg( 'movepage-page-unmoved' )->rawParams( $oldLink )
665 ->params( Title::makeName( $newNs, $newPageName ) )->escaped();
666 continue;
667 }
668
669 # This was copy-pasted from Renameuser, bleh.
670 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
671 $link = Linker::linkKnown( $newSubpage );
672 $extraOutput[] = $this->msg( 'movepage-page-exists' )->rawParams( $link )->escaped();
673 } else {
674 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason, $createRedirect );
675
676 if ( $success === true ) {
677 if ( $this->fixRedirects ) {
678 DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
679 }
680 $oldLink = Linker::link(
681 $oldSubpage,
682 null,
683 array(),
684 array( 'redirect' => 'no' )
685 );
686
687 $newLink = Linker::linkKnown( $newSubpage );
688 $extraOutput[] = $this->msg( 'movepage-page-moved' )->rawParams( $oldLink, $newLink )->escaped();
689 ++$count;
690
691 if ( $count >= $wgMaximumMovedPages ) {
692 $extraOutput[] = $this->msg( 'movepage-max-pages' )->numParams( $wgMaximumMovedPages )->escaped();
693 break;
694 }
695 } else {
696 $oldLink = Linker::linkKnown( $oldSubpage );
697 $newLink = Linker::link( $newSubpage );
698 $extraOutput[] = $this->msg( 'movepage-page-unmoved' )->rawParams( $oldLink, $newLink )->escaped();
699 }
700 }
701 }
702
703 if ( $extraOutput !== array() ) {
704 $out->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
705 }
706
707 # Deal with watches (we don't watch subpages)
708 WatchAction::doWatchOrUnwatch( $this->watch, $ot, $user );
709 WatchAction::doWatchOrUnwatch( $this->watch, $nt, $user );
710 }
711
712 function showLogFragment( $title ) {
713 $moveLogPage = new LogPage( 'move' );
714 $out = $this->getOutput();
715 $out->addHTML( Xml::element( 'h2', null, $moveLogPage->getName()->text() ) );
716 LogEventsList::showLogExtract( $out, 'move', $title );
717 }
718
719 function showSubpages( $title ) {
720 if ( !MWNamespace::hasSubpages( $title->getNamespace() ) ) {
721 return;
722 }
723
724 $subpages = $title->getSubpages();
725 $count = $subpages instanceof TitleArray ? $subpages->count() : 0;
726
727 $out = $this->getOutput();
728 $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
729
730 # No subpages.
731 if ( $count == 0 ) {
732 $out->addWikiMsg( 'movenosubpage' );
733
734 return;
735 }
736
737 $out->addWikiMsg( 'movesubpagetext', $this->getLanguage()->formatNum( $count ) );
738 $out->addHTML( "<ul>\n" );
739
740 foreach ( $subpages as $subpage ) {
741 $link = Linker::link( $subpage );
742 $out->addHTML( "<li>$link</li>\n" );
743 }
744 $out->addHTML( "</ul>\n" );
745 }
746
747 protected function getGroupName() {
748 return 'pagetools';
749 }
750 }