80 $target = $par ?? $request->getVal(
'target' );
84 $oldTitleText = $request->getVal(
'wpOldTitle', $target );
85 $this->oldTitle = Title::newFromText( $oldTitleText );
87 if ( !$this->oldTitle ) {
91 if ( !$this->oldTitle->exists() ) {
95 $newTitleTextMain = $request->getText(
'wpNewTitleMain' );
96 $newTitleTextNs = $request->getInt(
'wpNewTitleNs', $this->oldTitle->getNamespace() );
99 $newTitleText_bc = $request->getText(
'wpNewTitle' );
100 $this->newTitle = strlen( $newTitleText_bc ) > 0
101 ? Title::newFromText( $newTitleText_bc )
102 : Title::makeTitleSafe( $newTitleTextNs, $newTitleTextMain );
107 $permErrors = $this->oldTitle->getUserPermissionsErrors(
'move', $user );
108 if ( count( $permErrors ) ) {
110 DeferredUpdates::addCallableUpdate(
function () use ( $user ) {
111 $user->spreadAnyEditBlock();
116 $def = !$request->wasPosted();
118 $this->reason = $request->getText(
'wpReason' );
119 $this->moveTalk = $request->getBool(
'wpMovetalk', $def );
120 $this->fixRedirects = $request->getBool(
'wpFixRedirects', $def );
121 $this->leaveRedirect = $request->getBool(
'wpLeaveRedirect', $def );
122 $this->moveSubpages = $request->getBool(
'wpMovesubpages' );
123 $this->deleteAndMove = $request->getBool(
'wpDeleteAndMove' );
124 $this->moveOverShared = $request->getBool(
'wpMoveOverSharedFile' );
125 $this->watch = $request->getCheck(
'wpWatch' ) && $user->isLoggedIn();
127 if ( $request->getVal(
'action' ) ==
'submit' && $request->wasPosted()
128 && $user->matchEditToken( $request->getVal(
'wpEditToken' ) )
145 $this->
getSkin()->setRelevantTitle( $this->oldTitle );
148 $out->setPageTitle( $this->
msg(
'move-page', $this->oldTitle->getPrefixedText() ) );
149 $out->addModuleStyles(
'mediawiki.special' );
150 $out->addModules(
'mediawiki.misc-authed-ooui' );
153 $handlerSupportsRedirects = ContentHandler::getForTitle( $this->oldTitle )
154 ->supportsRedirects();
156 if ( $this->
getConfig()->
get(
'FixDoubleRedirects' ) ) {
157 $out->addWikiMsg(
'movepagetext' );
159 $out->addWikiMsg( $handlerSupportsRedirects ?
160 'movepagetext-noredirectfixer' :
161 'movepagetext-noredirectsupport' );
164 if ( $this->oldTitle->getNamespace() ==
NS_USER && !$this->oldTitle->isSubpage() ) {
166 "<div class=\"warningbox mw-moveuserpage-warning\">\n$1\n</div>",
167 'moveuserpage-warning'
169 } elseif ( $this->oldTitle->getNamespace() ==
NS_CATEGORY ) {
171 "<div class=\"warningbox mw-movecategorypage-warning\">\n$1\n</div>",
172 'movecategorypage-warning'
184 # Show the current title as a default
185 # when the form is first opened.
187 } elseif ( !count( $err ) ) {
188 # If a title was supplied, probably from the move log revert
189 # link, check for validity. We can then show some diagnostic
190 # information and save a click.
192 $status = $mp->isValidMove();
193 $status->merge( $mp->checkPermissions( $user,
null ) );
194 if ( $status->getErrors() ) {
195 $err = $status->getErrorsArray();
199 if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] ==
'articleexists'
201 ->quickUserCan(
'delete', $user,
$newTitle )
204 "<div class='warningbox'>\n$1\n</div>\n",
211 if ( count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] ==
'file-exists-sharedrepo'
212 && MediaWikiServices::getInstance()
214 ->userHasRight( $user,
'reupload-shared' )
217 "<div class='warningbox'>\n$1\n</div>\n",
219 'move-over-sharedrepo',
227 $oldTalk = $this->oldTitle->getTalkPage();
228 $oldTitleSubpages = $this->oldTitle->hasSubpages();
229 $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
231 $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
232 !count( $this->oldTitle->getUserPermissionsErrors(
'move-subpages', $user ) );
234 # We also want to be able to move assoc. subpage talk-pages even if base page
235 # has no associated talk page, so || with $oldTitleTalkSubpages.
236 $considerTalk = !$this->oldTitle->isTalkPage() &&
238 || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
241 if ( $this->
getConfig()->
get(
'FixDoubleRedirects' ) ) {
242 $hasRedirects =
$dbr->selectField(
'redirect',
'1',
244 'rd_namespace' => $this->oldTitle->getNamespace(),
245 'rd_title' => $this->oldTitle->getDBkey(),
248 $hasRedirects =
false;
251 if ( count( $err ) ) {
252 if ( $isPermError ) {
253 $action_desc = $this->
msg(
'action-move' )->plain();
254 $errMsgHtml = $this->
msg(
'permissionserrorstext-withaction',
255 count( $err ), $action_desc )->parseAsBlock();
257 $errMsgHtml = $this->
msg(
'cannotmove', count( $err ) )->parseAsBlock();
260 if ( count( $err ) == 1 ) {
262 $errMsgName = array_shift( $errMsg );
264 if ( $errMsgName ==
'hookaborted' ) {
265 $errMsgHtml .=
"<p>{$errMsg[0]}</p>\n";
267 $errMsgHtml .= $this->
msg( $errMsgName, $errMsg )->parseAsBlock();
272 foreach ( $err as $errMsg ) {
273 if ( $errMsg[0] ==
'hookaborted' ) {
274 $errStr[] = $errMsg[1];
276 $errMsgName = array_shift( $errMsg );
277 $errStr[] = $this->
msg( $errMsgName, $errMsg )->parse();
281 $errMsgHtml .=
'<ul><li>' . implode(
"</li>\n<li>", $errStr ) .
"</li></ul>\n";
283 $out->addHTML( Html::errorBox( $errMsgHtml ) );
286 if ( $this->oldTitle->isProtected(
'move' ) ) {
287 # Is the title semi-protected?
288 if ( $this->oldTitle->isSemiProtected(
'move' ) ) {
289 $noticeMsg =
'semiprotectedpagemovewarning';
291 # Then it must be protected based on static groups (regular)
292 $noticeMsg =
'protectedpagemovewarning';
294 $out->addHTML(
"<div class='mw-warning-with-logexcerpt'>\n" );
295 $out->addWikiMsg( $noticeMsg );
303 $out->addHTML(
"</div>\n" );
309 $immovableNamespaces = [];
310 $namespaceInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
311 foreach ( array_keys( $this->
getLanguage()->getNamespaces() ) as $nsId ) {
312 if ( !$namespaceInfo->isMovable( $nsId ) ) {
313 $immovableNamespaces[] = $nsId;
320 $fields[] =
new OOUI\FieldLayout(
321 new MediaWiki\Widget\ComplexTitleInputWidget( [
322 'id' =>
'wpNewTitle',
324 'id' =>
'wpNewTitleNs',
325 'name' =>
'wpNewTitleNs',
327 'exclude' => $immovableNamespaces,
330 'id' =>
'wpNewTitleMain',
331 'name' =>
'wpNewTitleMain',
334 'suggestions' =>
false,
339 'label' => $this->msg(
'newtitle' )->text(),
347 $fields[] =
new OOUI\FieldLayout(
348 new OOUI\TextInputWidget( [
349 'name' =>
'wpReason',
351 'maxLength' => CommentStore::COMMENT_CHARACTER_LIMIT,
353 'value' => $this->reason,
356 'label' => $this->
msg(
'movereason' )->text(),
361 if ( $considerTalk ) {
362 $fields[] =
new OOUI\FieldLayout(
363 new OOUI\CheckboxInputWidget( [
364 'name' =>
'wpMovetalk',
365 'id' =>
'wpMovetalk',
367 'selected' => $this->moveTalk,
370 'label' => $this->
msg(
'movetalk' )->text(),
371 'help' =>
new OOUI\HtmlSnippet( $this->
msg(
'movepagetalktext' )->parseAsBlock() ),
372 'helpInline' =>
true,
374 'id' =>
'wpMovetalk-field',
379 if ( MediaWikiServices::getInstance()
381 ->userHasRight( $user,
'suppressredirect' )
383 if ( $handlerSupportsRedirects ) {
390 $fields[] =
new OOUI\FieldLayout(
391 new OOUI\CheckboxInputWidget( [
392 'name' =>
'wpLeaveRedirect',
393 'id' =>
'wpLeaveRedirect',
395 'selected' => $isChecked,
396 'disabled' => $isDisabled,
399 'label' => $this->
msg(
'move-leave-redirect' )->text(),
405 if ( $hasRedirects ) {
406 $fields[] =
new OOUI\FieldLayout(
407 new OOUI\CheckboxInputWidget( [
408 'name' =>
'wpFixRedirects',
409 'id' =>
'wpFixRedirects',
411 'selected' => $this->fixRedirects,
414 'label' => $this->
msg(
'fix-double-redirects' )->text(),
420 if ( $canMoveSubpage ) {
421 $maximumMovedPages = $this->
getConfig()->get(
'MaximumMovedPages' );
422 $fields[] =
new OOUI\FieldLayout(
423 new OOUI\CheckboxInputWidget( [
424 'name' =>
'wpMovesubpages',
425 'id' =>
'wpMovesubpages',
430 'label' =>
new OOUI\HtmlSnippet(
432 ( $this->oldTitle->hasSubpages()
434 :
'move-talk-subpages' )
435 )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
442 # Don't allow watching if user is not logged in
443 if ( $user->isLoggedIn() ) {
444 $watchChecked = $user->isLoggedIn() && ( $this->watch || $user->getBoolOption(
'watchmoves' )
445 || $user->isWatched( $this->oldTitle ) );
446 $fields[] =
new OOUI\FieldLayout(
447 new OOUI\CheckboxInputWidget( [
449 'id' =>
'watch', # ew
451 'selected' => $watchChecked,
454 'label' => $this->
msg(
'move-watch' )->text(),
462 $hiddenFields .= Html::hidden(
'wpMoveOverSharedFile',
'1' );
466 $fields[] =
new OOUI\FieldLayout(
467 new OOUI\CheckboxInputWidget( [
468 'name' =>
'wpDeleteAndMove',
469 'id' =>
'wpDeleteAndMove',
473 'label' => $this->
msg(
'delete_and_move_confirm' )->text(),
479 $fields[] =
new OOUI\FieldLayout(
480 new OOUI\ButtonInputWidget( [
482 'value' => $this->
msg(
'movepagebtn' )->text(),
483 'label' => $this->
msg(
'movepagebtn' )->text(),
484 'flags' => [
'primary',
'progressive' ],
492 $fieldset =
new OOUI\FieldsetLayout( [
493 'label' => $this->
msg(
'move-page-legend' )->text(),
494 'id' =>
'mw-movepage-table',
498 $form =
new OOUI\FormLayout( [
500 'action' => $this->
getPageTitle()->getLocalURL(
'action=submit' ),
503 $form->appendContent(
505 new OOUI\HtmlSnippet(
507 Html::hidden(
'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
508 Html::hidden(
'wpEditToken', $user->getEditToken() )
513 new OOUI\PanelLayout( [
514 'classes' => [
'movepage-wrapper' ],
528 $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
530 if ( $user->pingLimiter(
'move' ) ) {
537 # don't allow moving to pages with # in
538 if ( !$nt || $nt->hasFragment() ) {
539 $this->
showForm( [ [
'badtitletext' ] ] );
544 $services = MediaWikiServices::getInstance();
546 # Show a warning if the target file exists on a shared repo
547 $repoGroup = $services->getRepoGroup();
548 if ( $nt->getNamespace() ==
NS_FILE
549 && !( $this->moveOverShared && $permissionManager->userHasRight( $user,
'reupload-shared' ) )
550 && !$repoGroup->getLocalRepo()->findFile( $nt )
551 && $repoGroup->findFile( $nt )
553 $this->
showForm( [ [
'file-exists-sharedrepo' ] ] );
558 # Delete to make way if requested
559 if ( $this->deleteAndMove ) {
560 $permErrors = $permissionManager->getPermissionErrors(
'delete', $user, $nt );
561 if ( count( $permErrors ) ) {
562 # Only show the first error
563 $this->
showForm( $permErrors,
true );
568 $page = WikiPage::factory( $nt );
571 if ( $page->isBatchedDelete( 5 ) ) {
572 $this->
showForm( [ [
'movepage-delete-first' ] ] );
577 $reason = $this->
msg(
'delete_and_move_reason', $ot )->inContentLanguage()->text();
580 if ( $nt->getNamespace() ==
NS_FILE ) {
581 $file = $repoGroup->getLocalRepo()->newFile( $nt );
582 $file->load( File::READ_LATEST );
583 if (
$file->exists() ) {
589 $deleteStatus = $page->doDeleteArticleReal(
$reason,
false, 0,
true, $error, $user );
590 if ( !$deleteStatus->isGood() ) {
591 $this->
showForm( $deleteStatus->getErrorsArray() );
597 $handler = ContentHandler::getForTitle( $ot );
599 if ( !$handler->supportsRedirects() ) {
600 $createRedirect =
false;
601 } elseif ( $permissionManager->userHasRight( $user,
'suppressredirect' ) ) {
604 $createRedirect =
true;
607 # Do the actual move.
610 # check whether the requested actions are permitted / possible
611 $userPermitted = $mp->checkPermissions( $user, $this->reason )->isOK();
612 if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
613 $this->moveTalk =
false;
615 if ( $this->moveSubpages ) {
616 $this->moveSubpages = $permissionManager->userCan(
'move-subpages', $user, $ot );
619 $status = $mp->moveIfAllowed( $user, $this->reason, $createRedirect );
620 if ( !$status->isOK() ) {
621 $this->
showForm( $status->getErrorsArray(), !$userPermitted );
625 if ( $this->
getConfig()->
get(
'FixDoubleRedirects' ) && $this->fixRedirects ) {
630 $out->setPageTitle( $this->
msg(
'pagemovedsub' ) );
636 [
'id' =>
'movepage-oldlink' ],
637 [
'redirect' =>
'no' ]
642 [
'id' =>
'movepage-newlink' ]
644 $oldText = $ot->getPrefixedText();
645 $newText = $nt->getPrefixedText();
647 if ( $ot->exists() ) {
653 $msgName =
'movepage-moved-redirect';
655 $msgName =
'movepage-moved-noredirect';
658 $out->addHTML( $this->
msg(
'movepage-moved' )->rawParams( $oldLink,
659 $newLink )->params( $oldText, $newText )->parseAsBlock() );
660 $out->addWikiMsg( $msgName );
664 Hooks::run(
'SpecialMovepageAfterMove', [ &$movePage, &$ot, &$nt ] );
681 $nsInfo = $services->getNamespaceInfo();
683 if ( $this->moveSubpages && (
684 $nsInfo->hasSubpages( $nt->getNamespace() ) || (
686 && $nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
690 'page_title' .
$dbr->buildLike( $ot->getDBkey() .
'/',
$dbr->anyString() )
691 .
' OR page_title = ' .
$dbr->addQuotes( $ot->getDBkey() )
693 $conds[
'page_namespace'] = [];
694 if ( $nsInfo->hasSubpages( $nt->getNamespace() ) ) {
695 $conds[
'page_namespace'][] = $ot->getNamespace();
697 if ( $this->moveTalk &&
698 $nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
700 $conds[
'page_namespace'][] = $ot->getTalkPage()->getNamespace();
702 } elseif ( $this->moveTalk ) {
704 'page_namespace' => $ot->getTalkPage()->getNamespace(),
705 'page_title' => $ot->getDBkey()
713 if ( !is_null( $conds ) ) {
715 $dbr->select(
'page',
716 [
'page_id',
'page_namespace',
'page_title' ],
725 foreach ( $extraPages as $oldSubpage ) {
726 if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
727 # Already did this one.
731 $newPageName = preg_replace(
732 '#^' . preg_quote( $ot->getDBkey(),
'#' ) .
'#',
733 StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # T23234
734 $oldSubpage->getDBkey()
737 if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
739 $newNs = $nt->getNamespace();
740 } elseif ( $oldSubpage->isTalkPage() ) {
741 $newNs = $nt->getTalkPage()->getNamespace();
743 $newNs = $nt->getSubjectPage()->getNamespace();
746 # T16385: we need makeTitleSafe because the new page names may
747 # be longer than 255 characters.
748 $newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
749 if ( !$newSubpage ) {
751 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )->rawParams( $oldLink )
752 ->params( Title::makeName( $newNs, $newPageName ) )->escaped();
756 $mp =
new MovePage( $oldSubpage, $newSubpage );
757 # This was copy-pasted from Renameuser, bleh.
758 if ( $newSubpage->exists() && !$mp->isValidMove()->isOK() ) {
760 $extraOutput[] = $this->
msg(
'movepage-page-exists' )->rawParams( $link )->escaped();
762 $status = $mp->moveIfAllowed( $user, $this->reason, $createRedirect );
764 if ( $status->isOK() ) {
765 if ( $this->fixRedirects ) {
772 [
'redirect' =>
'no' ]
776 $extraOutput[] = $this->
msg(
'movepage-page-moved' )
777 ->rawParams( $oldLink, $newLink )->escaped();
780 $maximumMovedPages = $this->
getConfig()->get(
'MaximumMovedPages' );
781 if ( $count >= $maximumMovedPages ) {
782 $extraOutput[] = $this->
msg(
'movepage-max-pages' )
783 ->numParams( $maximumMovedPages )->escaped();
789 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )
790 ->rawParams( $oldLink, $newLink )->escaped();
795 if ( $extraOutput !== [] ) {
796 $out->addHTML(
"<ul>\n<li>" . implode(
"</li>\n<li>", $extraOutput ) .
"</li>\n</ul>" );
799 # Deal with watches (we don't watch subpages)