Don't return expired user groups in UserRightsProxy
authorThis, that and the other <at.light@live.com.au>
Tue, 31 Jan 2017 10:24:20 +0000 (21:24 +1100)
committerThis, that and the other <at.light@live.com.au>
Tue, 31 Jan 2017 10:24:20 +0000 (21:24 +1100)
Also add a missing type hint in UserGroupMembership.

Bug: T156779
Change-Id: Ica31541f59115db3db92de82592e6a9422082bba

includes/user/UserGroupMembership.php
includes/user/UserRightsProxy.php

index bb0b7d2..59ca31c 100644 (file)
@@ -313,7 +313,7 @@ class UserGroupMembership {
         * @param IDatabase|null $db Optional database connection
         * @return array Associative array of (group name => UserGroupMembership object)
         */
-       public static function getMembershipsForUser( $userId, $db = null ) {
+       public static function getMembershipsForUser( $userId, IDatabase $db = null ) {
                if ( !$db ) {
                        $db = wfGetDB( DB_REPLICA );
                }
index 23c2177..d801fa0 100644 (file)
@@ -198,15 +198,7 @@ class UserRightsProxy {
         * @return array
         */
        function getGroups() {
-               $res = $this->db->select( 'user_groups',
-                       [ 'ug_group' ],
-                       [ 'ug_user' => $this->id ],
-                       __METHOD__ );
-               $groups = [];
-               foreach ( $res as $row ) {
-                       $groups[] = $row->ug_group;
-               }
-               return $groups;
+               return array_keys( self::getGroupMemberships() );
        }
 
        /**
@@ -216,15 +208,7 @@ class UserRightsProxy {
         * @since 1.29
         */
        function getGroupMemberships() {
-               $res = $this->db->select( 'user_groups',
-                       UserGroupMembership::selectFields(),
-                       [ 'ug_user' => $this->id ],
-                       __METHOD__ );
-               $ugms = [];
-               foreach ( $res as $row ) {
-                       $ugms[$row->ug_group] = UserGroupMembership::newFromRow( $row );
-               }
-               return $ugms;
+               return UserGroupMembership::getMembershipsForUser( $this->id, $this->db );
        }
 
        /**