User group memberships that expire
authorThis, that and the other <at.light@live.com.au>
Thu, 12 Jan 2017 06:07:56 +0000 (17:07 +1100)
committerTTO <at.light@live.com.au>
Fri, 27 Jan 2017 09:24:20 +0000 (09:24 +0000)
commit73224f4f8b8a26b9a9a04e338bb1c3c2f163a820
tree82af60159983715db181af49df086da89f95d4e8
parent2e5eb693de627ef0503d380429b8c042a50f1b1b
User group memberships that expire

This patch adds an ug_expiry column to the user_groups table, a timestamp
giving a date when the user group expires. A new UserGroupMembership class,
based on the Block class, manages entries in this table.

When the expiry date passes, the row in user_groups is ignored, and will
eventually be purged from the DB when UserGroupMembership::insert is next
called. Old, expired user group memberships are not kept; instead, the log
entries are available to find the history of these memberships, similar
to the way it has always worked for blocks and protections.

Anyone getting user group info through the User object will get correct
information. However, code that reads the user_groups table directly will
now need to skip over rows with ug_expiry < wfTimestampNow(). See
UsersPager for an example of how to do this.

NULL is used to represent infinite (no) expiry, rather than a string
'infinity' or similar (except in the API). This allows existing user group
assignments and log entries, which are all infinite in duration, to be
treated the same as new, infinite-length memberships, without special
casing everything.

The whole thing is behind the temporary feature flag
$wgDisableUserGroupExpiry, in accordance with the WMF schema change policy.

The opportunity has been taken to refactor some static user-group-related
functions out of User into UserGroupMembership, and also to add a primary
key (ug_user, ug_group) to the user_groups table.

There are a few breaking changes:
- UserRightsProxy-like objects are now required to have a
  getGroupMemberships() function.
- $user->mGroups (on a User object) is no longer present.
- Some protected functions in UsersPager are altered or removed.
- The UsersPagerDoBatchLookups hook (unused in any Wikimedia Git-hosted
  extension) has a change of parameter.

Bug: T12493
Depends-On: Ia9616e1e35184fed9058d2d39afbe1038f56d7fa
Depends-On: I86eb1d5619347ce54a5f33a591417742ebe5d6f8
Change-Id: I93c955dc7a970f78e32aa503c01c67da30971d1a
43 files changed:
RELEASE-NOTES-1.29
autoload.php
docs/hooks.txt
includes/DefaultSettings.php
includes/Preferences.php
includes/Title.php
includes/api/ApiQueryUserInfo.php
includes/api/ApiQueryUsers.php
includes/api/ApiUserrights.php
includes/api/i18n/en.json
includes/api/i18n/qqq.json
includes/exception/PermissionsError.php
includes/installer/MysqlUpdater.php
includes/installer/OracleUpdater.php
includes/installer/PostgresUpdater.php
includes/installer/SqliteUpdater.php
includes/logging/RightsLogFormatter.php
includes/specials/SpecialActiveusers.php
includes/specials/SpecialListgrouprights.php
includes/specials/SpecialUserrights.php
includes/specials/pagers/ActiveUsersPager.php
includes/specials/pagers/UsersPager.php
includes/user/User.php
includes/user/UserGroupMembership.php [new file with mode: 0644]
includes/user/UserRightsProxy.php
languages/i18n/en.json
languages/i18n/qqq.json
maintenance/archives/patch-user_groups-ug_expiry.sql [new file with mode: 0644]
maintenance/mssql/archives/patch-user_groups-ug_expiry.sql [new file with mode: 0644]
maintenance/mssql/tables.sql
maintenance/oracle/archives/patch-user_groups-ug_expiry.sql [new file with mode: 0644]
maintenance/oracle/tables.sql
maintenance/postgres/tables.sql
maintenance/sqlite/archives/patch-user_groups-ug_expiry.sql [new file with mode: 0644]
maintenance/tables.sql
resources/Resources.php
resources/src/mediawiki.special/mediawiki.special.userrights.css [new file with mode: 0644]
resources/src/mediawiki.special/mediawiki.special.userrights.js
tests/phpunit/includes/logging/RightsLogFormatterTest.php
tests/phpunit/includes/page/WikiPageTest.php
tests/phpunit/includes/password/UserPasswordPolicyTest.php
tests/phpunit/includes/user/UserGroupMembershipTest.php [new file with mode: 0644]
tests/phpunit/includes/user/UserTest.php