title: Remove protection related deprecated Title functions

- Title::areCascadeProtectionSourcesLoaded()
- Title::areRestrictionsCascading()
- Title::areRestrictionsLoaded()
- Title::getAllRestrictions()
- Title::getCascadeProtectionSources()
- Title::getFilteredRestrictionTypes()
- Title::getRestrictionExpiry()
- Title::getRestrictionTypes()
- Title::getRestrictions()
- Title::isCascadeProtected()
- Title::isProtected()
- Title::isSemiProtected()
- Title::loadRestrictionsFromRows()

Bug: T306131
Change-Id: Id6c3a648453db51c464faeef2ecac4ffaa0676c1
This commit is contained in:
Umherirrender 2023-05-09 21:15:34 +02:00
parent 32222c9bc7
commit e8bf1a18db
7 changed files with 20 additions and 619 deletions

View file

@ -107,6 +107,21 @@ because of Phabricator reports.
- ::wasConnectionLoss()
* PrevNextNavigationRenderer class, deprecated in 1.39,
has been removed.
* The following methods in the Title class, deprecated since 1.37, have been
removed:
- ::areCascadeProtectionSourcesLoaded()
- ::areRestrictionsCascading()
- ::areRestrictionsLoaded()
- ::getAllRestrictions()
- ::getCascadeProtectionSources()
- ::getFilteredRestrictionTypes()
- ::getRestrictionExpiry()
- ::getRestrictionTypes()
- ::getRestrictions()
- ::isCascadeProtected()
- ::isProtected()
- ::isSemiProtected()
- ::loadRestrictionsFromRows()
* LinkBatch::__construct() now requires that all parameters be passed. The
fallback to MediaWikiServices emitted deprecation notices since 1.35.
* The methods IndexPager::getPagingLinks(), IndexPager::getLimitLinks() and

View file

@ -4965,7 +4965,7 @@ config-schema:
Set of available actions that can be restricted via action=protect
You probably shouldn't change this.
Translated through restriction-* messages.
Title::getRestrictionTypes() will remove restrictions that are not
RestrictionStore::listApplicableRestrictionTypes() will remove restrictions that are not
applicable to a specific title (create and upload)
RestrictionLevels:
default:

View file

@ -7881,7 +7881,7 @@ class MainConfigSchema {
* You probably shouldn't change this.
*
* Translated through restriction-* messages.
* Title::getRestrictionTypes() will remove restrictions that are not
* RestrictionStore::listApplicableRestrictionTypes() will remove restrictions that are not
* applicable to a specific title (create and upload)
*/
public const RestrictionTypes = [

View file

@ -150,8 +150,7 @@ class RestrictionStore {
* @param PageIdentity $page Must be local
* @param string $action
* @return ?string 14-char timestamp, or 'infinity' if the page is protected forever or not
* protected at all, or null if the action is not recognized. NOTE: This returns null for
* unrecognized actions, unlike Title::getRestrictionExpiry which returns false.
* protected at all, or null if the action is not recognized.
*/
public function getRestrictionExpiry( PageIdentity $page, string $action ): ?string {
$page->assertWiki( PageIdentity::LOCAL );
@ -545,9 +544,7 @@ class RestrictionStore {
* @param PageIdentity $page Must be local
* @return array[] Two elements: First is an array of PageIdentity objects of the pages from
* which cascading restrictions have come, which may be empty. Second is an array like that
* returned by getAllRestrictions(). NOTE: The first element of the return is always an
* array, unlike Title::getCascadeProtectionSources where the first element is false if there
* are no sources.
* returned by getAllRestrictions().
*/
public function getCascadeProtectionSources( PageIdentity $page ): array {
$page->assertWiki( PageIdentity::LOCAL );

View file

@ -2465,42 +2465,11 @@ class Title implements LinkTarget, PageIdentity, IDBAccessObject {
return $s;
}
/**
* Get a filtered list of all restriction types supported by this wiki.
*
* @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::listAllRestrictionTypes instead
*
* @param bool $exists True to get all restriction types that apply to
* titles that do exist, False for all restriction types that apply to
* titles that do not exist
* @return array
*/
public static function getFilteredRestrictionTypes( $exists = true ) {
wfDeprecated( __METHOD__, '1.37' );
return MediaWikiServices::getInstance()
->getRestrictionStore()
->listAllRestrictionTypes( $exists );
}
/**
* Returns restriction types for the current Title
*
* @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::listApplicableRestrictionTypes instead
*
* @return array Applicable restriction types
*/
public function getRestrictionTypes() {
wfDeprecated( __METHOD__, '1.37' );
return MediaWikiServices::getInstance()
->getRestrictionStore()
->listApplicableRestrictionTypes( $this );
}
/**
* Is this title subject to title protection?
* Title protection is the one applied against creation of such title.
*
* @deprecated since 1.37, use RestrictionStore::getRestrictions() instead
* @deprecated since 1.37, use RestrictionStore::getCreateProtection() instead
*
* @return array|bool An associative array representing any existent title
* protection, or false if there's none.
@ -2519,184 +2488,6 @@ class Title implements LinkTarget, PageIdentity, IDBAccessObject {
MediaWikiServices::getInstance()->getRestrictionStore()->deleteCreateProtection( $this );
}
/**
* Is this page "semi-protected" - the *only* protection levels are listed
* in $wgSemiprotectedRestrictionLevels?
*
* @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::isSemiProtected instead
*
* @param string $action Action to check (default: edit)
* @return bool
*/
public function isSemiProtected( $action = 'edit' ) {
wfDeprecated( __METHOD__, '1.37' );
return MediaWikiServices::getInstance()->getRestrictionStore()->isSemiProtected(
$this, $action
);
}
/**
* Does the title correspond to a protected article?
*
* @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::isProtected instead
*
* @param string $action The action the page is protected from,
* by default checks all actions.
* @return bool
*/
public function isProtected( $action = '' ) {
wfDeprecated( __METHOD__, '1.37' );
return MediaWikiServices::getInstance()->getRestrictionStore()->isProtected(
$this, $action
);
}
/**
* Cascading protection: Return true if cascading restrictions apply to this page, false if not.
*
* @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::isCascadeProtected instead
*
* @return bool If the page is subject to cascading restrictions.
*/
public function isCascadeProtected() {
wfDeprecated( __METHOD__, '1.37' );
return MediaWikiServices::getInstance()->getRestrictionStore()->isCascadeProtected( $this );
}
/**
* Determines whether cascading protection sources have already been loaded from
* the database.
*
* @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::areCascadeProtectionSourcesLoaded instead
*
* @return bool
* @since 1.23
*/
public function areCascadeProtectionSourcesLoaded() {
wfDeprecated( __METHOD__, '1.37' );
return MediaWikiServices::getInstance()->getRestrictionStore()
->areCascadeProtectionSourcesLoaded( $this );
}
/**
* Cascading protection: Get the source of any cascading restrictions on this page.
*
* @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::getCascadeProtectionSources instead
*
* @param bool $getPages Whether or not to retrieve the actual pages
* that the restrictions have come from and the actual restrictions
* themselves.
* @return array Two elements: First is an array of Title objects of the
* pages from which cascading restrictions have come if $getPages
* is true, or a bool indicating whether any cascading protection
* applies if $getPages was set to false.
* Second is an array like that returned by Title::getAllRestrictions(),
* or an empty array if $getPages is false.
*/
public function getCascadeProtectionSources( $getPages = true ) {
wfDeprecated( __METHOD__, '1.37' );
$restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
if ( !$getPages ) {
return [ $restrictionStore->isCascadeProtected( $this ), [] ];
}
$ret = $restrictionStore->getCascadeProtectionSources( $this );
$ret[0] = array_map( '\MediaWiki\Title\Title::castFromPageIdentity', $ret[0] );
return $ret;
}
/**
* Accessor for mRestrictionsLoaded
*
* @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::areRestrictionsLoaded instead
*
* @return bool Whether or not the page's restrictions have already been
* loaded from the database
* @since 1.23
*/
public function areRestrictionsLoaded() {
wfDeprecated( __METHOD__, '1.37' );
return MediaWikiServices::getInstance()
->getRestrictionStore()
->areRestrictionsLoaded( $this );
}
/**
* Accessor/initialisation for mRestrictions
*
* @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::getRestrictions instead
*
* @param string $action Action that permission needs to be checked for
* @return array Restriction levels needed to take the action. All levels are
* required. Note that restriction levels are normally user rights, but 'sysop'
* and 'autoconfirmed' are also allowed for backwards compatibility. These should
* be mapped to 'editprotected' and 'editsemiprotected' respectively.
*/
public function getRestrictions( $action ) {
wfDeprecated( __METHOD__, '1.37' );
return MediaWikiServices::getInstance()->getRestrictionStore()->getRestrictions( $this, $action );
}
/**
* Accessor/initialisation for mRestrictions
*
* @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::getAllRestrictions instead
*
* @return array Keys are actions, values are arrays as returned by
* Title::getRestrictions()
* @since 1.23
*/
public function getAllRestrictions() {
wfDeprecated( __METHOD__, '1.37' );
return MediaWikiServices::getInstance()->getRestrictionStore()->getAllRestrictions( $this );
}
/**
* Get the expiry time for the restriction against a given action
*
* @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::getRestrictionExpiry instead
*
* @param string $action
* @return string|bool 14-char timestamp, or 'infinity' if the page is protected forever
* or not protected at all, or false if the action is not recognised.
*/
public function getRestrictionExpiry( $action ) {
wfDeprecated( __METHOD__, '1.37' );
return MediaWikiServices::getInstance()->getRestrictionStore()->getRestrictionExpiry(
$this, $action
) ?? false;
}
/**
* Returns cascading restrictions for the current article
*
* @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::areRestrictionsCascading instead
*
* @return bool
*/
public function areRestrictionsCascading() {
wfDeprecated( __METHOD__, '1.37' );
return MediaWikiServices::getInstance()
->getRestrictionStore()
->areRestrictionsCascading( $this );
}
/**
* Compiles list of active page restrictions from both page table (pre 1.10)
* and page_restrictions table for this existing page.
* Public for usage by LiquidThreads.
*
* @deprecated since 1.37, hard deprecated 1.40, use RestrictionStore::loadRestrictionsFromRows instead
*
* @param stdClass[] $rows Array of db result objects
*/
public function loadRestrictionsFromRows( $rows ) {
wfDeprecated( __METHOD__, '1.37' );
MediaWikiServices::getInstance()->getRestrictionStore()->loadRestrictionsFromRows(
$this, $rows
);
}
/**
* Load restrictions from the page_restrictions table
*

View file

@ -1,16 +1,13 @@
<?php
use MediaWiki\Cache\CacheKeyHelper;
use MediaWiki\Language\RawMessage;
use MediaWiki\Linker\LinkTarget;
use MediaWiki\MainConfigNames;
use MediaWiki\Page\PageIdentity;
use MediaWiki\Page\PageIdentityValue;
use MediaWiki\Permissions\RestrictionStore;
use MediaWiki\Tests\Unit\DummyServicesTrait;
use MediaWiki\Title\Title;
use Wikimedia\Assert\PreconditionException;
use Wikimedia\TestingAccessWrapper;
/**
* @group Database
@ -1832,256 +1829,6 @@ class TitleTest extends MediaWikiIntegrationTestCase {
);
}
/**
* @covers Title::loadRestrictions
*/
public function testLoadRestrictions() {
$this->hideDeprecated( Title::class . '::areRestrictionsLoaded' );
$this->hideDeprecated( Title::class . '::getRestrictionExpiry' );
$title = Title::newFromText( 'UTPage1' );
$title->loadRestrictions();
$this->assertTrue( $title->areRestrictionsLoaded() );
$title = $this->getExistingTestPage( 'UTest1' )->getTitle();
$title->loadRestrictions();
$this->assertTrue( $title->areRestrictionsLoaded() );
$this->assertFalse( $title->getRestrictionExpiry( 'create' ),
"Existing page can't have create protection" );
$this->assertSame( 'infinity', $title->getRestrictionExpiry( 'edit' ) );
$page = $this->getNonexistingTestPage( 'UTest1' );
$title = $page->getTitle();
$protectExpiry = wfTimestamp( TS_MW, time() + 10000 );
$cascade = 0;
$page->doUpdateRestrictions(
[ 'create' => 'sysop' ],
[ 'create' => $protectExpiry ],
$cascade,
'test',
$this->getTestSysop()->getUser()
);
$title->flushRestrictions();
$title->loadRestrictions();
$this->assertSame(
$protectExpiry,
$title->getRestrictionExpiry( 'create' )
);
}
public static function provideRestrictionsRows() {
yield [ [ (object)[
'pr_id' => 1,
'pr_page' => 1,
'pr_type' => 'edit',
'pr_level' => 'sysop',
'pr_cascade' => 0,
'pr_expiry' => 'infinity'
] ] ];
yield [ [ (object)[
'pr_id' => 1,
'pr_page' => 1,
'pr_type' => 'edit',
'pr_level' => 'sysop',
'pr_cascade' => 0,
'pr_expiry' => 'infinity'
] ] ];
yield [ [ (object)[
'pr_id' => 1,
'pr_page' => 1,
'pr_type' => 'move',
'pr_level' => 'sysop',
'pr_cascade' => 0,
'pr_expiry' => wfTimestamp( TS_MW, time() + 10000 )
] ] ];
}
/**
* @covers Title::loadRestrictionsFromRows
* @dataProvider provideRestrictionsRows
*/
public function testloadRestrictionsFromRows( $rows ) {
$this->hideDeprecated( Title::class . '::loadRestrictionsFromRows' );
$this->hideDeprecated( Title::class . '::getRestrictions' );
$this->hideDeprecated( Title::class . '::getRestrictionExpiry' );
$title = $this->getExistingTestPage( 'UTest1' )->getTitle();
$title->loadRestrictionsFromRows( $rows );
$this->assertSame(
$rows[0]->pr_level,
$title->getRestrictions( $rows[0]->pr_type )[0]
);
$this->assertSame(
$rows[0]->pr_expiry,
$title->getRestrictionExpiry( $rows[0]->pr_type )
);
}
/**
* @dataProvider provideRestrictionStoreForwarding
* @covers Title::getFilteredRestrictionTypes
* @covers Title::getRestrictionTypes
* @covers Title::getTitleProtection
* @covers Title::deleteTitleProtection
* @covers Title::isSemiProtected
* @covers Title::isProtected
* @covers Title::isCascadeProtected
* @covers Title::areCascadeProtectionSourcesLoaded
* @covers Title::getCascadeProtectionSources
* @covers Title::areRestrictionsLoaded
* @covers Title::getRestrictions
* @covers Title::getAllRestrictions
* @covers Title::getRestrictionExpiry
* @covers Title::areRestrictionsCascading
* @covers Title::loadRestrictionsFromRows
* @covers Title::loadRestrictions
* @covers Title::flushRestrictions
*/
public function testRestrictionStoreForwarding(
string $method, array $params, $return, array $options = []
) {
$this->hideDeprecated( Title::class . '::' . $method );
$expectedParams = $options['expectedParams'] ?? $params;
if ( isset( $options['static'] ) ) {
$callee = 'Title';
} else {
$callee = $this->getExistingTestPage()->getTitle();
$expectedParams = array_merge( [ $callee ], $expectedParams );
}
$expectedMethod = $options['expectedMethod'] ?? $method;
$mockRestrictionStore = $this->createNoOpMock( RestrictionStore::class, [ $expectedMethod ] );
$expectedCall = $mockRestrictionStore->expects( $this->once() )
->method( $expectedMethod )
->with( ...$expectedParams );
if ( !isset( $options['void'] ) ) {
$expectedCall->willReturn( $return );
}
$this->setService( 'RestrictionStore', $mockRestrictionStore );
$options['expectedReturn'] ??= $return;
$comparisonMethod = isset( $options['weakCompareReturn'] ) ? 'assertEquals' : 'assertSame';
$this->$comparisonMethod( $options['expectedReturn'], [ $callee, $method ]( ...$params ) );
}
public static function provideRestrictionStoreForwarding() {
$pageIdentity = PageIdentityValue::localIdentity( 144, NS_MAIN, 'Sample' );
$title = Title::newFromPageIdentity( $pageIdentity );
return [
[ 'getFilteredRestrictionTypes', [ true ], [ 'abc' ],
[ 'static' => true, 'expectedMethod' => 'listAllRestrictionTypes' ] ],
[ 'getFilteredRestrictionTypes', [ false ], [ 'def' ],
[ 'static' => true, 'expectedMethod' => 'listAllRestrictionTypes' ] ],
[ 'getRestrictionTypes', [], [ 'ghi' ],
[ 'expectedMethod' => 'listApplicableRestrictionTypes' ] ],
[ 'getTitleProtection', [], [ 'jkl' ], [ 'expectedMethod' => 'getCreateProtection' ] ],
[ 'getTitleProtection', [], null,
[ 'expectedMethod' => 'getCreateProtection', 'expectedReturn' => false ] ],
[ 'deleteTitleProtection', [], null,
[ 'expectedMethod' => 'deleteCreateProtection', 'void' => true ] ],
[ 'isSemiProtected', [ 'phlebotomize' ], true ],
[ 'isSemiProtected', [ 'splecotomize' ], false ],
[ 'isProtected', [ 'strezotomize' ], true ],
[ 'isProtected', [ 'chrelotomize' ], false ],
[ 'isCascadeProtected', [], true ],
[ 'isCascadeProtected', [], false ],
[ 'areCascadeProtectionSourcesLoaded', [ true ], true, [ 'expectedParams' => [] ] ],
[ 'areCascadeProtectionSourcesLoaded', [ true ], false, [ 'expectedParams' => [] ] ],
[ 'areCascadeProtectionSourcesLoaded', [ false ], true, [ 'expectedParams' => [] ] ],
[ 'areCascadeProtectionSourcesLoaded', [ false ], false, [ 'expectedParams' => [] ] ],
[ 'getCascadeProtectionSources', [], [ [ $pageIdentity ], [ 'mno' ] ],
[ 'expectedReturn' => [ [ $title ], [ 'mno' ] ], 'weakCompareReturn' => true ] ],
[ 'getCascadeProtectionSources', [], [ [], [] ],
[ 'expectedReturn' => [ [], [] ] ] ],
[ 'getCascadeProtectionSources', [ true ], [ [ $pageIdentity ], [ 'mno' ] ],
[ 'expectedParams' => [], 'expectedReturn' => [ [ $title ], [ 'mno' ] ],
'weakCompareReturn' => true ] ],
[ 'getCascadeProtectionSources', [ true ], [ [], [] ],
[ 'expectedParams' => [], 'expectedReturn' => [ [], [] ] ] ],
[ 'getCascadeProtectionSources', [ false ], false,
[ 'expectedMethod' => 'isCascadeProtected', 'expectedParams' => [],
'expectedReturn' => [ false, [] ] ] ],
[ 'getCascadeProtectionSources', [ false ], true,
[ 'expectedMethod' => 'isCascadeProtected', 'expectedParams' => [],
'expectedReturn' => [ true, [] ] ] ],
[ 'areRestrictionsLoaded', [], true ],
[ 'areRestrictionsLoaded', [], false ],
[ 'getRestrictions', [ 'stu' ], [ 'vwx' ] ],
[ 'getAllRestrictions', [], [ 'yza' ] ],
[ 'getRestrictionExpiry', [ 'bcd' ], 'efg' ],
[ 'getRestrictionExpiry', [ 'hij' ], null, [ 'expectedReturn' => false ] ],
[ 'areRestrictionsCascading', [], true ],
[ 'areRestrictionsCascading', [], false ],
[ 'loadRestrictionsFromRows', [ [ 'hij' ] ], null, [ 'void' => true ] ],
[ 'loadRestrictions', [ 123 ], null,
[ 'void' => true, 'expectedParams' => [ 123 ] ] ],
[ 'flushRestrictions', [], null, [ 'void' => true ] ],
];
}
/**
* @covers Title::getRestrictions
*/
public function testGetRestrictions() {
$this->hideDeprecated( Title::class . '::getRestrictions' );
$title = $this->getExistingTestPage( 'UTest1' )->getTitle();
$rs = $this->getServiceContainer()->getRestrictionStore();
$wrapper = TestingAccessWrapper::newFromObject( $rs );
$wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [
'restrictions' => [
'a' => [ 'sysop' ],
'b' => [ 'sysop' ],
'c' => [ 'sysop' ]
],
] ];
$this->assertArrayEquals( [ 'sysop' ], $title->getRestrictions( 'a' ) );
$this->assertArrayEquals( [], $title->getRestrictions( 'error' ) );
// TODO: maybe test if loadRestrictionsFromRows() is called?
}
/**
* @covers Title::getAllRestrictions
*/
public function testGetAllRestrictions() {
$this->hideDeprecated( Title::class . '::getAllRestrictions' );
$restrictions = [
'a' => [ 'sysop' ],
'b' => [ 'sysop' ],
'c' => [ 'sysop' ],
];
$title = $this->getExistingTestPage( 'UTest1' )->getTitle();
$rs = $this->getServiceContainer()->getRestrictionStore();
$wrapper = TestingAccessWrapper::newFromObject( $rs );
$wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [
'restrictions' => $restrictions
] ];
$this->assertArrayEquals(
$restrictions,
$title->getAllRestrictions()
);
}
/**
* @covers Title::getRestrictionExpiry
*/
public function testGetRestrictionExpiry() {
$this->hideDeprecated( Title::class . '::getRestrictionExpiry' );
$this->hideDeprecated( Title::class . '::getRestrictions' );
$title = $this->getExistingTestPage( 'UTest1' )->getTitle();
$rs = $this->getServiceContainer()->getRestrictionStore();
$wrapper = TestingAccessWrapper::newFromObject( $rs );
$wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [
'expiry' => [
'a' => 'infinity', 'b' => 'infinity', 'c' => 'infinity'
],
// XXX This is bogus, restrictions will never be empty when expiry is not
'restrictions' => [],
] ];
$this->assertSame( 'infinity', $title->getRestrictionExpiry( 'a' ) );
$this->assertArrayEquals( [], $title->getRestrictions( 'error' ) );
}
/**
* @covers Title::getTitleProtection
*/
@ -2090,28 +1837,6 @@ class TitleTest extends MediaWikiIntegrationTestCase {
$this->assertFalse( $title->getTitleProtection() );
}
/**
* @covers Title::isSemiProtected
*/
public function testIsSemiProtected() {
$this->hideDeprecated( Title::class . '::isSemiProtected' );
$title = $this->getExistingTestPage( 'UTest1' )->getTitle();
$this->overrideConfigValues( [
MainConfigNames::SemiprotectedRestrictionLevels => [ 'autoconfirmed' ],
MainConfigNames::RestrictionLevels => [ '', 'autoconfirmed', 'sysop' ]
] );
$rs = $this->getServiceContainer()->getRestrictionStore();
$wrapper = TestingAccessWrapper::newFromObject( $rs );
$wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [
'restrictions' => [ 'edit' => [ 'sysop' ] ],
] ];
$this->assertFalse( $title->isSemiProtected( 'edit' ) );
$wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [
'restrictions' => [ 'edit' => [ 'autoconfirmed' ] ],
] ];
$this->assertTrue( $title->isSemiProtected( 'edit' ) );
}
/**
* @covers Title::deleteTitleProtection
*/
@ -2120,132 +1845,6 @@ class TitleTest extends MediaWikiIntegrationTestCase {
$this->assertFalse( $title->getTitleProtection() );
}
/**
* @covers Title::isProtected
*/
public function testIsProtected() {
$this->hideDeprecated( Title::class . '::isProtected' );
$title = $this->getExistingTestPage( 'UTest1' )->getTitle();
$this->overrideConfigValues( [
MainConfigNames::RestrictionLevels => [ '', 'autoconfirmed', 'sysop' ],
MainConfigNames::RestrictionTypes => [ 'create', 'edit', 'move', 'upload' ]
] );
$rs = $this->getServiceContainer()->getRestrictionStore();
$wrapper = TestingAccessWrapper::newFromObject( $rs );
$wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [
'restrictions' => [ 'edit' => [ 'sysop' ] ],
] ];
$this->assertTrue( $title->isProtected( 'edit' ) );
$wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [
'restrictions' => [ 'edit' => [ 'test' ] ],
] ];
$this->assertFalse( $title->isProtected( 'edit' ) );
}
/**
* @covers Title::isCascadeProtected
*/
public function testIsCascadeProtected() {
$this->hideDeprecated( Title::class . '::isCascadeProtected' );
$page = $this->getExistingTestPage( 'UTest1' );
$title = $page->getTitle();
$rs = $this->getServiceContainer()->getRestrictionStore();
$wrapper = TestingAccessWrapper::newFromObject( $rs );
$wrapper->cache = [ CacheKeyHelper::getKeyForPage( $title ) => [
'has_cascading' => true,
] ];
$this->assertTrue( $title->isCascadeProtected() );
$wrapper->cache = [];
$this->assertFalse( $title->isCascadeProtected() );
$wrapper->cache = [];
$cascade = 1;
$anotherPage = $this->getExistingTestPage( 'UTest2' );
$anotherPage->doUserEditContent(
new WikitextContent( '{{:UTest1}}' ),
$this->getTestSysop()->getUser(),
'test'
);
$anotherPage->doUpdateRestrictions(
[ 'edit' => 'sysop' ],
[],
$cascade,
'test',
$this->getTestSysop()->getUser()
);
$this->assertTrue( $title->isCascadeProtected() );
}
/**
* @covers Title::getCascadeProtectionSources
* @group Broken
*/
public function testGetCascadeProtectionSources() {
$this->hideDeprecated( Title::class . '::getCascadeProtectionSources' );
$page = $this->getExistingTestPage( 'UTest1' );
$title = $page->getTitle();
$title->mCascadeSources = [];
$this->assertArrayEquals(
[ [], [] ],
$title->getCascadeProtectionSources( true )
);
$reflection = new ReflectionClass( $title );
$reflection_property = $reflection->getProperty( 'mHasCascadingRestrictions' );
$reflection_property->setAccessible( true );
$reflection_property->setValue( $title, true );
$this->assertArrayEquals(
[ true, [] ],
$title->getCascadeProtectionSources( false )
);
$title->mCascadeSources = null;
$reflection_property->setValue( $title, null );
$this->assertArrayEquals(
[ false, [] ],
$title->getCascadeProtectionSources( false )
);
$title->mCascadeSources = null;
$reflection_property->setValue( $title, null );
$this->assertArrayEquals(
[ [], [] ],
$title->getCascadeProtectionSources( true )
);
// TODO: this might partially duplicate testIsCascadeProtected method above
$cascade = 1;
$anotherPage = $this->getExistingTestPage( 'UTest2' );
$anotherPage->doUserEditContent(
new WikitextContent( '{{:UTest1}}' ),
$this->getTestSysop()->getUser(),
'test'
);
$anotherPage->doUpdateRestrictions(
[ 'edit' => 'sysop' ],
[],
$cascade,
'test',
$this->getTestSysop()->getUser()
);
$this->assertArrayEquals(
[ true, [] ],
$title->getCascadeProtectionSources( false )
);
$title->mCascadeSources = null;
$result = $title->getCascadeProtectionSources( true );
$this->assertArrayEquals(
[ 'edit' => [ 'sysop' ] ],
$result[1]
);
$this->assertArrayHasKey(
$anotherPage->getTitle()->getArticleID(), $result[0]
);
}
/**
* @covers Title::getCdnUrls
*/

View file

@ -68,7 +68,6 @@ trait MockTitleTrait {
$title->method( 'getPageLanguage' )->willReturn( $props['language'] ?? 'qqx' );
$title->method( 'getContentModel' )
->willReturn( $props['contentModel'] ?? CONTENT_MODEL_WIKITEXT );
$title->method( 'getRestrictions' )->willReturn( [] );
$title->method( 'getTitleProtection' )->willReturn( false );
$title->method( 'canExist' )
->willReturn( $ns >= 0 && empty( $props['interwiki'] ) && $text !== '' );