Add new UsersPagerDoBatchLookups hook to allow for extensions to modify UsersPager...
authorJack Phoenix <jack@countervandalism.net>
Wed, 24 Aug 2016 14:00:22 +0000 (17:00 +0300)
committerJack Phoenix <jack@countervandalism.net>
Thu, 25 Aug 2016 19:24:21 +0000 (22:24 +0300)
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
includes/specials/pagers/UsersPager.php

index a0ee8bd..5c1fe3e 100644 (file)
@@ -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).
index 7b058c1..adc1dd8 100644 (file)
@@ -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