35 static $instance =
null;
36 if ( $instance ===
null ) {
37 $instance =
new self();
53 public function getProp( $userId, $prop ) {
54 if ( !isset( $this->cache[$userId][$prop] ) ) {
55 wfDebug( __METHOD__ .
": querying DB for prop '$prop' for user ID '$userId'.\n" );
59 return $this->cache[$userId][$prop] ??
false;
71 return $userId > 0 ? $this->
getProp( $userId,
'name' ) : $ip;
80 public function doQuery( array $userIds, $options = [], $caller =
'' ) {
84 $userIds = array_unique( $userIds );
86 foreach ( $userIds as $userId ) {
87 $userId = (int)$userId;
91 if ( isset( $this->cache[$userId][
'name'] ) ) {
92 $usersToCheck[$userId] = $this->cache[$userId][
'name'];
94 $usersToQuery[] = $userId;
99 if ( count( $usersToQuery ) ) {
101 $tables = [
'user',
'actor' ];
102 $conds = [
'user_id' => $usersToQuery ];
103 $fields = [
'user_name',
'user_real_name',
'user_registration',
'user_id',
'actor_id' ];
105 'actor' => [
'JOIN',
'actor_user = user_id' ],
108 $comment = __METHOD__;
109 if ( strval( $caller ) !==
'' ) {
110 $comment .=
"/$caller";
113 $res =
$dbr->select( $tables, $fields, $conds, $comment, [], $joinConds );
114 foreach (
$res as $row ) {
115 $userId = (int)$row->user_id;
116 $this->cache[$userId][
'name'] = $row->user_name;
117 $this->cache[$userId][
'real_name'] = $row->user_real_name;
118 $this->cache[$userId][
'registration'] = $row->user_registration;
119 $this->cache[$userId][
'actor'] = $row->actor_id;
120 $usersToCheck[$userId] = $row->user_name;
125 foreach ( $usersToCheck as $userId => $name ) {
126 if ( $this->
queryNeeded( $userId,
'userpage', $options ) ) {
128 $this->typesCached[$userId][
'userpage'] = 1;
130 if ( $this->
queryNeeded( $userId,
'usertalk', $options ) ) {
132 $this->typesCached[$userId][
'usertalk'] = 1;
147 return ( in_array(
$type, $options ) && !isset( $this->typesCached[$uid][
$type] ) );