41 private $loadBalancer;
47 private $sharedTables;
50 private $localDatabases;
60 $this->sharedDB = $config->
get( MainConfigNames::SharedDB );
61 $this->sharedTables = $config->
get( MainConfigNames::SharedTables );
62 $this->localDatabases = $config->
get( MainConfigNames::LocalDatabases );
63 $this->loadBalancer = $loadBalancer;
68 if ( !$user->isRegistered() ) {
73 if ( !$wikiId || WikiMap::isCurrentWikiId( $wikiId ) ) {
79 return $this->sharedDB !==
null &&
80 in_array(
'user', $this->sharedTables,
true ) &&
81 in_array( $wikiId, $this->localDatabases,
true );
85 array $idToName, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
90 $audience = $this->checkAudience( $audience );
91 [ $index, $options ] = DBAccessObjectUtils::getDBOptions( $flags );
92 $db = $this->loadBalancer->getConnectionRef( $index );
95 $fields = [
'user_id',
'user_name' ];
97 'user_id' => array_map(
'intval', array_keys( $idToName ) ),
100 if ( $audience && !$audience->isAllowed(
'hideuser' ) ) {
101 $tables[] =
'ipblocks';
102 $join[
'ipblocks'] = [
'LEFT JOIN',
'ipb_user=user_id' ];
103 $fields[] =
'ipb_deleted';
106 $res = $db->select( $tables, $fields, $where, __METHOD__, $options, $join );
107 foreach (
$res as $row ) {
108 $idToName[$row->user_id] = empty( $row->ipb_deleted ) ? $row->user_name :
'';
115 array $nameToId, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL
121 $audience = $this->checkAudience( $audience );
122 [ $index, $options ] = DBAccessObjectUtils::getDBOptions( $flags );
123 $db = $this->loadBalancer->getConnectionRef( $index );
125 $tables = [
'user' ];
126 $fields = [
'user_id',
'user_name' ];
128 'user_name' => array_map(
'strval', array_keys( $nameToId ) ),
131 if ( $audience && !$audience->isAllowed(
'hideuser' ) ) {
132 $tables[] =
'ipblocks';
133 $join[
'ipblocks'] = [
'LEFT JOIN',
'ipb_user=user_id' ];
134 $where[] =
'ipb_deleted = 0 OR ipb_deleted IS NULL';
137 $res = $db->select( $tables, $fields, $where, __METHOD__, $options, $join );
138 foreach (
$res as $row ) {
139 $nameToId[$row->user_name] = (int)$row->user_id;
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
The CentralIdLookup service allows for connecting local users with cluster-wide IDs.
A CentralIdLookup provider that just uses local IDs.
lookupUserNames(array $nameToId, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given (local) user names, return the central IDs.
lookupCentralIds(array $idToName, $audience=self::AUDIENCE_PUBLIC, $flags=self::READ_NORMAL)
Given central user IDs, return the (local) user names.
__construct(Config $config, ILoadBalancer $loadBalancer)
isAttached(UserIdentity $user, $wikiId=UserIdentity::LOCAL)
Check that a user is attached on the specified wiki.
A class containing constants representing the names of configuration variables.
Interface for configuration instances.
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".