62 parent::__construct(
'Movepage' );
78 $target = $par ??
$request->getVal(
'target' );
82 $oldTitleText =
$request->getVal(
'wpOldTitle', $target );
85 if ( !$this->oldTitle ) {
89 if ( !$this->oldTitle->exists() ) {
93 $newTitleTextMain =
$request->getText(
'wpNewTitleMain' );
94 $newTitleTextNs =
$request->getInt(
'wpNewTitleNs', $this->oldTitle->getNamespace() );
97 $newTitleText_bc =
$request->getText(
'wpNewTitle' );
98 $this->newTitle = strlen( $newTitleText_bc ) > 0
105 $permErrors = $this->oldTitle->getUserPermissionsErrors(
'move',
$user );
106 if (
count( $permErrors ) ) {
109 $user->spreadAnyEditBlock();
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();
126 &&
$user->matchEditToken(
$request->getVal(
'wpEditToken' ) )
143 $this->
getSkin()->setRelevantTitle( $this->oldTitle );
146 $out->setPageTitle( $this->
msg(
'move-page', $this->oldTitle->getPrefixedText() ) );
147 $out->addModuleStyles(
'mediawiki.special' );
148 $out->addModules(
'mediawiki.special.movePage' );
151 $out->addWikiMsg( $this->
getConfig()->
get(
'FixDoubleRedirects' ) ?
153 'movepagetext-noredirectfixer'
156 if ( $this->oldTitle->getNamespace() ==
NS_USER && !$this->oldTitle->isSubpage() ) {
158 "<div class=\"warningbox mw-moveuserpage-warning\">\n$1\n</div>",
159 'moveuserpage-warning'
161 } elseif ( $this->oldTitle->getNamespace() ==
NS_CATEGORY ) {
163 "<div class=\"warningbox mw-movecategorypage-warning\">\n$1\n</div>",
164 'movecategorypage-warning'
174 # Show the current title as a default
175 # when the form is first opened.
177 } elseif ( !
count( $err ) ) {
178 # If a title was supplied, probably from the move log revert
179 # link, check for validity. We can then show some diagnostic
180 # information and save a click.
182 if ( is_array( $newerr ) ) {
189 if (
count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] ==
'articleexists'
193 "<div class='warningbox'>\n$1\n</div>\n",
200 if (
count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] ==
'file-exists-sharedrepo'
201 &&
$user->isAllowed(
'reupload-shared' )
204 "<div class='warningbox'>\n$1\n</div>\n",
206 'move-over-sharedrepo',
214 $oldTalk = $this->oldTitle->getTalkPage();
215 $oldTitleSubpages = $this->oldTitle->hasSubpages();
216 $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
218 $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
219 !
count( $this->oldTitle->getUserPermissionsErrors(
'move-subpages',
$user ) );
221 # We also want to be able to move assoc. subpage talk-pages even if base page
222 # has no associated talk page, so || with $oldTitleTalkSubpages.
223 $considerTalk = !$this->oldTitle->isTalkPage() &&
225 || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
228 if ( $this->
getConfig()->
get(
'FixDoubleRedirects' ) ) {
229 $hasRedirects =
$dbr->selectField(
'redirect',
'1',
231 'rd_namespace' => $this->oldTitle->getNamespace(),
232 'rd_title' => $this->oldTitle->getDBkey(),
235 $hasRedirects =
false;
238 if (
count( $err ) ) {
239 if ( $isPermError ) {
240 $action_desc = $this->
msg(
'action-move' )->plain();
241 $errMsgHtml = $this->
msg(
'permissionserrorstext-withaction',
242 count( $err ), $action_desc )->parseAsBlock();
244 $errMsgHtml = $this->
msg(
'cannotmove',
count( $err ) )->parseAsBlock();
247 if (
count( $err ) == 1 ) {
249 $errMsgName = array_shift( $errMsg );
251 if ( $errMsgName ==
'hookaborted' ) {
252 $errMsgHtml .=
"<p>{$errMsg[0]}</p>\n";
254 $errMsgHtml .= $this->
msg( $errMsgName, $errMsg )->parseAsBlock();
259 foreach ( $err
as $errMsg ) {
260 if ( $errMsg[0] ==
'hookaborted' ) {
261 $errStr[] = $errMsg[1];
263 $errMsgName = array_shift( $errMsg );
264 $errStr[] = $this->
msg( $errMsgName, $errMsg )->parse();
268 $errMsgHtml .=
'<ul><li>' . implode(
"</li>\n<li>", $errStr ) .
"</li></ul>\n";
270 $out->addHTML( Html::errorBox( $errMsgHtml ) );
273 if ( $this->oldTitle->isProtected(
'move' ) ) {
274 # Is the title semi-protected?
275 if ( $this->oldTitle->isSemiProtected(
'move' ) ) {
276 $noticeMsg =
'semiprotectedpagemovewarning';
277 $classes[] =
'mw-textarea-sprotected';
279 # Then it must be protected based on static groups (regular)
280 $noticeMsg =
'protectedpagemovewarning';
281 $classes[] =
'mw-textarea-protected';
283 $out->addHTML(
"<div class='mw-warning-with-logexcerpt'>\n" );
284 $out->addWikiMsg( $noticeMsg );
292 $out->addHTML(
"</div>\n" );
298 $immovableNamespaces = [];
299 foreach ( array_keys( $this->
getLanguage()->getNamespaces() )
as $nsId ) {
301 $immovableNamespaces[] = $nsId;
310 $fields[] =
new OOUI\FieldLayout(
311 new MediaWiki\Widget\ComplexTitleInputWidget( [
312 'id' =>
'wpNewTitle',
314 'id' =>
'wpNewTitleNs',
315 'name' =>
'wpNewTitleNs',
317 'exclude' => $immovableNamespaces,
320 'id' =>
'wpNewTitleMain',
321 'name' =>
'wpNewTitleMain',
324 'suggestions' =>
false,
329 'label' => $this->
msg(
'newtitle' )->text(),
337 $fields[] =
new OOUI\FieldLayout(
338 new OOUI\TextInputWidget( [
339 'name' =>
'wpReason',
346 'label' => $this->
msg(
'movereason' )->
text(),
351 if ( $considerTalk ) {
352 $fields[] =
new OOUI\FieldLayout(
353 new OOUI\CheckboxInputWidget( [
354 'name' =>
'wpMovetalk',
355 'id' =>
'wpMovetalk',
357 'selected' => $this->moveTalk,
360 'label' => $this->
msg(
'movetalk' )->
text(),
361 'help' =>
new OOUI\HtmlSnippet( $this->
msg(
'movepagetalktext' )->parseAsBlock() ),
362 'helpInline' =>
true,
364 'id' =>
'wpMovetalk-field',
369 if (
$user->isAllowed(
'suppressredirect' ) ) {
370 if (
$handler->supportsRedirects() ) {
377 $fields[] =
new OOUI\FieldLayout(
378 new OOUI\CheckboxInputWidget( [
379 'name' =>
'wpLeaveRedirect',
380 'id' =>
'wpLeaveRedirect',
382 'selected' => $isChecked,
383 'disabled' => $isDisabled,
386 'label' => $this->
msg(
'move-leave-redirect' )->
text(),
392 if ( $hasRedirects ) {
393 $fields[] =
new OOUI\FieldLayout(
394 new OOUI\CheckboxInputWidget( [
395 'name' =>
'wpFixRedirects',
396 'id' =>
'wpFixRedirects',
398 'selected' => $this->fixRedirects,
401 'label' => $this->
msg(
'fix-double-redirects' )->
text(),
407 if ( $canMoveSubpage ) {
408 $maximumMovedPages = $this->
getConfig()->get(
'MaximumMovedPages' );
409 $fields[] =
new OOUI\FieldLayout(
410 new OOUI\CheckboxInputWidget( [
411 'name' =>
'wpMovesubpages',
412 'id' =>
'wpMovesubpages',
414 # Don
't check the box if we only have talk subpages to
415 # move and we aren't moving the talk
page.
416 'selected' => $this->moveSubpages && ( $this->oldTitle->hasSubpages() ||
$this->moveTalk ),
419 'label' =>
new OOUI\HtmlSnippet(
421 ( $this->oldTitle->hasSubpages()
423 :
'move-talk-subpages' )
424 )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
431 # Don't allow watching if user is not logged in
432 if (
$user->isLoggedIn() ) {
433 $watchChecked =
$user->isLoggedIn() && ( $this->watch ||
$user->getBoolOption(
'watchmoves' )
434 ||
$user->isWatched( $this->oldTitle ) );
435 $fields[] =
new OOUI\FieldLayout(
436 new OOUI\CheckboxInputWidget( [
438 'id' =>
'watch', # ew
440 'selected' => $watchChecked,
443 'label' => $this->
msg(
'move-watch' )->
text(),
451 $hiddenFields .= Html::hidden(
'wpMoveOverSharedFile',
'1' );
455 $fields[] =
new OOUI\FieldLayout(
456 new OOUI\CheckboxInputWidget( [
457 'name' =>
'wpDeleteAndMove',
458 'id' =>
'wpDeleteAndMove',
462 'label' => $this->
msg(
'delete_and_move_confirm' )->
text(),
468 $fields[] =
new OOUI\FieldLayout(
469 new OOUI\ButtonInputWidget( [
471 'value' => $this->
msg(
'movepagebtn' )->
text(),
472 'label' => $this->
msg(
'movepagebtn' )->
text(),
473 'flags' => [
'primary',
'progressive' ],
481 $fieldset =
new OOUI\FieldsetLayout( [
482 'label' => $this->
msg(
'move-page-legend' )->
text(),
483 'id' =>
'mw-movepage-table',
487 $form =
new OOUI\FormLayout( [
489 'action' => $this->
getPageTitle()->getLocalURL(
'action=submit' ),
492 $form->appendContent(
494 new OOUI\HtmlSnippet(
496 Html::hidden(
'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
497 Html::hidden(
'wpEditToken',
$user->getEditToken() )
502 new OOUI\PanelLayout( [
503 'classes' => [
'movepage-wrapper' ],
518 if (
$user->pingLimiter(
'move' ) ) {
525 # don't allow moving to pages with # in
526 if ( !$nt || $nt->hasFragment() ) {
527 $this->
showForm( [ [
'badtitletext' ] ] );
532 # Show a warning if the target file exists on a shared repo
533 if ( $nt->getNamespace() ==
NS_FILE
534 && !( $this->moveOverShared &&
$user->isAllowed(
'reupload-shared' ) )
538 $this->
showForm( [ [
'file-exists-sharedrepo' ] ] );
543 # Delete to make way if requested
544 if ( $this->deleteAndMove ) {
545 $permErrors = $nt->getUserPermissionsErrors(
'delete',
$user );
546 if (
count( $permErrors ) ) {
547 # Only show the first error
548 $this->
showForm( $permErrors,
true );
556 if ( $page->isBatchedDelete( 5 ) ) {
557 $this->
showForm( [ [
'movepage-delete-first' ] ] );
562 $reason = $this->
msg(
'delete_and_move_reason', $ot )->inContentLanguage()->text();
565 if ( $nt->getNamespace() ==
NS_FILE ) {
567 $file->load( File::READ_LATEST );
568 if (
$file->exists() ) {
574 $deleteStatus = $page->doDeleteArticleReal(
$reason,
false, 0,
true, $error,
$user );
575 if ( !$deleteStatus->isGood() ) {
576 $this->
showForm( $deleteStatus->getErrorsArray() );
584 if ( !
$handler->supportsRedirects() ) {
585 $createRedirect =
false;
586 } elseif (
$user->isAllowed(
'suppressredirect' ) ) {
589 $createRedirect =
true;
592 # Do the actual move.
594 $valid = $mp->isValidMove();
595 if ( !$valid->isOK() ) {
596 $this->
showForm( $valid->getErrorsArray() );
600 $permStatus = $mp->checkPermissions(
$user, $this->
reason );
601 if ( !$permStatus->isOK() ) {
617 $out->setPageTitle( $this->
msg(
'pagemovedsub' ) );
623 [
'id' =>
'movepage-oldlink' ],
624 [
'redirect' =>
'no' ]
629 [
'id' =>
'movepage-newlink' ]
631 $oldText = $ot->getPrefixedText();
632 $newText = $nt->getPrefixedText();
634 if ( $ot->exists() ) {
640 $msgName =
'movepage-moved-redirect';
642 $msgName =
'movepage-moved-noredirect';
645 $out->addHTML( $this->
msg(
'movepage-moved' )->rawParams( $oldLink,
646 $newLink )->params( $oldText, $newText )->parseAsBlock() );
647 $out->addWikiMsg( $msgName );
651 Hooks::run(
'SpecialMovepageAfterMove', [ &$movePage, &$ot, &$nt ] );
653 # Now we move extra pages we've been asked to move: subpages and talk
654 # pages. First, if the old page or the new page is a talk page, we
655 # can't move any talk pages: cancel that.
656 if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
657 $this->moveTalk =
false;
660 if (
count( $ot->getUserPermissionsErrors(
'move-subpages',
$user ) ) ) {
661 $this->moveSubpages =
false;
677 if ( $this->moveSubpages && (
684 'page_title' .
$dbr->buildLike( $ot->getDBkey() .
'/',
$dbr->anyString() )
685 .
' OR page_title = ' .
$dbr->addQuotes( $ot->getDBkey() )
687 $conds[
'page_namespace'] = [];
689 $conds[
'page_namespace'][] = $ot->getNamespace();
691 if ( $this->moveTalk &&
694 $conds[
'page_namespace'][] = $ot->getTalkPage()->getNamespace();
696 } elseif ( $this->moveTalk ) {
698 'page_namespace' => $ot->getTalkPage()->getNamespace(),
699 'page_title' => $ot->getDBkey()
707 if ( !is_null( $conds ) ) {
709 $dbr->select(
'page',
710 [
'page_id',
'page_namespace',
'page_title' ],
719 foreach ( $extraPages
as $oldSubpage ) {
720 if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
721 # Already did this one.
725 $newPageName = preg_replace(
726 '#^' . preg_quote( $ot->getDBkey(),
'#' ) .
'#',
728 $oldSubpage->getDBkey()
731 if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
733 $newNs = $nt->getNamespace();
734 } elseif ( $oldSubpage->isTalkPage() ) {
735 $newNs = $nt->getTalkPage()->getNamespace();
737 $newNs = $nt->getSubjectPage()->getNamespace();
740 # T16385: we need makeTitleSafe because the new page names may
741 # be longer than 255 characters.
743 if ( !$newSubpage ) {
745 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )->rawParams( $oldLink )
750 # This was copy-pasted from Renameuser, bleh.
751 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
753 $extraOutput[] = $this->
msg(
'movepage-page-exists' )->rawParams(
$link )->escaped();
755 $success = $oldSubpage->moveTo( $newSubpage,
true, $this->
reason, $createRedirect );
758 if ( $this->fixRedirects ) {
765 [
'redirect' =>
'no' ]
769 $extraOutput[] = $this->
msg(
'movepage-page-moved' )
770 ->rawParams( $oldLink, $newLink )->escaped();
773 $maximumMovedPages = $this->
getConfig()->get(
'MaximumMovedPages' );
774 if ( $count >= $maximumMovedPages ) {
775 $extraOutput[] = $this->
msg(
'movepage-max-pages' )
776 ->numParams( $maximumMovedPages )->escaped();
782 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )
783 ->rawParams( $oldLink, $newLink )->escaped();
788 if ( $extraOutput !== [] ) {
789 $out->addHTML(
"<ul>\n<li>" . implode(
"</li>\n<li>", $extraOutput ) .
"</li>\n</ul>" );
792 # Deal with watches (we don't watch subpages)
798 $moveLogPage =
new LogPage(
'move' );
800 $out->addHTML(
Xml::element(
'h2',
null, $moveLogPage->getName()->text() ) );
812 $subpages =
$title->getSubpages();
813 $count = $subpages instanceof
TitleArray ? $subpages->count() : 0;
815 $titleIsTalk =
$title->isTalkPage();
816 $subpagesTalk =
$title->getTalkPage()->getSubpages();
817 $countTalk = $subpagesTalk instanceof
TitleArray ? $subpagesTalk->count() : 0;
818 $totalCount = $count + $countTalk;
820 if ( !$nsHasSubpages && $countTalk == 0 ) {
826 [
'movesubpage', ( $titleIsTalk ? $count : $totalCount ) ]
829 if ( $nsHasSubpages ) {
833 if ( !$titleIsTalk && $countTalk > 0 ) {
834 $this->
showSubpagesList( $subpagesTalk, $countTalk,
'movesubpagetalktext' );
842 if ( $pagecount == 0 && $noSubpageMsg ) {
843 $out->addWikiMsg(
'movenosubpage' );
847 $out->addWikiMsg( $wikiMsg, $this->
getLanguage()->formatNum( $pagecount ) );
848 $out->addHTML(
"<ul>\n" );
851 $linkBatch->setCaller( __METHOD__ );
852 $linkBatch->execute();
855 foreach ( $subpages
as $subpage ) {
857 $out->addHTML(
"<li>$link</li>\n" );
859 $out->addHTML(
"</ul>\n" );