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