Remove usage of protection related deprecated Title function
Bug: T306131 Change-Id: I487a12a88ae82c367d1cbb2e52083fe20b27d4ce
This commit is contained in:
parent
fe58a16796
commit
e3a741661a
10 changed files with 57 additions and 26 deletions
|
|
@ -31,6 +31,7 @@ use MediaWiki\Page\PageIdentity;
|
|||
use MediaWiki\Page\WikiPageFactory;
|
||||
use MediaWiki\Permissions\Authority;
|
||||
use MediaWiki\Permissions\PermissionStatus;
|
||||
use MediaWiki\Permissions\RestrictionStore;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\RevisionStore;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
|
|
@ -134,6 +135,9 @@ class MovePage {
|
|||
/** @var PageUpdaterFactory */
|
||||
private $pageUpdaterFactory;
|
||||
|
||||
/** @var RestrictionStore */
|
||||
private $restrictionStore;
|
||||
|
||||
/**
|
||||
* @internal Extensions should use the MovePageFactory.
|
||||
*
|
||||
|
|
@ -154,6 +158,7 @@ class MovePage {
|
|||
* @param MovePageFactory|null $movePageFactory
|
||||
* @param CollationFactory|null $collationFactory
|
||||
* @param PageUpdaterFactory|null $pageUpdaterFactory
|
||||
* @param RestrictionStore|null $restrictionStore
|
||||
* @deprecated since 1.34, hard deprecated since 1.37. Use MovePageFactory instead.
|
||||
*/
|
||||
public function __construct(
|
||||
|
|
@ -173,7 +178,8 @@ class MovePage {
|
|||
UserEditTracker $userEditTracker = null,
|
||||
MovePageFactory $movePageFactory = null,
|
||||
CollationFactory $collationFactory = null,
|
||||
PageUpdaterFactory $pageUpdaterFactory = null
|
||||
PageUpdaterFactory $pageUpdaterFactory = null,
|
||||
RestrictionStore $restrictionStore = null
|
||||
) {
|
||||
if ( !$options ) {
|
||||
wfDeprecatedMsg(
|
||||
|
|
@ -210,6 +216,7 @@ class MovePage {
|
|||
$this->movePageFactory = $movePageFactory ?? $services()->getMovePageFactory();
|
||||
$this->collationFactory = $collationFactory ?? $services()->getCollationFactory();
|
||||
$this->pageUpdaterFactory = $pageUpdaterFactory ?? $services()->getPageUpdaterFactory();
|
||||
$this->restrictionStore = $restrictionStore ?? $services()->getRestrictionStore();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -679,7 +686,7 @@ class MovePage {
|
|||
$this->hookRunner->onTitleMoveStarting( $this->oldTitle, $this->newTitle, $userObj );
|
||||
|
||||
$pageid = $this->oldTitle->getArticleID( Title::READ_LATEST );
|
||||
$protected = $this->oldTitle->isProtected();
|
||||
$protected = $this->restrictionStore->isProtected( $this->oldTitle );
|
||||
|
||||
// Attempt the actual move
|
||||
$moveAttemptResult = $this->moveToInternal( $user, $this->newTitle, $reason, $createRedirect,
|
||||
|
|
|
|||
|
|
@ -3570,10 +3570,11 @@ class OutputPage extends ContextSource {
|
|||
$vars['wgIsProbablyEditable'] = $this->getAuthority()->probablyCan( 'edit', $title );
|
||||
$vars['wgRelevantPageIsProbablyEditable'] = $relevantTitle &&
|
||||
$this->getAuthority()->probablyCan( 'edit', $relevantTitle );
|
||||
foreach ( $services->getRestrictionStore()->listApplicableRestrictionTypes( $title ) as $type ) {
|
||||
$restrictionStore = $services->getRestrictionStore();
|
||||
foreach ( $restrictionStore->listApplicableRestrictionTypes( $title ) as $type ) {
|
||||
// Following keys are set in $vars:
|
||||
// wgRestrictionCreate, wgRestrictionEdit, wgRestrictionMove, wgRestrictionUpload
|
||||
$vars['wgRestriction' . ucfirst( $type )] = $title->getRestrictions( $type );
|
||||
$vars['wgRestriction' . ucfirst( $type )] = $restrictionStore->getRestrictions( $title, $type );
|
||||
}
|
||||
if ( $title->isMainPage() ) {
|
||||
$vars['wgIsMainPage'] = true;
|
||||
|
|
|
|||
|
|
@ -2190,7 +2190,8 @@ return [
|
|||
$services->getMessageFormatterFactory()->getTextFormatter(
|
||||
$services->getContentLanguage()->getCode()
|
||||
),
|
||||
$services->getArchivedRevisionLookup()
|
||||
$services->getArchivedRevisionLookup(),
|
||||
$services->getRestrictionStore()
|
||||
);
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -111,9 +111,11 @@ class TemplatesOnThisPageFormatter {
|
|||
* @return string
|
||||
*/
|
||||
private function formatTemplate( LinkTarget $target ) {
|
||||
// TODO Would be nice if we didn't have to use Title here
|
||||
// TODO Would be nice to have a better way to convert LinkTarget to PageIdentity
|
||||
$titleObj = Title::newFromLinkTarget( $target );
|
||||
$protected = $this->getRestrictionsText( $titleObj->getRestrictions( 'edit' ) );
|
||||
$protected = $this->getRestrictionsText(
|
||||
MediaWikiServices::getInstance()->getRestrictionStore()->getRestrictions( $titleObj, 'edit' )
|
||||
);
|
||||
$editLink = $this->buildEditLink( $titleObj );
|
||||
return '<li>' . $this->linkRenderer->makeLink( $target )
|
||||
. $this->context->msg( 'word-separator' )->escaped()
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ use MediaWiki\Content\IContentHandlerFactory;
|
|||
use MediaWiki\EditPage\SpamChecker;
|
||||
use MediaWiki\HookContainer\HookContainer;
|
||||
use MediaWiki\Permissions\Authority;
|
||||
use MediaWiki\Permissions\RestrictionStore;
|
||||
use MediaWiki\Revision\ArchivedRevisionLookup;
|
||||
use MediaWiki\Revision\RevisionStore;
|
||||
use MediaWiki\Storage\PageUpdaterFactory;
|
||||
|
|
@ -153,6 +154,9 @@ class PageCommandFactory implements
|
|||
/** @var ArchivedRevisionLookup */
|
||||
private $archivedRevisionLookup;
|
||||
|
||||
/** @var RestrictionStore */
|
||||
private $restrictionStore;
|
||||
|
||||
public function __construct(
|
||||
Config $config,
|
||||
LBFactory $lbFactory,
|
||||
|
|
@ -181,7 +185,8 @@ class PageCommandFactory implements
|
|||
LoggerInterface $undeletePageLogger,
|
||||
PageUpdaterFactory $pageUpdaterFactory,
|
||||
ITextFormatter $contLangMsgTextFormatter,
|
||||
ArchivedRevisionLookup $archivedRevisionLookup
|
||||
ArchivedRevisionLookup $archivedRevisionLookup,
|
||||
RestrictionStore $restrictionStore
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->lbFactory = $lbFactory;
|
||||
|
|
@ -211,6 +216,7 @@ class PageCommandFactory implements
|
|||
$this->pageUpdaterFactory = $pageUpdaterFactory;
|
||||
$this->contLangMsgTextFormatter = $contLangMsgTextFormatter;
|
||||
$this->archivedRevisionLookup = $archivedRevisionLookup;
|
||||
$this->restrictionStore = $restrictionStore;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -309,7 +315,8 @@ class PageCommandFactory implements
|
|||
$this->userEditTracker,
|
||||
$this,
|
||||
$this->collationFactory,
|
||||
$this->pageUpdaterFactory
|
||||
$this->pageUpdaterFactory,
|
||||
$this->restrictionStore
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -906,9 +906,10 @@ class CoreParserFunctions {
|
|||
*/
|
||||
public static function protectionlevel( $parser, $type = '', $title = '' ) {
|
||||
$titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
|
||||
if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) {
|
||||
$restrictions = $titleObject->getRestrictions( strtolower( $type ) );
|
||||
# Title::getRestrictions returns an array, its possible it may have
|
||||
$restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
|
||||
if ( $restrictionStore->areRestrictionsLoaded( $titleObject ) || $parser->incrementExpensiveFunctionCount() ) {
|
||||
$restrictions = $restrictionStore->getRestrictions( $titleObject, strtolower( $type ) );
|
||||
# RestrictionStore::getRestrictions returns an array, its possible it may have
|
||||
# multiple values in the future
|
||||
return implode( ',', $restrictions );
|
||||
}
|
||||
|
|
@ -929,11 +930,12 @@ class CoreParserFunctions {
|
|||
*/
|
||||
public static function protectionexpiry( $parser, $type = '', $title = '' ) {
|
||||
$titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
|
||||
if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) {
|
||||
$expiry = $titleObject->getRestrictionExpiry( strtolower( $type ) );
|
||||
// getRestrictionExpiry() returns false on invalid type; trying to
|
||||
$restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
|
||||
if ( $restrictionStore->areRestrictionsLoaded( $titleObject ) || $parser->incrementExpensiveFunctionCount() ) {
|
||||
$expiry = $restrictionStore->getRestrictionExpiry( $titleObject, strtolower( $type ) );
|
||||
// getRestrictionExpiry() returns null on invalid type; trying to
|
||||
// match protectionlevel() function that returns empty string instead
|
||||
if ( $expiry === false ) {
|
||||
if ( $expiry === null ) {
|
||||
$expiry = '';
|
||||
}
|
||||
return $expiry;
|
||||
|
|
@ -1466,13 +1468,15 @@ class CoreParserFunctions {
|
|||
*/
|
||||
public static function cascadingsources( $parser, $title = '' ) {
|
||||
$titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
|
||||
if ( $titleObject->areCascadeProtectionSourcesLoaded()
|
||||
$restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
|
||||
if ( $restrictionStore->areCascadeProtectionSourcesLoaded( $titleObject )
|
||||
|| $parser->incrementExpensiveFunctionCount()
|
||||
) {
|
||||
$names = [];
|
||||
$sources = $titleObject->getCascadeProtectionSources();
|
||||
foreach ( $sources[0] as $sourceTitle ) {
|
||||
$names[] = $sourceTitle->getPrefixedText();
|
||||
$sources = $restrictionStore->getCascadeProtectionSources( $titleObject );
|
||||
$titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
|
||||
foreach ( $sources[0] as $sourcePageIdentity ) {
|
||||
$names[] = $titleFormatter->getPrefixedText( $sourcePageIdentity );
|
||||
}
|
||||
return implode( '|', $names );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1389,14 +1389,15 @@ class SkinTemplate extends Skin {
|
|||
}
|
||||
}
|
||||
|
||||
$restrictionStore = $services->getRestrictionStore();
|
||||
if ( $this->getAuthority()->probablyCan( 'protect', $title ) &&
|
||||
$services->getRestrictionStore()->listApplicableRestrictionTypes( $title ) &&
|
||||
$restrictionStore->listApplicableRestrictionTypes( $title ) &&
|
||||
$permissionManager->getNamespaceRestrictionLevels(
|
||||
$title->getNamespace(),
|
||||
$performer->getUser()
|
||||
) !== [ '' ]
|
||||
) {
|
||||
$mode = $title->isProtected() ? 'unprotect' : 'protect';
|
||||
$mode = $restrictionStore->isProtected( $title ) ? 'unprotect' : 'protect';
|
||||
$content_navigation['actions'][$mode] = [
|
||||
'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
|
||||
'text' => $this->getSkinNavOverrideableLabel(
|
||||
|
|
|
|||
|
|
@ -899,6 +899,7 @@ class SpecialPageFactory {
|
|||
'WikiPageFactory',
|
||||
'SearchEngineFactory',
|
||||
'WatchlistManager',
|
||||
'RestrictionStore',
|
||||
]
|
||||
],
|
||||
'Mycontributions' => [
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use MediaWiki\MainConfigNames;
|
|||
use MediaWiki\Page\MovePageFactory;
|
||||
use MediaWiki\Page\WikiPageFactory;
|
||||
use MediaWiki\Permissions\PermissionManager;
|
||||
use MediaWiki\Permissions\RestrictionStore;
|
||||
use MediaWiki\User\UserOptionsLookup;
|
||||
use MediaWiki\Watchlist\WatchlistManager;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
|
|
@ -101,6 +102,9 @@ class MovePageForm extends UnlistedSpecialPage {
|
|||
/** @var WatchlistManager */
|
||||
private $watchlistManager;
|
||||
|
||||
/** @var RestrictionStore */
|
||||
private $restrictionStore;
|
||||
|
||||
/**
|
||||
* @param MovePageFactory $movePageFactory
|
||||
* @param PermissionManager $permManager
|
||||
|
|
@ -113,6 +117,7 @@ class MovePageForm extends UnlistedSpecialPage {
|
|||
* @param WikiPageFactory $wikiPageFactory
|
||||
* @param SearchEngineFactory $searchEngineFactory
|
||||
* @param WatchlistManager $watchlistManager
|
||||
* @param RestrictionStore $restrictionStore
|
||||
*/
|
||||
public function __construct(
|
||||
MovePageFactory $movePageFactory,
|
||||
|
|
@ -125,7 +130,8 @@ class MovePageForm extends UnlistedSpecialPage {
|
|||
RepoGroup $repoGroup,
|
||||
WikiPageFactory $wikiPageFactory,
|
||||
SearchEngineFactory $searchEngineFactory,
|
||||
WatchlistManager $watchlistManager
|
||||
WatchlistManager $watchlistManager,
|
||||
RestrictionStore $restrictionStore
|
||||
) {
|
||||
parent::__construct( 'Movepage' );
|
||||
$this->movePageFactory = $movePageFactory;
|
||||
|
|
@ -139,6 +145,7 @@ class MovePageForm extends UnlistedSpecialPage {
|
|||
$this->wikiPageFactory = $wikiPageFactory;
|
||||
$this->searchEngineFactory = $searchEngineFactory;
|
||||
$this->watchlistManager = $watchlistManager;
|
||||
$this->restrictionStore = $restrictionStore;
|
||||
}
|
||||
|
||||
public function doesWrites() {
|
||||
|
|
@ -383,9 +390,9 @@ class MovePageForm extends UnlistedSpecialPage {
|
|||
$out->addHTML( Html::errorBox( $errMsgHtml ) );
|
||||
}
|
||||
|
||||
if ( $this->oldTitle->isProtected( 'move' ) ) {
|
||||
if ( $this->restrictionStore->isProtected( $this->oldTitle, 'move' ) ) {
|
||||
# Is the title semi-protected?
|
||||
if ( $this->oldTitle->isSemiProtected( 'move' ) ) {
|
||||
if ( $this->restrictionStore->isSemiProtected( $this->oldTitle, 'move' ) ) {
|
||||
$noticeMsg = 'semiprotectedpagemovewarning';
|
||||
} else {
|
||||
# Then it must be protected based on static groups (regular)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class ApiProtectTest extends ApiTestCase {
|
|||
|
||||
$this->assertArrayHasKey( 'protect', $apiResult );
|
||||
$this->assertSame( $name, $apiResult['protect']['title'] );
|
||||
$this->assertTrue( $title->isProtected( 'edit' ) );
|
||||
$this->assertTrue( $this->getServiceContainer()->getRestrictionStore()->isProtected( $title, 'edit' ) );
|
||||
$this->assertTrue( $this->getServiceContainer()->getWatchlistManager()->isTempWatched(
|
||||
$this->getTestSysop()->getUser(),
|
||||
$title
|
||||
|
|
|
|||
Loading…
Reference in a new issue