X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%2C%22id_auteur=%24connecte%22%29%20.%20%22?a=blobdiff_plain;f=includes%2Fuser%2FUser.php;h=b1c270fd294dd9f072d05181e3d95b4f7638369b;hb=279dd4156c6195be16fe497980d73cd2e5c95884;hp=04eba97b31dc9142551c57e6b17f57522b0a5f4c;hpb=f8d030880004ed7ca196fae804d59813efafdbeb;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/user/User.php b/includes/user/User.php index 04eba97b31..b1c270fd29 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; @@ -126,6 +127,7 @@ class User implements IDBAccessObject { 'createpage', 'createtalk', 'delete', + 'deletechangetags', 'deletedhistory', 'deletedtext', 'deletelogentry', @@ -275,8 +277,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 +476,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; } @@ -1070,9 +1072,9 @@ class User implements IDBAccessObject { // Clean up name according to title rules, // but only when validation is requested (bug 12654) $t = ( $validate !== false ) ? - Title::newFromText( $name ) : Title::makeTitle( NS_USER, $name ); + Title::newFromText( $name, NS_USER ) : Title::makeTitle( NS_USER, $name ); // Check for invalid titles - if ( is_null( $t ) ) { + if ( is_null( $t ) || $t->getNamespace() !== NS_USER || $t->isExternal() ) { return false; } @@ -1534,7 +1536,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 +1995,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 +2019,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; } /** @@ -2465,9 +2490,9 @@ class User implements IDBAccessObject { throw new PasswordError( wfMessage( 'externaldberror' )->text() ); } - $this->setToken(); $this->setOption( 'watchlisttoken', false ); $this->setPasswordInternal( $str ); + SessionManager::singleton()->invalidateSessionsForUser( $this ); return true; } @@ -2484,9 +2509,9 @@ class User implements IDBAccessObject { global $wgAuth; if ( $wgAuth->allowSetLocalPassword() ) { - $this->setToken(); $this->setOption( 'watchlisttoken', false ); $this->setPasswordInternal( $str ); + SessionManager::singleton()->invalidateSessionsForUser( $this ); } } @@ -3374,6 +3399,19 @@ class User implements IDBAccessObject { return !$this->isLoggedIn(); } + /** + * @return bool Whether this user is flagged as being a bot role account + * @since 1.28 + */ + public function isBot() { + $isBot = false; + if ( !Hooks::run( "UserIsBot", [ $this, &$isBot ] ) ) { + return $isBot; + } + + return ( $isBot || in_array( 'bot', $this->getGroups() ) ); + } + /** * Check if user is allowed to access a feature / make an action * @@ -3476,7 +3514,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 +3528,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 +3545,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 +3616,7 @@ class User implements IDBAccessObject { $force = 'force'; } - WatchedItemStore::getDefaultInstance() + MediaWikiServices::getInstance()->getWatchedItemStore() ->resetNotificationTimestamp( $this, $title, $force, $oldid ); }