From 271c418765a8b4ee2219487246822b46eb3eb023 Mon Sep 17 00:00:00 2001 From: Jack Phoenix Date: Wed, 24 Aug 2016 17:00:22 +0300 Subject: [PATCH] Add new UsersPagerDoBatchLookups hook to allow for extensions to modify UsersPager::doBatchLookup()'s rigid behavior Currently UsersPager::doBatchLookup() assumes that group data comes *only* from one place, the (local) user_groups DB table. But this isn't correct when an extension like [[mw:Extension:GlobalUserrights]] is installed. With the current master version of the GlobalUserrights ext. installed under MW 1.27, only the *local* groups are shown on Special:ListUsers. Even if you have a global group called 'staff' and you go to the [[Special:ListUsers/staff]] page, it *will* display the correct list of users, but the group data in parentheses is wrong; it's either 1) missing (if the user is only a member of a global group but not any local groups) or 2) incorrect in that it omits global group membership(s) entirely. With this hook, an extension such as GlobalUserrights is able to query an additional source of user group data (such as the global_user_groups table in $wgSharedDB in the case of the GlobalUserrights ext.) and have this data stored in the cache to ensure that global group data shows up as it should. Change-Id: Ied2c0f2d5738cf96a66a9672182345d630285639 --- docs/hooks.txt | 10 ++++++++++ includes/specials/pagers/UsersPager.php | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/docs/hooks.txt b/docs/hooks.txt index a0ee8bde3a..5c1fe3ed46 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -3649,6 +3649,16 @@ $userId: User id of the current user $userText: User name of the current user &$items: Array of user tool links as HTML fragments +'UsersPagerDoBatchLookups': Called in UsersPager::doBatchLookups() to give +extensions providing user group data from an alternate source a chance to add +their data into the cache array so that things like global user groups are +displayed correctly in Special:ListUsers. +$dbr: Read-only database handle +$userIds: Array of user IDs whose groups we should look up +&$cache: Array of user ID -> internal user group name (e.g. 'sysop') mappings +&$groups: Array of group name -> bool true mappings for members of a given user +group + 'ValidateExtendedMetadataCache': Called to validate the cached metadata in FormatMetadata::getExtendedMeta (return false means cache will be invalidated and GetExtendedMetadata hook called again). diff --git a/includes/specials/pagers/UsersPager.php b/includes/specials/pagers/UsersPager.php index 7b058c19eb..adc1dd8923 100644 --- a/includes/specials/pagers/UsersPager.php +++ b/includes/specials/pagers/UsersPager.php @@ -241,6 +241,11 @@ class UsersPager extends AlphabeticPager { $cache[intval( $row->ug_user )][] = $row->ug_group; $groups[$row->ug_group] = true; } + + // Give extensions a chance to add things like global user group data + // into the cache array to ensure proper output later on + Hooks::run( 'UsersPagerDoBatchLookups', [ $dbr, $userIds, &$cache, &$groups ] ); + $this->userGroupCache = $cache; // Add page of groups to link batch -- 2.20.1