MediaWiki  master
MediaWiki\Permissions\RestrictionStore Class Reference

Class RestrictionStore. More...

Collaboration diagram for MediaWiki\Permissions\RestrictionStore:

Public Member Functions

 __construct (ServiceOptions $options, WANObjectCache $wanCache, ILoadBalancer $loadBalancer, LinkCache $linkCache, CommentStore $commentStore, HookContainer $hookContainer, PageStore $pageStore)
 
 areCascadeProtectionSourcesLoaded (PageIdentity $page)
 Determines whether cascading protection sources have already been loaded from the database. More...
 
 areRestrictionsCascading (PageIdentity $page)
 Checks if restrictions are cascading for the current page. More...
 
 areRestrictionsLoaded (PageIdentity $page)
 
 deleteCreateProtection (PageIdentity $page)
 Remove any title creation protection due to page existing. More...
 
 flushRestrictions (PageIdentity $page)
 Flush the protection cache in this object and force reload from the database. More...
 
 getAllRestrictions (PageIdentity $page)
 Returns the restricted actions and their restrictions for the specified page. More...
 
 getCascadeProtectionSources (PageIdentity $page)
 Cascading protection: Get the source of any cascading restrictions on this page. More...
 
 getCreateProtection (PageIdentity $page)
 Is this title subject to protection against creation? More...
 
 getRestrictionExpiry (PageIdentity $page, string $action)
 Get the expiry time for the restriction against a given action. More...
 
 getRestrictions (PageIdentity $page, string $action)
 Returns list of restrictions for specified page. More...
 
 isCascadeProtected (PageIdentity $page)
 Cascading protection: Return true if cascading restrictions apply to this page, false if not. More...
 
 isProtected (PageIdentity $page, string $action='')
 Does the title correspond to a protected article? More...
 
 isSemiProtected (PageIdentity $page, string $action='edit')
 Is this page "semi-protected" - the only protection levels are listed in $wgSemiprotectedRestrictionLevels? More...
 
 listAllRestrictionTypes (bool $exists=true)
 Get a filtered list of all restriction types supported by this wiki. More...
 
 listApplicableRestrictionTypes (PageIdentity $page)
 Returns restriction types for the current page. More...
 
 loadRestrictions (PageIdentity $page, int $flags=IDBAccessObject::READ_NORMAL, ?string $oldRestrictions=null)
 Load restrictions from page.page_restrictions and the page_restrictions table. More...
 
 loadRestrictionsFromRows (PageIdentity $page, array $rows, ?string $oldRestrictions=null)
 Compiles list of active page restrictions for this existing page. More...
 
 registerOldRestrictions (PageIdentity $page, string $oldRestrictions)
 Register legacy restrictions from page.page_restrictions. More...
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

Private Member Functions

 convertOldRestrictions (string $oldRestrictions)
 Given a string formatted like the legacy page.page_restrictions field, return an array of restrictions in the format returned by getAllRestrictions(). More...
 
 getCascadeProtectionSourcesInternal (PageIdentity $page, bool $shortCircuit=false)
 Cascading protection: Get the source of any cascading restrictions on this page. More...
 
 getCreateProtectionInternal (PageIdentity $page)
 Fetch title protection settings. More...
 

Private Attributes

array[] $cache = []
 Caching various restrictions data in the following format: cache key => [ string[] restrictions => restrictions loaded for pages string oldRestrictions => legacy-formatted restrictions from page.page_restrictions ?string expiry => restrictions expiry data for pages ?array create_protection => value for getCreateProtection bool cascade => cascade restrictions on this page to included templates and images? array[] cascade_sources => the results of getCascadeProtectionSources bool has_cascading => Are cascading restrictions in effect on this page? ]. More...
 
CommentStore $commentStore
 
HookContainer $hookContainer
 
HookRunner $hookRunner
 
LinkCache $linkCache
 
ILoadBalancer $loadBalancer
 
ServiceOptions $options
 
PageStore $pageStore
 
WANObjectCache $wanCache
 

Detailed Description

Class RestrictionStore.

Since
1.37

Definition at line 28 of file RestrictionStore.php.

Constructor & Destructor Documentation

◆ __construct()

Member Function Documentation

◆ areCascadeProtectionSourcesLoaded()

MediaWiki\Permissions\RestrictionStore::areCascadeProtectionSourcesLoaded ( PageIdentity  $page)

Determines whether cascading protection sources have already been loaded from the database.

Parameters
PageIdentity$pageMust be local
Returns
bool

Definition at line 700 of file RestrictionStore.php.

References MediaWiki\DAO\WikiAwareEntity\assertWiki(), and MediaWiki\Cache\CacheKeyHelper\getKeyForPage().

◆ areRestrictionsCascading()

MediaWiki\Permissions\RestrictionStore::areRestrictionsCascading ( PageIdentity  $page)

Checks if restrictions are cascading for the current page.

Parameters
PageIdentity$pageMust be local
Returns
bool

Definition at line 712 of file RestrictionStore.php.

References MediaWiki\Permissions\RestrictionStore\areRestrictionsLoaded(), MediaWiki\DAO\WikiAwareEntity\assertWiki(), MediaWiki\Cache\CacheKeyHelper\getKeyForPage(), and MediaWiki\Permissions\RestrictionStore\loadRestrictions().

◆ areRestrictionsLoaded()

MediaWiki\Permissions\RestrictionStore::areRestrictionsLoaded ( PageIdentity  $page)

◆ convertOldRestrictions()

MediaWiki\Permissions\RestrictionStore::convertOldRestrictions ( string  $oldRestrictions)
private

Given a string formatted like the legacy page.page_restrictions field, return an array of restrictions in the format returned by getAllRestrictions().

Parameters
string$oldRestrictionsRestrictions in legacy format (page.page_restrictions). Example: "edit=autoconfirmed,sysop:move=sysop"
Returns
array As returned by getAllRestrictions()

Definition at line 511 of file RestrictionStore.php.

Referenced by MediaWiki\Permissions\RestrictionStore\loadRestrictionsFromRows().

◆ deleteCreateProtection()

MediaWiki\Permissions\RestrictionStore::deleteCreateProtection ( PageIdentity  $page)

Remove any title creation protection due to page existing.

Parameters
PageIdentity$pageMust be local
Access: internal
Only to be called by WikiPage::onArticleCreate.

Definition at line 193 of file RestrictionStore.php.

References MediaWiki\DAO\WikiAwareEntity\assertWiki(), DB_PRIMARY, Page\PageReference\getDBkey(), MediaWiki\Cache\CacheKeyHelper\getKeyForPage(), and Page\PageReference\getNamespace().

◆ flushRestrictions()

MediaWiki\Permissions\RestrictionStore::flushRestrictions ( PageIdentity  $page)

Flush the protection cache in this object and force reload from the database.

This is used when updating protection from WikiPage::doUpdateRestrictions().

Parameters
PageIdentity$pageMust be local
Access: internal

Definition at line 728 of file RestrictionStore.php.

References MediaWiki\DAO\WikiAwareEntity\assertWiki(), and MediaWiki\Cache\CacheKeyHelper\getKeyForPage().

◆ getAllRestrictions()

MediaWiki\Permissions\RestrictionStore::getAllRestrictions ( PageIdentity  $page)

Returns the restricted actions and their restrictions for the specified page.

Parameters
PageIdentity$pageMust be local
Returns
string[][] Keys are actions, values are arrays as returned by RestrictionStore::getRestrictions(). Empty if no restrictions are in place.

Definition at line 130 of file RestrictionStore.php.

References MediaWiki\Permissions\RestrictionStore\areRestrictionsLoaded(), MediaWiki\DAO\WikiAwareEntity\assertWiki(), MediaWiki\Cache\CacheKeyHelper\getKeyForPage(), and MediaWiki\Permissions\RestrictionStore\loadRestrictions().

Referenced by MediaWiki\Permissions\RestrictionStore\getRestrictions().

◆ getCascadeProtectionSources()

MediaWiki\Permissions\RestrictionStore::getCascadeProtectionSources ( PageIdentity  $page)

Cascading protection: Get the source of any cascading restrictions on this page.

Parameters
PageIdentity$pageMust be local
Returns
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.

Definition at line 590 of file RestrictionStore.php.

References MediaWiki\DAO\WikiAwareEntity\assertWiki(), and MediaWiki\Permissions\RestrictionStore\getCascadeProtectionSourcesInternal().

◆ getCascadeProtectionSourcesInternal()

MediaWiki\Permissions\RestrictionStore::getCascadeProtectionSourcesInternal ( PageIdentity  $page,
bool  $shortCircuit = false 
)
private

Cascading protection: Get the source of any cascading restrictions on this page.

Parameters
PageIdentity$pageMust be local
bool$shortCircuitIf true, just return true or false instead of the actual lists.
Returns
array|bool If $shortCircuit is true, return true if there is some cascading protection and false otherwise. Otherwise, same as getCascadeProtectionSources().

Definition at line 604 of file RestrictionStore.php.

References $dbr, $res, DB_REPLICA, Page\PageReference\getDBkey(), MediaWiki\Cache\CacheKeyHelper\getKeyForPage(), Page\PageReference\getNamespace(), NS_FILE, and wfTimestampNow().

Referenced by MediaWiki\Permissions\RestrictionStore\getCascadeProtectionSources(), and MediaWiki\Permissions\RestrictionStore\isCascadeProtected().

◆ getCreateProtection()

MediaWiki\Permissions\RestrictionStore::getCreateProtection ( PageIdentity  $page)

Is this title subject to protection against creation?

Parameters
PageIdentity$pageMust be local
Returns
?array Null if no restrictions. Otherwise an array with the following keys:
  • user: user id
  • expiry: 14-digit timestamp or 'infinity'
  • permission: string (pt_create_perm)
  • reason: string
Access: internal
Only to be called by Title::getTitleProtection. When that is discontinued, this will be too, in favor of getRestrictions( $page, 'create' ). If someone wants to know who protected it or the reason, there should be a method that exposes that for all restriction types.

Definition at line 171 of file RestrictionStore.php.

References MediaWiki\DAO\WikiAwareEntity\assertWiki(), and MediaWiki\Permissions\RestrictionStore\getCreateProtectionInternal().

◆ getCreateProtectionInternal()

MediaWiki\Permissions\RestrictionStore::getCreateProtectionInternal ( PageIdentity  $page)
private

Fetch title protection settings.

To work correctly, $this->loadRestrictions() needs to have access to the actual protections in the database without munging 'sysop' => 'editprotected' and 'autoconfirmed' => 'editsemiprotected'.

Parameters
PageIdentity$pageMust be local
Returns
?array Same format as getCreateProtection().

Definition at line 539 of file RestrictionStore.php.

References $dbr, Page\PageIdentity\canExist(), DB_REPLICA, Page\PageIdentity\exists(), Page\PageReference\getDBkey(), MediaWiki\Cache\CacheKeyHelper\getKeyForPage(), and Page\PageReference\getNamespace().

Referenced by MediaWiki\Permissions\RestrictionStore\getCreateProtection(), and MediaWiki\Permissions\RestrictionStore\loadRestrictions().

◆ getRestrictionExpiry()

MediaWiki\Permissions\RestrictionStore::getRestrictionExpiry ( PageIdentity  $page,
string  $action 
)

Get the expiry time for the restriction against a given action.

Parameters
PageIdentity$pageMust be local
string$action
Returns
?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.

Definition at line 148 of file RestrictionStore.php.

References MediaWiki\$action, MediaWiki\Permissions\RestrictionStore\areRestrictionsLoaded(), MediaWiki\DAO\WikiAwareEntity\assertWiki(), MediaWiki\Cache\CacheKeyHelper\getKeyForPage(), and MediaWiki\Permissions\RestrictionStore\loadRestrictions().

◆ getRestrictions()

MediaWiki\Permissions\RestrictionStore::getRestrictions ( PageIdentity  $page,
string  $action 
)

Returns list of restrictions for specified page.

Parameters
PageIdentity$pageMust be local
string$actionAction that restrictions need to be checked for
Returns
string[] 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. Returns an empty array if there are no restrictions set for this action (including for unrecognized actions).

Definition at line 116 of file RestrictionStore.php.

References MediaWiki\$action, MediaWiki\DAO\WikiAwareEntity\assertWiki(), and MediaWiki\Permissions\RestrictionStore\getAllRestrictions().

Referenced by MediaWiki\Permissions\RestrictionStore\isProtected(), and MediaWiki\Permissions\RestrictionStore\isSemiProtected().

◆ isCascadeProtected()

MediaWiki\Permissions\RestrictionStore::isCascadeProtected ( PageIdentity  $page)

Cascading protection: Return true if cascading restrictions apply to this page, false if not.

Parameters
PageIdentity$pageMust be local
Returns
bool If the page is subject to cascading restrictions.

Definition at line 280 of file RestrictionStore.php.

References MediaWiki\DAO\WikiAwareEntity\assertWiki(), and MediaWiki\Permissions\RestrictionStore\getCascadeProtectionSourcesInternal().

◆ isProtected()

MediaWiki\Permissions\RestrictionStore::isProtected ( PageIdentity  $page,
string  $action = '' 
)

Does the title correspond to a protected article?

Parameters
PageIdentity$pageMust be local
string$actionThe action the page is protected from, by default checks all actions.
Returns
bool

Definition at line 241 of file RestrictionStore.php.

References MediaWiki\$action, $type, MediaWiki\DAO\WikiAwareEntity\assertWiki(), Page\PageReference\getNamespace(), MediaWiki\Permissions\RestrictionStore\getRestrictions(), MediaWiki\Permissions\RestrictionStore\listApplicableRestrictionTypes(), and NS_SPECIAL.

◆ isSemiProtected()

MediaWiki\Permissions\RestrictionStore::isSemiProtected ( PageIdentity  $page,
string  $action = 'edit' 
)

Is this page "semi-protected" - the only protection levels are listed in $wgSemiprotectedRestrictionLevels?

Parameters
PageIdentity$pageMust be local
string$actionAction to check (default: edit)
Returns
bool

Definition at line 213 of file RestrictionStore.php.

References MediaWiki\$action, MediaWiki\DAO\WikiAwareEntity\assertWiki(), and MediaWiki\Permissions\RestrictionStore\getRestrictions().

◆ listAllRestrictionTypes()

MediaWiki\Permissions\RestrictionStore::listAllRestrictionTypes ( bool  $exists = true)

Get a filtered list of all restriction types supported by this wiki.

Parameters
bool$existsTrue 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
Returns
string[]

Definition at line 321 of file RestrictionStore.php.

Referenced by MediaWiki\Permissions\RestrictionStore\listApplicableRestrictionTypes().

◆ listApplicableRestrictionTypes()

MediaWiki\Permissions\RestrictionStore::listApplicableRestrictionTypes ( PageIdentity  $page)

◆ loadRestrictions()

MediaWiki\Permissions\RestrictionStore::loadRestrictions ( PageIdentity  $page,
int  $flags = IDBAccessObject::READ_NORMAL,
?string  $oldRestrictions = null 
)

Load restrictions from page.page_restrictions and the page_restrictions table.

Parameters
PageIdentity$pageMust be local
int$flagsIDBAccessObject::READ_XXX constants (e.g., READ_LATEST to read from primary DB)
string | null$oldRestrictionsRestrictions in legacy format (page.page_restrictions). null means we don't know about any legacy restrictions and they need to be looked up. Example: "edit=autoconfirmed,sysop:move=sysop"
Access: internal

Definition at line 343 of file RestrictionStore.php.

References $dbr, MediaWiki\Permissions\RestrictionStore\areRestrictionsLoaded(), MediaWiki\DAO\WikiAwareEntity\assertWiki(), Page\PageIdentity\canExist(), DB_PRIMARY, DB_REPLICA, Wikimedia\Rdbms\Database\getCacheSetOptions(), MediaWiki\Permissions\RestrictionStore\getCreateProtectionInternal(), Page\PageIdentity\getId(), MediaWiki\Cache\CacheKeyHelper\getKeyForPage(), DBAccessObjectUtils\hasFlags(), MediaWiki\Permissions\RestrictionStore\loadRestrictionsFromRows(), and wfTimestampNow().

Referenced by MediaWiki\Permissions\RestrictionStore\areRestrictionsCascading(), MediaWiki\Permissions\RestrictionStore\getAllRestrictions(), and MediaWiki\Permissions\RestrictionStore\getRestrictionExpiry().

◆ loadRestrictionsFromRows()

MediaWiki\Permissions\RestrictionStore::loadRestrictionsFromRows ( PageIdentity  $page,
array  $rows,
?string  $oldRestrictions = null 
)

Compiles list of active page restrictions for this existing page.

Public for usage by LiquidThreads.

Parameters
PageIdentity$pageMust be local
stdClass[]$rowsArray of db result objects
string | null$oldRestrictionsRestrictions in legacy format (page.page_restrictions). null means we don't know about any legacy restrictions and they need to be looked up. Example: "edit=autoconfirmed,sysop:move=sysop"

Definition at line 436 of file RestrictionStore.php.

References $dbr, $type, MediaWiki\DAO\WikiAwareEntity\assertWiki(), MediaWiki\Permissions\RestrictionStore\convertOldRestrictions(), DB_REPLICA, MediaWiki\Cache\CacheKeyHelper\getKeyForPage(), MediaWiki\Permissions\RestrictionStore\listApplicableRestrictionTypes(), and wfTimestampNow().

Referenced by MediaWiki\Permissions\RestrictionStore\loadRestrictions().

◆ registerOldRestrictions()

MediaWiki\Permissions\RestrictionStore::registerOldRestrictions ( PageIdentity  $page,
string  $oldRestrictions 
)

Register legacy restrictions from page.page_restrictions.

This is nice to do if you have a page row handy anyway, so we don't have to look them up separately later.

Parameters
PageIdentity$pageMust be local
string$oldRestrictionsRestrictions in legacy format (page.page_restrictions). Example: "edit=autoconfirmed,sysop:move=sysop"
Access: internal

Definition at line 744 of file RestrictionStore.php.

References MediaWiki\DAO\WikiAwareEntity\assertWiki(), and MediaWiki\Cache\CacheKeyHelper\getKeyForPage().

Member Data Documentation

◆ $cache

array [] MediaWiki\Permissions\RestrictionStore::$cache = []
private

Caching various restrictions data in the following format: cache key => [ string[] restrictions => restrictions loaded for pages string oldRestrictions => legacy-formatted restrictions from page.page_restrictions ?string expiry => restrictions expiry data for pages ?array create_protection => value for getCreateProtection bool cascade => cascade restrictions on this page to included templates and images? array[] cascade_sources => the results of getCascadeProtectionSources bool has_cascading => Are cascading restrictions in effect on this page? ].

Definition at line 74 of file RestrictionStore.php.

◆ $commentStore

CommentStore MediaWiki\Permissions\RestrictionStore::$commentStore
private

◆ $hookContainer

HookContainer MediaWiki\Permissions\RestrictionStore::$hookContainer
private

◆ $hookRunner

HookRunner MediaWiki\Permissions\RestrictionStore::$hookRunner
private

Definition at line 57 of file RestrictionStore.php.

◆ $linkCache

LinkCache MediaWiki\Permissions\RestrictionStore::$linkCache
private

◆ $loadBalancer

ILoadBalancer MediaWiki\Permissions\RestrictionStore::$loadBalancer
private

◆ $options

ServiceOptions MediaWiki\Permissions\RestrictionStore::$options
private

◆ $pageStore

PageStore MediaWiki\Permissions\RestrictionStore::$pageStore
private

◆ $wanCache

WANObjectCache MediaWiki\Permissions\RestrictionStore::$wanCache
private

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\Permissions\RestrictionStore::CONSTRUCTOR_OPTIONS
Initial value:
= [
'NamespaceProtection',
'RestrictionLevels',
'RestrictionTypes',
'SemiprotectedRestrictionLevels',
]
Access: internal

Definition at line 31 of file RestrictionStore.php.


The documentation for this class was generated from the following file: