2008-01-28 19:05:26 +00:00
|
|
|
<?php
|
2010-02-26 13:18:56 +00:00
|
|
|
/**
|
2023-03-16 17:27:37 +00:00
|
|
|
* Copyright © 2007 Roan Kattouw <roan.kattouw@gmail.com>
|
2008-01-28 19:05:26 +00:00
|
|
|
*
|
|
|
|
|
* 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.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-01-28 19:05:26 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2008-01-28 19:05:26 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-07-03 21:57:18 +00:00
|
|
|
use MediaWiki\Auth\AuthManager;
|
2019-09-05 18:24:28 +00:00
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
2021-07-03 21:57:18 +00:00
|
|
|
use MediaWiki\User\UserFactory;
|
|
|
|
|
use MediaWiki\User\UserGroupManager;
|
2021-05-28 13:38:53 +00:00
|
|
|
use MediaWiki\User\UserNameUtils;
|
2022-06-05 23:18:50 +00:00
|
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
2019-09-05 18:24:28 +00:00
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
/**
|
|
|
|
|
* Query module to get information about a list of users
|
2008-04-14 07:45:50 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup API
|
2008-01-28 19:05:26 +00:00
|
|
|
*/
|
2011-03-06 18:17:28 +00:00
|
|
|
class ApiQueryUsers extends ApiQueryBase {
|
2019-09-05 18:24:28 +00:00
|
|
|
use ApiQueryBlockInfoTrait;
|
2008-01-28 19:05:26 +00:00
|
|
|
|
2021-04-20 13:42:53 +00:00
|
|
|
private $prop;
|
2010-10-06 21:18:55 +00:00
|
|
|
|
2023-08-28 15:32:58 +00:00
|
|
|
private UserNameUtils $userNameUtils;
|
|
|
|
|
private UserFactory $userFactory;
|
|
|
|
|
private UserGroupManager $userGroupManager;
|
|
|
|
|
private GenderCache $genderCache;
|
|
|
|
|
private AuthManager $authManager;
|
2021-07-03 21:57:18 +00:00
|
|
|
|
2014-04-22 01:45:42 +00:00
|
|
|
/**
|
|
|
|
|
* Properties whose contents does not depend on who is looking at them. If the usprops field
|
|
|
|
|
* contains anything not listed here, the cache mode will never be public for logged-in users.
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
2016-02-17 09:09:32 +00:00
|
|
|
protected static $publicProps = [
|
2014-04-22 01:45:42 +00:00
|
|
|
// everything except 'blockinfo' which might show hidden records if the user
|
|
|
|
|
// making the request has the appropriate permissions
|
|
|
|
|
'groups',
|
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
|
|
|
'groupmemberships',
|
2014-04-22 01:45:42 +00:00
|
|
|
'implicitgroups',
|
|
|
|
|
'rights',
|
|
|
|
|
'editcount',
|
|
|
|
|
'registration',
|
|
|
|
|
'emailable',
|
|
|
|
|
'gender',
|
2015-11-19 20:57:12 +00:00
|
|
|
'centralids',
|
2016-01-11 18:20:22 +00:00
|
|
|
'cancreate',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2014-04-22 01:45:42 +00:00
|
|
|
|
2021-05-28 13:38:53 +00:00
|
|
|
/**
|
|
|
|
|
* @param ApiQuery $query
|
|
|
|
|
* @param string $moduleName
|
|
|
|
|
* @param UserNameUtils $userNameUtils
|
2021-07-03 21:57:18 +00:00
|
|
|
* @param UserFactory $userFactory
|
|
|
|
|
* @param UserGroupManager $userGroupManager
|
2021-11-30 19:40:45 +00:00
|
|
|
* @param GenderCache $genderCache
|
2021-07-03 21:57:18 +00:00
|
|
|
* @param AuthManager $authManager
|
2021-05-28 13:38:53 +00:00
|
|
|
*/
|
2021-07-03 21:57:18 +00:00
|
|
|
public function __construct(
|
|
|
|
|
ApiQuery $query,
|
|
|
|
|
$moduleName,
|
|
|
|
|
UserNameUtils $userNameUtils,
|
|
|
|
|
UserFactory $userFactory,
|
|
|
|
|
UserGroupManager $userGroupManager,
|
2021-11-30 19:40:45 +00:00
|
|
|
GenderCache $genderCache,
|
2021-07-03 21:57:18 +00:00
|
|
|
AuthManager $authManager
|
|
|
|
|
) {
|
2010-02-26 13:18:56 +00:00
|
|
|
parent::__construct( $query, $moduleName, 'us' );
|
2021-05-28 13:38:53 +00:00
|
|
|
$this->userNameUtils = $userNameUtils;
|
2021-07-03 21:57:18 +00:00
|
|
|
$this->userFactory = $userFactory;
|
|
|
|
|
$this->userGroupManager = $userGroupManager;
|
2021-11-30 19:40:45 +00:00
|
|
|
$this->genderCache = $genderCache;
|
2021-07-03 21:57:18 +00:00
|
|
|
$this->authManager = $authManager;
|
2008-01-28 19:05:26 +00:00
|
|
|
}
|
2010-02-26 13:18:56 +00:00
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function execute() {
|
2016-12-23 02:07:59 +00:00
|
|
|
$db = $this->getDB();
|
2008-01-28 19:05:26 +00:00
|
|
|
$params = $this->extractRequestParams();
|
2016-12-05 07:35:42 +00:00
|
|
|
$this->requireMaxOneParameter( $params, 'userids', 'users' );
|
2008-01-28 19:05:26 +00:00
|
|
|
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $params['prop'] !== null ) {
|
2021-06-11 02:52:06 +00:00
|
|
|
$this->prop = array_fill_keys( $params['prop'], true );
|
2008-01-28 19:05:26 +00:00
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->prop = [];
|
2008-01-28 19:05:26 +00:00
|
|
|
}
|
2020-01-09 23:48:34 +00:00
|
|
|
$useNames = $params['users'] !== null;
|
2008-04-14 07:45:50 +00:00
|
|
|
|
* API: BREAKING CHANGE: (bug 11430) Return fewer results than the limit in some cases to prevent running out of memory
* This means queries could possibly return fewer results than the limit and still set a query-continue
* Add iicontinue, rvcontinue, cicontinue, incontinue, amfrom to faciliate query-continue for these modules
* Implemented by blocking additions to the ApiResult object if they would make it too large
** Important things like query-continue values and warnings are exempt from this check
** RSS feeds and exported XML are also exempted (size-checking them would be too messy)
** Result size is checked against $wgAPIMaxResultSize, which defaults to 8 MB
For those who really care, per-file details follow:
ApiResult.php:
* Introduced ApiResult::$mSize which keeps track of the result size.
* Introduced ApiResult::size() which calculates an array's size
(which is the sum of the strlen()s of its elements).
* ApiResult::addValue() now checks that the result size stays below
$wgAPIMaxResultSize. If the item won't fit, it won't be added and addValue()
will return false. Callers should check the return value and set a
query-continue if it's false.
* Closed the back door that is ApiResult::getData(): callers can't manipulate
the data array directly anymore so they can't bypass the result size limit.
* Added ApiResult::setIndexedTagName_internal() which will call
setIndexedTagName() on an array already in the result. This is needed for the
'new' order of adding results, which means addValue()ing one result at a time
until you hit the limit or run out, then calling this function to set the tag
name.
* Added ApiResult::disableSizeCheck() and enableSizeCheck() which disable and
enable size checking in addValue(). This is used for stuff like query-continue
elements and warnings which shouldn't count towards the result size.
* Added ApiResult::unsetValue() which removes an element from the result and
decreases $mSize.
ApiBase.php:
* Like ApiResult::getData(), ApiBase::getResultData() no longer returns a
reference.
* Use ApiResult::disableSizeCheck() in ApiBase::setWarning()
ApiQueryBase.php:
* Added ApiQueryBase::addPageSubItem(), which adds page subitems one item
at a time.
* addPageSubItem() and addPageSubItems() now return whether the subitem
fit in the result.
* Use ApiResult::disableSizeCheck() in setContinueEnumParameter()
ApiMain.php:
* Use ApiResult::disableSizeCheck() in ApiMain::substituteResultWithError()
* Use getParameter() rather than $mRequest to obtain requestid
DefaultSettings.php:
* Added $wgAPIMaxResultSize, with a default value of 8 MB
ApiQuery*.php:
* Added results one at a time, and set a query-continue if the result is full.
ApiQueryLangLinks.php and friends:
* Migrated from addPageSubItems() to addPageSubItem(). This eliminates the
need for $lastId.
ApiQueryAllLinks.php, ApiQueryWatchlist.php, ApiQueryAllimages.php, ApiQuerySearch.php:
* Renamed $data to something more appropriate ($pageids, $ids or $titles)
ApiQuerySiteinfo.php:
* Abuse siprop as a query-continue parameter and set it to all props that
couldn't be processed.
ApiQueryRandom.php:
* Doesn't do continuations, because the result is supposed to be random.
* Be smart enough to not run the second query if the results of the first
didn't fit.
ApiQueryImageInfo.php, ApiQueryRevisions.php, ApiQueryCategoryInfo.php, ApiQueryInfo.php:
* Added continue parameter which basically skips the first so many items
ApiQueryBacklinks.php:
* Throw the result in a big array first and addValue() that one element at a time if necessary
** This is necessary because the results aren't retrieved in order
* Introduced $this->pageMap to map namespace and title to page ID
* Rewritten extractRowInfo() and extractRedirRowInfo() a little
* Declared all private member variables explicitly
ApiQueryDeletedrevs.php:
* Use a pagemap just like in Backlinks
* Introduce fake page IDs and keep track of them so we know where to add what
** This doesn't change the output format, because the fake page IDs start at 0 and are consecutive
ApiQueryAllmessages.php:
* Add amfrom to facilitate query-continue
ApiQueryUsers.php:
* Rewrite: put the getOtherUsersInfo() code in execute()
2009-02-05 14:30:59 +00:00
|
|
|
$users = (array)$params['users'];
|
2016-12-05 07:35:42 +00:00
|
|
|
$userids = (array)$params['userids'];
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$goodNames = $done = [];
|
* API: BREAKING CHANGE: (bug 11430) Return fewer results than the limit in some cases to prevent running out of memory
* This means queries could possibly return fewer results than the limit and still set a query-continue
* Add iicontinue, rvcontinue, cicontinue, incontinue, amfrom to faciliate query-continue for these modules
* Implemented by blocking additions to the ApiResult object if they would make it too large
** Important things like query-continue values and warnings are exempt from this check
** RSS feeds and exported XML are also exempted (size-checking them would be too messy)
** Result size is checked against $wgAPIMaxResultSize, which defaults to 8 MB
For those who really care, per-file details follow:
ApiResult.php:
* Introduced ApiResult::$mSize which keeps track of the result size.
* Introduced ApiResult::size() which calculates an array's size
(which is the sum of the strlen()s of its elements).
* ApiResult::addValue() now checks that the result size stays below
$wgAPIMaxResultSize. If the item won't fit, it won't be added and addValue()
will return false. Callers should check the return value and set a
query-continue if it's false.
* Closed the back door that is ApiResult::getData(): callers can't manipulate
the data array directly anymore so they can't bypass the result size limit.
* Added ApiResult::setIndexedTagName_internal() which will call
setIndexedTagName() on an array already in the result. This is needed for the
'new' order of adding results, which means addValue()ing one result at a time
until you hit the limit or run out, then calling this function to set the tag
name.
* Added ApiResult::disableSizeCheck() and enableSizeCheck() which disable and
enable size checking in addValue(). This is used for stuff like query-continue
elements and warnings which shouldn't count towards the result size.
* Added ApiResult::unsetValue() which removes an element from the result and
decreases $mSize.
ApiBase.php:
* Like ApiResult::getData(), ApiBase::getResultData() no longer returns a
reference.
* Use ApiResult::disableSizeCheck() in ApiBase::setWarning()
ApiQueryBase.php:
* Added ApiQueryBase::addPageSubItem(), which adds page subitems one item
at a time.
* addPageSubItem() and addPageSubItems() now return whether the subitem
fit in the result.
* Use ApiResult::disableSizeCheck() in setContinueEnumParameter()
ApiMain.php:
* Use ApiResult::disableSizeCheck() in ApiMain::substituteResultWithError()
* Use getParameter() rather than $mRequest to obtain requestid
DefaultSettings.php:
* Added $wgAPIMaxResultSize, with a default value of 8 MB
ApiQuery*.php:
* Added results one at a time, and set a query-continue if the result is full.
ApiQueryLangLinks.php and friends:
* Migrated from addPageSubItems() to addPageSubItem(). This eliminates the
need for $lastId.
ApiQueryAllLinks.php, ApiQueryWatchlist.php, ApiQueryAllimages.php, ApiQuerySearch.php:
* Renamed $data to something more appropriate ($pageids, $ids or $titles)
ApiQuerySiteinfo.php:
* Abuse siprop as a query-continue parameter and set it to all props that
couldn't be processed.
ApiQueryRandom.php:
* Doesn't do continuations, because the result is supposed to be random.
* Be smart enough to not run the second query if the results of the first
didn't fit.
ApiQueryImageInfo.php, ApiQueryRevisions.php, ApiQueryCategoryInfo.php, ApiQueryInfo.php:
* Added continue parameter which basically skips the first so many items
ApiQueryBacklinks.php:
* Throw the result in a big array first and addValue() that one element at a time if necessary
** This is necessary because the results aren't retrieved in order
* Introduced $this->pageMap to map namespace and title to page ID
* Rewritten extractRowInfo() and extractRedirRowInfo() a little
* Declared all private member variables explicitly
ApiQueryDeletedrevs.php:
* Use a pagemap just like in Backlinks
* Introduce fake page IDs and keep track of them so we know where to add what
** This doesn't change the output format, because the fake page IDs start at 0 and are consecutive
ApiQueryAllmessages.php:
* Add amfrom to facilitate query-continue
ApiQueryUsers.php:
* Rewrite: put the getOtherUsersInfo() code in execute()
2009-02-05 14:30:59 +00:00
|
|
|
$result = $this->getResult();
|
2008-01-28 19:05:26 +00:00
|
|
|
// Canonicalize user names
|
2010-01-11 15:55:52 +00:00
|
|
|
foreach ( $users as $u ) {
|
2021-05-28 13:38:53 +00:00
|
|
|
$n = $this->userNameUtils->getCanonical( $u );
|
2010-02-26 13:18:56 +00:00
|
|
|
if ( $n === false || $n === '' ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$vals = [ 'name' => $u, 'invalid' => true ];
|
|
|
|
|
$fit = $result->addValue( [ 'query', $this->getModuleName() ],
|
2013-11-14 13:00:02 +00:00
|
|
|
null, $vals );
|
2010-02-26 13:18:56 +00:00
|
|
|
if ( !$fit ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->setContinueEnumParameter( 'users',
|
2013-11-14 13:00:02 +00:00
|
|
|
implode( '|', array_diff( $users, $done ) ) );
|
2016-02-17 09:09:32 +00:00
|
|
|
$goodNames = [];
|
* API: BREAKING CHANGE: (bug 11430) Return fewer results than the limit in some cases to prevent running out of memory
* This means queries could possibly return fewer results than the limit and still set a query-continue
* Add iicontinue, rvcontinue, cicontinue, incontinue, amfrom to faciliate query-continue for these modules
* Implemented by blocking additions to the ApiResult object if they would make it too large
** Important things like query-continue values and warnings are exempt from this check
** RSS feeds and exported XML are also exempted (size-checking them would be too messy)
** Result size is checked against $wgAPIMaxResultSize, which defaults to 8 MB
For those who really care, per-file details follow:
ApiResult.php:
* Introduced ApiResult::$mSize which keeps track of the result size.
* Introduced ApiResult::size() which calculates an array's size
(which is the sum of the strlen()s of its elements).
* ApiResult::addValue() now checks that the result size stays below
$wgAPIMaxResultSize. If the item won't fit, it won't be added and addValue()
will return false. Callers should check the return value and set a
query-continue if it's false.
* Closed the back door that is ApiResult::getData(): callers can't manipulate
the data array directly anymore so they can't bypass the result size limit.
* Added ApiResult::setIndexedTagName_internal() which will call
setIndexedTagName() on an array already in the result. This is needed for the
'new' order of adding results, which means addValue()ing one result at a time
until you hit the limit or run out, then calling this function to set the tag
name.
* Added ApiResult::disableSizeCheck() and enableSizeCheck() which disable and
enable size checking in addValue(). This is used for stuff like query-continue
elements and warnings which shouldn't count towards the result size.
* Added ApiResult::unsetValue() which removes an element from the result and
decreases $mSize.
ApiBase.php:
* Like ApiResult::getData(), ApiBase::getResultData() no longer returns a
reference.
* Use ApiResult::disableSizeCheck() in ApiBase::setWarning()
ApiQueryBase.php:
* Added ApiQueryBase::addPageSubItem(), which adds page subitems one item
at a time.
* addPageSubItem() and addPageSubItems() now return whether the subitem
fit in the result.
* Use ApiResult::disableSizeCheck() in setContinueEnumParameter()
ApiMain.php:
* Use ApiResult::disableSizeCheck() in ApiMain::substituteResultWithError()
* Use getParameter() rather than $mRequest to obtain requestid
DefaultSettings.php:
* Added $wgAPIMaxResultSize, with a default value of 8 MB
ApiQuery*.php:
* Added results one at a time, and set a query-continue if the result is full.
ApiQueryLangLinks.php and friends:
* Migrated from addPageSubItems() to addPageSubItem(). This eliminates the
need for $lastId.
ApiQueryAllLinks.php, ApiQueryWatchlist.php, ApiQueryAllimages.php, ApiQuerySearch.php:
* Renamed $data to something more appropriate ($pageids, $ids or $titles)
ApiQuerySiteinfo.php:
* Abuse siprop as a query-continue parameter and set it to all props that
couldn't be processed.
ApiQueryRandom.php:
* Doesn't do continuations, because the result is supposed to be random.
* Be smart enough to not run the second query if the results of the first
didn't fit.
ApiQueryImageInfo.php, ApiQueryRevisions.php, ApiQueryCategoryInfo.php, ApiQueryInfo.php:
* Added continue parameter which basically skips the first so many items
ApiQueryBacklinks.php:
* Throw the result in a big array first and addValue() that one element at a time if necessary
** This is necessary because the results aren't retrieved in order
* Introduced $this->pageMap to map namespace and title to page ID
* Rewritten extractRowInfo() and extractRedirRowInfo() a little
* Declared all private member variables explicitly
ApiQueryDeletedrevs.php:
* Use a pagemap just like in Backlinks
* Introduce fake page IDs and keep track of them so we know where to add what
** This doesn't change the output format, because the fake page IDs start at 0 and are consecutive
ApiQueryAllmessages.php:
* Add amfrom to facilitate query-continue
ApiQueryUsers.php:
* Rewrite: put the getOtherUsersInfo() code in execute()
2009-02-05 14:30:59 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
$done[] = $u;
|
2010-02-26 13:18:56 +00:00
|
|
|
} else {
|
2008-01-28 19:05:26 +00:00
|
|
|
$goodNames[] = $n;
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2008-01-28 19:05:26 +00:00
|
|
|
}
|
2010-01-23 22:26:40 +00:00
|
|
|
|
2016-12-05 07:35:42 +00:00
|
|
|
if ( $useNames ) {
|
|
|
|
|
$parameters = &$goodNames;
|
|
|
|
|
} else {
|
|
|
|
|
$parameters = &$userids;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:23:43 +00:00
|
|
|
$result = $this->getResult();
|
|
|
|
|
|
2016-12-05 07:35:42 +00:00
|
|
|
if ( count( $parameters ) ) {
|
2023-06-26 06:43:41 +00:00
|
|
|
$this->getQueryBuilder()->merge( User::newQueryBuilder( $db ) );
|
2016-12-05 07:35:42 +00:00
|
|
|
if ( $useNames ) {
|
|
|
|
|
$this->addWhereFld( 'user_name', $goodNames );
|
|
|
|
|
} else {
|
|
|
|
|
$this->addWhereFld( 'user_id', $userids );
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2019-09-05 18:24:28 +00:00
|
|
|
$this->addBlockInfoToQuery( isset( $this->prop['blockinfo'] ) );
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$data = [];
|
2010-01-11 15:55:52 +00:00
|
|
|
$res = $this->select( __METHOD__ );
|
2012-09-11 23:45:35 +00:00
|
|
|
$this->resetQueryParams();
|
|
|
|
|
|
|
|
|
|
// get user groups if needed
|
|
|
|
|
if ( isset( $this->prop['groups'] ) || isset( $this->prop['rights'] ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$userGroups = [];
|
2012-09-11 23:45:35 +00:00
|
|
|
|
|
|
|
|
$this->addTables( 'user' );
|
2016-12-05 07:35:42 +00:00
|
|
|
if ( $useNames ) {
|
|
|
|
|
$this->addWhereFld( 'user_name', $goodNames );
|
|
|
|
|
} else {
|
|
|
|
|
$this->addWhereFld( 'user_id', $userids );
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-11 23:45:35 +00:00
|
|
|
$this->addTables( 'user_groups' );
|
2019-03-06 17:17:27 +00:00
|
|
|
$this->addJoinConds( [ 'user_groups' => [ 'JOIN', 'ug_user=user_id' ] ] );
|
2016-12-23 02:07:59 +00:00
|
|
|
$this->addFields( [ 'user_name' ] );
|
2022-10-28 11:32:54 +00:00
|
|
|
$this->addFields( [ 'ug_user', 'ug_group', 'ug_expiry' ] );
|
2017-04-11 02:32:02 +00:00
|
|
|
$this->addWhere( 'ug_expiry IS NULL OR ug_expiry >= ' .
|
|
|
|
|
$db->addQuotes( $db->timestamp() ) );
|
2012-09-11 23:45:35 +00:00
|
|
|
$userGroupsRes = $this->select( __METHOD__ );
|
|
|
|
|
|
2013-04-19 18:03:05 +00:00
|
|
|
foreach ( $userGroupsRes as $row ) {
|
2016-12-23 02:07:59 +00:00
|
|
|
$userGroups[$row->user_name][] = $row;
|
2012-09-11 23:45:35 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-11-30 19:40:45 +00:00
|
|
|
if ( isset( $this->prop['gender'] ) ) {
|
|
|
|
|
$userNames = [];
|
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
|
$userNames[] = $row->user_name;
|
|
|
|
|
}
|
|
|
|
|
$this->genderCache->doQuery( $userNames, __METHOD__ );
|
|
|
|
|
}
|
2011-01-04 03:36:39 +00:00
|
|
|
|
2010-06-22 06:05:20 +00:00
|
|
|
foreach ( $res as $row ) {
|
2012-09-11 23:45:35 +00:00
|
|
|
// create user object and pass along $userGroups if set
|
|
|
|
|
// that reduces the number of database queries needed in User dramatically
|
|
|
|
|
if ( !isset( $userGroups ) ) {
|
2021-07-03 21:57:18 +00:00
|
|
|
$user = $this->userFactory->newFromRow( $row );
|
2012-09-11 23:45:35 +00:00
|
|
|
} else {
|
2012-11-09 21:23:14 +00:00
|
|
|
if ( !isset( $userGroups[$row->user_name] ) || !is_array( $userGroups[$row->user_name] ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$userGroups[$row->user_name] = [];
|
2012-09-11 23:45:35 +00:00
|
|
|
}
|
2021-07-03 21:57:18 +00:00
|
|
|
$user = $this->userFactory->newFromRow( $row, [ 'user_groups' => $userGroups[$row->user_name] ] );
|
2012-09-11 23:45:35 +00:00
|
|
|
}
|
2016-12-05 07:35:42 +00:00
|
|
|
if ( $useNames ) {
|
|
|
|
|
$key = $user->getName();
|
|
|
|
|
} else {
|
|
|
|
|
$key = $user->getId();
|
|
|
|
|
}
|
|
|
|
|
$data[$key]['userid'] = $user->getId();
|
|
|
|
|
$data[$key]['name'] = $user->getName();
|
2010-06-17 07:39:31 +00:00
|
|
|
|
2010-02-26 13:18:56 +00:00
|
|
|
if ( isset( $this->prop['editcount'] ) ) {
|
2016-12-05 07:35:42 +00:00
|
|
|
$data[$key]['editcount'] = $user->getEditCount();
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2010-06-17 07:39:31 +00:00
|
|
|
|
2010-02-26 13:18:56 +00:00
|
|
|
if ( isset( $this->prop['registration'] ) ) {
|
2016-12-05 07:35:42 +00:00
|
|
|
$data[$key]['registration'] = wfTimestampOrNull( TS_ISO_8601, $user->getRegistration() );
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2010-06-17 07:39:31 +00:00
|
|
|
|
2011-03-12 22:23:43 +00:00
|
|
|
if ( isset( $this->prop['groups'] ) ) {
|
2021-07-03 21:57:18 +00:00
|
|
|
$data[$key]['groups'] = $this->userGroupManager->getUserEffectiveGroups( $user );
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2010-06-17 07:39:31 +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
|
|
|
if ( isset( $this->prop['groupmemberships'] ) ) {
|
2021-02-10 22:31:02 +00:00
|
|
|
$data[$key]['groupmemberships'] = array_map( static function ( $ugm ) {
|
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
|
|
|
return [
|
|
|
|
|
'group' => $ugm->getGroup(),
|
|
|
|
|
'expiry' => ApiResult::formatExpiry( $ugm->getExpiry() ),
|
|
|
|
|
];
|
2021-07-03 21:57:18 +00:00
|
|
|
}, $this->userGroupManager->getUserGroupMemberships( $user ) );
|
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
|
|
|
}
|
|
|
|
|
|
2012-09-11 23:45:35 +00:00
|
|
|
if ( isset( $this->prop['implicitgroups'] ) ) {
|
2021-07-03 21:57:18 +00:00
|
|
|
$data[$key]['implicitgroups'] = $this->userGroupManager->getUserImplicitGroups( $user );
|
2011-09-28 16:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-12 22:23:43 +00:00
|
|
|
if ( isset( $this->prop['rights'] ) ) {
|
2019-08-21 02:21:13 +00:00
|
|
|
$data[$key]['rights'] = $this->getPermissionManager()
|
|
|
|
|
->getUserPermissions( $user );
|
2011-01-04 01:39:02 +00:00
|
|
|
}
|
2011-03-06 20:51:31 +00:00
|
|
|
if ( $row->ipb_deleted ) {
|
2016-12-05 07:35:42 +00:00
|
|
|
$data[$key]['hidden'] = true;
|
2011-03-06 20:51:31 +00:00
|
|
|
}
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( isset( $this->prop['blockinfo'] ) && $row->ipb_by_text !== null ) {
|
2019-09-05 18:24:28 +00:00
|
|
|
$data[$key] += $this->getBlockDetails( DatabaseBlock::newFromRow( $row ) );
|
2009-02-18 22:31:46 +00:00
|
|
|
}
|
2010-06-17 07:39:31 +00:00
|
|
|
|
2015-01-16 19:00:07 +00:00
|
|
|
if ( isset( $this->prop['emailable'] ) ) {
|
2016-12-05 07:35:42 +00:00
|
|
|
$data[$key]['emailable'] = $user->canReceiveEmail();
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2009-06-03 15:36:44 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( isset( $this->prop['gender'] ) ) {
|
2021-11-30 19:40:45 +00:00
|
|
|
$data[$key]['gender'] = $this->genderCache->getGenderOf( $user, __METHOD__ );
|
2009-06-03 15:36:44 +00:00
|
|
|
}
|
|
|
|
|
|
2015-11-19 20:57:12 +00:00
|
|
|
if ( isset( $this->prop['centralids'] ) ) {
|
2016-12-05 07:35:42 +00:00
|
|
|
$data[$key] += ApiQueryUserInfo::getCentralUserInfo(
|
2015-11-19 20:57:12 +00:00
|
|
|
$this->getConfig(), $user, $params['attachedwiki']
|
|
|
|
|
);
|
|
|
|
|
}
|
* API: BREAKING CHANGE: (bug 11430) Return fewer results than the limit in some cases to prevent running out of memory
* This means queries could possibly return fewer results than the limit and still set a query-continue
* Add iicontinue, rvcontinue, cicontinue, incontinue, amfrom to faciliate query-continue for these modules
* Implemented by blocking additions to the ApiResult object if they would make it too large
** Important things like query-continue values and warnings are exempt from this check
** RSS feeds and exported XML are also exempted (size-checking them would be too messy)
** Result size is checked against $wgAPIMaxResultSize, which defaults to 8 MB
For those who really care, per-file details follow:
ApiResult.php:
* Introduced ApiResult::$mSize which keeps track of the result size.
* Introduced ApiResult::size() which calculates an array's size
(which is the sum of the strlen()s of its elements).
* ApiResult::addValue() now checks that the result size stays below
$wgAPIMaxResultSize. If the item won't fit, it won't be added and addValue()
will return false. Callers should check the return value and set a
query-continue if it's false.
* Closed the back door that is ApiResult::getData(): callers can't manipulate
the data array directly anymore so they can't bypass the result size limit.
* Added ApiResult::setIndexedTagName_internal() which will call
setIndexedTagName() on an array already in the result. This is needed for the
'new' order of adding results, which means addValue()ing one result at a time
until you hit the limit or run out, then calling this function to set the tag
name.
* Added ApiResult::disableSizeCheck() and enableSizeCheck() which disable and
enable size checking in addValue(). This is used for stuff like query-continue
elements and warnings which shouldn't count towards the result size.
* Added ApiResult::unsetValue() which removes an element from the result and
decreases $mSize.
ApiBase.php:
* Like ApiResult::getData(), ApiBase::getResultData() no longer returns a
reference.
* Use ApiResult::disableSizeCheck() in ApiBase::setWarning()
ApiQueryBase.php:
* Added ApiQueryBase::addPageSubItem(), which adds page subitems one item
at a time.
* addPageSubItem() and addPageSubItems() now return whether the subitem
fit in the result.
* Use ApiResult::disableSizeCheck() in setContinueEnumParameter()
ApiMain.php:
* Use ApiResult::disableSizeCheck() in ApiMain::substituteResultWithError()
* Use getParameter() rather than $mRequest to obtain requestid
DefaultSettings.php:
* Added $wgAPIMaxResultSize, with a default value of 8 MB
ApiQuery*.php:
* Added results one at a time, and set a query-continue if the result is full.
ApiQueryLangLinks.php and friends:
* Migrated from addPageSubItems() to addPageSubItem(). This eliminates the
need for $lastId.
ApiQueryAllLinks.php, ApiQueryWatchlist.php, ApiQueryAllimages.php, ApiQuerySearch.php:
* Renamed $data to something more appropriate ($pageids, $ids or $titles)
ApiQuerySiteinfo.php:
* Abuse siprop as a query-continue parameter and set it to all props that
couldn't be processed.
ApiQueryRandom.php:
* Doesn't do continuations, because the result is supposed to be random.
* Be smart enough to not run the second query if the results of the first
didn't fit.
ApiQueryImageInfo.php, ApiQueryRevisions.php, ApiQueryCategoryInfo.php, ApiQueryInfo.php:
* Added continue parameter which basically skips the first so many items
ApiQueryBacklinks.php:
* Throw the result in a big array first and addValue() that one element at a time if necessary
** This is necessary because the results aren't retrieved in order
* Introduced $this->pageMap to map namespace and title to page ID
* Rewritten extractRowInfo() and extractRedirRowInfo() a little
* Declared all private member variables explicitly
ApiQueryDeletedrevs.php:
* Use a pagemap just like in Backlinks
* Introduce fake page IDs and keep track of them so we know where to add what
** This doesn't change the output format, because the fake page IDs start at 0 and are consecutive
ApiQueryAllmessages.php:
* Add amfrom to facilitate query-continue
ApiQueryUsers.php:
* Rewrite: put the getOtherUsersInfo() code in execute()
2009-02-05 14:30:59 +00:00
|
|
|
}
|
2008-01-28 19:05:26 +00:00
|
|
|
}
|
2011-03-12 22:23:43 +00:00
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
// Second pass: add result data to $retval
|
2016-12-05 07:35:42 +00:00
|
|
|
foreach ( $parameters as $u ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !isset( $data[$u] ) ) {
|
2016-12-05 07:35:42 +00:00
|
|
|
if ( $useNames ) {
|
2023-01-28 00:08:38 +00:00
|
|
|
$data[$u] = [ 'name' => $u, 'missing' => true ];
|
|
|
|
|
if ( isset( $this->prop['cancreate'] ) ) {
|
|
|
|
|
$status = $this->authManager->canCreateAccount( $u );
|
|
|
|
|
$data[$u]['cancreate'] = $status->isGood();
|
|
|
|
|
if ( !$status->isGood() ) {
|
|
|
|
|
$data[$u]['cancreateerror'] = $this->getErrorFormatter()->arrayFromStatus( $status );
|
2016-05-30 18:16:07 +00:00
|
|
|
}
|
2016-01-11 18:20:22 +00:00
|
|
|
}
|
2016-12-05 07:35:42 +00:00
|
|
|
} else {
|
|
|
|
|
$data[$u] = [ 'userid' => $u, 'missing' => true ];
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2016-12-05 07:35:42 +00:00
|
|
|
|
2011-03-12 22:23:43 +00:00
|
|
|
} else {
|
|
|
|
|
if ( isset( $this->prop['groups'] ) && isset( $data[$u]['groups'] ) ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
ApiResult::setArrayType( $data[$u]['groups'], 'array' );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setIndexedTagName( $data[$u]['groups'], 'g' );
|
2011-03-12 22:23:43 +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
|
|
|
if ( isset( $this->prop['groupmemberships'] ) && isset( $data[$u]['groupmemberships'] ) ) {
|
|
|
|
|
ApiResult::setArrayType( $data[$u]['groupmemberships'], 'array' );
|
|
|
|
|
ApiResult::setIndexedTagName( $data[$u]['groupmemberships'], 'groupmembership' );
|
|
|
|
|
}
|
2011-09-28 16:36:17 +00:00
|
|
|
if ( isset( $this->prop['implicitgroups'] ) && isset( $data[$u]['implicitgroups'] ) ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
ApiResult::setArrayType( $data[$u]['implicitgroups'], 'array' );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setIndexedTagName( $data[$u]['implicitgroups'], 'g' );
|
2011-09-28 16:36:17 +00:00
|
|
|
}
|
2011-03-12 22:23:43 +00:00
|
|
|
if ( isset( $this->prop['rights'] ) && isset( $data[$u]['rights'] ) ) {
|
2015-01-16 19:00:07 +00:00
|
|
|
ApiResult::setArrayType( $data[$u]['rights'], 'array' );
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
ApiResult::setIndexedTagName( $data[$u]['rights'], 'r' );
|
2011-03-12 22:23:43 +00:00
|
|
|
}
|
2009-02-16 17:47:54 +00:00
|
|
|
}
|
2011-01-04 03:36:39 +00:00
|
|
|
|
2019-08-30 16:01:28 +00:00
|
|
|
$fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $data[$u] );
|
2010-02-26 13:18:56 +00:00
|
|
|
if ( !$fit ) {
|
2016-12-05 07:35:42 +00:00
|
|
|
if ( $useNames ) {
|
|
|
|
|
$this->setContinueEnumParameter( 'users',
|
|
|
|
|
implode( '|', array_diff( $users, $done ) ) );
|
|
|
|
|
} else {
|
|
|
|
|
$this->setContinueEnumParameter( 'userids',
|
|
|
|
|
implode( '|', array_diff( $userids, $done ) ) );
|
|
|
|
|
}
|
2009-02-16 19:08:07 +00:00
|
|
|
break;
|
2008-01-28 19:05:26 +00:00
|
|
|
}
|
* API: BREAKING CHANGE: (bug 11430) Return fewer results than the limit in some cases to prevent running out of memory
* This means queries could possibly return fewer results than the limit and still set a query-continue
* Add iicontinue, rvcontinue, cicontinue, incontinue, amfrom to faciliate query-continue for these modules
* Implemented by blocking additions to the ApiResult object if they would make it too large
** Important things like query-continue values and warnings are exempt from this check
** RSS feeds and exported XML are also exempted (size-checking them would be too messy)
** Result size is checked against $wgAPIMaxResultSize, which defaults to 8 MB
For those who really care, per-file details follow:
ApiResult.php:
* Introduced ApiResult::$mSize which keeps track of the result size.
* Introduced ApiResult::size() which calculates an array's size
(which is the sum of the strlen()s of its elements).
* ApiResult::addValue() now checks that the result size stays below
$wgAPIMaxResultSize. If the item won't fit, it won't be added and addValue()
will return false. Callers should check the return value and set a
query-continue if it's false.
* Closed the back door that is ApiResult::getData(): callers can't manipulate
the data array directly anymore so they can't bypass the result size limit.
* Added ApiResult::setIndexedTagName_internal() which will call
setIndexedTagName() on an array already in the result. This is needed for the
'new' order of adding results, which means addValue()ing one result at a time
until you hit the limit or run out, then calling this function to set the tag
name.
* Added ApiResult::disableSizeCheck() and enableSizeCheck() which disable and
enable size checking in addValue(). This is used for stuff like query-continue
elements and warnings which shouldn't count towards the result size.
* Added ApiResult::unsetValue() which removes an element from the result and
decreases $mSize.
ApiBase.php:
* Like ApiResult::getData(), ApiBase::getResultData() no longer returns a
reference.
* Use ApiResult::disableSizeCheck() in ApiBase::setWarning()
ApiQueryBase.php:
* Added ApiQueryBase::addPageSubItem(), which adds page subitems one item
at a time.
* addPageSubItem() and addPageSubItems() now return whether the subitem
fit in the result.
* Use ApiResult::disableSizeCheck() in setContinueEnumParameter()
ApiMain.php:
* Use ApiResult::disableSizeCheck() in ApiMain::substituteResultWithError()
* Use getParameter() rather than $mRequest to obtain requestid
DefaultSettings.php:
* Added $wgAPIMaxResultSize, with a default value of 8 MB
ApiQuery*.php:
* Added results one at a time, and set a query-continue if the result is full.
ApiQueryLangLinks.php and friends:
* Migrated from addPageSubItems() to addPageSubItem(). This eliminates the
need for $lastId.
ApiQueryAllLinks.php, ApiQueryWatchlist.php, ApiQueryAllimages.php, ApiQuerySearch.php:
* Renamed $data to something more appropriate ($pageids, $ids or $titles)
ApiQuerySiteinfo.php:
* Abuse siprop as a query-continue parameter and set it to all props that
couldn't be processed.
ApiQueryRandom.php:
* Doesn't do continuations, because the result is supposed to be random.
* Be smart enough to not run the second query if the results of the first
didn't fit.
ApiQueryImageInfo.php, ApiQueryRevisions.php, ApiQueryCategoryInfo.php, ApiQueryInfo.php:
* Added continue parameter which basically skips the first so many items
ApiQueryBacklinks.php:
* Throw the result in a big array first and addValue() that one element at a time if necessary
** This is necessary because the results aren't retrieved in order
* Introduced $this->pageMap to map namespace and title to page ID
* Rewritten extractRowInfo() and extractRedirRowInfo() a little
* Declared all private member variables explicitly
ApiQueryDeletedrevs.php:
* Use a pagemap just like in Backlinks
* Introduce fake page IDs and keep track of them so we know where to add what
** This doesn't change the output format, because the fake page IDs start at 0 and are consecutive
ApiQueryAllmessages.php:
* Add amfrom to facilitate query-continue
ApiQueryUsers.php:
* Rewrite: put the getOtherUsersInfo() code in execute()
2009-02-05 14:30:59 +00:00
|
|
|
$done[] = $u;
|
2008-01-28 19:05:26 +00:00
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
$result->addIndexedTagName( [ 'query', $this->getModuleName() ], 'user' );
|
2008-01-28 19:05:26 +00:00
|
|
|
}
|
2010-07-23 07:33:40 +00:00
|
|
|
|
2010-07-23 07:17:56 +00:00
|
|
|
public function getCacheMode( $params ) {
|
2021-04-20 13:42:53 +00:00
|
|
|
if ( array_diff( (array)$params['prop'], static::$publicProps ) ) {
|
2014-04-22 01:45:42 +00:00
|
|
|
return 'anon-public-user-private';
|
|
|
|
|
} else {
|
|
|
|
|
return 'public';
|
|
|
|
|
}
|
2010-07-23 07:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getAllowedParams() {
|
2016-04-01 16:49:26 +00:00
|
|
|
return [
|
2016-02-17 09:09:32 +00:00
|
|
|
'prop' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
|
|
|
|
ParamValidator::PARAM_TYPE => [
|
2008-01-28 19:05:26 +00:00
|
|
|
'blockinfo',
|
|
|
|
|
'groups',
|
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
|
|
|
'groupmemberships',
|
2011-09-28 16:36:17 +00:00
|
|
|
'implicitgroups',
|
2011-01-04 01:39:02 +00:00
|
|
|
'rights',
|
2008-05-10 10:49:26 +00:00
|
|
|
'editcount',
|
2008-12-04 14:42:30 +00:00
|
|
|
'registration',
|
|
|
|
|
'emailable',
|
2009-03-31 03:48:08 +00:00
|
|
|
'gender',
|
2015-11-19 20:57:12 +00:00
|
|
|
'centralids',
|
2016-04-01 16:49:26 +00:00
|
|
|
'cancreate',
|
2016-01-11 18:20:22 +00:00
|
|
|
// When adding a prop, consider whether it should be added
|
|
|
|
|
// to self::$publicProps
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
|
|
|
|
|
],
|
2015-11-19 20:57:12 +00:00
|
|
|
'attachedwiki' => null,
|
2016-02-17 09:09:32 +00:00
|
|
|
'users' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_ISMULTI => true
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-12-05 07:35:42 +00:00
|
|
|
'userids' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
|
|
|
|
ParamValidator::PARAM_TYPE => 'integer'
|
2016-12-05 07:35:42 +00:00
|
|
|
],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2008-01-28 19:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
2014-10-28 17:17:02 +00:00
|
|
|
protected function getExamplesMessages() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-09-18 17:38:23 +00:00
|
|
|
'action=query&list=users&ususers=Example&usprop=groups|editcount|gender'
|
|
|
|
|
=> 'apihelp-query+users-example-simple',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2008-01-28 19:05:26 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-17 17:02:06 +00:00
|
|
|
public function getHelpUrls() {
|
2017-04-04 22:52:57 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Users';
|
2011-07-17 17:02:06 +00:00
|
|
|
}
|
2008-01-28 19:05:26 +00:00
|
|
|
}
|