*/
use MediaWiki\Block\AbstractBlock;
+use MediaWiki\Block\DatabaseBlock;
use MediaWiki\Block\SystemBlock;
use MediaWiki\MediaWikiServices;
use MediaWiki\Session\SessionManager;
* shared cache (memcached). Any operation which changes the
* corresponding database fields must call a cache-clearing function.
* @showinitializer
+ * @var string[]
*/
protected static $mCacheVars = [
// user table
* Each of these should have a corresponding message of the form
* "right-$right".
* @showinitializer
+ * @var string[]
*/
protected static $mCoreRights = [
'apihighlimits',
];
/**
- * String Cached results of getAllRights()
+ * @var string[] Cached results of getAllRights()
*/
protected static $mAllRights = false;
protected $mOptionOverrides;
// @}
+ // @{
/**
- * Bool Whether the cache variables have been loaded.
+ * @var bool Whether the cache variables have been loaded.
*/
- // @{
public $mOptionsLoaded;
/**
- * Array with already loaded items or true if all items have been loaded.
+ * @var array|bool Array with already loaded items or true if all items have been loaded.
*/
protected $mLoadedItems = [];
// @}
/**
- * String Initialization data source if mLoadedItems!==true. May be one of:
+ * @var string Initialization data source if mLoadedItems!==true. May be one of:
* - 'defaults' anonymous user initialised from class defaults
* - 'name' initialise from mName
* - 'id' initialise from mId
/**
* Lazy-initialized variables, invalidated with clearInstanceCache
*/
+ /** @var int|bool */
protected $mNewtalk;
/** @var string */
protected $mDatePreference;
/** @var bool */
protected $mAllowUsertalk;
- /** @var AbstractBlock */
+ /** @var AbstractBlock|bool */
private $mBlockedFromCreateAccount = false;
/** @var int User::READ_* constant bitfield used to load data */
protected $queryFlagsUsed = self::READ_NORMAL;
+ /** @var int[] */
public static $idCacheByName = [];
/**
$result = (int)$s->user_id;
}
- self::$idCacheByName[$name] = $result;
-
- if ( count( self::$idCacheByName ) > 1000 ) {
+ if ( count( self::$idCacheByName ) >= 1000 ) {
self::$idCacheByName = [];
}
+ self::$idCacheByName[$name] = $result;
+
return $result;
}
if ( $user->isLoggedIn() ) {
$this->loadFromUserObject( $user );
if ( $user->getBlock() ) {
- // If this user is autoblocked, set a cookie to track the Block. This has to be done on
+ // If this user is autoblocked, set a cookie to track the block. This has to be done on
// every session load, because an autoblocked editor might not edit again from the same
// IP address after being blocked.
- $this->trackBlockWithCookie();
+ MediaWikiServices::getInstance()->getBlockManager()->trackBlockWithCookie( $this );
}
// Other code expects these to be set in the session, so set them.
/**
* Set the 'BlockID' cookie depending on block type and user authentication status.
+ *
+ * @deprecated since 1.34 Use BlockManager::trackBlockWithCookie instead
*/
public function trackBlockWithCookie() {
- $block = $this->getBlock();
-
- if ( $block && $this->getRequest()->getCookie( 'BlockID' ) === null
- && $block->shouldTrackWithCookie( $this->isAnon() )
- ) {
- $block->setCookie( $this->getRequest()->response() );
- }
+ MediaWikiServices::getInstance()->getBlockManager()->trackBlockWithCookie( $this );
}
/**
$fromReplica
);
- if ( $block instanceof AbstractBlock ) {
- wfDebug( __METHOD__ . ": Found block.\n" );
+ if ( $block ) {
$this->mBlock = $block;
$this->mBlockedby = $block->getByName();
$this->mBlockreason = $block->getReason();
$dbw->insert( 'user_newtalk',
[ $field => $id, 'user_last_timestamp' => $dbw->timestampOrNull( $ts ) ],
__METHOD__,
- 'IGNORE' );
+ [ 'IGNORE' ] );
if ( $dbw->affectedRows() ) {
wfDebug( __METHOD__ . ": set on ($field, $id)\n" );
return true;
return false;
}
- $userblock = Block::newFromTarget( $this->getName() );
+ $userblock = DatabaseBlock::newFromTarget( $this->getName() );
if ( !$userblock ) {
return false;
}
# blocked with createaccount disabled, prevent new account creation there even
# when the user is logged in
if ( $this->mBlockedFromCreateAccount === false && !$this->isAllowed( 'ipblock-exempt' ) ) {
- $this->mBlockedFromCreateAccount = Block::newFromTarget( null, $this->getRequest()->getIP() );
+ $this->mBlockedFromCreateAccount = DatabaseBlock::newFromTarget(
+ null, $this->getRequest()->getIP()
+ );
}
return $this->mBlockedFromCreateAccount instanceof AbstractBlock
&& $this->mBlockedFromCreateAccount->appliesToRight( 'createaccount' )