62 parent::__construct(
'Movepage' );
78 $target = !is_null( $par ) ? $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' ) )
142 $this->
getSkin()->setRelevantTitle( $this->oldTitle );
145 $out->setPageTitle( $this->
msg(
'move-page', $this->oldTitle->getPrefixedText() ) );
146 $out->addModules(
'mediawiki.special.movePage' );
147 $out->addModuleStyles(
'mediawiki.special.movePage.styles' );
150 $out->addWikiMsg( $this->
getConfig()->
get(
'FixDoubleRedirects' ) ?
152 'movepagetext-noredirectfixer'
155 if ( $this->oldTitle->getNamespace() ==
NS_USER && !$this->oldTitle->isSubpage() ) {
157 "<div class=\"warningbox mw-moveuserpage-warning\">\n$1\n</div>",
158 'moveuserpage-warning'
160 } elseif ( $this->oldTitle->getNamespace() ==
NS_CATEGORY ) {
162 "<div class=\"warningbox mw-movecategorypage-warning\">\n$1\n</div>",
163 'movecategorypage-warning'
173 # Show the current title as a default
174 # when the form is first opened.
176 } elseif ( !
count( $err ) ) {
177 # If a title was supplied, probably from the move log revert
178 # link, check for validity. We can then show some diagnostic
179 # information and save a click.
181 if ( is_array( $newerr ) ) {
188 if (
count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] ==
'articleexists'
192 "<div class='warningbox'>\n$1\n</div>\n",
199 if (
count( $err ) == 1 && isset( $err[0][0] ) && $err[0][0] ==
'file-exists-sharedrepo'
200 &&
$user->isAllowed(
'reupload-shared' )
203 "<div class='warningbox'>\n$1\n</div>\n",
205 'move-over-sharedrepo',
213 $oldTalk = $this->oldTitle->getTalkPage();
214 $oldTitleSubpages = $this->oldTitle->hasSubpages();
215 $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
217 $canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
218 !
count( $this->oldTitle->getUserPermissionsErrors(
'move-subpages',
$user ) );
220 # We also want to be able to move assoc. subpage talk-pages even if base page
221 # has no associated talk page, so || with $oldTitleTalkSubpages.
222 $considerTalk = !$this->oldTitle->isTalkPage() &&
224 || ( $oldTitleTalkSubpages && $canMoveSubpage ) );
227 if ( $this->
getConfig()->
get(
'FixDoubleRedirects' ) ) {
228 $hasRedirects =
$dbr->selectField(
'redirect',
'1',
230 'rd_namespace' => $this->oldTitle->getNamespace(),
231 'rd_title' => $this->oldTitle->getDBkey(),
234 $hasRedirects =
false;
237 if (
count( $err ) ) {
238 $out->addHTML(
"<div class='errorbox'>\n" );
239 $action_desc = $this->
msg(
'action-move' )->plain();
240 $out->addWikiMsg(
'permissionserrorstext-withaction',
count( $err ), $action_desc );
242 if (
count( $err ) == 1 ) {
244 $errMsgName = array_shift( $errMsg );
246 if ( $errMsgName ==
'hookaborted' ) {
247 $out->addHTML(
"<p>{$errMsg[0]}</p>\n" );
249 $out->addWikiMsgArray( $errMsgName, $errMsg );
254 foreach ( $err
as $errMsg ) {
255 if ( $errMsg[0] ==
'hookaborted' ) {
256 $errStr[] = $errMsg[1];
258 $errMsgName = array_shift( $errMsg );
259 $errStr[] = $this->
msg( $errMsgName, $errMsg )->parse();
263 $out->addHTML(
'<ul><li>' . implode(
"</li>\n<li>", $errStr ) .
"</li></ul>\n" );
265 $out->addHTML(
"</div>\n" );
268 if ( $this->oldTitle->isProtected(
'move' ) ) {
269 # Is the title semi-protected?
270 if ( $this->oldTitle->isSemiProtected(
'move' ) ) {
271 $noticeMsg =
'semiprotectedpagemovewarning';
272 $classes[] =
'mw-textarea-sprotected';
274 # Then it must be protected based on static groups (regular)
275 $noticeMsg =
'protectedpagemovewarning';
276 $classes[] =
'mw-textarea-protected';
278 $out->addHTML(
"<div class='mw-warning-with-logexcerpt'>\n" );
279 $out->addWikiMsg( $noticeMsg );
287 $out->addHTML(
"</div>\n" );
293 $immovableNamespaces = [];
294 foreach ( array_keys( $this->
getLanguage()->getNamespaces() )
as $nsId ) {
296 $immovableNamespaces[] = $nsId;
305 $fields[] =
new OOUI\FieldLayout(
306 new MediaWiki\Widget\ComplexTitleInputWidget( [
307 'id' =>
'wpNewTitle',
309 'id' =>
'wpNewTitleNs',
310 'name' =>
'wpNewTitleNs',
312 'exclude' => $immovableNamespaces,
315 'id' =>
'wpNewTitleMain',
316 'name' =>
'wpNewTitleMain',
319 'suggestions' =>
false,
324 'label' => $this->
msg(
'newtitle' )->text(),
329 $fields[] =
new OOUI\FieldLayout(
330 new OOUI\TextInputWidget( [
331 'name' =>
'wpReason',
338 'label' => $this->
msg(
'movereason' )->
text(),
343 if ( $considerTalk ) {
344 $fields[] =
new OOUI\FieldLayout(
345 new OOUI\CheckboxInputWidget( [
346 'name' =>
'wpMovetalk',
347 'id' =>
'wpMovetalk',
349 'selected' => $this->moveTalk,
352 'label' => $this->
msg(
'movetalk' )->
text(),
353 'help' =>
new OOUI\HtmlSnippet( $this->
msg(
'movepagetalktext' )->parseAsBlock() ),
356 'id' =>
'wpMovetalk-field',
361 if (
$user->isAllowed(
'suppressredirect' ) ) {
362 if (
$handler->supportsRedirects() ) {
369 $fields[] =
new OOUI\FieldLayout(
370 new OOUI\CheckboxInputWidget( [
371 'name' =>
'wpLeaveRedirect',
372 'id' =>
'wpLeaveRedirect',
374 'selected' => $isChecked,
375 'disabled' => $isDisabled,
378 'label' => $this->
msg(
'move-leave-redirect' )->
text(),
384 if ( $hasRedirects ) {
385 $fields[] =
new OOUI\FieldLayout(
386 new OOUI\CheckboxInputWidget( [
387 'name' =>
'wpFixRedirects',
388 'id' =>
'wpFixRedirects',
390 'selected' => $this->fixRedirects,
393 'label' => $this->
msg(
'fix-double-redirects' )->
text(),
399 if ( $canMoveSubpage ) {
400 $maximumMovedPages = $this->
getConfig()->get(
'MaximumMovedPages' );
401 $fields[] =
new OOUI\FieldLayout(
402 new OOUI\CheckboxInputWidget( [
403 'name' =>
'wpMovesubpages',
404 'id' =>
'wpMovesubpages',
406 # Don
't check the box if we only have talk subpages to
407 # move and we aren't moving the talk
page.
408 'selected' => $this->moveSubpages && ( $this->oldTitle->hasSubpages() ||
$this->moveTalk ),
411 'label' =>
new OOUI\HtmlSnippet(
413 ( $this->oldTitle->hasSubpages()
415 :
'move-talk-subpages' )
416 )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
423 # Don't allow watching if user is not logged in
424 if (
$user->isLoggedIn() ) {
425 $watchChecked =
$user->isLoggedIn() && ( $this->watch ||
$user->getBoolOption(
'watchmoves' )
426 ||
$user->isWatched( $this->oldTitle ) );
427 $fields[] =
new OOUI\FieldLayout(
428 new OOUI\CheckboxInputWidget( [
430 'id' =>
'watch', # ew
432 'selected' => $watchChecked,
435 'label' => $this->
msg(
'move-watch' )->
text(),
443 $hiddenFields .=
Html::hidden(
'wpMoveOverSharedFile',
'1' );
447 $fields[] =
new OOUI\FieldLayout(
448 new OOUI\CheckboxInputWidget( [
449 'name' =>
'wpDeleteAndMove',
450 'id' =>
'wpDeleteAndMove',
454 'label' => $this->
msg(
'delete_and_move_confirm' )->
text(),
460 $fields[] =
new OOUI\FieldLayout(
461 new OOUI\ButtonInputWidget( [
463 'value' => $this->
msg(
'movepagebtn' )->
text(),
464 'label' => $this->
msg(
'movepagebtn' )->
text(),
465 'flags' => [
'primary',
'progressive' ],
473 $fieldset =
new OOUI\FieldsetLayout( [
474 'label' => $this->
msg(
'move-page-legend' )->
text(),
475 'id' =>
'mw-movepage-table',
479 $form =
new OOUI\FormLayout( [
481 'action' => $this->
getPageTitle()->getLocalURL(
'action=submit' ),
484 $form->appendContent(
486 new OOUI\HtmlSnippet(
488 Html::hidden(
'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
494 new OOUI\PanelLayout( [
495 'classes' => [
'movepage-wrapper' ],
510 if (
$user->pingLimiter(
'move' ) ) {
517 # don't allow moving to pages with # in
518 if ( !$nt || $nt->hasFragment() ) {
519 $this->
showForm( [ [
'badtitletext' ] ] );
524 # Show a warning if the target file exists on a shared repo
525 if ( $nt->getNamespace() ==
NS_FILE
526 && !( $this->moveOverShared &&
$user->isAllowed(
'reupload-shared' ) )
530 $this->
showForm( [ [
'file-exists-sharedrepo' ] ] );
535 # Delete to make way if requested
536 if ( $this->deleteAndMove ) {
537 $permErrors = $nt->getUserPermissionsErrors(
'delete',
$user );
538 if (
count( $permErrors ) ) {
539 # Only show the first error
545 $reason = $this->
msg(
'delete_and_move_reason', $ot )->inContentLanguage()->text();
548 if ( $nt->getNamespace() ==
NS_FILE ) {
550 $file->load( File::READ_LATEST );
551 if ( $file->exists() ) {
558 $deleteStatus = $page->doDeleteArticleReal(
$reason,
false, 0,
true, $error,
$user );
559 if ( !$deleteStatus->isGood() ) {
560 $this->
showForm( $deleteStatus->getErrorsArray() );
568 if ( !
$handler->supportsRedirects() ) {
569 $createRedirect =
false;
570 } elseif (
$user->isAllowed(
'suppressredirect' ) ) {
573 $createRedirect =
true;
576 # Do the actual move.
578 $valid = $mp->isValidMove();
579 if ( !$valid->isOK() ) {
580 $this->
showForm( $valid->getErrorsArray() );
584 $permStatus = $mp->checkPermissions(
$user, $this->
reason );
585 if ( !$permStatus->isOK() ) {
586 $this->
showForm( $permStatus->getErrorsArray() );
601 $out->setPageTitle( $this->
msg(
'pagemovedsub' ) );
607 [
'id' =>
'movepage-oldlink' ],
608 [
'redirect' =>
'no' ]
613 [
'id' =>
'movepage-newlink' ]
615 $oldText = $ot->getPrefixedText();
616 $newText = $nt->getPrefixedText();
618 if ( $ot->exists() ) {
624 $msgName =
'movepage-moved-redirect';
626 $msgName =
'movepage-moved-noredirect';
629 $out->addHTML( $this->
msg(
'movepage-moved' )->rawParams( $oldLink,
630 $newLink )->params( $oldText, $newText )->parseAsBlock() );
631 $out->addWikiMsg( $msgName );
635 Hooks::run(
'SpecialMovepageAfterMove', [ &$movePage, &$ot, &$nt ] );
637 # Now we move extra pages we've been asked to move: subpages and talk
638 # pages. First, if the old page or the new page is a talk page, we
639 # can't move any talk pages: cancel that.
640 if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
641 $this->moveTalk =
false;
644 if (
count( $ot->getUserPermissionsErrors(
'move-subpages',
$user ) ) ) {
645 $this->moveSubpages =
false;
661 if ( $this->moveSubpages && (
668 'page_title' .
$dbr->buildLike( $ot->getDBkey() .
'/',
$dbr->anyString() )
669 .
' OR page_title = ' .
$dbr->addQuotes( $ot->getDBkey() )
671 $conds[
'page_namespace'] = [];
673 $conds[
'page_namespace'][] = $ot->getNamespace();
675 if ( $this->moveTalk &&
678 $conds[
'page_namespace'][] = $ot->getTalkPage()->getNamespace();
680 } elseif ( $this->moveTalk ) {
682 'page_namespace' => $ot->getTalkPage()->getNamespace(),
683 'page_title' => $ot->getDBkey()
691 if ( !is_null( $conds ) ) {
693 $dbr->select(
'page',
694 [
'page_id',
'page_namespace',
'page_title' ],
703 foreach ( $extraPages
as $oldSubpage ) {
704 if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
705 # Already did this one.
709 $newPageName = preg_replace(
710 '#^' . preg_quote( $ot->getDBkey(),
'#' ) .
'#',
712 $oldSubpage->getDBkey()
715 if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
717 $newNs = $nt->getNamespace();
718 } elseif ( $oldSubpage->isTalkPage() ) {
719 $newNs = $nt->getTalkPage()->getNamespace();
721 $newNs = $nt->getSubjectPage()->getNamespace();
724 # T16385: we need makeTitleSafe because the new page names may
725 # be longer than 255 characters.
727 if ( !$newSubpage ) {
729 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )->rawParams( $oldLink )
734 # This was copy-pasted from Renameuser, bleh.
735 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
737 $extraOutput[] = $this->
msg(
'movepage-page-exists' )->rawParams(
$link )->escaped();
739 $success = $oldSubpage->moveTo( $newSubpage,
true, $this->
reason, $createRedirect );
742 if ( $this->fixRedirects ) {
749 [
'redirect' =>
'no' ]
753 $extraOutput[] = $this->
msg(
'movepage-page-moved' )
754 ->rawParams( $oldLink, $newLink )->escaped();
757 $maximumMovedPages = $this->
getConfig()->get(
'MaximumMovedPages' );
758 if ( $count >= $maximumMovedPages ) {
759 $extraOutput[] = $this->
msg(
'movepage-max-pages' )
760 ->numParams( $maximumMovedPages )->escaped();
766 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )
767 ->rawParams( $oldLink, $newLink )->escaped();
772 if ( $extraOutput !== [] ) {
773 $out->addHTML(
"<ul>\n<li>" . implode(
"</li>\n<li>", $extraOutput ) .
"</li>\n</ul>" );
776 # Deal with watches (we don't watch subpages)
784 $user->incEditCount();
788 $moveLogPage =
new LogPage(
'move' );
790 $out->addHTML(
Xml::element(
'h2',
null, $moveLogPage->getName()->text() ) );
802 $subpages =
$title->getSubpages();
803 $count = $subpages instanceof
TitleArray ? $subpages->count() : 0;
805 $titleIsTalk =
$title->isTalkPage();
806 $subpagesTalk =
$title->getTalkPage()->getSubpages();
807 $countTalk = $subpagesTalk instanceof
TitleArray ? $subpagesTalk->count() : 0;
808 $totalCount = $count + $countTalk;
810 if ( !$nsHasSubpages && $countTalk == 0 ) {
816 [
'movesubpage', ( $titleIsTalk ? $count : $totalCount ) ]
819 if ( $nsHasSubpages ) {
823 if ( !$titleIsTalk && $countTalk > 0 ) {
824 $this->
showSubpagesList( $subpagesTalk, $countTalk,
'movesubpagetalktext' );
832 if ( $pagecount == 0 && $noSubpageMsg ) {
833 $out->addWikiMsg(
'movenosubpage' );
837 $out->addWikiMsg( $wikiMsg, $this->
getLanguage()->formatNum( $pagecount ) );
838 $out->addHTML(
"<ul>\n" );
841 $linkBatch->setCaller( __METHOD__ );
842 $linkBatch->execute();
845 foreach ( $subpages
as $subpage ) {
847 $out->addHTML(
"<li>$link</li>\n" );
849 $out->addHTML(
"</ul>\n" );