mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-11-27 16:50:00 +00:00
Tighten some type hints
* Gadget::isEnabled() only requires a UserIdentity, not the whole User * Gadget::isAllowed() only requires an Authority, not the whole User Both of those interfaces are implemented by the User class, so this is compatible with all existing code, and it's easier to call from code that only has access to a UserIdentity/Authority. Change-Id: I8ea710c555f6fb7790ae575bb60aab1a05e288d8
This commit is contained in:
parent
b4632bc4b9
commit
4e27ab0e01
|
@ -12,6 +12,8 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Permissions\Authority;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
|
||||
/**
|
||||
* Wrapper for one gadget.
|
||||
|
@ -178,10 +180,10 @@ class Gadget {
|
|||
/**
|
||||
* Checks whether this gadget is enabled for given user
|
||||
*
|
||||
* @param User $user user to check against
|
||||
* @param UserIdentity $user user to check against
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled( $user ) {
|
||||
public function isEnabled( UserIdentity $user ) {
|
||||
$userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
|
||||
return (bool)$userOptionsLookup->getOption( $user, "gadget-{$this->name}", $this->onByDefault );
|
||||
}
|
||||
|
@ -189,10 +191,10 @@ class Gadget {
|
|||
/**
|
||||
* Checks whether given user has permissions to use this gadget
|
||||
*
|
||||
* @param User $user The user to check against
|
||||
* @param Authority $user The user to check against
|
||||
* @return bool
|
||||
*/
|
||||
public function isAllowed( User $user ) {
|
||||
public function isAllowed( Authority $user ) {
|
||||
if ( count( $this->requiredRights ) ) {
|
||||
return $user->isAllowedAll( ...$this->requiredRights );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue