MediaWiki REL1_39
|
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()->getPermissionManager(). More...
Public Member Functions | |
__construct (ServiceOptions $options, SpecialPageFactory $specialPageFactory, NamespaceInfo $nsInfo, GroupPermissionsLookup $groupPermissionsLookup, UserGroupManager $userGroupManager, BlockErrorFormatter $blockErrorFormatter, HookContainer $hookContainer, UserCache $userCache, RedirectLookup $redirectLookup, RestrictionStore $restrictionStore, TitleFormatter $titleFormatter, TempUserConfig $tempUserConfig, UserFactory $userFactory, ActionFactory $actionFactory) | |
addTemporaryUserRights (UserIdentity $user, $rights) | |
Add temporary user rights, only valid for the current function scope. | |
getAllPermissions () | |
Get a list of all available permissions. | |
getGroupPermissions ( $groups) | |
Get the permissions associated with a given list of groups. | |
getGroupsWithPermission ( $role) | |
Get all the groups who have a given permission. | |
getNamespaceRestrictionLevels ( $index, UserIdentity $user=null) | |
Determine which restriction levels it makes sense to use in a namespace, optionally filtered by a user's rights. | |
getPermissionErrors ( $action, User $user, LinkTarget $page, $rigor=self::RIGOR_SECURE, $ignoreErrors=[]) | |
Can $user perform $action on a page? | |
getUserPermissions (UserIdentity $user) | |
Get the permissions this user has. | |
groupHasPermission ( $group, $role) | |
Check, if the given group has the given permission. | |
invalidateUsersRightsCache ( $user=null) | |
Clear the in-process permission cache for one or all users. | |
isBlockedFrom (User $user, $page, $fromReplica=false) | |
Check if user is blocked from editing a particular article. | |
isEveryoneAllowed ( $right) | |
Check if all users may be assumed to have the given permission. | |
overrideUserRightsForTesting ( $user, $rights=[]) | |
Override the user permissions cache. | |
quickUserCan ( $action, User $user, LinkTarget $page) | |
A convenience method for calling PermissionManager::userCan with PermissionManager::RIGOR_QUICK. | |
throwPermissionErrors ( $action, User $user, LinkTarget $page, $rigor=self::RIGOR_SECURE, $ignoreErrors=[]) | |
Like getPermissionErrors , but immediately throw if there are any errors. | |
userCan ( $action, User $user, LinkTarget $page, $rigor=self::RIGOR_SECURE) | |
Can $user perform $action on a page? | |
userHasAllRights (UserIdentity $user,... $actions) | |
Whether the user is allowed to perform all of the given actions. | |
userHasAnyRight (UserIdentity $user,... $actions) | |
Whether the user is generally allowed to perform at least one of the actions. | |
userHasRight (UserIdentity $user, $action='') | |
Whether the user is generally allowed to perform the given action. | |
Public Attributes | |
const | CONSTRUCTOR_OPTIONS |
A service class for checking permissions To obtain an instance, use MediaWikiServices::getInstance()->getPermissionManager().
Definition at line 57 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::__construct | ( | ServiceOptions | $options, |
SpecialPageFactory | $specialPageFactory, | ||
NamespaceInfo | $nsInfo, | ||
GroupPermissionsLookup | $groupPermissionsLookup, | ||
UserGroupManager | $userGroupManager, | ||
BlockErrorFormatter | $blockErrorFormatter, | ||
HookContainer | $hookContainer, | ||
UserCache | $userCache, | ||
RedirectLookup | $redirectLookup, | ||
RestrictionStore | $restrictionStore, | ||
TitleFormatter | $titleFormatter, | ||
TempUserConfig | $tempUserConfig, | ||
UserFactory | $userFactory, | ||
ActionFactory | $actionFactory ) |
ServiceOptions | $options | |
SpecialPageFactory | $specialPageFactory | |
NamespaceInfo | $nsInfo | |
GroupPermissionsLookup | $groupPermissionsLookup | |
UserGroupManager | $userGroupManager | |
BlockErrorFormatter | $blockErrorFormatter | |
HookContainer | $hookContainer | |
UserCache | $userCache | |
RedirectLookup | $redirectLookup | |
RestrictionStore | $restrictionStore | |
TitleFormatter | $titleFormatter | |
TempUserConfig | $tempUserConfig | |
UserFactory | $userFactory | |
ActionFactory | $actionFactory |
Definition at line 248 of file PermissionManager.php.
References MediaWiki\Config\ServiceOptions\assertRequiredOptions().
MediaWiki\Permissions\PermissionManager::addTemporaryUserRights | ( | UserIdentity | $user, |
$rights ) |
Add temporary user rights, only valid for the current function scope.
This is meant for making it possible to programatically trigger certain actions that the user wouldn't be able to trigger themselves; e.g. allow users without the bot right to make bot-flagged actions through certain special pages.
This returns a "scope guard" variable. Its only purpose is to be stored in a variable by the caller, which is automatically closed at the end of the function, at which point the rights are revoked again. Alternatively, you can close it earlier by consuming it via ScopedCallback::consume().
UserIdentity | $user | |
string | string[] | $rights |
Definition at line 1797 of file PermissionManager.php.
References MediaWiki\User\UserIdentity\getId().
MediaWiki\Permissions\PermissionManager::getAllPermissions | ( | ) |
Get a list of all available permissions.
Definition at line 1658 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::getGroupPermissions | ( | $groups | ) |
Get the permissions associated with a given list of groups.
string[] | $groups | internal group names |
Definition at line 1578 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::getGroupsWithPermission | ( | $role | ) |
Get all the groups who have a given permission.
string | $role | Role to check |
Definition at line 1590 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::getNamespaceRestrictionLevels | ( | $index, | |
UserIdentity | $user = null ) |
Determine which restriction levels it makes sense to use in a namespace, optionally filtered by a user's rights.
int | $index | Namespace ID (index) to check |
UserIdentity | null | $user | User to check |
Definition at line 1696 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::getPermissionErrors | ( | $action, | |
User | $user, | ||
LinkTarget | $page, | ||
$rigor = self::RIGOR_SECURE, | |||
$ignoreErrors = [] ) |
Can $user perform $action on a page?
string | $action | Action that permission needs to be checked for |
User | $user | User to check |
LinkTarget | $page | |
string | $rigor | One of PermissionManager::RIGOR_ constants
|
string[] | $ignoreErrors | Set this to a list of message keys whose corresponding errors may be ignored. |
Definition at line 339 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::getUserPermissions | ( | UserIdentity | $user | ) |
Get the permissions this user has.
UserIdentity | $user |
Definition at line 1477 of file PermissionManager.php.
References User\newFromIdentity().
MediaWiki\Permissions\PermissionManager::groupHasPermission | ( | $group, | |
$role ) |
Check, if the given group has the given permission.
If you're wanting to check whether all users have a permission, use PermissionManager::isEveryoneAllowed() instead. That properly checks if it's revoked from anyone.
string | $group | Group to check |
string | $role | Role to check |
Definition at line 1566 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::invalidateUsersRightsCache | ( | $user = null | ) |
Clear the in-process permission cache for one or all users.
UserIdentity | null | $user | If a specific user is provided it will clear the permission cache only for that user. |
Definition at line 1534 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::isBlockedFrom | ( | User | $user, |
$page, | |||
$fromReplica = false ) |
Check if user is blocked from editing a particular article.
If the user does not have a block, this will return false.
User | $user | |
PageIdentity | LinkTarget | $page | Title to check |
bool | $fromReplica | Whether to check the replica DB instead of the primary DB |
Definition at line 401 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::isEveryoneAllowed | ( | $right | ) |
Check if all users may be assumed to have the given permission.
We generally assume so if the right is granted to '*' and isn't revoked on any group. It doesn't attempt to take grants or other extension limitations on rights into account in the general case, though, as that would require it to always return false and defeat the purpose. Specifically, session-based rights restrictions (such as OAuth or bot passwords) are applied based on the current session.
string | $right | Right to check |
Definition at line 1608 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::overrideUserRightsForTesting | ( | $user, | |
$rights = [] ) |
Override the user permissions cache.
User | $user | |
string[] | string | $rights |
Definition at line 1814 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::quickUserCan | ( | $action, | |
User | $user, | ||
LinkTarget | $page ) |
A convenience method for calling PermissionManager::userCan with PermissionManager::RIGOR_QUICK.
Suitable for use for nonessential UI controls in common cases, but not for functional access control. May provide false positives, but should never provide a false negative.
string | $action | |
User | $user | |
LinkTarget | $page |
Definition at line 317 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::throwPermissionErrors | ( | $action, | |
User | $user, | ||
LinkTarget | $page, | ||
$rigor = self::RIGOR_SECURE, | |||
$ignoreErrors = [] ) |
Like getPermissionErrors
, but immediately throw if there are any errors.
string | $action | Action that permission needs to be checked for |
User | $user | User to check |
LinkTarget | $page | |
string | $rigor | One of PermissionManager::RIGOR_ constants
|
string[] | $ignoreErrors | Set this to a list of message keys whose corresponding errors may be ignored. |
PermissionsError |
Definition at line 378 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::userCan | ( | $action, | |
User | $user, | ||
LinkTarget | $page, | ||
$rigor = self::RIGOR_SECURE ) |
Can $user perform $action on a page?
The method replaced Title::userCan() The $user parameter need to be superseded by UserIdentity value in future The $title parameter need to be superseded by PageIdentity value in future
string | $action | |
User | $user | |
LinkTarget | $page | |
string | $rigor | One of PermissionManager::RIGOR_ constants
|
Definition at line 298 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::userHasAllRights | ( | UserIdentity | $user, |
$actions ) |
Whether the user is allowed to perform all of the given actions.
UserIdentity | $user | |
string | ...$actions |
Definition at line 1461 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::userHasAnyRight | ( | UserIdentity | $user, |
$actions ) |
Whether the user is generally allowed to perform at least one of the actions.
UserIdentity | $user | |
string | ...$actions |
Definition at line 1444 of file PermissionManager.php.
MediaWiki\Permissions\PermissionManager::userHasRight | ( | UserIdentity | $user, |
$action = '' ) |
Whether the user is generally allowed to perform the given action.
UserIdentity | $user | |
string | $action |
Definition at line 1426 of file PermissionManager.php.
const MediaWiki\Permissions\PermissionManager::CONSTRUCTOR_OPTIONS |
Definition at line 71 of file PermissionManager.php.