161 $target = $par ?? $request->getText(
'target' );
162 $oldTitleText = $request->getText(
'wpOldTitle', $target );
163 $this->oldTitle = Title::newFromText( $oldTitleText );
165 if ( !$this->oldTitle ) {
169 $this->
getOutput()->addBacklinkSubtitle( $this->oldTitle );
171 if ( !$this->oldTitle->exists() ) {
175 $newTitleTextMain = $request->getText(
'wpNewTitleMain' );
176 $newTitleTextNs = $request->getInt(
'wpNewTitleNs', $this->oldTitle->getNamespace() );
179 $newTitleText_bc = $request->getText(
'wpNewTitle' );
180 $this->newTitle = strlen( $newTitleText_bc ) > 0
181 ? Title::newFromText( $newTitleText_bc )
182 : Title::makeTitleSafe( $newTitleTextNs, $newTitleTextMain );
187 $permErrors = $this->permManager->getPermissionErrors(
'move', $user, $this->oldTitle );
188 if ( count( $permErrors ) ) {
190 DeferredUpdates::addCallableUpdate(
static function () use ( $user ) {
191 $user->spreadAnyEditBlock();
196 $def = !$request->wasPosted();
198 $this->reason = $request->getText(
'wpReason' );
199 $this->moveTalk = $request->getBool(
'wpMovetalk', $def );
200 $this->fixRedirects = $request->getBool(
'wpFixRedirects', $def );
201 $this->leaveRedirect = $request->getBool(
'wpLeaveRedirect', $def );
203 $this->moveSubpages = $request->getBool(
'wpMovesubpages', $def );
204 $this->deleteAndMove = $request->getBool(
'wpDeleteAndMove' );
205 $this->moveOverShared = $request->getBool(
'wpMoveOverSharedFile' );
206 $this->watch = $request->getCheck(
'wpWatch' ) && $user->isRegistered();
208 if ( $request->getRawVal(
'action' ) ==
'submit' && $request->wasPosted()
209 && $user->matchEditToken( $request->getVal(
'wpEditToken' ) )
225 protected function showForm( $err, $isPermError =
false ) {
226 $this->
getSkin()->setRelevantTitle( $this->oldTitle );
229 $out->setPageTitle( $this->
msg(
'move-page', $this->oldTitle->getPrefixedText() ) );
230 $out->addModuleStyles( [
232 'mediawiki.interface.helpers.styles'
234 $out->addModules(
'mediawiki.misc-authed-ooui' );
237 $handlerSupportsRedirects = $this->contentHandlerFactory
238 ->getContentHandler( $this->oldTitle->getContentModel() )
239 ->supportsRedirects();
241 if ( $this->
getConfig()->
get(
'FixDoubleRedirects' ) ) {
242 $out->addWikiMsg(
'movepagetext' );
244 $out->addWikiMsg( $handlerSupportsRedirects ?
245 'movepagetext-noredirectfixer' :
246 'movepagetext-noredirectsupport' );
249 if ( $this->oldTitle->getNamespace() ===
NS_USER && !$this->oldTitle->isSubpage() ) {
251 "<div class=\"warningbox mw-moveuserpage-warning\">\n$1\n</div>",
252 'moveuserpage-warning'
254 } elseif ( $this->oldTitle->getNamespace() ===
NS_CATEGORY ) {
256 "<div class=\"warningbox mw-movecategorypage-warning\">\n$1\n</div>",
257 'movecategorypage-warning'
269 # Show the current title as a default
270 # when the form is first opened.
272 } elseif ( !count( $err ) ) {
273 # If a title was supplied, probably from the move log revert
274 # link, check for validity. We can then show some diagnostic
275 # information and save a click.
276 $mp = $this->movePageFactory->newMovePage( $this->oldTitle,
$newTitle );
277 $status = $mp->isValidMove();
278 $status->merge( $mp->probablyCanMove( $this->getAuthority() ) );
279 if ( $status->getErrors() ) {
280 $err = $status->getErrorsArray();
284 if ( count( $err ) == 1 && isset( $err[0][0] ) ) {
285 if ( $err[0][0] ==
'articleexists'
286 && $this->permManager->quickUserCan(
'delete', $user,
$newTitle )
289 "<div class='warningbox'>\n$1\n</div>\n",
294 } elseif ( $err[0][0] ==
'redirectexists' && (
296 $this->permManager->quickUserCan(
'delete-redirect', $user,
$newTitle ) ||
297 $this->permManager->quickUserCan(
'delete', $user,
$newTitle ) )
300 "<div class='warningbox'>\n$1\n</div>\n",
305 } elseif ( $err[0][0] ==
'file-exists-sharedrepo'
306 && $this->permManager->userHasRight( $user,
'reupload-shared' )
309 "<div class='warningbox'>\n$1\n</div>\n",
317 $oldTalk = $this->oldTitle->getTalkPage();
318 $oldTitleSubpages = $this->oldTitle->hasSubpages();
319 $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
321 $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
322 !count( $this->permManager->getPermissionErrors(
328 # We also want to be able to move assoc. subpage talk-pages even if base page
329 # has no associated talk page, so || with $oldTitleTalkSubpages.
330 $considerTalk = !$this->oldTitle->isTalkPage() &&
332 || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
334 $dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
335 if ( $this->
getConfig()->get(
'FixDoubleRedirects' ) ) {
336 $hasRedirects = (bool)
$dbr->selectField(
'redirect',
'1',
338 'rd_namespace' => $this->oldTitle->getNamespace(),
339 'rd_title' => $this->oldTitle->getDBkey(),
342 $hasRedirects =
false;
345 if ( count( $err ) ) {
346 '@phan-var array[] $err';
347 if ( $isPermError ) {
348 $action_desc = $this->
msg(
'action-move' )->plain();
349 $errMsgHtml = $this->
msg(
'permissionserrorstext-withaction',
350 count( $err ), $action_desc )->parseAsBlock();
352 $errMsgHtml = $this->
msg(
'cannotmove', count( $err ) )->parseAsBlock();
355 if ( count( $err ) == 1 ) {
357 $errMsgName = array_shift( $errMsg );
359 if ( $errMsgName ==
'hookaborted' ) {
360 $errMsgHtml .=
"<p>{$errMsg[0]}</p>\n";
362 $errMsgHtml .= $this->
msg( $errMsgName, $errMsg )->parseAsBlock();
367 foreach ( $err as $errMsg ) {
368 if ( $errMsg[0] ==
'hookaborted' ) {
369 $errStr[] = $errMsg[1];
371 $errMsgName = array_shift( $errMsg );
372 $errStr[] = $this->
msg( $errMsgName, $errMsg )->parse();
376 $errMsgHtml .=
'<ul><li>' . implode(
"</li>\n<li>", $errStr ) .
"</li></ul>\n";
378 $out->addHTML( Html::errorBox( $errMsgHtml ) );
381 if ( $this->oldTitle->isProtected(
'move' ) ) {
382 # Is the title semi-protected?
383 if ( $this->oldTitle->isSemiProtected(
'move' ) ) {
384 $noticeMsg =
'semiprotectedpagemovewarning';
386 # Then it must be protected based on static groups (regular)
387 $noticeMsg =
'protectedpagemovewarning';
389 $out->addHTML(
"<div class='warningbox mw-warning-with-logexcerpt'>\n" );
390 $out->addWikiMsg( $noticeMsg );
391 LogEventsList::showLogExtract(
398 $out->addHTML(
"</div>\n" );
404 $immovableNamespaces = [];
405 foreach ( array_keys( $this->
getLanguage()->getNamespaces() ) as $nsId ) {
406 if ( !$this->nsInfo->isMovable( $nsId ) ) {
407 $immovableNamespaces[] = $nsId;
414 $fields[] =
new OOUI\FieldLayout(
415 new MediaWiki\Widget\ComplexTitleInputWidget( [
416 'id' =>
'wpNewTitle',
418 'id' =>
'wpNewTitleNs',
419 'name' =>
'wpNewTitleNs',
421 'exclude' => $immovableNamespaces,
424 'id' =>
'wpNewTitleMain',
425 'name' =>
'wpNewTitleMain',
428 'suggestions' =>
false,
433 'label' => $this->msg(
'newtitle' )->text(),
441 $fields[] =
new OOUI\FieldLayout(
442 new OOUI\TextInputWidget( [
443 'name' =>
'wpReason',
445 'maxLength' => CommentStore::COMMENT_CHARACTER_LIMIT,
447 'value' => $this->reason,
450 'label' => $this->
msg(
'movereason' )->text(),
455 if ( $considerTalk ) {
456 $fields[] =
new OOUI\FieldLayout(
457 new OOUI\CheckboxInputWidget( [
458 'name' =>
'wpMovetalk',
459 'id' =>
'wpMovetalk',
461 'selected' => $this->moveTalk,
464 'label' => $this->
msg(
'movetalk' )->text(),
465 'help' =>
new OOUI\HtmlSnippet( $this->
msg(
'movepagetalktext' )->parseAsBlock() ),
466 'helpInline' =>
true,
468 'id' =>
'wpMovetalk-field',
473 if ( $this->permManager->userHasRight( $user,
'suppressredirect' ) ) {
474 if ( $handlerSupportsRedirects ) {
475 $isChecked = $this->leaveRedirect;
481 $fields[] =
new OOUI\FieldLayout(
482 new OOUI\CheckboxInputWidget( [
483 'name' =>
'wpLeaveRedirect',
484 'id' =>
'wpLeaveRedirect',
486 'selected' => $isChecked,
487 'disabled' => $isDisabled,
490 'label' => $this->
msg(
'move-leave-redirect' )->text(),
496 if ( $hasRedirects ) {
497 $fields[] =
new OOUI\FieldLayout(
498 new OOUI\CheckboxInputWidget( [
499 'name' =>
'wpFixRedirects',
500 'id' =>
'wpFixRedirects',
502 'selected' => $this->fixRedirects,
505 'label' => $this->
msg(
'fix-double-redirects' )->text(),
511 if ( $canMoveSubpage ) {
512 $maximumMovedPages = $this->
getConfig()->get(
'MaximumMovedPages' );
513 $fields[] =
new OOUI\FieldLayout(
514 new OOUI\CheckboxInputWidget( [
515 'name' =>
'wpMovesubpages',
516 'id' =>
'wpMovesubpages',
518 'selected' => $this->moveSubpages,
521 'label' =>
new OOUI\HtmlSnippet(
523 ( $this->oldTitle->hasSubpages()
525 :
'move-talk-subpages' )
526 )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
533 # Don't allow watching if user is not logged in
534 if ( $user->isRegistered() ) {
535 $watchChecked = ( $this->watch || $this->userOptionsLookup->getBoolOption( $user,
'watchmoves' )
536 || $this->watchlistManager->isWatched( $user, $this->oldTitle ) );
537 $fields[] =
new OOUI\FieldLayout(
538 new OOUI\CheckboxInputWidget( [
540 'id' =>
'watch', # ew
542 'selected' => $watchChecked,
545 'label' => $this->
msg(
'move-watch' )->text(),
553 $hiddenFields .= Html::hidden(
'wpMoveOverSharedFile',
'1' );
557 $fields[] =
new OOUI\FieldLayout(
558 new OOUI\CheckboxInputWidget( [
559 'name' =>
'wpDeleteAndMove',
560 'id' =>
'wpDeleteAndMove',
564 'label' => $this->
msg(
'delete_and_move_confirm' )->text(),
570 $fields[] =
new OOUI\FieldLayout(
571 new OOUI\ButtonInputWidget( [
573 'value' => $this->
msg(
'movepagebtn' )->text(),
574 'label' => $this->
msg(
'movepagebtn' )->text(),
575 'flags' => [
'primary',
'progressive' ],
583 $fieldset =
new OOUI\FieldsetLayout( [
584 'label' => $this->
msg(
'move-page-legend' )->text(),
585 'id' =>
'mw-movepage-table',
589 $form =
new OOUI\FormLayout( [
591 'action' => $this->
getPageTitle()->getLocalURL(
'action=submit' ),
594 $form->appendContent(
596 new OOUI\HtmlSnippet(
598 Html::hidden(
'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
599 Html::hidden(
'wpEditToken', $user->getEditToken() )
604 new OOUI\PanelLayout( [
605 'classes' => [
'movepage-wrapper' ],
620 if ( $user->pingLimiter(
'move' ) ) {
624 $ot = $this->oldTitle;
625 $nt = $this->newTitle;
627 # don't allow moving to pages with # in
628 if ( !$nt || $nt->hasFragment() ) {
629 $this->
showForm( [ [
'badtitletext' ] ] );
634 # Show a warning if the target file exists on a shared repo
635 if ( $nt->getNamespace() ===
NS_FILE
636 && !( $this->moveOverShared && $this->permManager->userHasRight( $user,
'reupload-shared' ) )
637 && !$this->repoGroup->getLocalRepo()->findFile( $nt )
638 && $this->repoGroup->findFile( $nt )
640 $this->
showForm( [ [
'file-exists-sharedrepo' ] ] );
645 # Delete to make way if requested
646 if ( $this->deleteAndMove ) {
647 $redir2 = $nt->isSingleRevRedirect();
649 $permErrors = $this->permManager->getPermissionErrors(
650 $redir2 ?
'delete-redirect' :
'delete',
653 if ( count( $permErrors ) ) {
655 if ( count( $this->permManager->getPermissionErrors(
'delete', $user, $nt ) ) ) {
658 $this->
showForm( $permErrors,
true );
668 $this->
showForm( $permErrors,
true );
673 $page = $this->wikiPageFactory->newFromTitle( $nt );
676 if ( $page->isBatchedDelete( 5 ) ) {
677 $this->
showForm( [ [
'movepage-delete-first' ] ] );
682 $reason = $this->
msg(
'delete_and_move_reason', $ot )->inContentLanguage()->text();
685 if ( $nt->getNamespace() ===
NS_FILE ) {
686 $file = $this->repoGroup->getLocalRepo()->newFile( $nt );
687 $file->load( File::READ_LATEST );
688 if (
$file->exists() ) {
694 $deletionLog = $redir2 ?
'delete_redir2' :
'delete';
695 $deleteStatus = $page->doDeleteArticleReal(
696 $reason, $user,
false,
null, $error,
697 null, [], $deletionLog
699 if ( !$deleteStatus->isGood() ) {
700 $this->
showForm( $deleteStatus->getErrorsArray() );
706 $handler = $this->contentHandlerFactory->getContentHandler( $ot->getContentModel() );
708 if ( !$handler->supportsRedirects() ) {
709 $createRedirect =
false;
710 } elseif ( $this->permManager->userHasRight( $user,
'suppressredirect' ) ) {
711 $createRedirect = $this->leaveRedirect;
713 $createRedirect =
true;
716 # Do the actual move.
717 $mp = $this->movePageFactory->newMovePage( $ot, $nt );
719 # check whether the requested actions are permitted / possible
720 $userPermitted = $mp->authorizeMove( $this->
getAuthority(), $this->reason )->isOK();
721 if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
722 $this->moveTalk =
false;
724 if ( $this->moveSubpages ) {
725 $this->moveSubpages = $this->permManager->userCan(
'move-subpages', $user, $ot );
728 $status = $mp->moveIfAllowed( $this->
getAuthority(), $this->reason, $createRedirect );
729 if ( !$status->isOK() ) {
730 $this->
showForm( $status->getErrorsArray(), !$userPermitted );
734 if ( $this->
getConfig()->
get(
'FixDoubleRedirects' ) && $this->fixRedirects ) {
739 $out->setPageTitle( $this->
msg(
'pagemovedsub' ) );
745 [
'id' =>
'movepage-oldlink' ],
746 [
'redirect' =>
'no' ]
751 [
'id' =>
'movepage-newlink' ]
753 $oldText = $ot->getPrefixedText();
754 $newText = $nt->getPrefixedText();
756 if ( $ot->exists() ) {
762 $msgName =
'movepage-moved-redirect';
764 $msgName =
'movepage-moved-noredirect';
767 $out->addHTML( $this->
msg(
'movepage-moved' )->rawParams( $oldLink,
768 $newLink )->params( $oldText, $newText )->parseAsBlock() );
769 $out->addWikiMsg( $msgName );
771 $this->
getHookRunner()->onSpecialMovepageAfterMove( $this, $ot, $nt );
788 $dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
789 if ( $this->moveSubpages && (
790 $this->nsInfo->hasSubpages( $nt->getNamespace() ) || (
792 && $this->nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
796 'page_title' .
$dbr->buildLike( $ot->getDBkey() .
'/',
$dbr->anyString() )
797 .
' OR page_title = ' .
$dbr->addQuotes( $ot->getDBkey() )
799 $conds[
'page_namespace'] = [];
800 if ( $this->nsInfo->hasSubpages( $nt->getNamespace() ) ) {
801 $conds[
'page_namespace'][] = $ot->getNamespace();
803 if ( $this->moveTalk &&
804 $this->nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
806 $conds[
'page_namespace'][] = $ot->getTalkPage()->getNamespace();
808 } elseif ( $this->moveTalk ) {
810 'page_namespace' => $ot->getTalkPage()->getNamespace(),
811 'page_title' => $ot->getDBkey()
819 if ( $conds !==
null ) {
821 $dbr->select(
'page',
822 [
'page_id',
'page_namespace',
'page_title' ],
831 foreach ( $extraPages as $oldSubpage ) {
832 if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
833 # Already did this one.
837 $newPageName = preg_replace(
838 '#^' . preg_quote( $ot->getDBkey(),
'#' ) .
'#',
840 $oldSubpage->getDBkey()
843 if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
845 $newNs = $nt->getNamespace();
846 } elseif ( $oldSubpage->isTalkPage() ) {
847 $newNs = $nt->getTalkPage()->getNamespace();
849 $newNs = $nt->getSubjectPage()->getNamespace();
852 # T16385: we need makeTitleSafe because the new page names may
853 # be longer than 255 characters.
854 $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
855 if ( !$newSubpage ) {
857 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )->rawParams( $oldLink )
858 ->params( Title::makeName( $newNs, $newPageName ) )->escaped();
862 $mp = $this->movePageFactory->newMovePage( $oldSubpage, $newSubpage );
863 # This was copy-pasted from Renameuser, bleh.
864 if ( $newSubpage->exists() && !$mp->isValidMove()->isOK() ) {
866 $extraOutput[] = $this->
msg(
'movepage-page-exists' )->rawParams( $link )->escaped();
868 $status = $mp->moveIfAllowed( $this->
getAuthority(), $this->reason, $createRedirect );
870 if ( $status->isOK() ) {
871 if ( $this->fixRedirects ) {
878 [
'redirect' =>
'no' ]
882 $extraOutput[] = $this->
msg(
'movepage-page-moved' )
883 ->rawParams( $oldLink, $newLink )->escaped();
886 $maximumMovedPages = $this->
getConfig()->get(
'MaximumMovedPages' );
887 if ( $count >= $maximumMovedPages ) {
888 $extraOutput[] = $this->
msg(
'movepage-max-pages' )
889 ->numParams( $maximumMovedPages )->escaped();
895 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )
896 ->rawParams( $oldLink, $newLink )->escaped();
901 if ( $extraOutput !== [] ) {
902 $out->addHTML(
"<ul>\n<li>" . implode(
"</li>\n<li>", $extraOutput ) .
"</li>\n</ul>" );
905 # Deal with watches (we don't watch subpages)
906 $this->watchlistManager->setWatch( $this->watch, $this->
getAuthority(), $ot );
907 $this->watchlistManager->setWatch( $this->watch, $this->
getAuthority(), $nt );