2007-12-27 02:31:58 +00:00
|
|
|
<?php
|
2012-05-09 17:55:56 +00:00
|
|
|
/**
|
|
|
|
|
* Representation of an user on a other locally-hosted wiki.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
2007-12-27 02:31:58 +00:00
|
|
|
|
2021-08-24 14:55:38 +00:00
|
|
|
use MediaWiki\DAO\WikiAwareEntityTrait;
|
2019-10-24 03:14:31 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
use MediaWiki\User\UserGroupManager;
|
2021-08-24 14:55:38 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2017-02-10 18:09:05 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
|
|
|
|
|
2007-12-27 02:31:58 +00:00
|
|
|
/**
|
|
|
|
|
* Cut-down copy of User interface for local-interwiki-database
|
|
|
|
|
* user rights manipulation.
|
|
|
|
|
*/
|
2021-08-24 14:55:38 +00:00
|
|
|
class UserRightsProxy implements UserIdentity {
|
|
|
|
|
use WikiAwareEntityTrait;
|
|
|
|
|
|
2018-10-16 02:18:16 +00:00
|
|
|
/** @var IDatabase */
|
|
|
|
|
private $db;
|
|
|
|
|
/** @var string */
|
2019-06-28 01:23:18 +00:00
|
|
|
private $dbDomain;
|
2018-10-16 02:18:16 +00:00
|
|
|
/** @var string */
|
|
|
|
|
private $name;
|
|
|
|
|
/** @var int */
|
|
|
|
|
private $id;
|
|
|
|
|
/** @var array */
|
|
|
|
|
private $newOptions;
|
2019-10-24 03:14:31 +00:00
|
|
|
/** @var UserGroupManager */
|
|
|
|
|
private $userGroupManager;
|
2010-01-12 21:49:47 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see newFromId()
|
|
|
|
|
* @see newFromName()
|
2015-10-04 09:07:25 +00:00
|
|
|
* @param IDatabase $db Db connection
|
2019-06-28 01:23:18 +00:00
|
|
|
* @param string $dbDomain Database name
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param string $name User name
|
|
|
|
|
* @param int $id User ID
|
2010-01-12 21:49:47 +00:00
|
|
|
*/
|
2019-06-28 01:23:18 +00:00
|
|
|
private function __construct( $db, $dbDomain, $name, $id ) {
|
2007-12-27 02:31:58 +00:00
|
|
|
$this->db = $db;
|
2019-06-28 01:23:18 +00:00
|
|
|
$this->dbDomain = $dbDomain;
|
2007-12-27 02:31:58 +00:00
|
|
|
$this->name = $name;
|
|
|
|
|
$this->id = intval( $id );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->newOptions = [];
|
2019-10-24 03:14:31 +00:00
|
|
|
$this->userGroupManager = MediaWikiServices::getInstance()
|
|
|
|
|
->getUserGroupManagerFactory()
|
|
|
|
|
->getUserGroupManager( $dbDomain );
|
2007-12-27 02:31:58 +00:00
|
|
|
}
|
2010-01-12 21:49:47 +00:00
|
|
|
|
2007-12-27 02:31:58 +00:00
|
|
|
/**
|
|
|
|
|
* Confirm the selected database name is a valid local interwiki database name.
|
2010-01-12 21:49:47 +00:00
|
|
|
*
|
2019-06-28 01:23:18 +00:00
|
|
|
* @param string $dbDomain Database name
|
2014-04-22 11:07:02 +00:00
|
|
|
* @return bool
|
2007-12-27 02:31:58 +00:00
|
|
|
*/
|
2019-06-28 01:23:18 +00:00
|
|
|
public static function validDatabase( $dbDomain ) {
|
2007-12-27 02:31:58 +00:00
|
|
|
global $wgLocalDatabases;
|
2019-06-28 01:23:18 +00:00
|
|
|
return in_array( $dbDomain, $wgLocalDatabases );
|
2007-12-27 02:31:58 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-12 21:49:47 +00:00
|
|
|
/**
|
|
|
|
|
* Same as User::whoIs()
|
|
|
|
|
*
|
2019-06-28 01:23:18 +00:00
|
|
|
* @param string $dbDomain Database name
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param int $id User ID
|
2019-06-28 01:23:18 +00:00
|
|
|
* @param bool $ignoreInvalidDB If true, don't check if $dbDomain is in $wgLocalDatabases
|
2014-04-22 11:07:02 +00:00
|
|
|
* @return string User name or false if the user doesn't exist
|
2010-01-12 21:49:47 +00:00
|
|
|
*/
|
2019-06-28 01:23:18 +00:00
|
|
|
public static function whoIs( $dbDomain, $id, $ignoreInvalidDB = false ) {
|
|
|
|
|
$user = self::newFromId( $dbDomain, $id, $ignoreInvalidDB );
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $user ) {
|
2007-12-27 02:31:58 +00:00
|
|
|
return $user->name;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-12-27 02:31:58 +00:00
|
|
|
/**
|
|
|
|
|
* Factory function; get a remote user entry by ID number.
|
2010-01-12 21:49:47 +00:00
|
|
|
*
|
2019-06-28 01:23:18 +00:00
|
|
|
* @param string $dbDomain Database name
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param int $id User ID
|
2019-06-28 01:23:18 +00:00
|
|
|
* @param bool $ignoreInvalidDB If true, don't check if $dbDomain is in $wgLocalDatabases
|
2014-04-22 11:07:02 +00:00
|
|
|
* @return UserRightsProxy|null If doesn't exist
|
2007-12-27 02:31:58 +00:00
|
|
|
*/
|
2019-06-28 01:23:18 +00:00
|
|
|
public static function newFromId( $dbDomain, $id, $ignoreInvalidDB = false ) {
|
|
|
|
|
return self::newFromLookup( $dbDomain, 'user_id', intval( $id ), $ignoreInvalidDB );
|
2007-12-27 02:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-12 21:49:47 +00:00
|
|
|
/**
|
|
|
|
|
* Factory function; get a remote user entry by name.
|
|
|
|
|
*
|
2019-06-28 01:23:18 +00:00
|
|
|
* @param string $dbDomain Database name
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param string $name User name
|
2019-06-28 01:23:18 +00:00
|
|
|
* @param bool $ignoreInvalidDB If true, don't check if $dbDomain is in $wgLocalDatabases
|
2014-04-22 11:07:02 +00:00
|
|
|
* @return UserRightsProxy|null If doesn't exist
|
2010-01-12 21:49:47 +00:00
|
|
|
*/
|
2019-06-28 01:23:18 +00:00
|
|
|
public static function newFromName( $dbDomain, $name, $ignoreInvalidDB = false ) {
|
|
|
|
|
return self::newFromLookup( $dbDomain, 'user_name', $name, $ignoreInvalidDB );
|
2007-12-27 02:31:58 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-10-26 03:44:47 +00:00
|
|
|
/**
|
2019-06-28 01:23:18 +00:00
|
|
|
* @param string $dbDomain
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param string $field
|
|
|
|
|
* @param string $value
|
|
|
|
|
* @param bool $ignoreInvalidDB
|
2011-10-26 03:44:47 +00:00
|
|
|
* @return null|UserRightsProxy
|
|
|
|
|
*/
|
2019-06-28 01:23:18 +00:00
|
|
|
private static function newFromLookup( $dbDomain, $field, $value, $ignoreInvalidDB = false ) {
|
2014-02-05 21:03:15 +00:00
|
|
|
global $wgSharedDB, $wgSharedTables;
|
2015-03-03 18:29:54 +00:00
|
|
|
// If the user table is shared, perform the user query on it,
|
|
|
|
|
// but don't pass it to the UserRightsProxy,
|
2014-02-05 21:03:15 +00:00
|
|
|
// as user rights are normally not shared.
|
|
|
|
|
if ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
|
|
|
|
|
$userdb = self::getDB( $wgSharedDB, $ignoreInvalidDB );
|
|
|
|
|
} else {
|
2019-06-28 01:23:18 +00:00
|
|
|
$userdb = self::getDB( $dbDomain, $ignoreInvalidDB );
|
2014-02-05 21:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
2019-06-28 01:23:18 +00:00
|
|
|
$db = self::getDB( $dbDomain, $ignoreInvalidDB );
|
2014-02-05 21:03:15 +00:00
|
|
|
|
|
|
|
|
if ( $db && $userdb ) {
|
|
|
|
|
$row = $userdb->selectRow( 'user',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'user_id', 'user_name' ],
|
|
|
|
|
[ $field => $value ],
|
2007-12-27 02:31:58 +00:00
|
|
|
__METHOD__ );
|
2014-02-05 21:03:15 +00:00
|
|
|
|
2013-04-20 22:49:30 +00:00
|
|
|
if ( $row !== false ) {
|
2018-10-16 02:18:16 +00:00
|
|
|
return new UserRightsProxy(
|
2019-06-28 01:23:18 +00:00
|
|
|
$db, $dbDomain, $row->user_name, intval( $row->user_id ) );
|
2007-12-27 02:31:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Open a database connection to work on for the requested user.
|
|
|
|
|
* This may be a new connection to another database for remote users.
|
2010-01-12 21:49:47 +00:00
|
|
|
*
|
2019-06-28 01:23:18 +00:00
|
|
|
* @param string $dbDomain
|
|
|
|
|
* @param bool $ignoreInvalidDB If true, don't check if $dbDomain is in $wgLocalDatabases
|
2015-10-06 05:39:37 +00:00
|
|
|
* @return IDatabase|null If invalid selection
|
2007-12-27 02:31:58 +00:00
|
|
|
*/
|
2019-06-28 01:23:18 +00:00
|
|
|
public static function getDB( $dbDomain, $ignoreInvalidDB = false ) {
|
|
|
|
|
if ( $ignoreInvalidDB || self::validDatabase( $dbDomain ) ) {
|
|
|
|
|
if ( WikiMap::isCurrentWikiId( $dbDomain ) ) {
|
2007-12-27 02:31:58 +00:00
|
|
|
// Hmm... this shouldn't happen though. :)
|
2021-04-29 02:37:11 +00:00
|
|
|
return wfGetDB( DB_PRIMARY );
|
2007-12-27 02:31:58 +00:00
|
|
|
} else {
|
2021-04-29 02:37:11 +00:00
|
|
|
return wfGetDB( DB_PRIMARY, [], $dbDomain );
|
2007-12-27 02:31:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-10-26 03:44:47 +00:00
|
|
|
/**
|
2021-08-24 14:55:38 +00:00
|
|
|
* @param string|false $wikiId
|
2011-10-26 03:44:47 +00:00
|
|
|
* @return int
|
|
|
|
|
*/
|
2021-08-24 14:55:38 +00:00
|
|
|
public function getId( $wikiId = self::LOCAL ): int {
|
2007-12-27 02:31:58 +00:00
|
|
|
return $this->id;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2011-10-26 03:44:47 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2021-08-24 14:55:38 +00:00
|
|
|
public function isAnon(): bool {
|
|
|
|
|
return !$this->isRegistered();
|
2007-12-27 02:31:58 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-12 21:49:47 +00:00
|
|
|
/**
|
|
|
|
|
* Same as User::getName()
|
|
|
|
|
*
|
2014-04-22 11:07:02 +00:00
|
|
|
* @return string
|
2010-01-12 21:49:47 +00:00
|
|
|
*/
|
2021-08-24 14:55:38 +00:00
|
|
|
public function getName(): string {
|
2019-06-28 01:23:18 +00:00
|
|
|
return $this->name . '@' . $this->dbDomain;
|
2007-12-27 02:31:58 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-12 21:49:47 +00:00
|
|
|
/**
|
|
|
|
|
* Same as User::getUserPage()
|
|
|
|
|
*
|
2014-04-22 11:07:02 +00:00
|
|
|
* @return Title
|
2010-01-12 21:49:47 +00:00
|
|
|
*/
|
2007-12-27 02:31:58 +00:00
|
|
|
public function getUserPage() {
|
|
|
|
|
return Title::makeTitle( NS_USER, $this->getName() );
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-12 21:49:47 +00:00
|
|
|
/**
|
|
|
|
|
* Replaces User::getUserGroups()
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return string[]
|
2010-01-12 21:49:47 +00:00
|
|
|
*/
|
2020-05-17 22:39:57 +00:00
|
|
|
public function getGroups() {
|
2017-01-31 10:24:20 +00:00
|
|
|
return array_keys( self::getGroupMemberships() );
|
2007-12-27 02:31:58 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-12 21:49:47 +00:00
|
|
|
/**
|
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
2017-01-12 06:07:56 +00:00
|
|
|
* Replaces User::getGroupMemberships()
|
|
|
|
|
*
|
2020-10-28 10:01:33 +00:00
|
|
|
* @return UserGroupMembership[]
|
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
2017-01-12 06:07:56 +00:00
|
|
|
* @since 1.29
|
|
|
|
|
*/
|
2020-05-17 22:39:57 +00:00
|
|
|
public function getGroupMemberships() {
|
2021-08-24 14:55:38 +00:00
|
|
|
return $this->userGroupManager->getUserGroupMemberships( $this, IDBAccessObject::READ_LATEST );
|
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
2017-01-12 06:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Replaces User::addGroup()
|
2015-02-11 01:14:27 +00:00
|
|
|
*
|
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
2017-01-12 06:07:56 +00:00
|
|
|
* @param string $group
|
|
|
|
|
* @param string|null $expiry
|
2015-02-11 01:14:27 +00:00
|
|
|
* @return bool
|
2010-01-12 21:49:47 +00:00
|
|
|
*/
|
2020-05-17 22:39:57 +00:00
|
|
|
public function addGroup( $group, $expiry = null ) {
|
2019-10-24 03:14:31 +00:00
|
|
|
return $this->userGroupManager->addUserToGroup(
|
2021-08-24 14:55:38 +00:00
|
|
|
$this,
|
2019-10-24 03:14:31 +00:00
|
|
|
$group,
|
2021-02-11 05:28:20 +00:00
|
|
|
$expiry,
|
|
|
|
|
true
|
2019-10-24 03:14:31 +00:00
|
|
|
);
|
2007-12-27 02:31:58 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-12 21:49:47 +00:00
|
|
|
/**
|
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
2017-01-12 06:07:56 +00:00
|
|
|
* Replaces User::removeGroup()
|
2015-02-11 01:14:27 +00:00
|
|
|
*
|
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
2017-01-12 06:07:56 +00:00
|
|
|
* @param string $group
|
2015-02-11 01:14:27 +00:00
|
|
|
* @return bool
|
2010-01-12 21:49:47 +00:00
|
|
|
*/
|
2020-05-17 22:39:57 +00:00
|
|
|
public function removeGroup( $group ) {
|
2019-10-24 03:14:31 +00:00
|
|
|
return $this->userGroupManager->removeUserFromGroup(
|
2021-08-24 14:55:38 +00:00
|
|
|
$this,
|
2019-10-24 03:14:31 +00:00
|
|
|
$group
|
|
|
|
|
);
|
2007-12-27 02:31:58 +00:00
|
|
|
}
|
2011-10-26 03:44:47 +00:00
|
|
|
|
2010-08-07 16:08:22 +00:00
|
|
|
/**
|
|
|
|
|
* Replaces User::setOption()
|
2014-04-22 11:07:02 +00:00
|
|
|
* @param string $option
|
|
|
|
|
* @param mixed $value
|
2010-08-07 16:08:22 +00:00
|
|
|
*/
|
|
|
|
|
public function setOption( $option, $value ) {
|
|
|
|
|
$this->newOptions[$option] = $value;
|
|
|
|
|
}
|
2011-10-26 03:44:47 +00:00
|
|
|
|
2010-08-07 16:08:22 +00:00
|
|
|
public function saveSettings() {
|
2016-02-17 09:09:32 +00:00
|
|
|
$rows = [];
|
2010-08-07 16:08:22 +00:00
|
|
|
foreach ( $this->newOptions as $option => $value ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$rows[] = [
|
2010-08-07 16:08:22 +00:00
|
|
|
'up_user' => $this->id,
|
|
|
|
|
'up_property' => $option,
|
|
|
|
|
'up_value' => $value,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2010-08-07 16:08:22 +00:00
|
|
|
}
|
2020-03-24 22:28:16 +00:00
|
|
|
$this->db->replace(
|
|
|
|
|
'user_properties',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ [ 'up_user', 'up_property' ] ],
|
2020-03-24 22:28:16 +00:00
|
|
|
$rows,
|
|
|
|
|
__METHOD__
|
2010-08-07 16:08:22 +00:00
|
|
|
);
|
|
|
|
|
$this->invalidateCache();
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-01-12 21:49:47 +00:00
|
|
|
/**
|
|
|
|
|
* Replaces User::touchUser()
|
|
|
|
|
*/
|
2020-05-17 22:39:57 +00:00
|
|
|
public function invalidateCache() {
|
2016-09-15 21:40:00 +00:00
|
|
|
$this->db->update(
|
|
|
|
|
'user',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'user_touched' => $this->db->timestamp() ],
|
|
|
|
|
[ 'user_id' => $this->id ],
|
2016-09-15 21:40:00 +00:00
|
|
|
__METHOD__
|
|
|
|
|
);
|
2007-12-27 02:31:58 +00:00
|
|
|
|
2017-09-25 10:37:13 +00:00
|
|
|
$domainId = $this->db->getDomainID();
|
2015-10-27 23:43:40 +00:00
|
|
|
$userId = $this->id;
|
2016-09-15 21:40:00 +00:00
|
|
|
$this->db->onTransactionPreCommitOrIdle(
|
2021-02-10 22:31:02 +00:00
|
|
|
static function () use ( $domainId, $userId ) {
|
2017-09-25 10:37:13 +00:00
|
|
|
User::purge( $domainId, $userId );
|
2016-09-15 21:40:00 +00:00
|
|
|
},
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2007-12-27 02:31:58 +00:00
|
|
|
}
|
2021-08-24 14:55:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
*/
|
|
|
|
|
public function equals( ?UserIdentity $user ): bool {
|
|
|
|
|
if ( !$user ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return $this->getName() === $user->getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
*/
|
|
|
|
|
public function isRegistered(): bool {
|
|
|
|
|
return $this->getId( $this->getWikiId() ) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the db Domain of the wiki the UserRightsProxy is associated with.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.37
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getWikiId() {
|
|
|
|
|
return $this->dbDomain;
|
|
|
|
|
}
|
2007-12-27 02:31:58 +00:00
|
|
|
}
|