1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
|
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace MediaWiki\Specials;
use DoubleRedirectJob;
use ErrorPageError;
use LogEventsList;
use LogPage;
use MediaWiki\Cache\LinkBatchFactory;
use MediaWiki\CommentStore\CommentStore;
use MediaWiki\Content\IContentHandlerFactory;
use MediaWiki\Deferred\DeferredUpdates;
use MediaWiki\Html\Html;
use MediaWiki\MainConfigNames;
use MediaWiki\Page\DeletePageFactory;
use MediaWiki\Page\MovePageFactory;
use MediaWiki\Page\WikiPageFactory;
use MediaWiki\Permissions\PermissionManager;
use MediaWiki\Permissions\PermissionStatus;
use MediaWiki\Permissions\RestrictionStore;
use MediaWiki\SpecialPage\UnlistedSpecialPage;
use MediaWiki\Title\NamespaceInfo;
use MediaWiki\Title\Title;
use MediaWiki\Title\TitleArrayFromResult;
use MediaWiki\Title\TitleFactory;
use MediaWiki\User\Options\UserOptionsLookup;
use MediaWiki\Watchlist\WatchlistManager;
use MediaWiki\Widget\ComplexTitleInputWidget;
use MediaWiki\Xml\Xml;
use OOUI\ButtonInputWidget;
use OOUI\CheckboxInputWidget;
use OOUI\DropdownInputWidget;
use OOUI\FieldLayout;
use OOUI\FieldsetLayout;
use OOUI\FormLayout;
use OOUI\HtmlSnippet;
use OOUI\PanelLayout;
use OOUI\TextInputWidget;
use PermissionsError;
use RepoGroup;
use SearchEngineFactory;
use StatusValue;
use StringUtils;
use ThrottledError;
use Wikimedia\Rdbms\IConnectionProvider;
use Wikimedia\Rdbms\IDBAccessObject;
use Wikimedia\Rdbms\IExpression;
use Wikimedia\Rdbms\LikeValue;
/**
* Implement Special:Movepage for changing page titles
*
* @ingroup SpecialPage
*/
class SpecialMovePage extends UnlistedSpecialPage {
/** @var Title */
protected $oldTitle = null;
/** @var Title */
protected $newTitle;
/** @var string Text input */
protected $reason;
/** @var bool */
protected $moveTalk;
/** @var bool */
protected $deleteAndMove;
/** @var bool */
protected $moveSubpages;
/** @var bool */
protected $fixRedirects;
/** @var bool */
protected $leaveRedirect;
/** @var bool */
protected $moveOverShared;
/** @var bool */
private $watch = false;
private MovePageFactory $movePageFactory;
private PermissionManager $permManager;
private UserOptionsLookup $userOptionsLookup;
private IConnectionProvider $dbProvider;
private IContentHandlerFactory $contentHandlerFactory;
private NamespaceInfo $nsInfo;
private LinkBatchFactory $linkBatchFactory;
private RepoGroup $repoGroup;
private WikiPageFactory $wikiPageFactory;
private SearchEngineFactory $searchEngineFactory;
private WatchlistManager $watchlistManager;
private RestrictionStore $restrictionStore;
private TitleFactory $titleFactory;
private DeletePageFactory $deletePageFactory;
/**
* @param MovePageFactory $movePageFactory
* @param PermissionManager $permManager
* @param UserOptionsLookup $userOptionsLookup
* @param IConnectionProvider $dbProvider
* @param IContentHandlerFactory $contentHandlerFactory
* @param NamespaceInfo $nsInfo
* @param LinkBatchFactory $linkBatchFactory
* @param RepoGroup $repoGroup
* @param WikiPageFactory $wikiPageFactory
* @param SearchEngineFactory $searchEngineFactory
* @param WatchlistManager $watchlistManager
* @param RestrictionStore $restrictionStore
* @param TitleFactory $titleFactory
* @param DeletePageFactory $deletePageFactory
*/
public function __construct(
MovePageFactory $movePageFactory,
PermissionManager $permManager,
UserOptionsLookup $userOptionsLookup,
IConnectionProvider $dbProvider,
IContentHandlerFactory $contentHandlerFactory,
NamespaceInfo $nsInfo,
LinkBatchFactory $linkBatchFactory,
RepoGroup $repoGroup,
WikiPageFactory $wikiPageFactory,
SearchEngineFactory $searchEngineFactory,
WatchlistManager $watchlistManager,
RestrictionStore $restrictionStore,
TitleFactory $titleFactory,
DeletePageFactory $deletePageFactory
) {
parent::__construct( 'Movepage' );
$this->movePageFactory = $movePageFactory;
$this->permManager = $permManager;
$this->userOptionsLookup = $userOptionsLookup;
$this->dbProvider = $dbProvider;
$this->contentHandlerFactory = $contentHandlerFactory;
$this->nsInfo = $nsInfo;
$this->linkBatchFactory = $linkBatchFactory;
$this->repoGroup = $repoGroup;
$this->wikiPageFactory = $wikiPageFactory;
$this->searchEngineFactory = $searchEngineFactory;
$this->watchlistManager = $watchlistManager;
$this->restrictionStore = $restrictionStore;
$this->titleFactory = $titleFactory;
$this->deletePageFactory = $deletePageFactory;
}
public function doesWrites() {
return true;
}
public function execute( $par ) {
$this->useTransactionalTimeLimit();
$this->checkReadOnly();
$this->setHeaders();
$this->outputHeader();
$request = $this->getRequest();
// Beware: The use of WebRequest::getText() is wanted! See T22365
$target = $par ?? $request->getText( 'target' );
$oldTitleText = $request->getText( 'wpOldTitle', $target );
$this->oldTitle = Title::newFromText( $oldTitleText );
if ( !$this->oldTitle ) {
// Either oldTitle wasn't passed, or newFromText returned null
throw new ErrorPageError( 'notargettitle', 'notargettext' );
}
$this->getOutput()->addBacklinkSubtitle( $this->oldTitle );
if ( !$this->oldTitle->exists() ) {
throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
}
$newTitleTextMain = $request->getText( 'wpNewTitleMain' );
$newTitleTextNs = $request->getInt( 'wpNewTitleNs', $this->oldTitle->getNamespace() );
// Backwards compatibility for forms submitting here from other sources
// which is more common than it should be.
$newTitleText_bc = $request->getText( 'wpNewTitle' );
$this->newTitle = strlen( $newTitleText_bc ) > 0
? Title::newFromText( $newTitleText_bc )
: Title::makeTitleSafe( $newTitleTextNs, $newTitleTextMain );
$user = $this->getUser();
$isSubmit = $request->getRawVal( 'action' ) === 'submit' && $request->wasPosted();
$reasonList = $request->getText( 'wpReasonList', 'other' );
$reason = $request->getText( 'wpReason' );
if ( $reasonList === 'other' ) {
$this->reason = $reason;
} elseif ( $reason !== '' ) {
$this->reason = $reasonList . $this->msg( 'colon-separator' )->inContentLanguage()->text() . $reason;
} else {
$this->reason = $reasonList;
}
// Default to checked, but don't fill in true during submission (browsers only submit checked values)
// TODO: Use HTMLForm to take care of this.
$def = !$isSubmit;
$this->moveTalk = $request->getBool( 'wpMovetalk', $def );
$this->fixRedirects = $request->getBool( 'wpFixRedirects', $def );
$this->leaveRedirect = $request->getBool( 'wpLeaveRedirect', $def );
// T222953: Tick the "move subpages" box by default
$this->moveSubpages = $request->getBool( 'wpMovesubpages', $def );
$this->deleteAndMove = $request->getBool( 'wpDeleteAndMove' );
$this->moveOverShared = $request->getBool( 'wpMoveOverSharedFile' );
$this->watch = $request->getCheck( 'wpWatch' ) && $user->isRegistered();
// Similar to other SpecialPage/Action classes, when tokens fail (likely due to reset or expiry),
// do not show an error but show the form again for easy re-submit.
if ( $isSubmit && $user->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) {
// Check rights
$permStatus = $this->permManager->getPermissionStatus( 'move', $user, $this->oldTitle,
PermissionManager::RIGOR_SECURE );
// If the account is "hard" blocked, auto-block IP
DeferredUpdates::addCallableUpdate( [ $user, 'spreadAnyEditBlock' ] );
if ( !$permStatus->isGood() ) {
throw new PermissionsError( 'move', $permStatus );
}
$this->doSubmit();
} else {
// Avoid primary DB connection on form view (T283265)
$permStatus = $this->permManager->getPermissionStatus( 'move', $user, $this->oldTitle,
PermissionManager::RIGOR_FULL );
if ( !$permStatus->isGood() ) {
DeferredUpdates::addCallableUpdate( [ $user, 'spreadAnyEditBlock' ] );
throw new PermissionsError( 'move', $permStatus );
}
$this->showForm();
}
}
/**
* Show the form
*
* @param ?StatusValue $status Form submission status.
* If it is a PermissionStatus, a special message will be shown.
*/
private function showForm( ?StatusValue $status = null ) {
$this->getSkin()->setRelevantTitle( $this->oldTitle );
$out = $this->getOutput();
$out->setPageTitleMsg( $this->msg( 'move-page' )->plaintextParams( $this->oldTitle->getPrefixedText() ) );
$out->addModuleStyles( [
'mediawiki.special',
'mediawiki.interface.helpers.styles'
] );
$out->addModules( 'mediawiki.misc-authed-ooui' );
$this->addHelpLink( 'Help:Moving a page' );
$handler = $this->contentHandlerFactory
->getContentHandler( $this->oldTitle->getContentModel() );
$createRedirect = $handler->supportsRedirects() && !(
// Do not create redirects for wikitext message overrides (T376399).
// Maybe one day they will have a custom content model and this special case won't be needed.
$this->oldTitle->getNamespace() === NS_MEDIAWIKI &&
$this->oldTitle->getContentModel() === CONTENT_MODEL_WIKITEXT
);
if ( $this->getConfig()->get( MainConfigNames::FixDoubleRedirects ) ) {
$out->addWikiMsg( 'movepagetext' );
} else {
$out->addWikiMsg( $createRedirect ?
'movepagetext-noredirectfixer' :
'movepagetext-noredirectsupport' );
}
if ( $this->oldTitle->getNamespace() === NS_USER && !$this->oldTitle->isSubpage() ) {
$out->addHTML(
Html::warningBox(
$out->msg( 'moveuserpage-warning' )->parse(),
'mw-moveuserpage-warning'
)
);
} elseif ( $this->oldTitle->getNamespace() === NS_CATEGORY ) {
$out->addHTML(
Html::warningBox(
$out->msg( 'movecategorypage-warning' )->parse(),
'mw-movecategorypage-warning'
)
);
}
$deleteAndMove = false;
$moveOverShared = false;
$user = $this->getUser();
$newTitle = $this->newTitle;
if ( !$newTitle ) {
# Show the current title as a default
# when the form is first opened.
$newTitle = $this->oldTitle;
} elseif ( !$status ) {
# If a title was supplied, probably from the move log revert
# link, check for validity. We can then show some diagnostic
# information and save a click.
$mp = $this->movePageFactory->newMovePage( $this->oldTitle, $newTitle );
$status = $mp->isValidMove();
$status->merge( $mp->probablyCanMove( $this->getAuthority() ) );
}
if ( !$status ) {
$status = StatusValue::newGood();
}
if ( count( $status->getMessages() ) == 1 ) {
if ( $status->hasMessage( 'articleexists' )
&& $this->permManager->quickUserCan( 'delete', $user, $newTitle )
) {
$out->addHTML(
Html::warningBox(
$out->msg( 'delete_and_move_text', $newTitle->getPrefixedText() )->parse()
)
);
$deleteAndMove = true;
$status = StatusValue::newGood();
} elseif ( $status->hasMessage( 'redirectexists' ) && (
// Any user that can delete normally can also delete a redirect here
$this->permManager->quickUserCan( 'delete-redirect', $user, $newTitle ) ||
$this->permManager->quickUserCan( 'delete', $user, $newTitle ) )
) {
$out->addHTML(
Html::warningBox(
$out->msg( 'delete_redirect_and_move_text', $newTitle->getPrefixedText() )->parse()
)
);
$deleteAndMove = true;
$status = StatusValue::newGood();
} elseif ( $status->hasMessage( 'file-exists-sharedrepo' )
&& $this->permManager->userHasRight( $user, 'reupload-shared' )
) {
$out->addHTML(
Html::warningBox(
$out->msg( 'move-over-sharedrepo', $newTitle->getPrefixedText() )->parse()
)
);
$moveOverShared = true;
$status = StatusValue::newGood();
}
}
$oldTalk = $this->oldTitle->getTalkPageIfDefined();
$oldTitleSubpages = $this->oldTitle->hasSubpages();
$oldTitleTalkSubpages = $this->oldTitle->getTalkPageIfDefined()->hasSubpages();
$canMoveSubpage = ( $oldTitleSubpages || $oldTitleTalkSubpages ) &&
$this->permManager->quickUserCan(
'move-subpages',
$user,
$this->oldTitle
);
# We also want to be able to move assoc. subpage talk-pages even if base page
# has no associated talk page, so || with $oldTitleTalkSubpages.
$considerTalk = !$this->oldTitle->isTalkPage() &&
( $oldTalk->exists()
|| ( $oldTitleTalkSubpages && $canMoveSubpage ) );
if ( $this->getConfig()->get( MainConfigNames::FixDoubleRedirects ) ) {
$queryBuilder = $this->dbProvider->getReplicaDatabase()->newSelectQueryBuilder()
->select( '1' )
->from( 'redirect' )
->where( [ 'rd_namespace' => $this->oldTitle->getNamespace() ] )
->andWhere( [ 'rd_title' => $this->oldTitle->getDBkey() ] )
->andWhere( [ 'rd_interwiki' => '' ] );
$hasRedirects = (bool)$queryBuilder->caller( __METHOD__ )->fetchField();
} else {
$hasRedirects = false;
}
$messages = $status->getMessages();
if ( $messages ) {
if ( $status instanceof PermissionStatus ) {
$action_desc = $this->msg( 'action-move' )->plain();
$errMsgHtml = $this->msg( 'permissionserrorstext-withaction',
count( $messages ), $action_desc )->parseAsBlock();
} else {
$errMsgHtml = $this->msg( 'cannotmove', count( $messages ) )->parseAsBlock();
}
if ( count( $messages ) == 1 ) {
$errMsgHtml .= $this->msg( $messages[0] )->parseAsBlock();
} else {
$errStr = [];
foreach ( $messages as $msg ) {
$errStr[] = $this->msg( $msg )->parse();
}
$errMsgHtml .= '<ul><li>' . implode( "</li>\n<li>", $errStr ) . "</li></ul>\n";
}
$out->addHTML( Html::errorBox( $errMsgHtml ) );
}
if ( $this->restrictionStore->isProtected( $this->oldTitle, 'move' ) ) {
# Is the title semi-protected?
if ( $this->restrictionStore->isSemiProtected( $this->oldTitle, 'move' ) ) {
$noticeMsg = 'semiprotectedpagemovewarning';
} else {
# Then it must be protected based on static groups (regular)
$noticeMsg = 'protectedpagemovewarning';
}
LogEventsList::showLogExtract(
$out,
'protect',
$this->oldTitle,
'',
[ 'lim' => 1, 'msgKey' => $noticeMsg ]
);
}
// Length limit for wpReason and wpNewTitleMain is enforced in the
// mediawiki.special.movePage module
$immovableNamespaces = [];
foreach ( $this->getLanguage()->getNamespaces() as $nsId => $_ ) {
if ( !$this->nsInfo->isMovable( $nsId ) ) {
$immovableNamespaces[] = $nsId;
}
}
$out->enableOOUI();
$fields = [];
$fields[] = new FieldLayout(
new ComplexTitleInputWidget( [
'id' => 'wpNewTitle',
'namespace' => [
'id' => 'wpNewTitleNs',
'name' => 'wpNewTitleNs',
'value' => $newTitle->getNamespace(),
'exclude' => $immovableNamespaces,
],
'title' => [
'id' => 'wpNewTitleMain',
'name' => 'wpNewTitleMain',
'value' => $newTitle->getText(),
// Inappropriate, since we're expecting the user to input a non-existent page's title
'suggestions' => false,
],
'infusable' => true,
] ),
[
'label' => $this->msg( 'newtitle' )->text(),
'align' => 'top',
]
);
$options = Html::listDropdownOptions(
$this->msg( 'movepage-reason-dropdown' )
->page( $this->oldTitle )
->inContentLanguage()
->text(),
[ 'other' => $this->msg( 'movereasonotherlist' )->text() ]
);
$options = Html::listDropdownOptionsOoui( $options );
$fields[] = new FieldLayout(
new DropdownInputWidget( [
'name' => 'wpReasonList',
'inputId' => 'wpReasonList',
'infusable' => true,
'value' => $this->getRequest()->getText( 'wpReasonList', 'other' ),
'options' => $options,
] ),
[
'label' => $this->msg( 'movereason' )->text(),
'align' => 'top',
]
);
// HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
// (e.g. emojis) count for two each. This limit is overridden in JS to instead count
// Unicode codepoints.
$fields[] = new FieldLayout(
new TextInputWidget( [
'name' => 'wpReason',
'id' => 'wpReason',
'maxLength' => CommentStore::COMMENT_CHARACTER_LIMIT,
'infusable' => true,
'value' => $this->getRequest()->getText( 'wpReason' ),
] ),
[
'label' => $this->msg( 'moveotherreason' )->text(),
'align' => 'top',
]
);
if ( $considerTalk ) {
$fields[] = new FieldLayout(
new CheckboxInputWidget( [
'name' => 'wpMovetalk',
'id' => 'wpMovetalk',
'value' => '1',
'selected' => $this->moveTalk,
] ),
[
'label' => $this->msg( 'movetalk' )->text(),
'help' => new HtmlSnippet( $this->msg( 'movepagetalktext' )->parseAsBlock() ),
'helpInline' => true,
'align' => 'inline',
'id' => 'wpMovetalk-field',
]
);
}
if ( $this->permManager->userHasRight( $user, 'suppressredirect' ) ) {
if ( $createRedirect ) {
$isChecked = $this->leaveRedirect;
$isDisabled = false;
} else {
$isChecked = false;
$isDisabled = true;
}
$fields[] = new FieldLayout(
new CheckboxInputWidget( [
'name' => 'wpLeaveRedirect',
'id' => 'wpLeaveRedirect',
'value' => '1',
'selected' => $isChecked,
'disabled' => $isDisabled,
] ),
[
'label' => $this->msg( 'move-leave-redirect' )->text(),
'align' => 'inline',
]
);
}
if ( $hasRedirects ) {
$fields[] = new FieldLayout(
new CheckboxInputWidget( [
'name' => 'wpFixRedirects',
'id' => 'wpFixRedirects',
'value' => '1',
'selected' => $this->fixRedirects,
] ),
[
'label' => $this->msg( 'fix-double-redirects' )->text(),
'align' => 'inline',
]
);
}
if ( $canMoveSubpage ) {
$maximumMovedPages = $this->getConfig()->get( MainConfigNames::MaximumMovedPages );
$fields[] = new FieldLayout(
new CheckboxInputWidget( [
'name' => 'wpMovesubpages',
'id' => 'wpMovesubpages',
'value' => '1',
'selected' => $this->moveSubpages,
] ),
[
'label' => new HtmlSnippet(
$this->msg(
( $this->oldTitle->hasSubpages()
? 'move-subpages'
: 'move-talk-subpages' )
)->numParams( $maximumMovedPages )->params( $maximumMovedPages )->parse()
),
'align' => 'inline',
]
);
}
# Don't allow watching if user is not logged in
if ( $user->isRegistered() ) {
$watchChecked = ( $this->watch || $this->userOptionsLookup->getBoolOption( $user, 'watchmoves' )
|| $this->watchlistManager->isWatched( $user, $this->oldTitle ) );
$fields[] = new FieldLayout(
new CheckboxInputWidget( [
'name' => 'wpWatch',
'id' => 'watch', # ew
'value' => '1',
'selected' => $watchChecked,
] ),
[
'label' => $this->msg( 'move-watch' )->text(),
'align' => 'inline',
]
);
}
$hiddenFields = '';
if ( $moveOverShared ) {
$hiddenFields .= Html::hidden( 'wpMoveOverSharedFile', '1' );
}
if ( $deleteAndMove ) {
$fields[] = new FieldLayout(
new CheckboxInputWidget( [
'name' => 'wpDeleteAndMove',
'id' => 'wpDeleteAndMove',
'value' => '1',
] ),
[
'label' => $this->msg( 'delete_and_move_confirm', $newTitle->getPrefixedText() )->text(),
'align' => 'inline',
]
);
}
$fields[] = new FieldLayout(
new ButtonInputWidget( [
'name' => 'wpMove',
'value' => $this->msg( 'movepagebtn' )->text(),
'label' => $this->msg( 'movepagebtn' )->text(),
'flags' => [ 'primary', 'progressive' ],
'type' => 'submit',
] ),
[
'align' => 'top',
]
);
$fieldset = new FieldsetLayout( [
'label' => $this->msg( 'move-page-legend' )->text(),
'id' => 'mw-movepage-table',
'items' => $fields,
] );
$form = new FormLayout( [
'method' => 'post',
'action' => $this->getPageTitle()->getLocalURL( 'action=submit' ),
'id' => 'movepage',
] );
$form->appendContent(
$fieldset,
new HtmlSnippet(
$hiddenFields .
Html::hidden( 'wpOldTitle', $this->oldTitle->getPrefixedText() ) .
Html::hidden( 'wpEditToken', $user->getEditToken() )
)
);
$out->addHTML(
new PanelLayout( [
'classes' => [ 'movepage-wrapper' ],
'expanded' => false,
'padded' => true,
'framed' => true,
'content' => $form,
] )
);
if ( $this->getAuthority()->isAllowed( 'editinterface' ) ) {
$link = $this->getLinkRenderer()->makeKnownLink(
$this->msg( 'movepage-reason-dropdown' )->inContentLanguage()->getTitle(),
$this->msg( 'movepage-edit-reasonlist' )->text(),
[],
[ 'action' => 'edit' ]
);
$out->addHTML( Html::rawElement( 'p', [ 'class' => 'mw-movepage-editreasons' ], $link ) );
}
$this->showLogFragment( $this->oldTitle );
$this->showSubpages( $this->oldTitle );
}
private function doSubmit() {
$user = $this->getUser();
if ( $user->pingLimiter( 'move' ) ) {
throw new ThrottledError;
}
$ot = $this->oldTitle;
$nt = $this->newTitle;
# don't allow moving to pages with # in
if ( !$nt || $nt->hasFragment() ) {
$this->showForm( StatusValue::newFatal( 'badtitletext' ) );
return;
}
# Show a warning if the target file exists on a shared repo
if ( $nt->getNamespace() === NS_FILE
&& !( $this->moveOverShared && $this->permManager->userHasRight( $user, 'reupload-shared' ) )
&& !$this->repoGroup->getLocalRepo()->findFile( $nt )
&& $this->repoGroup->findFile( $nt )
) {
$this->showForm( StatusValue::newFatal( 'file-exists-sharedrepo' ) );
return;
}
# Delete to make way if requested
if ( $this->deleteAndMove ) {
$redir2 = $nt->isSingleRevRedirect();
$permStatus = $this->permManager->getPermissionStatus(
$redir2 ? 'delete-redirect' : 'delete',
$user, $nt
);
if ( !$permStatus->isGood() ) {
if ( $redir2 ) {
if ( !$this->permManager->userCan( 'delete', $user, $nt ) ) {
// Cannot delete-redirect, or delete normally
$this->showForm( $permStatus );
return;
} else {
// Cannot delete-redirect, but can delete normally,
// so log as a normal deletion
$redir2 = false;
}
} else {
// Cannot delete normally
$this->showForm( $permStatus );
return;
}
}
$page = $this->wikiPageFactory->newFromTitle( $nt );
$delPage = $this->deletePageFactory->newDeletePage( $page, $user );
// Small safety margin to guard against concurrent edits
if ( $delPage->isBatchedDelete( 5 ) ) {
$this->showForm( StatusValue::newFatal( 'movepage-delete-first' ) );
return;
}
$reason = $this->msg( 'delete_and_move_reason', $ot )->inContentLanguage()->text();
// Delete an associated image if there is
if ( $nt->getNamespace() === NS_FILE ) {
$file = $this->repoGroup->getLocalRepo()->newFile( $nt );
$file->load( IDBAccessObject::READ_LATEST );
if ( $file->exists() ) {
$file->deleteFile( $reason, $user, false );
}
}
$deletionLog = $redir2 ? 'delete_redir2' : 'delete';
$deleteStatus = $delPage
->setLogSubtype( $deletionLog )
// Should be redundant thanks to the isBatchedDelete check above.
->forceImmediate( true )
->deleteUnsafe( $reason );
if ( !$deleteStatus->isGood() ) {
$this->showForm( $deleteStatus );
return;
}
}
$handler = $this->contentHandlerFactory->getContentHandler( $ot->getContentModel() );
if ( !$handler->supportsRedirects() || (
// Do not create redirects for wikitext message overrides (T376399).
// Maybe one day they will have a custom content model and this special case won't be needed.
$ot->getNamespace() === NS_MEDIAWIKI &&
$ot->getContentModel() === CONTENT_MODEL_WIKITEXT
) ) {
$createRedirect = false;
} elseif ( $this->permManager->userHasRight( $user, 'suppressredirect' ) ) {
$createRedirect = $this->leaveRedirect;
} else {
$createRedirect = true;
}
# Do the actual move.
$mp = $this->movePageFactory->newMovePage( $ot, $nt );
if ( $ot->isTalkPage() || $nt->isTalkPage() ) {
$this->moveTalk = false;
}
if ( $this->moveSubpages ) {
$this->moveSubpages = $this->permManager->userCan( 'move-subpages', $user, $ot );
}
# check whether the requested actions are permitted / possible
$permStatus = $mp->authorizeMove( $this->getAuthority(), $this->reason );
if ( !$permStatus->isOK() ) {
$this->showForm( $permStatus );
return;
}
$status = $mp->moveIfAllowed( $this->getAuthority(), $this->reason, $createRedirect );
if ( !$status->isOK() ) {
$this->showForm( $status );
return;
}
if ( $this->getConfig()->get( MainConfigNames::FixDoubleRedirects ) &&
$this->fixRedirects ) {
DoubleRedirectJob::fixRedirects( 'move', $ot );
}
$out = $this->getOutput();
$out->setPageTitleMsg( $this->msg( 'pagemovedsub' ) );
$linkRenderer = $this->getLinkRenderer();
$oldLink = $linkRenderer->makeLink(
$ot,
null,
[ 'id' => 'movepage-oldlink' ],
[ 'redirect' => 'no' ]
);
$newLink = $linkRenderer->makeKnownLink(
$nt,
null,
[ 'id' => 'movepage-newlink' ]
);
$oldText = $ot->getPrefixedText();
$newText = $nt->getPrefixedText();
if ( $status->getValue()['redirectRevision'] !== null ) {
$msgName = 'movepage-moved-redirect';
} else {
$msgName = 'movepage-moved-noredirect';
}
$out->addHTML( $this->msg( 'movepage-moved' )->rawParams( $oldLink,
$newLink )->params( $oldText, $newText )->parseAsBlock() );
$out->addWikiMsg( $msgName );
$this->getHookRunner()->onSpecialMovepageAfterMove( $this, $ot, $nt );
/*
* Now we move extra pages we've been asked to move: subpages and talk
* pages.
*
* First, make a list of id's. This might be marginally less efficient
* than a more direct method, but this is not a highly performance-cri-
* tical code path and readable code is more important here.
*
* If the target namespace doesn't allow subpages, moving with subpages
* would mean that you couldn't move them back in one operation, which
* is bad.
* @todo FIXME: A specific error message should be given in this case.
*/
// @todo FIXME: Use MovePage::moveSubpages() here
$dbr = $this->dbProvider->getReplicaDatabase();
if ( $this->moveSubpages && (
$this->nsInfo->hasSubpages( $nt->getNamespace() ) || (
$this->moveTalk
&& $this->nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
)
) ) {
$conds = [
$dbr->expr(
'page_title',
IExpression::LIKE,
new LikeValue( $ot->getDBkey() . '/', $dbr->anyString() )
)->or( 'page_title', '=', $ot->getDBkey() )
];
$conds['page_namespace'] = [];
if ( $this->nsInfo->hasSubpages( $nt->getNamespace() ) ) {
$conds['page_namespace'][] = $ot->getNamespace();
}
if ( $this->moveTalk &&
$this->nsInfo->hasSubpages( $nt->getTalkPage()->getNamespace() )
) {
$conds['page_namespace'][] = $ot->getTalkPage()->getNamespace();
}
} elseif ( $this->moveTalk ) {
$conds = [
'page_namespace' => $ot->getTalkPage()->getNamespace(),
'page_title' => $ot->getDBkey()
];
} else {
# Skip the query
$conds = null;
}
$extraPages = [];
if ( $conds !== null ) {
$extraPages = $this->titleFactory->newTitleArrayFromResult(
$dbr->newSelectQueryBuilder()
->select( [ 'page_id', 'page_namespace', 'page_title' ] )
->from( 'page' )
->where( $conds )
->caller( __METHOD__ )->fetchResultSet()
);
}
$extraOutput = [];
$count = 1;
foreach ( $extraPages as $oldSubpage ) {
if ( $ot->equals( $oldSubpage ) || $nt->equals( $oldSubpage ) ) {
# Already did this one.
continue;
}
$newPageName = preg_replace(
'#^' . preg_quote( $ot->getDBkey(), '#' ) . '#',
StringUtils::escapeRegexReplacement( $nt->getDBkey() ), # T23234
$oldSubpage->getDBkey()
);
if ( $oldSubpage->isSubpage() && ( $ot->isTalkPage() xor $nt->isTalkPage() ) ) {
// Moving a subpage from a subject namespace to a talk namespace or vice-versa
$newNs = $nt->getNamespace();
} elseif ( $oldSubpage->isTalkPage() ) {
$newNs = $nt->getTalkPage()->getNamespace();
} else {
$newNs = $nt->getSubjectPage()->getNamespace();
}
# T16385: we need makeTitleSafe because the new page names may
# be longer than 255 characters.
$newSubpage = Title::makeTitleSafe( $newNs, $newPageName );
if ( !$newSubpage ) {
$oldLink = $linkRenderer->makeKnownLink( $oldSubpage );
$extraOutput[] = $this->msg( 'movepage-page-unmoved' )->rawParams( $oldLink )
->params( Title::makeName( $newNs, $newPageName ) )->escaped();
continue;
}
$mp = $this->movePageFactory->newMovePage( $oldSubpage, $newSubpage );
# This was copy-pasted from Renameuser, bleh.
if ( $newSubpage->exists() && !$mp->isValidMove()->isOK() ) {
$link = $linkRenderer->makeKnownLink( $newSubpage );
$extraOutput[] = $this->msg( 'movepage-page-exists' )->rawParams( $link )->escaped();
} else {
$status = $mp->moveIfAllowed( $this->getAuthority(), $this->reason, $createRedirect );
if ( $status->isOK() ) {
if ( $this->fixRedirects ) {
DoubleRedirectJob::fixRedirects( 'move', $oldSubpage );
}
$oldLink = $linkRenderer->makeLink(
$oldSubpage,
null,
[],
[ 'redirect' => 'no' ]
);
$newLink = $linkRenderer->makeKnownLink( $newSubpage );
$extraOutput[] = $this->msg( 'movepage-page-moved' )
->rawParams( $oldLink, $newLink )->escaped();
++$count;
$maximumMovedPages =
$this->getConfig()->get( MainConfigNames::MaximumMovedPages );
if ( $count >= $maximumMovedPages ) {
$extraOutput[] = $this->msg( 'movepage-max-pages' )
->numParams( $maximumMovedPages )->escaped();
break;
}
} else {
$oldLink = $linkRenderer->makeKnownLink( $oldSubpage );
$newLink = $linkRenderer->makeLink( $newSubpage );
$extraOutput[] = $this->msg( 'movepage-page-unmoved' )
->rawParams( $oldLink, $newLink )->escaped();
}
}
}
if ( $extraOutput !== [] ) {
$out->addHTML( "<ul>\n<li>" . implode( "</li>\n<li>", $extraOutput ) . "</li>\n</ul>" );
}
# Deal with watches (we don't watch subpages)
$this->watchlistManager->setWatch( $this->watch, $this->getAuthority(), $ot );
$this->watchlistManager->setWatch( $this->watch, $this->getAuthority(), $nt );
}
private function showLogFragment( $title ) {
$moveLogPage = new LogPage( 'move' );
$out = $this->getOutput();
$out->addHTML( Xml::element( 'h2', null, $moveLogPage->getName()->text() ) );
LogEventsList::showLogExtract( $out, 'move', $title );
}
/**
* Show subpages of the page being moved. Section is not shown if both current
* namespace does not support subpages and no talk subpages were found.
*
* @param Title $title Page being moved.
*/
private function showSubpages( $title ) {
$maximumMovedPages = $this->getConfig()->get( MainConfigNames::MaximumMovedPages );
$nsHasSubpages = $this->nsInfo->hasSubpages( $title->getNamespace() );
$subpages = $title->getSubpages( $maximumMovedPages + 1 );
$count = $subpages instanceof TitleArrayFromResult ? $subpages->count() : 0;
$titleIsTalk = $title->isTalkPage();
$subpagesTalk = $title->getTalkPage()->getSubpages( $maximumMovedPages + 1 );
$countTalk = $subpagesTalk instanceof TitleArrayFromResult ? $subpagesTalk->count() : 0;
$totalCount = $count + $countTalk;
if ( !$nsHasSubpages && $countTalk == 0 ) {
return;
}
$this->getOutput()->wrapWikiMsg(
'== $1 ==',
[ 'movesubpage', ( $titleIsTalk ? $count : $totalCount ) ]
);
if ( $nsHasSubpages ) {
$this->showSubpagesList(
$subpages, $count, 'movesubpagetext', 'movesubpagetext-truncated', true
);
}
if ( !$titleIsTalk && $countTalk > 0 ) {
$this->showSubpagesList(
$subpagesTalk, $countTalk, 'movesubpagetalktext', 'movesubpagetalktext-truncated'
);
}
}
private function showSubpagesList( $subpages, $pagecount, $msg, $truncatedMsg, $noSubpageMsg = false ) {
$out = $this->getOutput();
# No subpages.
if ( $pagecount == 0 && $noSubpageMsg ) {
$out->addWikiMsg( 'movenosubpage' );
return;
}
$maximumMovedPages = $this->getConfig()->get( MainConfigNames::MaximumMovedPages );
if ( $pagecount > $maximumMovedPages ) {
$subpages = $this->truncateSubpagesList( $subpages );
$out->addWikiMsg( $truncatedMsg, $this->getLanguage()->formatNum( $maximumMovedPages ) );
} else {
$out->addWikiMsg( $msg, $this->getLanguage()->formatNum( $pagecount ) );
}
$out->addHTML( "<ul>\n" );
$linkBatch = $this->linkBatchFactory->newLinkBatch( $subpages );
$linkBatch->setCaller( __METHOD__ );
$linkBatch->execute();
$linkRenderer = $this->getLinkRenderer();
foreach ( $subpages as $subpage ) {
$link = $linkRenderer->makeLink( $subpage );
$out->addHTML( "<li>$link</li>\n" );
}
$out->addHTML( "</ul>\n" );
}
private function truncateSubpagesList( iterable $subpages ): array {
$returnArray = [];
foreach ( $subpages as $subpage ) {
$returnArray[] = $subpage;
if ( count( $returnArray ) >= $this->getConfig()->get( MainConfigNames::MaximumMovedPages ) ) {
break;
}
}
return $returnArray;
}
/**
* Return an array of subpages beginning with $search that this special page will accept.
*
* @param string $search Prefix to search for
* @param int $limit Maximum number of results to return (usually 10)
* @param int $offset Number of results to skip (usually 0)
* @return string[] Matching subpages
*/
public function prefixSearchSubpages( $search, $limit, $offset ) {
return $this->prefixSearchString( $search, $limit, $offset, $this->searchEngineFactory );
}
protected function getGroupName() {
return 'pagetools';
}
}
/**
* Retain the old class name for backwards compatibility.
* @deprecated since 1.40
*/
class_alias( SpecialMovePage::class, 'MovePageForm' );
|