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