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