85 $target = $par ?? $request->getVal(
'target' );
89 $oldTitleText = $request->getVal(
'wpOldTitle', $target );
90 $this->oldTitle = Title::newFromText( $oldTitleText );
92 if ( !$this->oldTitle ) {
96 $this->
getOutput()->addBacklinkSubtitle( $this->oldTitle );
98 if ( !$this->oldTitle->exists() ) {
102 $newTitleTextMain = $request->getText(
'wpNewTitleMain' );
103 $newTitleTextNs = $request->getInt(
'wpNewTitleNs', $this->oldTitle->getNamespace() );
106 $newTitleText_bc = $request->getText(
'wpNewTitle' );
107 $this->newTitle = strlen( $newTitleText_bc ) > 0
108 ? Title::newFromText( $newTitleText_bc )
109 : Title::makeTitleSafe( $newTitleTextNs, $newTitleTextMain );
114 $permErrors = $this->permManager->getPermissionErrors(
'move', $user, $this->oldTitle );
115 if ( count( $permErrors ) ) {
117 DeferredUpdates::addCallableUpdate(
function () use ( $user ) {
118 $user->spreadAnyEditBlock();
123 $def = !$request->wasPosted();
125 $this->reason = $request->getText(
'wpReason' );
126 $this->moveTalk = $request->getBool(
'wpMovetalk', $def );
127 $this->fixRedirects = $request->getBool(
'wpFixRedirects', $def );
128 $this->leaveRedirect = $request->getBool(
'wpLeaveRedirect', $def );
130 $this->moveSubpages = $request->getBool(
'wpMovesubpages', $def );
131 $this->deleteAndMove = $request->getBool(
'wpDeleteAndMove' );
132 $this->moveOverShared = $request->getBool(
'wpMoveOverSharedFile' );
133 $this->watch = $request->getCheck(
'wpWatch' ) && $user->isLoggedIn();
135 if ( $request->getVal(
'action' ) ==
'submit' && $request->wasPosted()
136 && $user->matchEditToken( $request->getVal(
'wpEditToken' ) )
152 protected function showForm( $err, $isPermError =
false ) {
153 $this->
getSkin()->setRelevantTitle( $this->oldTitle );
156 $out->setPageTitle( $this->
msg(
'move-page', $this->oldTitle->getPrefixedText() ) );
157 $out->addModuleStyles(
'mediawiki.special' );
158 $out->addModules(
'mediawiki.misc-authed-ooui' );
161 $handlerSupportsRedirects = MediaWikiServices::getInstance()
162 ->getContentHandlerFactory()
163 ->getContentHandler( $this->oldTitle->getContentModel() )
164 ->supportsRedirects();
166 if ( $this->
getConfig()->
get(
'FixDoubleRedirects' ) ) {
167 $out->addWikiMsg(
'movepagetext' );
169 $out->addWikiMsg( $handlerSupportsRedirects ?
170 'movepagetext-noredirectfixer' :
171 'movepagetext-noredirectsupport' );
174 if ( $this->oldTitle->getNamespace() ==
NS_USER && !$this->oldTitle->isSubpage() ) {
176 "<div class=\"warningbox mw-moveuserpage-warning\">\n$1\n</div>",
177 'moveuserpage-warning'
179 } elseif ( $this->oldTitle->getNamespace() ==
NS_CATEGORY ) {
181 "<div class=\"warningbox mw-movecategorypage-warning\">\n$1\n</div>",
182 'movecategorypage-warning'
194 # Show the current title as a default
195 # when the form is first opened.
197 } elseif ( !count( $err ) ) {
198 # If a title was supplied, probably from the move log revert
199 # link, check for validity. We can then show some diagnostic
200 # information and save a click.
202 $status = $mp->isValidMove();
203 $status->merge( $mp->checkPermissions( $user,
null ) );
204 if ( $status->getErrors() ) {
205 $err = $status->getErrorsArray();
209 if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] ==
'articleexists'
210 && $this->permManager->quickUserCan(
'delete', $user,
$newTitle )
213 "<div class='warningbox'>\n$1\n</div>\n",
220 if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] ==
'file-exists-sharedrepo'
221 && $this->permManager->userHasRight( $user,
'reupload-shared' )
224 "<div class='warningbox'>\n$1\n</div>\n",
226 'move-over-sharedrepo',
234 $oldTalk = $this->oldTitle->getTalkPage();
235 $oldTitleSubpages = $this->oldTitle->hasSubpages();
236 $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
238 $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
239 !count( $this->permManager->getPermissionErrors(
245 # We also want to be able to move assoc. subpage talk-pages even if base page
246 # has no associated talk page, so || with $oldTitleTalkSubpages.
247 $considerTalk = !$this->oldTitle->isTalkPage() &&
249 || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
252 if ( $this->
getConfig()->
get(
'FixDoubleRedirects' ) ) {
253 $hasRedirects =
$dbr->selectField(
'redirect',
'1',
255 'rd_namespace' => $this->oldTitle->getNamespace(),
256 'rd_title' => $this->oldTitle->getDBkey(),
259 $hasRedirects =
false;
262 if ( count( $err ) ) {
263 '@phan-var array[] $err';
264 if ( $isPermError ) {
265 $action_desc = $this->
msg(
'action-move' )->plain();
266 $errMsgHtml = $this->
msg(
'permissionserrorstext-withaction',
267 count( $err ), $action_desc )->parseAsBlock();
269 $errMsgHtml = $this->
msg(
'cannotmove', count( $err ) )->parseAsBlock();
272 if ( count( $err ) == 1 ) {
274 $errMsgName = array_shift( $errMsg );
276 if ( $errMsgName ==
'hookaborted' ) {
277 $errMsgHtml .=
"<p>{$errMsg[0]}</p>\n";
279 $errMsgHtml .= $this->
msg( $errMsgName, $errMsg )->parseAsBlock();
284 foreach ( $err as $errMsg ) {
285 if ( $errMsg[0] ==
'hookaborted' ) {
286 $errStr[] = $errMsg[1];
288 $errMsgName = array_shift( $errMsg );
289 $errStr[] = $this->
msg( $errMsgName, $errMsg )->parse();
293 $errMsgHtml .=
'<ul><li>' . implode(
"</li>\n<li>", $errStr ) .
"</li></ul>\n";
295 $out->addHTML( Html::errorBox( $errMsgHtml ) );
298 if ( $this->oldTitle->isProtected(
'move' ) ) {
299 # Is the title semi-protected?
300 if ( $this->oldTitle->isSemiProtected(
'move' ) ) {
301 $noticeMsg =
'semiprotectedpagemovewarning';
303 # Then it must be protected based on static groups (regular)
304 $noticeMsg =
'protectedpagemovewarning';
306 $out->addHTML(
"<div class='warningbox mw-warning-with-logexcerpt'>\n" );
307 $out->addWikiMsg( $noticeMsg );
308 LogEventsList::showLogExtract(
315 $out->addHTML(
"</div>\n" );
321 $immovableNamespaces = [];
322 $namespaceInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
323 foreach ( array_keys( $this->
getLanguage()->getNamespaces() ) as $nsId ) {
324 if ( !$namespaceInfo->isMovable( $nsId ) ) {
325 $immovableNamespaces[] = $nsId;
332 $fields[] =
new OOUI\FieldLayout(
333 new MediaWiki\Widget\ComplexTitleInputWidget( [
334 'id' =>
'wpNewTitle',
336 'id' =>
'wpNewTitleNs',
337 'name' =>
'wpNewTitleNs',
339 'exclude' => $immovableNamespaces,
342 'id' =>
'wpNewTitleMain',
343 'name' =>
'wpNewTitleMain',
346 'suggestions' =>
false,
351 'label' => $this->msg(
'newtitle' )->text(),
359 $fields[] =
new OOUI\FieldLayout(
360 new OOUI\TextInputWidget( [
361 'name' =>
'wpReason',
363 'maxLength' => CommentStore::COMMENT_CHARACTER_LIMIT,
365 'value' => $this->reason,
368 'label' => $this->
msg(
'movereason' )->text(),
373 if ( $considerTalk ) {
374 $fields[] =
new OOUI\FieldLayout(
375 new OOUI\CheckboxInputWidget( [
376 'name' =>
'wpMovetalk',
377 'id' =>
'wpMovetalk',
379 'selected' => $this->moveTalk,
382 'label' => $this->
msg(
'movetalk' )->text(),
383 'help' =>
new OOUI\HtmlSnippet( $this->
msg(
'movepagetalktext' )->parseAsBlock() ),
384 'helpInline' =>
true,
386 'id' =>
'wpMovetalk-field',
391 if ( $this->permManager->userHasRight( $user,
'suppressredirect' )
393 if ( $handlerSupportsRedirects ) {
394 $isChecked = $this->leaveRedirect;
400 $fields[] =
new OOUI\FieldLayout(
401 new OOUI\CheckboxInputWidget( [
402 'name' =>
'wpLeaveRedirect',
403 'id' =>
'wpLeaveRedirect',
405 'selected' => $isChecked,
406 'disabled' => $isDisabled,
409 'label' => $this->
msg(
'move-leave-redirect' )->text(),
415 if ( $hasRedirects ) {
416 $fields[] =
new OOUI\FieldLayout(
417 new OOUI\CheckboxInputWidget( [
418 'name' =>
'wpFixRedirects',
419 'id' =>
'wpFixRedirects',
421 'selected' => $this->fixRedirects,
424 'label' => $this->
msg(
'fix-double-redirects' )->text(),
430 if ( $canMoveSubpage ) {
431 $maximumMovedPages = $this->
getConfig()->get(
'MaximumMovedPages' );
432 $fields[] =
new OOUI\FieldLayout(
433 new OOUI\CheckboxInputWidget( [
434 'name' =>
'wpMovesubpages',
435 'id' =>
'wpMovesubpages',
437 'selected' => $this->moveSubpages,
440 'label' =>
new OOUI\HtmlSnippet(
442 ( $this->oldTitle->hasSubpages()
444 :
'move-talk-subpages' )
445 )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
452 # Don't allow watching if user is not logged in
453 if ( $user->isLoggedIn() ) {
454 $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption(
'watchmoves' )
455 || $user->isWatched( $this->oldTitle ) );
456 $fields[] =
new OOUI\FieldLayout(
457 new OOUI\CheckboxInputWidget( [
459 'id' =>
'watch', # ew
461 'selected' => $watchChecked,
464 'label' => $this->
msg(
'move-watch' )->text(),
472 $hiddenFields .= Html::hidden(
'wpMoveOverSharedFile',
'1' );
476 $fields[] =
new OOUI\FieldLayout(
477 new OOUI\CheckboxInputWidget( [
478 'name' =>
'wpDeleteAndMove',
479 'id' =>
'wpDeleteAndMove',
483 'label' => $this->
msg(
'delete_and_move_confirm' )->text(),
489 $fields[] =
new OOUI\FieldLayout(
490 new OOUI\ButtonInputWidget( [
492 'value' => $this->
msg(
'movepagebtn' )->text(),
493 'label' => $this->
msg(
'movepagebtn' )->text(),
494 'flags' => [
'primary',
'progressive' ],
502 $fieldset =
new OOUI\FieldsetLayout( [
503 'label' => $this->
msg(
'move-page-legend' )->text(),
504 'id' =>
'mw-movepage-table',
508 $form =
new OOUI\FormLayout( [
510 'action' => $this->
getPageTitle()->getLocalURL(
'action=submit' ),
513 $form->appendContent(
515 new OOUI\HtmlSnippet(
517 Html::hidden(
'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
518 Html::hidden(
'wpEditToken', $user->getEditToken() )
523 new OOUI\PanelLayout( [
524 'classes' => [
'movepage-wrapper' ],
539 if ( $user->pingLimiter(
'move' ) ) {
543 $ot = $this->oldTitle;
544 $nt = $this->newTitle;
546 # don't allow moving to pages with # in
547 if ( !$nt || $nt->hasFragment() ) {
548 $this->
showForm( [ [
'badtitletext' ] ] );
553 $services = MediaWikiServices::getInstance();
555 # Show a warning if the target file exists on a shared repo
556 $repoGroup = $services->getRepoGroup();
557 if ( $nt->getNamespace() ==
NS_FILE
558 && !( $this->moveOverShared && $this->permManager->userHasRight( $user,
'reupload-shared' ) )
559 && !$repoGroup->getLocalRepo()->findFile( $nt )
560 && $repoGroup->findFile( $nt )
562 $this->
showForm( [ [
'file-exists-sharedrepo' ] ] );
567 # Delete to make way if requested
568 if ( $this->deleteAndMove ) {
569 $permErrors = $this->permManager->getPermissionErrors(
'delete', $user, $nt );
570 if ( count( $permErrors ) ) {
571 # Only show the first error
572 $this->
showForm( $permErrors,
true );
577 $page = WikiPage::factory( $nt );
580 if ( $page->isBatchedDelete( 5 ) ) {
581 $this->
showForm( [ [
'movepage-delete-first' ] ] );
586 $reason = $this->
msg(
'delete_and_move_reason', $ot )->inContentLanguage()->text();
589 if ( $nt->getNamespace() ==
NS_FILE ) {
590 $file = $repoGroup->getLocalRepo()->newFile( $nt );
591 $file->load( File::READ_LATEST );
592 if (
$file->exists() ) {
597 $deleteStatus = $page->doDeleteArticleReal(
602 if ( !$deleteStatus->isGood() ) {
603 $this->
showForm( $deleteStatus->getErrorsArray() );
609 $handler = MediaWikiServices::getInstance()
610 ->getContentHandlerFactory()
611 ->getContentHandler( $ot->getContentModel() );
613 if ( !$handler->supportsRedirects() ) {
614 $createRedirect =
false;
615 } elseif ( $this->permManager->userHasRight( $user,
'suppressredirect' ) ) {
616 $createRedirect = $this->leaveRedirect;
618 $createRedirect =
true;
621 # Do the actual move.
624 # check whether the requested actions are permitted / possible
625 $userPermitted = $mp->checkPermissions( $user, $this->reason )->isOK();
626 if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
627 $this->moveTalk =
false;
629 if ( $this->moveSubpages ) {
630 $this->moveSubpages = $this->permManager->userCan(
'move-subpages', $user, $ot );
633 $status = $mp->moveIfAllowed( $user, $this->reason, $createRedirect );
634 if ( !$status->isOK() ) {
635 $this->
showForm( $status->getErrorsArray(), !$userPermitted );
639 if ( $this->
getConfig()->
get(
'FixDoubleRedirects' ) && $this->fixRedirects ) {
644 $out->setPageTitle( $this->
msg(
'pagemovedsub' ) );
650 [
'id' =>
'movepage-oldlink' ],
651 [
'redirect' =>
'no' ]
656 [
'id' =>
'movepage-newlink' ]
658 $oldText = $ot->getPrefixedText();
659 $newText = $nt->getPrefixedText();
661 if ( $ot->exists() ) {
667 $msgName =
'movepage-moved-redirect';
669 $msgName =
'movepage-moved-noredirect';
672 $out->addHTML( $this->
msg(
'movepage-moved' )->rawParams( $oldLink,
673 $newLink )->params( $oldText, $newText )->parseAsBlock() );
674 $out->addWikiMsg( $msgName );
676 $this->
getHookRunner()->onSpecialMovepageAfterMove( $this, $ot, $nt );
693 $nsInfo = $services->getNamespaceInfo();
695 if ( $this->moveSubpages && (
696 $nsInfo->hasSubpages( $nt->getNamespace() ) || (
698 && $nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
702 'page_title' .
$dbr->buildLike( $ot->getDBkey() .
'/',
$dbr->anyString() )
703 .
' OR page_title = ' .
$dbr->addQuotes( $ot->getDBkey() )
705 $conds[
'page_namespace'] = [];
706 if ( $nsInfo->hasSubpages( $nt->getNamespace() ) ) {
707 $conds[
'page_namespace'][] = $ot->getNamespace();
709 if ( $this->moveTalk &&
710 $nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
712 $conds[
'page_namespace'][] = $ot->getTalkPage()->getNamespace();
714 } elseif ( $this->moveTalk ) {
716 'page_namespace' => $ot->getTalkPage()->getNamespace(),
717 'page_title' => $ot->getDBkey()
725 if ( $conds !==
null ) {
726 $extraPages = TitleArray::newFromResult(
727 $dbr->select(
'page',
728 [
'page_id',
'page_namespace',
'page_title' ],
737 foreach ( $extraPages as $oldSubpage ) {
738 if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
739 # Already did this one.
743 $newPageName = preg_replace(
744 '#^' . preg_quote( $ot->getDBkey(),
'#' ) .
'#',
746 $oldSubpage->getDBkey()
749 if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
751 $newNs = $nt->getNamespace();
752 } elseif ( $oldSubpage->isTalkPage() ) {
753 $newNs = $nt->getTalkPage()->getNamespace();
755 $newNs = $nt->getSubjectPage()->getNamespace();
758 # T16385: we need makeTitleSafe because the new page names may
759 # be longer than 255 characters.
760 $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
761 if ( !$newSubpage ) {
763 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )->rawParams( $oldLink )
764 ->params( Title::makeName( $newNs, $newPageName ) )->escaped();
768 $mp =
new MovePage( $oldSubpage, $newSubpage );
769 # This was copy-pasted from Renameuser, bleh.
770 if ( $newSubpage->exists() && !$mp->isValidMove()->isOK() ) {
772 $extraOutput[] = $this->
msg(
'movepage-page-exists' )->rawParams( $link )->escaped();
774 $status = $mp->moveIfAllowed( $user, $this->reason, $createRedirect );
776 if ( $status->isOK() ) {
777 if ( $this->fixRedirects ) {
784 [
'redirect' =>
'no' ]
788 $extraOutput[] = $this->
msg(
'movepage-page-moved' )
789 ->rawParams( $oldLink, $newLink )->escaped();
792 $maximumMovedPages = $this->
getConfig()->get(
'MaximumMovedPages' );
793 if ( $count >= $maximumMovedPages ) {
794 $extraOutput[] = $this->
msg(
'movepage-max-pages' )
795 ->numParams( $maximumMovedPages )->escaped();
801 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )
802 ->rawParams( $oldLink, $newLink )->escaped();
807 if ( $extraOutput !== [] ) {
808 $out->addHTML(
"<ul>\n<li>" . implode(
"</li>\n<li>", $extraOutput ) .
"</li>\n</ul>" );
811 # Deal with watches (we don't watch subpages)