MovePageForm: Add value attribute to reason field back again
[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 'value' => $this->reason,
346 ) ),
347 array(
348 'label' => $this->msg( 'movereason' )->text(),
349 'align' => 'top',
350 )
351 );
352
353 if ( $considerTalk ) {
354 $fields[] = new OOUI\FieldLayout(
355 new OOUI\CheckboxInputWidget( array(
356 'name' => 'wpMovetalk',
357 'id' => 'wpMovetalk',
358 'value' => '1',
359 'selected' => $this->moveTalk,
360 ) ),
361 array(
362 'label' => $this->msg( 'movetalk' )->text(),
363 'align' => 'inline',
364 )
365 );
366 }
367
368 if ( $user->isAllowed( 'suppressredirect' ) ) {
369 if ( $handler->supportsRedirects() ) {
370 $isChecked = $this->leaveRedirect;
371 $isDisabled = false;
372 } else {
373 $isChecked = false;
374 $isDisabled = true;
375 }
376 $fields[] = new OOUI\FieldLayout(
377 new OOUI\CheckboxInputWidget( array(
378 'name' => 'wpLeaveRedirect',
379 'id' => 'wpLeaveRedirect',
380 'value' => '1',
381 'selected' => $isChecked,
382 'disabled' => $isDisabled,
383 ) ),
384 array(
385 'label' => $this->msg( 'move-leave-redirect' )->text(),
386 'align' => 'inline',
387 )
388 );
389 }
390
391 if ( $hasRedirects ) {
392 $fields[] = new OOUI\FieldLayout(
393 new OOUI\CheckboxInputWidget( array(
394 'name' => 'wpFixRedirects',
395 'id' => 'wpFixRedirects',
396 'value' => '1',
397 'selected' => $this->fixRedirects,
398 ) ),
399 array(
400 'label' => $this->msg( 'fix-double-redirects' )->text(),
401 'align' => 'inline',
402 )
403 );
404 }
405
406 if ( $canMoveSubpage ) {
407 $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
408 $fields[] = new OOUI\FieldLayout(
409 new OOUI\CheckboxInputWidget( array(
410 'name' => 'wpMovesubpages',
411 'id' => 'wpMovesubpages',
412 'value' => '1',
413 # Don't check the box if we only have talk subpages to
414 # move and we aren't moving the talk page.
415 'selected' => $this->moveSubpages && ( $this->oldTitle->hasSubpages() || $this->moveTalk ),
416 ) ),
417 array(
418 'label' => new OOUI\HtmlSnippet(
419 $this->msg(
420 ( $this->oldTitle->hasSubpages()
421 ? 'move-subpages'
422 : 'move-talk-subpages' )
423 )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
424 ),
425 'align' => 'inline',
426 )
427 );
428 }
429
430 # Don't allow watching if user is not logged in
431 if ( $user->isLoggedIn() ) {
432 $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption( 'watchmoves' )
433 || $user->isWatched( $this->oldTitle ) );
434 $fields[] = new OOUI\FieldLayout(
435 new OOUI\CheckboxInputWidget( array(
436 'name' => 'wpWatch',
437 'id' => 'watch', # ew
438 'value' => '1',
439 'selected' => $watchChecked,
440 ) ),
441 array(
442 'label' => $this->msg( 'move-watch' )->text(),
443 'align' => 'inline',
444 )
445 );
446 }
447
448 if ( $confirm ) {
449 $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption( 'watchmoves' )
450 || $user->isWatched( $this->oldTitle ) );
451 $fields[] = new OOUI\FieldLayout(
452 new OOUI\CheckboxInputWidget( array(
453 'name' => 'wpConfirm',
454 'id' => 'wpConfirm',
455 'value' => '1',
456 ) ),
457 array(
458 'label' => $this->msg( 'delete_and_move_confirm' )->text(),
459 'align' => 'inline',
460 )
461 );
462 }
463
464 $fields[] = new OOUI\FieldLayout(
465 new OOUI\ButtonInputWidget( array(
466 'name' => $submitVar,
467 'value' => $movepagebtn,
468 'label' => $movepagebtn,
469 'flags' => array( 'progressive', 'primary' ),
470 'type' => 'submit',
471 ) ),
472 array(
473 'align' => 'top',
474 )
475 );
476
477 $fieldset = new OOUI\FieldsetLayout( array(
478 'label' => $this->msg( 'move-page-legend' )->text(),
479 'id' => 'mw-movepage-table',
480 'items' => $fields,
481 ) );
482
483 $form = new OOUI\FormLayout( array(
484 'method' => 'post',
485 'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ),
486 'id' => 'movepage',
487 ) );
488 $form->appendContent(
489 $fieldset,
490 new OOUI\HtmlSnippet(
491 Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
492 Html::hidden( 'wpEditToken', $user->getEditToken() )
493 )
494 );
495
496 $out->addHTML(
497 new OOUI\PanelLayout( array(
498 'classes' => array( 'movepage-wrapper' ),
499 'expanded' => false,
500 'padded' => true,
501 'framed' => true,
502 'content' => $form,
503 ) )
504 );
505
506 $this->showLogFragment( $this->oldTitle );
507 $this->showSubpages( $this->oldTitle );
508 }
509
510 function doSubmit() {
511 $user = $this->getUser();
512
513 if ( $user->pingLimiter( 'move' ) ) {
514 throw new ThrottledError;
515 }
516
517 $ot = $this->oldTitle;
518 $nt = $this->newTitle;
519
520 # don't allow moving to pages with # in
521 if ( !$nt || $nt->hasFragment() ) {
522 $this->showForm( array( array( 'badtitletext' ) ) );
523
524 return;
525 }
526
527 # Show a warning if the target file exists on a shared repo
528 if ( $nt->getNamespace() == NS_FILE
529 && !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) )
530 && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt )
531 && wfFindFile( $nt )
532 ) {
533 $this->showForm( array( array( 'file-exists-sharedrepo' ) ) );
534
535 return;
536 }
537
538 # Delete to make way if requested
539 if ( $this->deleteAndMove ) {
540 $permErrors = $nt->getUserPermissionsErrors( 'delete', $user );
541 if ( count( $permErrors ) ) {
542 # Only show the first error
543 $this->showForm( $permErrors );
544
545 return;
546 }
547
548 $reason = $this->msg( 'delete_and_move_reason', $ot )->inContentLanguage()->text();
549
550 // Delete an associated image if there is
551 if ( $nt->getNamespace() == NS_FILE ) {
552 $file = wfLocalFile( $nt );
553 $file->load( File::READ_LATEST );
554 if ( $file->exists() ) {
555 $file->delete( $reason, false, $user );
556 }
557 }
558
559 $error = ''; // passed by ref
560 $page = WikiPage::factory( $nt );
561 $deleteStatus = $page->doDeleteArticleReal( $reason, false, 0, true, $error, $user );
562 if ( !$deleteStatus->isGood() ) {
563 $this->showForm( $deleteStatus->getErrorsArray() );
564
565 return;
566 }
567 }
568
569 $handler = ContentHandler::getForTitle( $ot );
570
571 if ( !$handler->supportsRedirects() ) {
572 $createRedirect = false;
573 } elseif ( $user->isAllowed( 'suppressredirect' ) ) {
574 $createRedirect = $this->leaveRedirect;
575 } else {
576 $createRedirect = true;
577 }
578
579 # Do the actual move.
580 $mp = new MovePage( $ot, $nt );
581 $valid = $mp->isValidMove();
582 if ( !$valid->isOK() ) {
583 $this->showForm( $valid->getErrorsArray() );
584 return;
585 }
586
587 $permStatus = $mp->checkPermissions( $user, $this->reason );
588 if ( !$permStatus->isOK() ) {
589 $this->showForm( $permStatus->getErrorsArray() );
590 return;
591 }
592
593 $status = $mp->move( $user, $this->reason, $createRedirect );
594 if ( !$status->isOK() ) {
595 $this->showForm( $status->getErrorsArray() );
596 return;
597 }
598
599 if ( $this->getConfig()->get( 'FixDoubleRedirects' ) && $this->fixRedirects ) {
600 DoubleRedirectJob::fixRedirects( 'move', $ot, $nt );
601 }
602
603 $out = $this->getOutput();
604 $out->setPageTitle( $this->msg( 'pagemovedsub' ) );
605
606 $oldLink = Linker::link(
607 $ot,
608 null,
609 array( 'id' => 'movepage-oldlink' ),
610 array( 'redirect' => 'no' )
611 );
612 $newLink = Linker::linkKnown(
613 $nt,
614 null,
615 array( 'id' => 'movepage-newlink' )
616 );
617 $oldText = $ot->getPrefixedText();
618 $newText = $nt->getPrefixedText();
619
620 if ( $ot->exists() ) {
621 //NOTE: we assume that if the old title exists, it's because it was re-created as
622 // a redirect to the new title. This is not safe, but what we did before was
623 // even worse: we just determined whether a redirect should have been created,
624 // and reported that it was created if it should have, without any checks.
625 // Also note that isRedirect() is unreliable because of bug 37209.
626 $msgName = 'movepage-moved-redirect';
627 } else {
628 $msgName = 'movepage-moved-noredirect';
629 }
630
631 $out->addHTML( $this->msg( 'movepage-moved' )->rawParams( $oldLink,
632 $newLink )->params( $oldText, $newText )->parseAsBlock() );
633 $out->addWikiMsg( $msgName );
634
635 Hooks::run( 'SpecialMovepageAfterMove', array( &$this, &$ot, &$nt ) );
636
637 # Now we move extra pages we've been asked to move: subpages and talk
638 # pages. First, if the old page or the new page is a talk page, we
639 # can't move any talk pages: cancel that.
640 if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
641 $this->moveTalk = false;
642 }
643
644 if ( count( $ot->getUserPermissionsErrors( 'move-subpages', $user ) ) ) {
645 $this->moveSubpages = false;
646 }
647
648 # Next make a list of id's. This might be marginally less efficient
649 # than a more direct method, but this is not a highly performance-cri-
650 # tical code path and readable code is more important here.
651 #
652 # Note: this query works nicely on MySQL 5, but the optimizer in MySQL
653 # 4 might get confused. If so, consider rewriting as a UNION.
654 #
655 # If the target namespace doesn't allow subpages, moving with subpages
656 # would mean that you couldn't move them back in one operation, which
657 # is bad.
658 # @todo FIXME: A specific error message should be given in this case.
659
660 // @todo FIXME: Use Title::moveSubpages() here
661 $dbr = wfGetDB( DB_MASTER );
662 if ( $this->moveSubpages && (
663 MWNamespace::hasSubpages( $nt->getNamespace() ) || (
664 $this->moveTalk
665 && MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
666 )
667 ) ) {
668 $conds = array(
669 'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
670 . ' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
671 );
672 $conds['page_namespace'] = array();
673 if ( MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
674 $conds['page_namespace'][] = $ot->getNamespace();
675 }
676 if ( $this->moveTalk &&
677 MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
678 ) {
679 $conds['page_namespace'][] = $ot->getTalkPage()->getNamespace();
680 }
681 } elseif ( $this->moveTalk ) {
682 $conds = array(
683 'page_namespace' => $ot->getTalkPage()->getNamespace(),
684 'page_title' => $ot->getDBkey()
685 );
686 } else {
687 # Skip the query
688 $conds = null;
689 }
690
691 $extraPages = array();
692 if ( !is_null( $conds ) ) {
693 $extraPages = TitleArray::newFromResult(
694 $dbr->select( 'page',
695 array( 'page_id', 'page_namespace', 'page_title' ),
696 $conds,
697 __METHOD__
698 )
699 );
700 }
701
702 $extraOutput = array();
703 $count = 1;
704 foreach ( $extraPages as $oldSubpage ) {
705 if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
706 # Already did this one.
707 continue;
708 }
709
710 $newPageName = preg_replace(
711 '#^' . preg_quote( $ot->getDBkey(), '#' ) . '#',
712 StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # bug 21234
713 $oldSubpage->getDBkey()
714 );
715
716 if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
717 // Moving a subpage from a subject namespace to a talk namespace or vice-versa
718 $newNs = $nt->getNamespace();
719 } elseif ( $oldSubpage->isTalkPage() ) {
720 $newNs = $nt->getTalkPage()->getNamespace();
721 } else {
722 $newNs = $nt->getSubjectPage()->getNamespace();
723 }
724
725 # Bug 14385: we need makeTitleSafe because the new page names may
726 # be longer than 255 characters.
727 $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
728 if ( !$newSubpage ) {
729 $oldLink = Linker::linkKnown( $oldSubpage );
730 $extraOutput[] = $this->msg( 'movepage-page-unmoved' )->rawParams( $oldLink )
731 ->params( Title::makeName( $newNs, $newPageName ) )->escaped();
732 continue;
733 }
734
735 # This was copy-pasted from Renameuser, bleh.
736 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
737 $link = Linker::linkKnown( $newSubpage );
738 $extraOutput[] = $this->msg( 'movepage-page-exists' )->rawParams( $link )->escaped();
739 } else {
740 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason, $createRedirect );
741
742 if ( $success === true ) {
743 if ( $this->fixRedirects ) {
744 DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
745 }
746 $oldLink = Linker::link(
747 $oldSubpage,
748 null,
749 array(),
750 array( 'redirect' => 'no' )
751 );
752
753 $newLink = Linker::linkKnown( $newSubpage );
754 $extraOutput[] = $this->msg( 'movepage-page-moved' )
755 ->rawParams( $oldLink, $newLink )->escaped();
756 ++$count;
757
758 $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
759 if ( $count >= $maximumMovedPages ) {
760 $extraOutput[] = $this->msg( 'movepage-max-pages' )
761 ->numParams( $maximumMovedPages )->escaped();
762 break;
763 }
764 } else {
765 $oldLink = Linker::linkKnown( $oldSubpage );
766 $newLink = Linker::link( $newSubpage );
767 $extraOutput[] = $this->msg( 'movepage-page-unmoved' )
768 ->rawParams( $oldLink, $newLink )->escaped();
769 }
770 }
771 }
772
773 if ( $extraOutput !== array() ) {
774 $out->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
775 }
776
777 # Deal with watches (we don't watch subpages)
778 WatchAction::doWatchOrUnwatch( $this->watch, $ot, $user );
779 WatchAction::doWatchOrUnwatch( $this->watch, $nt, $user );
780 }
781
782 function showLogFragment( $title ) {
783 $moveLogPage = new LogPage( 'move' );
784 $out = $this->getOutput();
785 $out->addHTML( Xml::element( 'h2', null, $moveLogPage->getName()->text() ) );
786 LogEventsList::showLogExtract( $out, 'move', $title );
787 }
788
789 function showSubpages( $title ) {
790 if ( !MWNamespace::hasSubpages( $title->getNamespace() ) ) {
791 return;
792 }
793
794 $subpages = $title->getSubpages();
795 $count = $subpages instanceof TitleArray ? $subpages->count() : 0;
796
797 $out = $this->getOutput();
798 $out->wrapWikiMsg( '== $1 ==', array( 'movesubpage', $count ) );
799
800 # No subpages.
801 if ( $count == 0 ) {
802 $out->addWikiMsg( 'movenosubpage' );
803
804 return;
805 }
806
807 $out->addWikiMsg( 'movesubpagetext', $this->getLanguage()->formatNum( $count ) );
808 $out->addHTML( "<ul>\n" );
809
810 foreach ( $subpages as $subpage ) {
811 $link = Linker::link( $subpage );
812 $out->addHTML( "<li>$link</li>\n" );
813 }
814 $out->addHTML( "</ul>\n" );
815 }
816
817 protected function getGroupName() {
818 return 'pagetools';
819 }
820 }