47 $this->nsInfo = $nsInfo;
48 $this->userOptionsLookup = $userOptionsLookup;
57 $this->
default ??= $this->userOptionsLookup->getDefaultOption(
'gender' );
70 $username = $username->getName();
73 $username = self::normalizeUsername( $username );
74 if ( !isset( $this->cache[$username] ) ) {
75 if ( $this->misses < $this->missLimit ||
76 RequestContext::getMain()->getUser()->getName() === $username
81 if ( $this->misses === $this->missLimit ) {
84 wfDebug( __METHOD__ .
': too many misses, returning default onwards' );
88 return $this->cache[$username] ?? $this->
getDefault();
99 foreach ( $data as $ns => $pagenames ) {
100 if ( $this->nsInfo->hasGenderDistinction( $ns ) ) {
101 $users += $pagenames;
104 $this->
doQuery( array_keys( $users ) );
116 foreach ( $titles as $titleObj ) {
117 if ( $this->nsInfo->hasGenderDistinction( $titleObj->getNamespace() ) ) {
118 $users[] = $titleObj->getText();
132 foreach ( $rows as $row ) {
133 if ( $this->nsInfo->hasGenderDistinction( (
int)$row->page_namespace ) ) {
134 $users[] = $row->page_title;
146 public function doQuery( $users, $caller =
'' ) {
148 foreach ( (array)$users as $userName ) {
149 $userName = self::normalizeUsername( $userName );
150 if ( !isset( $this->cache[$userName] ) ) {
151 $usersToFetch[] = $userName;
154 if ( !$usersToFetch ) {
161 foreach ( array_chunk( array_unique( $usersToFetch ), 1000 ) as $batch ) {
162 $genders = $this->userOptionsLookup->getOptionBatchForUserNames( $batch,
'gender' );
163 foreach ( $genders as $userName => $gender ) {
164 $this->cache[$userName] = $gender;
169 private static function normalizeUsername(
string $username ): string {
171 $indexSlash = strpos( $username,
'/' );
172 if ( $indexSlash !==
false ) {
173 $username = substr( $username, 0, $indexSlash );
177 return strtr( $username,
'_',
' ' );
182class_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.