100 private $watch =
false;
103 private $movePageFactory;
106 private $permManager;
109 private $userOptionsLookup;
112 private $loadBalancer;
115 private $contentHandlerFactory;
121 private $linkBatchFactory;
127 private $wikiPageFactory;
130 private $searchEngineFactory;
133 private $watchlistManager;
136 private $restrictionStore;
166 parent::__construct(
'Movepage' );
167 $this->movePageFactory = $movePageFactory;
168 $this->permManager = $permManager;
169 $this->userOptionsLookup = $userOptionsLookup;
170 $this->loadBalancer = $loadBalancer;
171 $this->contentHandlerFactory = $contentHandlerFactory;
172 $this->nsInfo = $nsInfo;
173 $this->linkBatchFactory = $linkBatchFactory;
174 $this->repoGroup = $repoGroup;
175 $this->wikiPageFactory = $wikiPageFactory;
176 $this->searchEngineFactory = $searchEngineFactory;
177 $this->watchlistManager = $watchlistManager;
178 $this->restrictionStore = $restrictionStore;
196 $target = $par ?? $request->getText(
'target' );
197 $oldTitleText = $request->getText(
'wpOldTitle', $target );
200 if ( !$this->oldTitle ) {
204 $this->
getOutput()->addBacklinkSubtitle( $this->oldTitle );
206 if ( !$this->oldTitle->exists() ) {
210 $newTitleTextMain = $request->getText(
'wpNewTitleMain' );
211 $newTitleTextNs = $request->getInt(
'wpNewTitleNs', $this->oldTitle->getNamespace() );
214 $newTitleText_bc = $request->getText(
'wpNewTitle' );
215 $this->newTitle = strlen( $newTitleText_bc ) > 0
222 $permErrors = $this->permManager->getPermissionErrors(
'move', $user, $this->oldTitle );
223 if ( count( $permErrors ) ) {
225 DeferredUpdates::addCallableUpdate(
static function () use ( $user ) {
226 $user->spreadAnyEditBlock();
231 $def = !$request->wasPosted();
233 $reasonList = $request->getText(
'wpReasonList',
'other' );
234 $reason = $request->getText(
'wpReason' );
235 if ( $reasonList ===
'other' ) {
238 $this->reason = $reasonList . $this->
msg(
'colon-separator' )->inContentLanguage()->text() .
$reason;
240 $this->reason = $reasonList;
242 $this->moveTalk = $request->getBool(
'wpMovetalk', $def );
243 $this->fixRedirects = $request->getBool(
'wpFixRedirects', $def );
244 $this->leaveRedirect = $request->getBool(
'wpLeaveRedirect', $def );
246 $this->moveSubpages = $request->getBool(
'wpMovesubpages', $def );
247 $this->deleteAndMove = $request->getBool(
'wpDeleteAndMove' );
248 $this->moveOverShared = $request->getBool(
'wpMoveOverSharedFile' );
249 $this->watch = $request->getCheck(
'wpWatch' ) && $user->isRegistered();
251 if ( $request->getRawVal(
'action' ) ==
'submit' && $request->wasPosted()
252 && $user->matchEditToken( $request->getVal(
'wpEditToken' ) )
268 protected function showForm( $err, $isPermError =
false ) {
269 $this->
getSkin()->setRelevantTitle( $this->oldTitle );
272 $out->setPageTitle( $this->
msg(
'move-page', $this->oldTitle->getPrefixedText() ) );
273 $out->addModuleStyles( [
275 'mediawiki.interface.helpers.styles'
277 $out->addModules(
'mediawiki.misc-authed-ooui' );
280 $handlerSupportsRedirects = $this->contentHandlerFactory
281 ->getContentHandler( $this->oldTitle->getContentModel() )
282 ->supportsRedirects();
285 $out->addWikiMsg(
'movepagetext' );
287 $out->addWikiMsg( $handlerSupportsRedirects ?
288 'movepagetext-noredirectfixer' :
289 'movepagetext-noredirectsupport' );
292 if ( $this->oldTitle->getNamespace() ===
NS_USER && !$this->oldTitle->isSubpage() ) {
295 $out->msg(
'moveuserpage-warning' )->parse(),
296 'mw-moveuserpage-warning'
299 } elseif ( $this->oldTitle->getNamespace() ===
NS_CATEGORY ) {
302 $out->msg(
'movecategorypage-warning' )->parse(),
303 'mw-movecategorypage-warning'
316 # Show the current title as a default
317 # when the form is first opened.
319 } elseif ( !count( $err ) ) {
320 # If a title was supplied, probably from the move log revert
321 # link, check for validity. We can then show some diagnostic
322 # information and save a click.
323 $mp = $this->movePageFactory->newMovePage( $this->oldTitle,
$newTitle );
324 $status = $mp->isValidMove();
325 $status->merge( $mp->probablyCanMove( $this->getAuthority() ) );
326 if ( $status->getErrors() ) {
327 $err = $status->getErrorsArray();
331 if ( count( $err ) == 1 && isset( $err[0][0] ) ) {
332 if ( $err[0][0] ==
'articleexists'
333 && $this->permManager->quickUserCan(
'delete', $user,
$newTitle )
342 } elseif ( $err[0][0] ==
'redirectexists' && (
344 $this->permManager->quickUserCan(
'delete-redirect', $user,
$newTitle ) ||
345 $this->permManager->quickUserCan(
'delete', $user,
$newTitle ) )
354 } elseif ( $err[0][0] ==
'file-exists-sharedrepo'
355 && $this->permManager->userHasRight( $user,
'reupload-shared' )
368 $oldTitleSubpages = $this->oldTitle->hasSubpages();
369 $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
371 $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
372 !count( $this->permManager->getPermissionErrors(
378 # We also want to be able to move assoc. subpage talk-pages even if base page
379 # has no associated talk page, so || with $oldTitleTalkSubpages.
380 $considerTalk = !$this->oldTitle->isTalkPage() &&
382 || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
384 $dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
386 $hasRedirects = (bool)
$dbr->selectField(
'redirect',
'1',
388 'rd_namespace' => $this->oldTitle->getNamespace(),
389 'rd_title' => $this->oldTitle->getDBkey(),
392 $hasRedirects =
false;
395 if ( count( $err ) ) {
396 '@phan-var array[] $err';
397 if ( $isPermError ) {
398 $action_desc = $this->
msg(
'action-move' )->plain();
399 $errMsgHtml = $this->
msg(
'permissionserrorstext-withaction',
400 count( $err ), $action_desc )->parseAsBlock();
402 $errMsgHtml = $this->
msg(
'cannotmove', count( $err ) )->parseAsBlock();
405 if ( count( $err ) == 1 ) {
407 $errMsgName = array_shift( $errMsg );
409 if ( $errMsgName ==
'hookaborted' ) {
410 $errMsgHtml .=
"<p>{$errMsg[0]}</p>\n";
412 $errMsgHtml .= $this->
msg( $errMsgName, $errMsg )->parseAsBlock();
417 foreach ( $err as $errMsg ) {
418 if ( $errMsg[0] ==
'hookaborted' ) {
419 $errStr[] = $errMsg[1];
421 $errMsgName = array_shift( $errMsg );
422 $errStr[] = $this->
msg( $errMsgName, $errMsg )->parse();
426 $errMsgHtml .=
'<ul><li>' . implode(
"</li>\n<li>", $errStr ) .
"</li></ul>\n";
428 $out->addHTML( Html::errorBox( $errMsgHtml ) );
431 if ( $this->restrictionStore->isProtected( $this->oldTitle,
'move' ) ) {
432 # Is the title semi-protected?
433 if ( $this->restrictionStore->isSemiProtected( $this->oldTitle,
'move' ) ) {
434 $noticeMsg =
'semiprotectedpagemovewarning';
436 # Then it must be protected based on static groups (regular)
437 $noticeMsg =
'protectedpagemovewarning';
439 LogEventsList::showLogExtract(
444 [
'lim' => 1,
'msgKey' => $noticeMsg ]
451 $immovableNamespaces = [];
452 foreach ( array_keys( $this->
getLanguage()->getNamespaces() ) as $nsId ) {
453 if ( !$this->nsInfo->isMovable( $nsId ) ) {
454 $immovableNamespaces[] = $nsId;
461 $fields[] =
new FieldLayout(
463 'id' =>
'wpNewTitle',
465 'id' =>
'wpNewTitleNs',
466 'name' =>
'wpNewTitleNs',
468 'exclude' => $immovableNamespaces,
471 'id' =>
'wpNewTitleMain',
472 'name' =>
'wpNewTitleMain',
475 'suggestions' =>
false,
480 'label' => $this->msg(
'newtitle' )->text(),
485 $options = Xml::listDropDownOptions(
486 $this->
msg(
'movepage-reason-dropdown' )->inContentLanguage()->text(),
487 [
'other' => $this->
msg(
'movereasonotherlist' )->text() ]
489 $options = Xml::listDropDownOptionsOoui( $options );
491 $fields[] =
new FieldLayout(
492 new DropdownInputWidget( [
493 'name' =>
'wpReasonList',
494 'inputId' =>
'wpReasonList',
497 'options' => $options,
500 'label' => $this->
msg(
'movereason' )->text(),
508 $fields[] =
new FieldLayout(
509 new TextInputWidget( [
510 'name' =>
'wpReason',
512 'maxLength' => CommentStore::COMMENT_CHARACTER_LIMIT,
514 'value' => $this->reason,
517 'label' => $this->
msg(
'moveotherreason' )->text(),
522 if ( $considerTalk ) {
523 $fields[] =
new FieldLayout(
524 new CheckboxInputWidget( [
525 'name' =>
'wpMovetalk',
526 'id' =>
'wpMovetalk',
528 'selected' => $this->moveTalk,
531 'label' => $this->
msg(
'movetalk' )->text(),
532 'help' =>
new HtmlSnippet( $this->
msg(
'movepagetalktext' )->parseAsBlock() ),
533 'helpInline' =>
true,
535 'id' =>
'wpMovetalk-field',
540 if ( $this->permManager->userHasRight( $user,
'suppressredirect' ) ) {
541 if ( $handlerSupportsRedirects ) {
548 $fields[] =
new FieldLayout(
549 new CheckboxInputWidget( [
550 'name' =>
'wpLeaveRedirect',
551 'id' =>
'wpLeaveRedirect',
553 'selected' => $isChecked,
554 'disabled' => $isDisabled,
557 'label' => $this->
msg(
'move-leave-redirect' )->text(),
563 if ( $hasRedirects ) {
564 $fields[] =
new FieldLayout(
565 new CheckboxInputWidget( [
566 'name' =>
'wpFixRedirects',
567 'id' =>
'wpFixRedirects',
569 'selected' => $this->fixRedirects,
572 'label' => $this->
msg(
'fix-double-redirects' )->text(),
578 if ( $canMoveSubpage ) {
580 $fields[] =
new FieldLayout(
581 new CheckboxInputWidget( [
582 'name' =>
'wpMovesubpages',
583 'id' =>
'wpMovesubpages',
585 'selected' => $this->moveSubpages,
588 'label' =>
new HtmlSnippet(
590 ( $this->oldTitle->hasSubpages()
592 :
'move-talk-subpages' )
593 )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
600 # Don't allow watching if user is not logged in
601 if ( $user->isRegistered() ) {
602 $watchChecked = ( $this->watch || $this->userOptionsLookup->getBoolOption( $user,
'watchmoves' )
603 || $this->watchlistManager->isWatched( $user, $this->oldTitle ) );
604 $fields[] =
new FieldLayout(
605 new CheckboxInputWidget( [
607 'id' =>
'watch', # ew
609 'selected' => $watchChecked,
612 'label' => $this->
msg(
'move-watch' )->text(),
620 $hiddenFields .= Html::hidden(
'wpMoveOverSharedFile',
'1' );
624 $fields[] =
new FieldLayout(
625 new CheckboxInputWidget( [
626 'name' =>
'wpDeleteAndMove',
627 'id' =>
'wpDeleteAndMove',
631 'label' => $this->
msg(
'delete_and_move_confirm' )->text(),
637 $fields[] =
new FieldLayout(
638 new ButtonInputWidget( [
640 'value' => $this->
msg(
'movepagebtn' )->text(),
641 'label' => $this->
msg(
'movepagebtn' )->text(),
642 'flags' => [
'primary',
'progressive' ],
650 $fieldset =
new FieldsetLayout( [
651 'label' => $this->
msg(
'move-page-legend' )->text(),
652 'id' =>
'mw-movepage-table',
656 $form =
new FormLayout( [
658 'action' => $this->
getPageTitle()->getLocalURL(
'action=submit' ),
661 $form->appendContent(
665 Html::hidden(
'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
666 Html::hidden(
'wpEditToken', $user->getEditToken() )
672 'classes' => [
'movepage-wrapper' ],
679 if ( $this->
getAuthority()->isAllowed(
'editinterface' ) ) {
681 $this->
msg(
'movepage-reason-dropdown' )->inContentLanguage()->
getTitle(),
682 $this->
msg(
'movepage-edit-reasonlist' )->text(),
684 [
'action' =>
'edit' ]
686 $out->addHTML( Html::rawElement(
'p', [
'class' =>
'mw-movepage-editreasons' ], $link ) );
689 $this->showLogFragment( $this->oldTitle );
690 $this->showSubpages( $this->oldTitle );
693 private function doSubmit() {
696 if ( $user->pingLimiter(
'move' ) ) {
703 # don't allow moving to pages with # in
704 if ( !$nt || $nt->hasFragment() ) {
705 $this->
showForm( [ [
'badtitletext' ] ] );
710 # Show a warning if the target file exists on a shared repo
711 if ( $nt->getNamespace() ===
NS_FILE
712 && !( $this->moveOverShared && $this->permManager->userHasRight( $user,
'reupload-shared' ) )
713 && !$this->repoGroup->getLocalRepo()->findFile( $nt )
714 && $this->repoGroup->findFile( $nt )
716 $this->
showForm( [ [
'file-exists-sharedrepo' ] ] );
721 # Delete to make way if requested
722 if ( $this->deleteAndMove ) {
723 $redir2 = $nt->isSingleRevRedirect();
725 $permErrors = $this->permManager->getPermissionErrors(
726 $redir2 ?
'delete-redirect' :
'delete',
729 if ( count( $permErrors ) ) {
731 if ( count( $this->permManager->getPermissionErrors(
'delete', $user, $nt ) ) ) {
734 $this->
showForm( $permErrors,
true );
744 $this->
showForm( $permErrors,
true );
749 $page = $this->wikiPageFactory->newFromTitle( $nt );
752 if ( $page->isBatchedDelete( 5 ) ) {
753 $this->
showForm( [ [
'movepage-delete-first' ] ] );
758 $reason = $this->
msg(
'delete_and_move_reason', $ot )->inContentLanguage()->text();
761 if ( $nt->getNamespace() ===
NS_FILE ) {
762 $file = $this->repoGroup->getLocalRepo()->newFile( $nt );
763 $file->load( File::READ_LATEST );
764 if (
$file->exists() ) {
770 $deletionLog = $redir2 ?
'delete_redir2' :
'delete';
771 $deleteStatus = $page->doDeleteArticleReal(
772 $reason, $user,
false,
null, $error,
773 null, [], $deletionLog
775 if ( !$deleteStatus->isGood() ) {
776 $this->
showForm( $deleteStatus->getErrorsArray() );
782 $handler = $this->contentHandlerFactory->getContentHandler( $ot->getContentModel() );
784 if ( !$handler->supportsRedirects() ) {
785 $createRedirect =
false;
786 } elseif ( $this->permManager->userHasRight( $user,
'suppressredirect' ) ) {
789 $createRedirect =
true;
792 # Do the actual move.
793 $mp = $this->movePageFactory->newMovePage( $ot, $nt );
795 # check whether the requested actions are permitted / possible
796 $userPermitted = $mp->authorizeMove( $this->
getAuthority(), $this->reason )->isOK();
797 if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
798 $this->moveTalk =
false;
800 if ( $this->moveSubpages ) {
801 $this->moveSubpages = $this->permManager->userCan(
'move-subpages', $user, $ot );
804 $status = $mp->moveIfAllowed( $this->
getAuthority(), $this->reason, $createRedirect );
805 if ( !$status->isOK() ) {
806 $this->
showForm( $status->getErrorsArray(), !$userPermitted );
811 $this->fixRedirects ) {
816 $out->setPageTitle( $this->
msg(
'pagemovedsub' ) );
819 $oldLink = $linkRenderer->makeLink(
822 [
'id' =>
'movepage-oldlink' ],
823 [
'redirect' =>
'no' ]
825 $newLink = $linkRenderer->makeKnownLink(
828 [
'id' =>
'movepage-newlink' ]
830 $oldText = $ot->getPrefixedText();
831 $newText = $nt->getPrefixedText();
833 if ( $status->getValue()[
'redirectRevision'] !==
null ) {
834 $msgName =
'movepage-moved-redirect';
836 $msgName =
'movepage-moved-noredirect';
839 $out->addHTML( $this->
msg(
'movepage-moved' )->rawParams( $oldLink,
840 $newLink )->params( $oldText, $newText )->parseAsBlock() );
841 $out->addWikiMsg( $msgName );
843 $this->
getHookRunner()->onSpecialMovepageAfterMove( $this, $ot, $nt );
860 $dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
861 if ( $this->moveSubpages && (
862 $this->nsInfo->hasSubpages( $nt->getNamespace() ) || (
864 && $this->nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
868 'page_title' .
$dbr->buildLike( $ot->getDBkey() .
'/',
$dbr->anyString() )
869 .
' OR page_title = ' .
$dbr->addQuotes( $ot->getDBkey() )
871 $conds[
'page_namespace'] = [];
872 if ( $this->nsInfo->hasSubpages( $nt->getNamespace() ) ) {
873 $conds[
'page_namespace'][] = $ot->getNamespace();
875 if ( $this->moveTalk &&
876 $this->nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
878 $conds[
'page_namespace'][] = $ot->getTalkPage()->getNamespace();
880 } elseif ( $this->moveTalk ) {
882 'page_namespace' => $ot->getTalkPage()->getNamespace(),
883 'page_title' => $ot->getDBkey()
891 if ( $conds !==
null ) {
892 $extraPages = TitleArray::newFromResult(
893 $dbr->select(
'page',
894 [
'page_id',
'page_namespace',
'page_title' ],
903 foreach ( $extraPages as $oldSubpage ) {
904 if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
905 # Already did this one.
909 $newPageName = preg_replace(
910 '#^' . preg_quote( $ot->getDBkey(),
'#' ) .
'#',
911 StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # T23234
912 $oldSubpage->getDBkey()
915 if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
917 $newNs = $nt->getNamespace();
918 } elseif ( $oldSubpage->isTalkPage() ) {
919 $newNs = $nt->getTalkPage()->getNamespace();
921 $newNs = $nt->getSubjectPage()->getNamespace();
924 # T16385: we need makeTitleSafe because the new page names may
925 # be longer than 255 characters.
927 if ( !$newSubpage ) {
928 $oldLink = $linkRenderer->makeKnownLink( $oldSubpage );
929 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )->rawParams( $oldLink )
930 ->params( Title::makeName( $newNs, $newPageName ) )->escaped();
934 $mp = $this->movePageFactory->newMovePage( $oldSubpage, $newSubpage );
935 # This was copy-pasted from Renameuser, bleh.
936 if ( $newSubpage->exists() && !$mp->isValidMove()->isOK() ) {
937 $link = $linkRenderer->makeKnownLink( $newSubpage );
938 $extraOutput[] = $this->
msg(
'movepage-page-exists' )->rawParams( $link )->escaped();
940 $status = $mp->moveIfAllowed( $this->
getAuthority(), $this->reason, $createRedirect );
942 if ( $status->isOK() ) {
943 if ( $this->fixRedirects ) {
946 $oldLink = $linkRenderer->makeLink(
950 [
'redirect' =>
'no' ]
953 $newLink = $linkRenderer->makeKnownLink( $newSubpage );
954 $extraOutput[] = $this->
msg(
'movepage-page-moved' )
955 ->rawParams( $oldLink, $newLink )->escaped();
960 if ( $count >= $maximumMovedPages ) {
961 $extraOutput[] = $this->
msg(
'movepage-max-pages' )
962 ->numParams( $maximumMovedPages )->escaped();
966 $oldLink = $linkRenderer->makeKnownLink( $oldSubpage );
967 $newLink = $linkRenderer->makeLink( $newSubpage );
968 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )
969 ->rawParams( $oldLink, $newLink )->escaped();
974 if ( $extraOutput !== [] ) {
975 $out->addHTML(
"<ul>\n<li>" . implode(
"</li>\n<li>", $extraOutput ) .
"</li>\n</ul>" );
978 # Deal with watches (we don't watch subpages)
979 $this->watchlistManager->setWatch( $this->watch, $this->
getAuthority(), $ot );
980 $this->watchlistManager->setWatch( $this->watch, $this->
getAuthority(), $nt );
983 private function showLogFragment(
$title ) {
984 $moveLogPage =
new LogPage(
'move' );
986 $out->addHTML( Xml::element(
'h2',
null, $moveLogPage->getName()->text() ) );
996 private function showSubpages(
$title ) {
998 $nsHasSubpages = $this->nsInfo->hasSubpages(
$title->getNamespace() );
999 $subpages =
$title->getSubpages( $maximumMovedPages + 1 );
1000 $count = $subpages instanceof TitleArray ? $subpages->count() : 0;
1002 $titleIsTalk =
$title->isTalkPage();
1003 $subpagesTalk =
$title->getTalkPage()->getSubpages( $maximumMovedPages + 1 );
1004 $countTalk = $subpagesTalk instanceof TitleArray ? $subpagesTalk->count() : 0;
1005 $totalCount = $count + $countTalk;
1007 if ( !$nsHasSubpages && $countTalk == 0 ) {
1013 [
'movesubpage', ( $titleIsTalk ? $count : $totalCount ) ]
1016 if ( $nsHasSubpages ) {
1017 $this->showSubpagesList(
1018 $subpages, $count,
'movesubpagetext',
'movesubpagetext-truncated',
true
1022 if ( !$titleIsTalk && $countTalk > 0 ) {
1023 $this->showSubpagesList(
1024 $subpagesTalk, $countTalk,
'movesubpagetalktext',
'movesubpagetalktext-truncated'
1029 private function showSubpagesList( $subpages, $pagecount, $msg, $truncatedMsg, $noSubpageMsg =
false ) {
1033 if ( $pagecount == 0 && $noSubpageMsg ) {
1034 $out->addWikiMsg(
'movenosubpage' );
1040 if ( $pagecount > $maximumMovedPages ) {
1041 $subpages = $this->truncateSubpagesList( $subpages );
1042 $out->addWikiMsg( $truncatedMsg, $this->
getLanguage()->formatNum( $maximumMovedPages ) );
1044 $out->addWikiMsg( $msg, $this->
getLanguage()->formatNum( $pagecount ) );
1046 $out->addHTML(
"<ul>\n" );
1048 $linkBatch = $this->linkBatchFactory->newLinkBatch( $subpages );
1049 $linkBatch->setCaller( __METHOD__ );
1050 $linkBatch->execute();
1053 foreach ( $subpages as $subpage ) {
1054 $link = $linkRenderer->makeLink( $subpage );
1055 $out->addHTML(
"<li>$link</li>\n" );
1057 $out->addHTML(
"</ul>\n" );
1060 private function truncateSubpagesList( iterable $subpages ): array {
1062 foreach ( $subpages as $subpage ) {
1063 $returnArray[] = $subpage;
1068 return $returnArray;
1080 return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );