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