X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fuser%2FUser.php;h=2f6deb5f48efa29c13f3f5bdfac193127c4a5ebb;hb=824655f3b74e3275458169f2c87fa81f3598204e;hp=99f4022487f62c2c62485ce0194327635346f03a;hpb=d4b72572a6fd6b7549edb1fe123ef869e3db0e8a;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/user/User.php b/includes/user/User.php index 99f4022487..2f6deb5f48 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -20,6 +20,8 @@ * @file */ +use MediaWiki\Block\AbstractBlock; +use MediaWiki\Block\SystemBlock; use MediaWiki\MediaWikiServices; use MediaWiki\Session\SessionManager; use MediaWiki\Session\Token; @@ -278,7 +280,7 @@ class User implements IDBAccessObject, UserIdentity { protected $mImplicitGroups; /** @var array */ protected $mFormerGroups; - /** @var Block */ + /** @var AbstractBlock */ protected $mGlobalBlock; /** @var bool */ protected $mLocked; @@ -290,13 +292,13 @@ class User implements IDBAccessObject, UserIdentity { /** @var WebRequest */ private $mRequest; - /** @var Block */ + /** @var AbstractBlock */ public $mBlock; /** @var bool */ protected $mAllowUsertalk; - /** @var Block */ + /** @var AbstractBlock */ private $mBlockedFromCreateAccount = false; /** @var int User::READ_* constant bitfield used to load data */ @@ -923,7 +925,7 @@ class User implements IDBAccessObject, UserIdentity { } if ( !( $flags & self::READ_LATEST ) && array_key_exists( $name, self::$idCacheByName ) ) { - return self::$idCacheByName[$name]; + return is_null( self::$idCacheByName[$name] ) ? null : (int)self::$idCacheByName[$name]; } list( $index, $options ) = DBAccessObjectUtils::getDBOptions( $flags ); @@ -1848,7 +1850,7 @@ class User implements IDBAccessObject, UserIdentity { $fromReplica ); - if ( $block instanceof Block ) { + if ( $block instanceof AbstractBlock ) { wfDebug( __METHOD__ . ": Found block.\n" ); $this->mBlock = $block; $this->mBlockedby = $block->getByName(); @@ -2162,7 +2164,7 @@ class User implements IDBAccessObject, UserIdentity { * @return bool True if blocked, false otherwise */ public function isBlocked( $fromReplica = true ) { - return $this->getBlock( $fromReplica ) instanceof Block && + return $this->getBlock( $fromReplica ) instanceof AbstractBlock && $this->getBlock()->appliesToRight( 'edit' ); } @@ -2170,11 +2172,11 @@ class User implements IDBAccessObject, UserIdentity { * Get the block affecting the user, or null if the user is not blocked * * @param bool $fromReplica Whether to check the replica DB instead of the master - * @return Block|null + * @return AbstractBlock|null */ public function getBlock( $fromReplica = true ) { $this->getBlockedStatus( $fromReplica ); - return $this->mBlock instanceof Block ? $this->mBlock : null; + return $this->mBlock instanceof AbstractBlock ? $this->mBlock : null; } /** @@ -2230,7 +2232,7 @@ class User implements IDBAccessObject, UserIdentity { * @return bool True if blocked, false otherwise */ public function isBlockedGlobally( $ip = '' ) { - return $this->getGlobalBlock( $ip ) instanceof Block; + return $this->getGlobalBlock( $ip ) instanceof AbstractBlock; } /** @@ -2239,7 +2241,7 @@ class User implements IDBAccessObject, UserIdentity { * This is intended for quick UI checks. * * @param string $ip IP address, uses current client if none given - * @return Block|null Block object if blocked, null otherwise + * @return AbstractBlock|null Block object if blocked, null otherwise * @throws FatalError * @throws MWException */ @@ -2261,7 +2263,7 @@ class User implements IDBAccessObject, UserIdentity { if ( $blocked && $block === null ) { // back-compat: UserIsBlockedGlobally didn't have $block param first - $block = new Block( [ + $block = new SystemBlock( [ 'address' => $ip, 'systemBlock' => 'global-block' ] ); @@ -3674,12 +3676,25 @@ class User implements IDBAccessObject, UserIdentity { return true; } + /** + * Alias of isLoggedIn() with a name that describes its actual functionality. UserIdentity has + * only this new name and not the old isLoggedIn() variant. + * + * @return bool True if user is registered on this wiki, i.e., has a user ID. False if user is + * anonymous or has no local account (which can happen when importing). This is equivalent to + * getId() != 0 and is provided for code readability. + * @since 1.34 + */ + public function isRegistered() { + return $this->getId() != 0; + } + /** * Get whether the user is logged in * @return bool */ public function isLoggedIn() { - return $this->getId() != 0; + return $this->isRegistered(); } /** @@ -3687,7 +3702,7 @@ class User implements IDBAccessObject, UserIdentity { * @return bool */ public function isAnon() { - return !$this->isLoggedIn(); + return !$this->isRegistered(); } /** @@ -4379,7 +4394,7 @@ class User implements IDBAccessObject, UserIdentity { /** * Get whether the user is explicitly blocked from account creation. - * @return bool|Block + * @return bool|AbstractBlock */ public function isBlockedFromCreateAccount() { $this->getBlockedStatus(); @@ -4393,7 +4408,7 @@ class User implements IDBAccessObject, UserIdentity { if ( $this->mBlockedFromCreateAccount === false && !$this->isAllowed( 'ipblock-exempt' ) ) { $this->mBlockedFromCreateAccount = Block::newFromTarget( null, $this->getRequest()->getIP() ); } - return $this->mBlockedFromCreateAccount instanceof Block + return $this->mBlockedFromCreateAccount instanceof AbstractBlock && $this->mBlockedFromCreateAccount->appliesToRight( 'createaccount' ) ? $this->mBlockedFromCreateAccount : false;