TTO has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/328491 )

Change subject: Disregard expired user_group rows in special page and API DB 
queries
......................................................................

Disregard expired user_group rows in special page and API DB queries

An essential follow-up to I93c955dc7a970f78e32aa503c01c67da30971d1a.

Bug: T12493
Change-Id: Icf78cce3f3e362677d10897b8d1103b3df91fa08
---
M includes/SiteStats.php
M includes/api/ApiQueryAllImages.php
M includes/api/ApiQueryAllUsers.php
M includes/api/ApiQueryContributors.php
M includes/api/ApiQueryUsers.php
M includes/specials/pagers/ActiveUsersPager.php
M includes/specials/pagers/ContribsPager.php
M includes/specials/pagers/NewFilesPager.php
M includes/specials/pagers/UsersPager.php
9 files changed, 48 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/91/328491/1

diff --git a/includes/SiteStats.php b/includes/SiteStats.php
index ff7875c..4b12715 100644
--- a/includes/SiteStats.php
+++ b/includes/SiteStats.php
@@ -193,7 +193,10 @@
                                return $dbr->selectField(
                                        'user_groups',
                                        'COUNT(*)',
-                                       [ 'ug_group' => $group ],
+                                       [
+                                               'ug_group' => $group,
+                                               'ug_expiry IS NULL OR ug_expiry 
> ' . $dbr->addQuotes( $dbr->timestamp() )
+                                       ],
                                        __METHOD__
                                );
                        },
diff --git a/includes/api/ApiQueryAllImages.php 
b/includes/api/ApiQueryAllImages.php
index e3e5ed6..22561a9 100644
--- a/includes/api/ApiQueryAllImages.php
+++ b/includes/api/ApiQueryAllImages.php
@@ -197,7 +197,8 @@
                                        'LEFT JOIN',
                                        [
                                                'ug_group' => 
User::getGroupsWithPermission( 'bot' ),
-                                               'ug_user = img_user'
+                                               'ug_user = img_user',
+                                               'ug_expiry IS NULL OR ug_expiry 
>=' . $db->addQuotes( $db->timestamp() )
                                        ]
                                ] ] );
                                $groupCond = ( $params['filterbots'] == 
'nobots' ? 'NULL' : 'NOT NULL' );
diff --git a/includes/api/ApiQueryAllUsers.php 
b/includes/api/ApiQueryAllUsers.php
index 2e2ac32..3faccf9 100644
--- a/includes/api/ApiQueryAllUsers.php
+++ b/includes/api/ApiQueryAllUsers.php
@@ -116,8 +116,16 @@
                        // Filter only users that belong to a given group. This 
might
                        // produce as many rows-per-user as there are groups 
being checked.
                        $this->addTables( 'user_groups', 'ug1' );
-                       $this->addJoinConds( [ 'ug1' => [ 'INNER JOIN', [ 
'ug1.ug_user=user_id',
-                               'ug1.ug_group' => $params['group'] ] ] ] );
+                       $this->addJoinConds( [
+                               'ug1' => [
+                                       'INNER JOIN',
+                                       [
+                                               'ug1.ug_user=user_id',
+                                               'ug1.ug_group' => 
$params['group'],
+                                               'ug1.ug_expiry IS NULL OR 
ug1.ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
+                                       ]
+                               ]
+                       ] );
                        $maxDuplicateRows *= count( $params['group'] );
                }
 
@@ -135,7 +143,10 @@
                                ) ];
                        }
                        $this->addJoinConds( [ 'ug1' => [ 'LEFT OUTER JOIN',
-                               array_merge( [ 'ug1.ug_user=user_id' ], 
$exclude )
+                               array_merge( [
+                                       'ug1.ug_user=user_id',
+                                       'ug1.ug_expiry IS NULL OR ug1.ug_expiry 
>= ' . $db->addQuotes( $db->timestamp() )
+                               ], $exclude )
                        ] ] );
                        $this->addWhere( 'ug1.ug_user IS NULL' );
                }
@@ -148,7 +159,10 @@
 
                if ( $fld_groups || $fld_rights ) {
                        $this->addFields( [ 'groups' =>
-                               $db->buildGroupConcatField( '|', 'user_groups', 
'ug_group', 'ug_user=user_id' )
+                               $db->buildGroupConcatField( '|', 'user_groups', 
'ug_group', [
+                                       'ug_user=user_id',
+                                       'ug_expiry IS NULL OR ug_expiry >= ' . 
$db->addQuotes( $db->timestamp() )
+                               ] )
                        ] );
                }
 
diff --git a/includes/api/ApiQueryContributors.php 
b/includes/api/ApiQueryContributors.php
index ac5ccca..89fffd6 100644
--- a/includes/api/ApiQueryContributors.php
+++ b/includes/api/ApiQueryContributors.php
@@ -160,7 +160,11 @@
                        $this->addTables( 'user_groups' );
                        $this->addJoinConds( [ 'user_groups' => [
                                $excludeGroups ? 'LEFT OUTER JOIN' : 'INNER 
JOIN',
-                               [ 'ug_user=rev_user', 'ug_group' => 
$limitGroups ]
+                               [
+                                       'ug_user=rev_user',
+                                       'ug_group' => $limitGroups,
+                                       'ug_expiry IS NULL OR ug_expiry >= ' . 
$db->addQuotes( $db->timestamp() )
+                               ]
                        ] ] );
                        $this->addWhereIf( 'ug_user IS NULL', $excludeGroups );
                }
diff --git a/includes/api/ApiQueryUsers.php b/includes/api/ApiQueryUsers.php
index 86b4c9f..d689eac 100644
--- a/includes/api/ApiQueryUsers.php
+++ b/includes/api/ApiQueryUsers.php
@@ -168,11 +168,15 @@
 
                                $this->addTables( 'user_groups' );
                                $this->addJoinConds( [ 'user_groups' => [ 
'INNER JOIN', 'ug_user=user_id' ] ] );
-                               $this->addFields( [ 'user_name', 'ug_group' ] );
+                               $this->addFields( array_merge( [ 'user_name' ], 
UserGroupMembership::selectFields() ) );
                                $userGroupsRes = $this->select( __METHOD__ );
 
+                               $now = wfTimestampNow();
                                foreach ( $userGroupsRes as $row ) {
-                                       $userGroups[$row->user_name][] = 
$row->ug_group;
+                                       // don't keep expired user groups
+                                       if ( !$row->ug_expiry || 
$row->ug_expiry >= $now ) {
+                                               $userGroups[$row->user_name][] 
= $row;
+                                       }
                                }
                        }
 
diff --git a/includes/specials/pagers/ActiveUsersPager.php 
b/includes/specials/pagers/ActiveUsersPager.php
index a748272..e2f4d4b 100644
--- a/includes/specials/pagers/ActiveUsersPager.php
+++ b/includes/specials/pagers/ActiveUsersPager.php
@@ -101,12 +101,17 @@
                        $tables[] = 'user_groups';
                        $conds[] = 'ug_user = user_id';
                        $conds['ug_group'] = $this->groups;
+                       $conds[] = 'ug_expiry IS NULL OR ug_expiry >= ' . 
$dbr->addQuotes( $dbr->timestamp() );
                }
                if ( $this->excludegroups !== [] ) {
                        foreach ( $this->excludegroups as $group ) {
                                $conds[] = 'NOT EXISTS (' . $dbr->selectSQLText(
-                                               'user_groups', '1', [ 'ug_user 
= user_id', 'ug_group' => $group ]
-                                       ) . ')';
+                                       'user_groups', '1', [
+                                               'ug_user = user_id',
+                                               'ug_group' => $group,
+                                               'ug_expiry IS NULL OR ug_expiry 
>= ' . $dbr->addQuotes( $dbr->timestamp() )
+                                       ]
+                               ) . ')';
                        }
                }
                if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
diff --git a/includes/specials/pagers/ContribsPager.php 
b/includes/specials/pagers/ContribsPager.php
index 39c55c8..3993f62 100644
--- a/includes/specials/pagers/ContribsPager.php
+++ b/includes/specials/pagers/ContribsPager.php
@@ -222,7 +222,8 @@
                                $join_conds['user_groups'] = [
                                        'LEFT JOIN', [
                                                'ug_user = rev_user',
-                                               'ug_group' => 
$groupsWithBotPermission
+                                               'ug_group' => 
$groupsWithBotPermission,
+                                               'ug_expiry IS NULL OR ug_expiry 
>= ' . $this->mDb->addQuotes( $this->mDb->timestamp() )
                                        ]
                                ];
                        }
diff --git a/includes/specials/pagers/NewFilesPager.php 
b/includes/specials/pagers/NewFilesPager.php
index 9f6c58c..67c81a6 100644
--- a/includes/specials/pagers/NewFilesPager.php
+++ b/includes/specials/pagers/NewFilesPager.php
@@ -59,13 +59,15 @@
                        $groupsWithBotPermission = 
User::getGroupsWithPermission( 'bot' );
 
                        if ( count( $groupsWithBotPermission ) ) {
+                               $dbr = wfGetDB( DB_REPLICA );
                                $tables[] = 'user_groups';
                                $conds[] = 'ug_group IS NULL';
                                $jconds['user_groups'] = [
                                        'LEFT JOIN',
                                        [
                                                'ug_group' => 
$groupsWithBotPermission,
-                                               'ug_user = img_user'
+                                               'ug_user = img_user',
+                                               'ug_expiry IS NULL OR ug_expiry 
>= ' . $dbr->addQuotes( $dbr->timestamp() )
                                        ]
                                ];
                        }
diff --git a/includes/specials/pagers/UsersPager.php 
b/includes/specials/pagers/UsersPager.php
index 359e0fe..d628432 100644
--- a/includes/specials/pagers/UsersPager.php
+++ b/includes/specials/pagers/UsersPager.php
@@ -112,6 +112,7 @@
 
                if ( $this->requestedGroup != '' ) {
                        $conds['ug_group'] = $this->requestedGroup;
+                       $conds[] = 'ug_expiry IS NULL OR ug_expiry >= ' . 
$dbr->addQuotes( $dbr->timestamp() );
                }
 
                if ( $this->requestedUser != '' ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/328491
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf78cce3f3e362677d10897b8d1103b3df91fa08
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: TTO <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to