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->addModuleStyles(
'mediawiki.special' );
147 $out->addModules(
'mediawiki.special.movePage' );
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 $action_desc = $this->
msg(
'action-move' )->plain();
239 $errMsgHtml = $this->
msg(
'permissionserrorstext-withaction',
240 count( $err ), $action_desc )->parseAsBlock();
242 if (
count( $err ) == 1 ) {
244 $errMsgName = array_shift( $errMsg );
246 if ( $errMsgName ==
'hookaborted' ) {
247 $errMsgHtml .=
"<p>{$errMsg[0]}</p>\n";
249 $errMsgHtml .= $this->
msg( $errMsgName, $errMsg )->parseAsBlock();
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 $errMsgHtml .=
'<ul><li>' . implode(
"</li>\n<li>", $errStr ) .
"</li></ul>\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(),
333 $oldCommentSchema = $conf->get(
'CommentTableSchemaMigrationStage' ) ===
MIGRATION_OLD;
334 $fields[] =
new OOUI\FieldLayout(
335 new OOUI\TextInputWidget( [
336 'name' =>
'wpReason',
343 'label' => $this->
msg(
'movereason' )->
text(),
348 if ( $considerTalk ) {
349 $fields[] =
new OOUI\FieldLayout(
350 new OOUI\CheckboxInputWidget( [
351 'name' =>
'wpMovetalk',
352 'id' =>
'wpMovetalk',
354 'selected' => $this->moveTalk,
357 'label' => $this->
msg(
'movetalk' )->
text(),
358 'help' =>
new OOUI\HtmlSnippet( $this->
msg(
'movepagetalktext' )->parseAsBlock() ),
359 'helpInline' =>
true,
361 'id' =>
'wpMovetalk-field',
366 if (
$user->isAllowed(
'suppressredirect' ) ) {
367 if (
$handler->supportsRedirects() ) {
374 $fields[] =
new OOUI\FieldLayout(
375 new OOUI\CheckboxInputWidget( [
376 'name' =>
'wpLeaveRedirect',
377 'id' =>
'wpLeaveRedirect',
379 'selected' => $isChecked,
380 'disabled' => $isDisabled,
383 'label' => $this->
msg(
'move-leave-redirect' )->
text(),
389 if ( $hasRedirects ) {
390 $fields[] =
new OOUI\FieldLayout(
391 new OOUI\CheckboxInputWidget( [
392 'name' =>
'wpFixRedirects',
393 'id' =>
'wpFixRedirects',
395 'selected' => $this->fixRedirects,
398 'label' => $this->
msg(
'fix-double-redirects' )->
text(),
404 if ( $canMoveSubpage ) {
405 $maximumMovedPages = $this->
getConfig()->get(
'MaximumMovedPages' );
406 $fields[] =
new OOUI\FieldLayout(
407 new OOUI\CheckboxInputWidget( [
408 'name' =>
'wpMovesubpages',
409 'id' =>
'wpMovesubpages',
411 # Don
't check the box if we only have talk subpages to
412 # move and we aren't moving the talk
page.
413 'selected' => $this->moveSubpages && ( $this->oldTitle->hasSubpages() ||
$this->moveTalk ),
416 'label' =>
new OOUI\HtmlSnippet(
418 ( $this->oldTitle->hasSubpages()
420 :
'move-talk-subpages' )
421 )->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
428 # Don't allow watching if user is not logged in
429 if (
$user->isLoggedIn() ) {
430 $watchChecked =
$user->isLoggedIn() && ( $this->watch ||
$user->getBoolOption(
'watchmoves' )
431 ||
$user->isWatched( $this->oldTitle ) );
432 $fields[] =
new OOUI\FieldLayout(
433 new OOUI\CheckboxInputWidget( [
435 'id' =>
'watch', # ew
437 'selected' => $watchChecked,
440 'label' => $this->
msg(
'move-watch' )->
text(),
448 $hiddenFields .=
Html::hidden(
'wpMoveOverSharedFile',
'1' );
452 $fields[] =
new OOUI\FieldLayout(
453 new OOUI\CheckboxInputWidget( [
454 'name' =>
'wpDeleteAndMove',
455 'id' =>
'wpDeleteAndMove',
459 'label' => $this->
msg(
'delete_and_move_confirm' )->
text(),
465 $fields[] =
new OOUI\FieldLayout(
466 new OOUI\ButtonInputWidget( [
468 'value' => $this->
msg(
'movepagebtn' )->
text(),
469 'label' => $this->
msg(
'movepagebtn' )->
text(),
470 'flags' => [
'primary',
'progressive' ],
478 $fieldset =
new OOUI\FieldsetLayout( [
479 'label' => $this->
msg(
'move-page-legend' )->
text(),
480 'id' =>
'mw-movepage-table',
484 $form =
new OOUI\FormLayout( [
486 'action' => $this->
getPageTitle()->getLocalURL(
'action=submit' ),
489 $form->appendContent(
491 new OOUI\HtmlSnippet(
493 Html::hidden(
'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
499 new OOUI\PanelLayout( [
500 'classes' => [
'movepage-wrapper' ],
515 if (
$user->pingLimiter(
'move' ) ) {
522 # don't allow moving to pages with # in
523 if ( !$nt || $nt->hasFragment() ) {
524 $this->
showForm( [ [
'badtitletext' ] ] );
529 # Show a warning if the target file exists on a shared repo
530 if ( $nt->getNamespace() ==
NS_FILE
531 && !( $this->moveOverShared &&
$user->isAllowed(
'reupload-shared' ) )
535 $this->
showForm( [ [
'file-exists-sharedrepo' ] ] );
540 # Delete to make way if requested
541 if ( $this->deleteAndMove ) {
542 $permErrors = $nt->getUserPermissionsErrors(
'delete',
$user );
543 if (
count( $permErrors ) ) {
544 # Only show the first error
553 if ( $page->isBatchedDelete( 5 ) ) {
554 $this->
showForm( [ [
'movepage-delete-first' ] ] );
559 $reason = $this->
msg(
'delete_and_move_reason', $ot )->inContentLanguage()->text();
562 if ( $nt->getNamespace() ==
NS_FILE ) {
564 $file->load( File::READ_LATEST );
565 if ( $file->exists() ) {
571 $deleteStatus = $page->doDeleteArticleReal(
$reason,
false, 0,
true, $error,
$user );
572 if ( !$deleteStatus->isGood() ) {
573 $this->
showForm( $deleteStatus->getErrorsArray() );
581 if ( !
$handler->supportsRedirects() ) {
582 $createRedirect =
false;
583 } elseif (
$user->isAllowed(
'suppressredirect' ) ) {
586 $createRedirect =
true;
589 # Do the actual move.
591 $valid = $mp->isValidMove();
592 if ( !$valid->isOK() ) {
593 $this->
showForm( $valid->getErrorsArray() );
597 $permStatus = $mp->checkPermissions(
$user, $this->
reason );
598 if ( !$permStatus->isOK() ) {
599 $this->
showForm( $permStatus->getErrorsArray() );
614 $out->setPageTitle( $this->
msg(
'pagemovedsub' ) );
620 [
'id' =>
'movepage-oldlink' ],
621 [
'redirect' =>
'no' ]
626 [
'id' =>
'movepage-newlink' ]
628 $oldText = $ot->getPrefixedText();
629 $newText = $nt->getPrefixedText();
631 if ( $ot->exists() ) {
637 $msgName =
'movepage-moved-redirect';
639 $msgName =
'movepage-moved-noredirect';
642 $out->addHTML( $this->
msg(
'movepage-moved' )->rawParams( $oldLink,
643 $newLink )->params( $oldText, $newText )->parseAsBlock() );
644 $out->addWikiMsg( $msgName );
648 Hooks::run(
'SpecialMovepageAfterMove', [ &$movePage, &$ot, &$nt ] );
650 # Now we move extra pages we've been asked to move: subpages and talk
651 # pages. First, if the old page or the new page is a talk page, we
652 # can't move any talk pages: cancel that.
653 if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
654 $this->moveTalk =
false;
657 if (
count( $ot->getUserPermissionsErrors(
'move-subpages',
$user ) ) ) {
658 $this->moveSubpages =
false;
674 if ( $this->moveSubpages && (
681 'page_title' .
$dbr->buildLike( $ot->getDBkey() .
'/',
$dbr->anyString() )
682 .
' OR page_title = ' .
$dbr->addQuotes( $ot->getDBkey() )
684 $conds[
'page_namespace'] = [];
686 $conds[
'page_namespace'][] = $ot->getNamespace();
688 if ( $this->moveTalk &&
691 $conds[
'page_namespace'][] = $ot->getTalkPage()->getNamespace();
693 } elseif ( $this->moveTalk ) {
695 'page_namespace' => $ot->getTalkPage()->getNamespace(),
696 'page_title' => $ot->getDBkey()
704 if ( !is_null( $conds ) ) {
706 $dbr->select(
'page',
707 [
'page_id',
'page_namespace',
'page_title' ],
716 foreach ( $extraPages
as $oldSubpage ) {
717 if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
718 # Already did this one.
722 $newPageName = preg_replace(
723 '#^' . preg_quote( $ot->getDBkey(),
'#' ) .
'#',
725 $oldSubpage->getDBkey()
728 if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
730 $newNs = $nt->getNamespace();
731 } elseif ( $oldSubpage->isTalkPage() ) {
732 $newNs = $nt->getTalkPage()->getNamespace();
734 $newNs = $nt->getSubjectPage()->getNamespace();
737 # T16385: we need makeTitleSafe because the new page names may
738 # be longer than 255 characters.
740 if ( !$newSubpage ) {
742 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )->rawParams( $oldLink )
747 # This was copy-pasted from Renameuser, bleh.
748 if ( $newSubpage->exists() && !$oldSubpage->isValidMoveTarget( $newSubpage ) ) {
750 $extraOutput[] = $this->
msg(
'movepage-page-exists' )->rawParams(
$link )->escaped();
752 $success = $oldSubpage->moveTo( $newSubpage,
true, $this->
reason, $createRedirect );
755 if ( $this->fixRedirects ) {
762 [
'redirect' =>
'no' ]
766 $extraOutput[] = $this->
msg(
'movepage-page-moved' )
767 ->rawParams( $oldLink, $newLink )->escaped();
770 $maximumMovedPages = $this->
getConfig()->get(
'MaximumMovedPages' );
771 if ( $count >= $maximumMovedPages ) {
772 $extraOutput[] = $this->
msg(
'movepage-max-pages' )
773 ->numParams( $maximumMovedPages )->escaped();
779 $extraOutput[] = $this->
msg(
'movepage-page-unmoved' )
780 ->rawParams( $oldLink, $newLink )->escaped();
785 if ( $extraOutput !== [] ) {
786 $out->addHTML(
"<ul>\n<li>" . implode(
"</li>\n<li>", $extraOutput ) .
"</li>\n</ul>" );
789 # Deal with watches (we don't watch subpages)
797 $user->incEditCount();
801 $moveLogPage =
new LogPage(
'move' );
803 $out->addHTML(
Xml::element(
'h2',
null, $moveLogPage->getName()->text() ) );
815 $subpages =
$title->getSubpages();
816 $count = $subpages instanceof
TitleArray ? $subpages->count() : 0;
818 $titleIsTalk =
$title->isTalkPage();
819 $subpagesTalk =
$title->getTalkPage()->getSubpages();
820 $countTalk = $subpagesTalk instanceof
TitleArray ? $subpagesTalk->count() : 0;
821 $totalCount = $count + $countTalk;
823 if ( !$nsHasSubpages && $countTalk == 0 ) {
829 [
'movesubpage', ( $titleIsTalk ? $count : $totalCount ) ]
832 if ( $nsHasSubpages ) {
836 if ( !$titleIsTalk && $countTalk > 0 ) {
837 $this->
showSubpagesList( $subpagesTalk, $countTalk,
'movesubpagetalktext' );
845 if ( $pagecount == 0 && $noSubpageMsg ) {
846 $out->addWikiMsg(
'movenosubpage' );
850 $out->addWikiMsg( $wikiMsg, $this->
getLanguage()->formatNum( $pagecount ) );
851 $out->addHTML(
"<ul>\n" );
854 $linkBatch->setCaller( __METHOD__ );
855 $linkBatch->execute();
858 foreach ( $subpages
as $subpage ) {
860 $out->addHTML(
"<li>$link</li>\n" );
862 $out->addHTML(
"</ul>\n" );