46 $this->nsInfo =
$nsInfo ?? MediaWikiServices::getInstance()->getNamespaceInfo();
55 return MediaWikiServices::getInstance()->getGenderCache();
63 if ( $this->
default ===
null ) {
79 if ( $username instanceof
User ) {
80 $username = $username->getName();
84 if ( !isset( $this->cache[$username] ) ) {
85 if ( $this->misses >= $this->missLimit && $wgUser->getName() !== $username ) {
86 if ( $this->misses === $this->missLimit ) {
88 wfDebug( __METHOD__ .
": too many misses, returning default onwards\n" );
94 $this->
doQuery( $username, $caller );
101 return $this->cache[$username] ?? $this->
getDefault();
112 foreach ( $data as $ns => $pagenames ) {
113 if ( !$this->nsInfo->hasGenderDistinction( $ns ) ) {
116 foreach ( array_keys( $pagenames ) as $username ) {
117 $users[$username] =
true;
121 $this->
doQuery( array_keys( $users ), $caller );
133 foreach ( $titles as
$title ) {
138 if ( !$this->nsInfo->hasGenderDistinction( $titleObj->getNamespace() ) ) {
141 $users[] = $titleObj->getText();
144 $this->
doQuery( $users, $caller );
152 public function doQuery( $users, $caller =
'' ) {
156 foreach ( (array)$users as $value ) {
159 if ( !isset( $this->cache[$name] ) ) {
164 $usersToCheck[] = $name;
169 if ( count( $usersToCheck ) === 0 ) {
175 if ( $this->loadBalancer ===
null ) {
180 $table = [
'user',
'user_properties' ];
181 $fields = [
'user_name',
'up_value' ];
182 $conds = [
'user_name' => $usersToCheck ];
183 $joins = [
'user_properties' =>
184 [
'LEFT JOIN', [
'user_id = up_user',
'up_property' =>
'gender' ] ] ];
186 $comment = __METHOD__;
187 if ( strval( $caller ) !==
'' ) {
188 $comment .=
"/$caller";
190 $res =
$dbr->select( $table, $fields, $conds, $comment, [], $joins );
192 foreach (
$res as $row ) {
193 $this->cache[$row->user_name] = $row->up_value ?:
$default;
199 $indexSlash = strpos( $username,
'/' );
200 if ( $indexSlash !==
false ) {
201 $username = substr( $username, 0, $indexSlash );
205 return strtr( $username,
'_',
' ' );