MediaWiki REL1_31
SpecialMovepage.php
Go to the documentation of this file.
1<?php
31 protected $oldTitle = null;
32
34 protected $newTitle;
35
37 protected $reason;
38
39 // Checks
40
42 protected $moveTalk;
43
45 protected $deleteAndMove;
46
48 protected $moveSubpages;
49
51 protected $fixRedirects;
52
54 protected $leaveRedirect;
55
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 ) {
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 T22365
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' );
121 $this->deleteAndMove = $request->getBool( 'wpDeleteAndMove' );
122 $this->moveOverShared = $request->getBool( 'wpMoveOverSharedFile' );
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( [] );
131 }
132 }
133
141 function showForm( $err ) {
142 $this->getSkin()->setRelevantTitle( $this->oldTitle );
143
144 $out = $this->getOutput();
145 $out->setPageTitle( $this->msg( 'move-page', $this->oldTitle->getPrefixedText() ) );
146 $out->addModules( 'mediawiki.special.movePage' );
147 $out->addModuleStyles( 'mediawiki.special.movePage.styles' );
148 $this->addHelpLink( 'Help:Moving a page' );
149
150 $out->addWikiMsg( $this->getConfig()->get( 'FixDoubleRedirects' ) ?
151 'movepagetext' :
152 'movepagetext-noredirectfixer'
153 );
154
155 if ( $this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage() ) {
156 $out->wrapWikiMsg(
157 "<div class=\"warningbox mw-moveuserpage-warning\">\n$1\n</div>",
158 'moveuserpage-warning'
159 );
160 } elseif ( $this->oldTitle->getNamespace() == NS_CATEGORY ) {
161 $out->wrapWikiMsg(
162 "<div class=\"warningbox mw-movecategorypage-warning\">\n$1\n</div>",
163 'movecategorypage-warning'
164 );
165 }
166
167 $deleteAndMove = false;
168 $moveOverShared = false;
169
171
172 if ( !$newTitle ) {
173 # Show the current title as a default
174 # when the form is first opened.
176 } elseif ( !count( $err ) ) {
177 # If a title was supplied, probably from the move log revert
178 # link, check for validity. We can then show some diagnostic
179 # information and save a click.
180 $newerr = $this->oldTitle->isValidMoveOperation( $newTitle );
181 if ( is_array( $newerr ) ) {
182 $err = $newerr;
183 }
184 }
185
186 $user = $this->getUser();
187
188 if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] == 'articleexists'
189 && $newTitle->quickUserCan( 'delete', $user )
190 ) {
191 $out->wrapWikiMsg(
192 "<div class='warningbox'>\n$1\n</div>\n",
193 [ 'delete_and_move_text', $newTitle->getPrefixedText() ]
194 );
195 $deleteAndMove = true;
196 $err = [];
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->wrapWikiMsg(
203 "<div class='warningbox'>\n$1\n</div>\n",
204 [
205 'move-over-sharedrepo',
207 ]
208 );
209 $moveOverShared = true;
210 $err = [];
211 }
212
213 $oldTalk = $this->oldTitle->getTalkPage();
214 $oldTitleSubpages = $this->oldTitle->hasSubpages();
215 $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
216
217 $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
218 !count( $this->oldTitle->getUserPermissionsErrors( 'move-subpages', $user ) );
219
220 # We also want to be able to move assoc. subpage talk-pages even if base page
221 # has no associated talk page, so || with $oldTitleTalkSubpages.
222 $considerTalk = !$this->oldTitle->isTalkPage() &&
223 ( $oldTalk->exists()
224 || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
225
227 if ( $this->getConfig()->get( 'FixDoubleRedirects' ) ) {
228 $hasRedirects = $dbr->selectField( 'redirect', '1',
229 [
230 'rd_namespace' => $this->oldTitle->getNamespace(),
231 'rd_title' => $this->oldTitle->getDBkey(),
232 ], __METHOD__ );
233 } else {
234 $hasRedirects = false;
235 }
236
237 if ( count( $err ) ) {
238 $action_desc = $this->msg( 'action-move' )->plain();
239 $errMsgHtml = $this->msg( 'permissionserrorstext-withaction',
240 count( $err ), $action_desc )->parseAsBlock();
241
242 if ( count( $err ) == 1 ) {
243 $errMsg = $err[0];
244 $errMsgName = array_shift( $errMsg );
245
246 if ( $errMsgName == 'hookaborted' ) {
247 $errMsgHtml .= "<p>{$errMsg[0]}</p>\n";
248 } else {
249 $errMsgHtml .= $this->msg( $errMsgName, $errMsg )->parseAsBlock();
250 }
251 } else {
252 $errStr = [];
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 $errMsgHtml .= '<ul><li>' . implode( "</li>\n<li>", $errStr ) . "</li></ul>\n";
264 }
265 $out->addHTML( Html::errorBox( $errMsgHtml ) );
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 );
281 $out,
282 'protect',
283 $this->oldTitle,
284 '',
285 [ 'lim' => 1 ]
286 );
287 $out->addHTML( "</div>\n" );
288 }
289
290 // Length limit for wpReason and wpNewTitleMain is enforced in the
291 // mediawiki.special.movePage module
292
293 $immovableNamespaces = [];
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 = [];
304
305 $fields[] = new OOUI\FieldLayout(
306 new MediaWiki\Widget\ComplexTitleInputWidget( [
307 'id' => 'wpNewTitle',
308 'namespace' => [
309 'id' => 'wpNewTitleNs',
310 'name' => 'wpNewTitleNs',
311 'value' => $newTitle->getNamespace(),
312 'exclude' => $immovableNamespaces,
313 ],
314 'title' => [
315 'id' => 'wpNewTitleMain',
316 'name' => 'wpNewTitleMain',
317 'value' => $newTitle->getText(),
318 // Inappropriate, since we're expecting the user to input a non-existent page's title
319 'suggestions' => false,
320 ],
321 'infusable' => true,
322 ] ),
323 [
324 'label' => $this->msg( 'newtitle' )->text(),
325 'align' => 'top',
326 ]
327 );
328
329 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
330 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
331 // Unicode codepoints (or 255 UTF-8 bytes for old schema).
332 $conf = $this->getConfig();
333 $oldCommentSchema = $conf->get( 'CommentTableSchemaMigrationStage' ) === MIGRATION_OLD;
334 $fields[] = new OOUI\FieldLayout(
335 new OOUI\TextInputWidget( [
336 'name' => 'wpReason',
337 'id' => 'wpReason',
338 'maxLength' => $oldCommentSchema ? 200 : CommentStore::COMMENT_CHARACTER_LIMIT,
339 'infusable' => true,
340 'value' => $this->reason,
341 ] ),
342 [
343 'label' => $this->msg( 'movereason' )->text(),
344 'align' => 'top',
345 ]
346 );
347
348 if ( $considerTalk ) {
349 $fields[] = new OOUI\FieldLayout(
350 new OOUI\CheckboxInputWidget( [
351 'name' => 'wpMovetalk',
352 'id' => 'wpMovetalk',
353 'value' => '1',
354 'selected' => $this->moveTalk,
355 ] ),
356 [
357 'label' => $this->msg( 'movetalk' )->text(),
358 'help' => new OOUI\HtmlSnippet( $this->msg( 'movepagetalktext' )->parseAsBlock() ),
359 'align' => 'inline',
360 'infusable' => true,
361 'id' => 'wpMovetalk-field',
362 ]
363 );
364 }
365
366 if ( $user->isAllowed( 'suppressredirect' ) ) {
367 if ( $handler->supportsRedirects() ) {
368 $isChecked = $this->leaveRedirect;
369 $isDisabled = false;
370 } else {
371 $isChecked = false;
372 $isDisabled = true;
373 }
374 $fields[] = new OOUI\FieldLayout(
375 new OOUI\CheckboxInputWidget( [
376 'name' => 'wpLeaveRedirect',
377 'id' => 'wpLeaveRedirect',
378 'value' => '1',
379 'selected' => $isChecked,
380 'disabled' => $isDisabled,
381 ] ),
382 [
383 'label' => $this->msg( 'move-leave-redirect' )->text(),
384 'align' => 'inline',
385 ]
386 );
387 }
388
389 if ( $hasRedirects ) {
390 $fields[] = new OOUI\FieldLayout(
391 new OOUI\CheckboxInputWidget( [
392 'name' => 'wpFixRedirects',
393 'id' => 'wpFixRedirects',
394 'value' => '1',
395 'selected' => $this->fixRedirects,
396 ] ),
397 [
398 'label' => $this->msg( 'fix-double-redirects' )->text(),
399 'align' => 'inline',
400 ]
401 );
402 }
403
404 if ( $canMoveSubpage ) {
405 $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
406 $fields[] = new OOUI\FieldLayout(
407 new OOUI\CheckboxInputWidget( [
408 'name' => 'wpMovesubpages',
409 'id' => 'wpMovesubpages',
410 'value' => '1',
411 # Don't check the box if we only have talk subpages to
412 # move and we aren't moving the talk page.
413 'selected' => $this->moveSubpages && ( $this->oldTitle->hasSubpages() || $this->moveTalk ),
414 ] ),
415 [
416 'label' => new OOUI\HtmlSnippet(
417 $this->msg(
418 ( $this->oldTitle->hasSubpages()
419 ? 'move-subpages'
420 : 'move-talk-subpages' )
421 )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
422 ),
423 'align' => 'inline',
424 ]
425 );
426 }
427
428 # Don't allow watching if user is not logged in
429 if ( $user->isLoggedIn() ) {
430 $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption( 'watchmoves' )
431 || $user->isWatched( $this->oldTitle ) );
432 $fields[] = new OOUI\FieldLayout(
433 new OOUI\CheckboxInputWidget( [
434 'name' => 'wpWatch',
435 'id' => 'watch', # ew
436 'value' => '1',
437 'selected' => $watchChecked,
438 ] ),
439 [
440 'label' => $this->msg( 'move-watch' )->text(),
441 'align' => 'inline',
442 ]
443 );
444 }
445
446 $hiddenFields = '';
447 if ( $moveOverShared ) {
448 $hiddenFields .= Html::hidden( 'wpMoveOverSharedFile', '1' );
449 }
450
451 if ( $deleteAndMove ) {
452 $fields[] = new OOUI\FieldLayout(
453 new OOUI\CheckboxInputWidget( [
454 'name' => 'wpDeleteAndMove',
455 'id' => 'wpDeleteAndMove',
456 'value' => '1',
457 ] ),
458 [
459 'label' => $this->msg( 'delete_and_move_confirm' )->text(),
460 'align' => 'inline',
461 ]
462 );
463 }
464
465 $fields[] = new OOUI\FieldLayout(
466 new OOUI\ButtonInputWidget( [
467 'name' => 'wpMove',
468 'value' => $this->msg( 'movepagebtn' )->text(),
469 'label' => $this->msg( 'movepagebtn' )->text(),
470 'flags' => [ 'primary', 'progressive' ],
471 'type' => 'submit',
472 ] ),
473 [
474 'align' => 'top',
475 ]
476 );
477
478 $fieldset = new OOUI\FieldsetLayout( [
479 'label' => $this->msg( 'move-page-legend' )->text(),
480 'id' => 'mw-movepage-table',
481 'items' => $fields,
482 ] );
483
484 $form = new OOUI\FormLayout( [
485 'method' => 'post',
486 'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ),
487 'id' => 'movepage',
488 ] );
489 $form->appendContent(
490 $fieldset,
491 new OOUI\HtmlSnippet(
492 $hiddenFields .
493 Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
494 Html::hidden( 'wpEditToken', $user->getEditToken() )
495 )
496 );
497
498 $out->addHTML(
499 new OOUI\PanelLayout( [
500 'classes' => [ 'movepage-wrapper' ],
501 'expanded' => false,
502 'padded' => true,
503 'framed' => true,
504 'content' => $form,
505 ] )
506 );
507
508 $this->showLogFragment( $this->oldTitle );
509 $this->showSubpages( $this->oldTitle );
510 }
511
512 function doSubmit() {
513 $user = $this->getUser();
514
515 if ( $user->pingLimiter( 'move' ) ) {
516 throw new ThrottledError;
517 }
518
519 $ot = $this->oldTitle;
520 $nt = $this->newTitle;
521
522 # don't allow moving to pages with # in
523 if ( !$nt || $nt->hasFragment() ) {
524 $this->showForm( [ [ 'badtitletext' ] ] );
525
526 return;
527 }
528
529 # Show a warning if the target file exists on a shared repo
530 if ( $nt->getNamespace() == NS_FILE
531 && !( $this->moveOverShared && $user->isAllowed( 'reupload-shared' ) )
532 && !RepoGroup::singleton()->getLocalRepo()->findFile( $nt )
533 && wfFindFile( $nt )
534 ) {
535 $this->showForm( [ [ 'file-exists-sharedrepo' ] ] );
536
537 return;
538 }
539
540 # Delete to make way if requested
541 if ( $this->deleteAndMove ) {
542 $permErrors = $nt->getUserPermissionsErrors( 'delete', $user );
543 if ( count( $permErrors ) ) {
544 # Only show the first error
545 $this->showForm( $permErrors );
546
547 return;
548 }
549
550 $reason = $this->msg( 'delete_and_move_reason', $ot )->inContentLanguage()->text();
551
552 // Delete an associated image if there is
553 if ( $nt->getNamespace() == NS_FILE ) {
554 $file = wfLocalFile( $nt );
555 $file->load( File::READ_LATEST );
556 if ( $file->exists() ) {
557 $file->delete( $reason, false, $user );
558 }
559 }
560
561 $error = ''; // passed by ref
562 $page = WikiPage::factory( $nt );
563 $deleteStatus = $page->doDeleteArticleReal( $reason, false, 0, true, $error, $user );
564 if ( !$deleteStatus->isGood() ) {
565 $this->showForm( $deleteStatus->getErrorsArray() );
566
567 return;
568 }
569 }
570
571 $handler = ContentHandler::getForTitle( $ot );
572
573 if ( !$handler->supportsRedirects() ) {
574 $createRedirect = false;
575 } elseif ( $user->isAllowed( 'suppressredirect' ) ) {
576 $createRedirect = $this->leaveRedirect;
577 } else {
578 $createRedirect = true;
579 }
580
581 # Do the actual move.
582 $mp = new MovePage( $ot, $nt );
583 $valid = $mp->isValidMove();
584 if ( !$valid->isOK() ) {
585 $this->showForm( $valid->getErrorsArray() );
586 return;
587 }
588
589 $permStatus = $mp->checkPermissions( $user, $this->reason );
590 if ( !$permStatus->isOK() ) {
591 $this->showForm( $permStatus->getErrorsArray() );
592 return;
593 }
594
595 $status = $mp->move( $user, $this->reason, $createRedirect );
596 if ( !$status->isOK() ) {
597 $this->showForm( $status->getErrorsArray() );
598 return;
599 }
600
601 if ( $this->getConfig()->get( 'FixDoubleRedirects' ) && $this->fixRedirects ) {
602 DoubleRedirectJob::fixRedirects( 'move', $ot, $nt );
603 }
604
605 $out = $this->getOutput();
606 $out->setPageTitle( $this->msg( 'pagemovedsub' ) );
607
609 $oldLink = $linkRenderer->makeLink(
610 $ot,
611 null,
612 [ 'id' => 'movepage-oldlink' ],
613 [ 'redirect' => 'no' ]
614 );
615 $newLink = $linkRenderer->makeKnownLink(
616 $nt,
617 null,
618 [ 'id' => 'movepage-newlink' ]
619 );
620 $oldText = $ot->getPrefixedText();
621 $newText = $nt->getPrefixedText();
622
623 if ( $ot->exists() ) {
624 // NOTE: we assume that if the old title exists, it's because it was re-created as
625 // a redirect to the new title. This is not safe, but what we did before was
626 // even worse: we just determined whether a redirect should have been created,
627 // and reported that it was created if it should have, without any checks.
628 // Also note that isRedirect() is unreliable because of T39209.
629 $msgName = 'movepage-moved-redirect';
630 } else {
631 $msgName = 'movepage-moved-noredirect';
632 }
633
634 $out->addHTML( $this->msg( 'movepage-moved' )->rawParams( $oldLink,
635 $newLink )->params( $oldText, $newText )->parseAsBlock() );
636 $out->addWikiMsg( $msgName );
637
638 // Avoid PHP 7.1 warning from passing $this by reference
639 $movePage = $this;
640 Hooks::run( 'SpecialMovepageAfterMove', [ &$movePage, &$ot, &$nt ] );
641
642 # Now we move extra pages we've been asked to move: subpages and talk
643 # pages. First, if the old page or the new page is a talk page, we
644 # can't move any talk pages: cancel that.
645 if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
646 $this->moveTalk = false;
647 }
648
649 if ( count( $ot->getUserPermissionsErrors( 'move-subpages', $user ) ) ) {
650 $this->moveSubpages = false;
651 }
652
664 // @todo FIXME: Use Title::moveSubpages() here
666 if ( $this->moveSubpages && (
667 MWNamespace::hasSubpages( $nt->getNamespace() ) || (
668 $this->moveTalk
669 && MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
670 )
671 ) ) {
672 $conds = [
673 'page_title' . $dbr->buildLike( $ot->getDBkey() . '/', $dbr->anyString() )
674 . ' OR page_title = ' . $dbr->addQuotes( $ot->getDBkey() )
675 ];
676 $conds['page_namespace'] = [];
677 if ( MWNamespace::hasSubpages( $nt->getNamespace() ) ) {
678 $conds['page_namespace'][] = $ot->getNamespace();
679 }
680 if ( $this->moveTalk &&
681 MWNamespace::hasSubpages( $nt->getTalkPage()->getNamespace() )
682 ) {
683 $conds['page_namespace'][] = $ot->getTalkPage()->getNamespace();
684 }
685 } elseif ( $this->moveTalk ) {
686 $conds = [
687 'page_namespace' => $ot->getTalkPage()->getNamespace(),
688 'page_title' => $ot->getDBkey()
689 ];
690 } else {
691 # Skip the query
692 $conds = null;
693 }
694
695 $extraPages = [];
696 if ( !is_null( $conds ) ) {
697 $extraPages = TitleArray::newFromResult(
698 $dbr->select( 'page',
699 [ 'page_id', 'page_namespace', 'page_title' ],
700 $conds,
701 __METHOD__
702 )
703 );
704 }
705
706 $extraOutput = [];
707 $count = 1;
708 foreach ( $extraPages as $oldSubpage ) {
709 if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
710 # Already did this one.
711 continue;
712 }
713
714 $newPageName = preg_replace(
715 '#^' . preg_quote( $ot->getDBkey(), '#' ) . '#',
716 StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # T23234
717 $oldSubpage->getDBkey()
718 );
719
720 if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
721 // Moving a subpage from a subject namespace to a talk namespace or vice-versa
722 $newNs = $nt->getNamespace();
723 } elseif ( $oldSubpage->isTalkPage() ) {
724 $newNs = $nt->getTalkPage()->getNamespace();
725 } else {
726 $newNs = $nt->getSubjectPage()->getNamespace();
727 }
728
729 # T16385: we need makeTitleSafe because the new page names may
730 # be longer than 255 characters.
731 $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
732 if ( !$newSubpage ) {
733 $oldLink = $linkRenderer->makeKnownLink( $oldSubpage );
734 $extraOutput[] = $this->msg( 'movepage-page-unmoved' )->rawParams( $oldLink )
735 ->params( Title::makeName( $newNs, $newPageName ) )->escaped();
736 continue;
737 }
738
739 # This was copy-pasted from Renameuser, bleh.
740 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
741 $link = $linkRenderer->makeKnownLink( $newSubpage );
742 $extraOutput[] = $this->msg( 'movepage-page-exists' )->rawParams( $link )->escaped();
743 } else {
744 $success = $oldSubpage->moveTo( $newSubpage, true, $this->reason, $createRedirect );
745
746 if ( $success === true ) {
747 if ( $this->fixRedirects ) {
748 DoubleRedirectJob::fixRedirects( 'move', $oldSubpage, $newSubpage );
749 }
750 $oldLink = $linkRenderer->makeLink(
751 $oldSubpage,
752 null,
753 [],
754 [ 'redirect' => 'no' ]
755 );
756
757 $newLink = $linkRenderer->makeKnownLink( $newSubpage );
758 $extraOutput[] = $this->msg( 'movepage-page-moved' )
759 ->rawParams( $oldLink, $newLink )->escaped();
760 ++$count;
761
762 $maximumMovedPages = $this->getConfig()->get( 'MaximumMovedPages' );
763 if ( $count >= $maximumMovedPages ) {
764 $extraOutput[] = $this->msg( 'movepage-max-pages' )
765 ->numParams( $maximumMovedPages )->escaped();
766 break;
767 }
768 } else {
769 $oldLink = $linkRenderer->makeKnownLink( $oldSubpage );
770 $newLink = $linkRenderer->makeLink( $newSubpage );
771 $extraOutput[] = $this->msg( 'movepage-page-unmoved' )
772 ->rawParams( $oldLink, $newLink )->escaped();
773 }
774 }
775 }
776
777 if ( $extraOutput !== [] ) {
778 $out->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
779 }
780
781 # Deal with watches (we don't watch subpages)
782 WatchAction::doWatchOrUnwatch( $this->watch, $ot, $user );
783 WatchAction::doWatchOrUnwatch( $this->watch, $nt, $user );
784
789 $user->incEditCount();
790 }
791
792 function showLogFragment( $title ) {
793 $moveLogPage = new LogPage( 'move' );
794 $out = $this->getOutput();
795 $out->addHTML( Xml::element( 'h2', null, $moveLogPage->getName()->text() ) );
796 LogEventsList::showLogExtract( $out, 'move', $title );
797 }
798
805 function showSubpages( $title ) {
806 $nsHasSubpages = MWNamespace::hasSubpages( $title->getNamespace() );
807 $subpages = $title->getSubpages();
808 $count = $subpages instanceof TitleArray ? $subpages->count() : 0;
809
810 $titleIsTalk = $title->isTalkPage();
811 $subpagesTalk = $title->getTalkPage()->getSubpages();
812 $countTalk = $subpagesTalk instanceof TitleArray ? $subpagesTalk->count() : 0;
813 $totalCount = $count + $countTalk;
814
815 if ( !$nsHasSubpages && $countTalk == 0 ) {
816 return;
817 }
818
819 $this->getOutput()->wrapWikiMsg(
820 '== $1 ==',
821 [ 'movesubpage', ( $titleIsTalk ? $count : $totalCount ) ]
822 );
823
824 if ( $nsHasSubpages ) {
825 $this->showSubpagesList( $subpages, $count, 'movesubpagetext', true );
826 }
827
828 if ( !$titleIsTalk && $countTalk > 0 ) {
829 $this->showSubpagesList( $subpagesTalk, $countTalk, 'movesubpagetalktext' );
830 }
831 }
832
833 function showSubpagesList( $subpages, $pagecount, $wikiMsg, $noSubpageMsg = false ) {
834 $out = $this->getOutput();
835
836 # No subpages.
837 if ( $pagecount == 0 && $noSubpageMsg ) {
838 $out->addWikiMsg( 'movenosubpage' );
839 return;
840 }
841
842 $out->addWikiMsg( $wikiMsg, $this->getLanguage()->formatNum( $pagecount ) );
843 $out->addHTML( "<ul>\n" );
844
845 $linkBatch = new LinkBatch( $subpages );
846 $linkBatch->setCaller( __METHOD__ );
847 $linkBatch->execute();
849
850 foreach ( $subpages as $subpage ) {
851 $link = $linkRenderer->makeLink( $subpage );
852 $out->addHTML( "<li>$link</li>\n" );
853 }
854 $out->addHTML( "</ul>\n" );
855 }
856
865 public function prefixSearchSubpages( $search, $limit, $offset ) {
866 return $this->prefixSearchString( $search, $limit, $offset );
867 }
868
869 protected function getGroupName() {
870 return 'pagetools';
871 }
872}
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfLocalFile( $title)
Get an object referring to a locally registered file.
wfFindFile( $title, $options=[])
Find a file.
static fixRedirects( $reason, $redirTitle, $destTitle=false)
Insert jobs into the job queue to fix redirects to the given title.
An error page which can definitely be safely rendered using the OutputPage.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:34
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
Class to simplify the use of log pages.
Definition LogPage.php:31
A special page that allows users to change page titles.
execute( $par)
Default execute method Checks user permissions.
showSubpages( $title)
Show subpages of the page being moved.
doesWrites()
Indicates whether this special page may perform database writes.
showSubpagesList( $subpages, $pagecount, $wikiMsg, $noSubpageMsg=false)
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
showLogFragment( $title)
string $reason
Text input.
prefixSearchSubpages( $search, $limit, $offset)
Return an array of subpages beginning with $search that this special page will accept.
showForm( $err)
Show the form.
Handles the backend logic of moving a page from one title to another.
Definition MovePage.php:30
Show an error when a user tries to do something they do not have the necessary permissions for.
static singleton()
Get a RepoGroup instance.
Definition RepoGroup.php:59
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
getUser()
Shortcut to get the User executing this instance.
getSkin()
Shortcut to get the skin being used for this instance.
msg( $key)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getRequest()
Get the WebRequest being used for this instance.
checkReadOnly()
If the wiki is currently in readonly mode, throws a ReadOnlyError.
getPageTitle( $subpage=false)
Get a self-referential title object.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
getLanguage()
Shortcut to get user's language.
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
prefixSearchString( $search, $limit, $offset)
Perform a regular substring search for prefixSearchSubpages.
MediaWiki Linker LinkRenderer null $linkRenderer
static escapeRegexReplacement( $string)
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.
Show an error when the user hits a rate limit.
The TitleArray class only exists to provide the newFromResult method at pre- sent.
static newFromResult( $res)
Represents a title within MediaWiki.
Definition Title.php:39
getNamespace()
Get the namespace index, i.e.
Definition Title.php:970
isValidMoveOperation(&$nt, $auth=true, $reason='')
Check whether a given move operation would be valid.
Definition Title.php:3878
getText()
Get the text form (spaces not underscores) of the main part.
Definition Title.php:929
quickUserCan( $action, $user=null)
Can $user perform $action on this page? This skips potentially expensive cascading permission checks ...
Definition Title.php:2095
getPrefixedText()
Get the prefixed title with spaces.
Definition Title.php:1625
Shortcut to construct a special page which is unlisted by default.
static doWatchOrUnwatch( $watch, Title $title, User $user)
Watch or unwatch a page.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition design.txt:18
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2806
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action or null $user:User who performed the tagging when the tagging is subsequent to the action or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy: boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
Definition hooks.txt:1051
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:864
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition hooks.txt:3021
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition hooks.txt:903
const NS_FILE
Definition Defines.php:80
const MIGRATION_OLD
Definition Defines.php:302
const NS_CATEGORY
Definition Defines.php:88
A helper class for throttling authentication attempts.
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:29