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