X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fuser%2FUser.php;h=ee617a2caf9bc31c3ad2fe50f9f8c0aaba18db4f;hb=6164423de0f34b5c264bacebb8371811e07fdaa8;hp=c1e096b93b06fed2db9006ea17a129882cce88a4;hpb=ea783ca68dce8da1b84b14c4134a5cbe9c4b1fed;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/user/User.php b/includes/user/User.php index c1e096b93b..ee617a2caf 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -20,6 +20,7 @@ * @file */ +use MediaWiki\MediaWikiServices; use MediaWiki\Session\SessionManager; use MediaWiki\Session\Token; @@ -275,8 +276,8 @@ class User implements IDBAccessObject { protected $mImplicitGroups; /** @var array */ protected $mFormerGroups; - /** @var bool */ - protected $mBlockedGlobally; + /** @var Block */ + protected $mGlobalBlock; /** @var bool */ protected $mLocked; /** @var bool */ @@ -474,7 +475,7 @@ class User implements IDBAccessObject { */ protected static function getInProcessCache() { if ( !self::$inProcessCache ) { - self::$inProcessCache = new HashBagOStuff( ['maxKeys' => 10] ); + self::$inProcessCache = new HashBagOStuff( [ 'maxKeys' => 10 ] ); } return self::$inProcessCache; } @@ -1534,7 +1535,8 @@ class User implements IDBAccessObject { foreach ( LanguageConverter::$languagesWithVariants as $langCode ) { $defOpt[$langCode == $wgContLang->getCode() ? 'variant' : "variant-$langCode"] = $langCode; } - foreach ( SearchEngine::searchableNamespaces() as $nsnum => $nsname ) { + $namespaces = MediaWikiServices::getInstance()->getSearchEngineConfig()->searchableNamespaces(); + foreach ( $namespaces as $nsnum => $nsname ) { $defOpt['searchNs' . $nsnum] = !empty( $wgNamespacesToBeSearchedDefault[$nsnum] ); } $defOpt['skin'] = Skin::normalizeKey( $wgDefaultSkin ); @@ -1992,8 +1994,22 @@ class User implements IDBAccessObject { * @return bool True if blocked, false otherwise */ public function isBlockedGlobally( $ip = '' ) { - if ( $this->mBlockedGlobally !== null ) { - return $this->mBlockedGlobally; + return $this->getGlobalBlock( $ip ) instanceof Block; + } + + /** + * Check if user is blocked on all wikis. + * Do not use for actual edit permission checks! + * 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 + * @throws FatalError + * @throws MWException + */ + public function getGlobalBlock( $ip = '' ) { + if ( $this->mGlobalBlock !== null ) { + return $this->mGlobalBlock ?: null; } // User is already an IP? if ( IP::isIPAddress( $this->getName() ) ) { @@ -2002,9 +2018,17 @@ class User implements IDBAccessObject { $ip = $this->getRequest()->getIP(); } $blocked = false; - Hooks::run( 'UserIsBlockedGlobally', [ &$this, $ip, &$blocked ] ); - $this->mBlockedGlobally = (bool)$blocked; - return $this->mBlockedGlobally; + $block = null; + Hooks::run( 'UserIsBlockedGlobally', [ &$this, $ip, &$blocked, &$block ] ); + + if ( $blocked && $block === null ) { + // back-compat: UserIsBlockedGlobally didn't have $block param first + $block = new Block; + $block->setTarget( $ip ); + } + + $this->mGlobalBlock = $blocked ? $block : false; + return $this->mGlobalBlock ?: null; } /** @@ -3476,7 +3500,7 @@ class User implements IDBAccessObject { */ public function isWatched( $title, $checkRights = self::CHECK_USER_RIGHTS ) { if ( $title->isWatchable() && ( !$checkRights || $this->isAllowed( 'viewmywatchlist' ) ) ) { - return WatchedItemStore::getDefaultInstance()->isWatched( $this, $title ); + return MediaWikiServices::getInstance()->getWatchedItemStore()->isWatched( $this, $title ); } return false; } @@ -3490,7 +3514,7 @@ class User implements IDBAccessObject { */ public function addWatch( $title, $checkRights = self::CHECK_USER_RIGHTS ) { if ( !$checkRights || $this->isAllowed( 'editmywatchlist' ) ) { - WatchedItemStore::getDefaultInstance()->addWatchBatchForUser( + MediaWikiServices::getInstance()->getWatchedItemStore()->addWatchBatchForUser( $this, [ $title->getSubjectPage(), $title->getTalkPage() ] ); @@ -3507,8 +3531,9 @@ class User implements IDBAccessObject { */ public function removeWatch( $title, $checkRights = self::CHECK_USER_RIGHTS ) { if ( !$checkRights || $this->isAllowed( 'editmywatchlist' ) ) { - WatchedItemStore::getDefaultInstance()->removeWatch( $this, $title->getSubjectPage() ); - WatchedItemStore::getDefaultInstance()->removeWatch( $this, $title->getTalkPage() ); + $store = MediaWikiServices::getInstance()->getWatchedItemStore(); + $store->removeWatch( $this, $title->getSubjectPage() ); + $store->removeWatch( $this, $title->getTalkPage() ); } $this->invalidateCache(); } @@ -3577,7 +3602,7 @@ class User implements IDBAccessObject { $force = 'force'; } - WatchedItemStore::getDefaultInstance() + MediaWikiServices::getInstance()->getWatchedItemStore() ->resetNotificationTimestamp( $this, $title, $force, $oldid ); }