60 $this->nsInfo = $nsInfo;
61 $this->userOptionsLookup = $userOptionsLookup;
70 $this->
default ??= $this->userOptionsLookup->getDefaultOption(
'gender' );
83 $username = $username->getName();
86 $username = self::normalizeUsername( $username );
87 if ( !isset( $this->cache[$username] ) ) {
88 if ( $this->misses < $this->missLimit ||
89 RequestContext::getMain()->getUser()->getName() === $username
92 $this->
doQuery( $username, $caller );
94 if ( $this->misses === $this->missLimit ) {
97 wfDebug( __METHOD__ .
': too many misses, returning default onwards' );
101 return $this->cache[$username] ?? $this->
getDefault();
112 foreach ( $data as $ns => $pagenames ) {
113 if ( $this->nsInfo->hasGenderDistinction( $ns ) ) {
114 $users += $pagenames;
117 $this->
doQuery( array_keys( $users ), $caller );
129 foreach ( $titles as $titleObj ) {
130 if ( $this->nsInfo->hasGenderDistinction( $titleObj->getNamespace() ) ) {
131 $users[] = $titleObj->getText();
134 $this->
doQuery( $users, $caller );
143 public function doQuery( $users, $caller =
'' ) {
145 foreach ( (array)$users as $userName ) {
146 $userName = self::normalizeUsername( $userName );
147 if ( !isset( $this->cache[$userName] ) ) {
148 $usersToFetch[] = $userName;
151 if ( !$usersToFetch ) {
155 $genders = $this->userOptionsLookup->getOptionBatchForUserNames( $usersToFetch,
'gender' );
156 foreach ( $genders as $userName => $gender ) {
157 $this->cache[$userName] = $gender;
161 private static function normalizeUsername(
string $username ): string {
163 $indexSlash = strpos( $username,
'/' );
164 if ( $indexSlash !==
false ) {
165 $username = substr( $username, 0, $indexSlash );
169 return strtr( $username,
'_',
' ' );
174class_alias( GenderCache::class,
'GenderCache' );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Group all the pieces relevant to the context of a request into one instance.