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