From 63601400e476c6cf43d985f3e7b9864681695ed4 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Fri, 18 Jan 2013 16:46:04 +0100 Subject: Update to MediaWiki 1.20.2 this update includes: * adjusted Arch Linux skin * updated FluxBBAuthPlugin * patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024 --- includes/cache/GenderCache.php | 93 +++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 19 deletions(-) (limited to 'includes/cache/GenderCache.php') diff --git a/includes/cache/GenderCache.php b/includes/cache/GenderCache.php index 342f8dba..2a169bb3 100644 --- a/includes/cache/GenderCache.php +++ b/includes/cache/GenderCache.php @@ -1,8 +1,30 @@ getName(); + } + + $username = self::normalizeUsername( $username ); if ( !isset( $this->cache[$username] ) ) { if ( $this->misses >= $this->missLimit && $wgUser->getName() !== $username ) { @@ -56,11 +82,7 @@ class GenderCache { } else { $this->misses++; - if ( !User::isValidUserName( $username ) ) { - $this->cache[$username] = $this->getDefault(); - } else { - $this->doQuery( $username, $caller ); - } + $this->doQuery( $username, $caller ); } } @@ -82,7 +104,6 @@ class GenderCache { foreach ( $data as $ns => $pagenames ) { if ( !MWNamespace::hasGenderDistinction( $ns ) ) continue; foreach ( array_keys( $pagenames ) as $username ) { - if ( isset( $this->cache[$username] ) ) continue; $users[$username] = true; } } @@ -90,6 +111,29 @@ class GenderCache { $this->doQuery( array_keys( $users ), $caller ); } + /** + * Wrapper for doQuery that processes a title or string array. + * + * @since 1.20 + * @param $titles List: array of Title objects or strings + * @param $caller String: the calling method + */ + public function doTitlesArray( $titles, $caller = '' ) { + $users = array(); + foreach ( $titles as $title ) { + $titleObj = is_string( $title ) ? Title::newFromText( $title ) : $title; + if ( !$titleObj ) { + continue; + } + if ( !MWNamespace::hasGenderDistinction( $titleObj->getNamespace() ) ) { + continue; + } + $users[] = $titleObj->getText(); + } + + $this->doQuery( $users, $caller ); + } + /** * Preloads genders for given list of users. * @param $users List|String: usernames @@ -98,26 +142,28 @@ class GenderCache { public function doQuery( $users, $caller = '' ) { $default = $this->getDefault(); - foreach ( (array) $users as $index => $value ) { - $name = strtr( $value, '_', ' ' ); - if ( isset( $this->cache[$name] ) ) { - // Skip users whose gender setting we already know - unset( $users[$index] ); - } else { - $users[$index] = $name; + $usersToCheck = array(); + foreach ( (array) $users as $value ) { + $name = self::normalizeUsername( $value ); + // Skip users whose gender setting we already know + if ( !isset( $this->cache[$name] ) ) { // For existing users, this value will be overwritten by the correct value $this->cache[$name] = $default; + // query only for valid names, which can be in the database + if( User::isValidUserName( $name ) ) { + $usersToCheck[] = $name; + } } } - if ( count( $users ) === 0 ) { + if ( count( $usersToCheck ) === 0 ) { return; } $dbr = wfGetDB( DB_SLAVE ); $table = array( 'user', 'user_properties' ); $fields = array( 'user_name', 'up_value' ); - $conds = array( 'user_name' => $users ); + $conds = array( 'user_name' => $usersToCheck ); $joins = array( 'user_properties' => array( 'LEFT JOIN', array( 'user_id = up_user', 'up_property' => 'gender' ) ) ); @@ -125,11 +171,20 @@ class GenderCache { if ( strval( $caller ) !== '' ) { $comment .= "/$caller"; } - $res = $dbr->select( $table, $fields, $conds, $comment, $joins, $joins ); + $res = $dbr->select( $table, $fields, $conds, $comment, array(), $joins ); foreach ( $res as $row ) { $this->cache[$row->user_name] = $row->up_value ? $row->up_value : $default; } } + private static function normalizeUsername( $username ) { + // Strip off subpages + $indexSlash = strpos( $username, '/' ); + if ( $indexSlash !== false ) { + $username = substr( $username, 0, $indexSlash ); + } + // normalize underscore/spaces + return strtr( $username, '_', ' ' ); + } } -- cgit v1.2.2