2008-01-28 19:05:26 +00:00
|
|
|
<?php
|
2010-02-26 13:18:56 +00:00
|
|
|
/**
|
2012-07-15 20:13:02 +00:00
|
|
|
* Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@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
|
|
|
*/
|
|
|
|
|
|
2019-09-05 18:24:28 +00:00
|
|
|
use MediaWiki\Block\DatabaseBlock;
|
2020-03-31 19:06:26 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
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
|
|
|
|
2010-11-23 21:43:56 +00:00
|
|
|
private $tokenFunctions, $prop;
|
2010-10-06 21:18:55 +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
|
|
|
|
2014-03-25 17:22:11 +00:00
|
|
|
public function __construct( ApiQuery $query, $moduleName ) {
|
2010-02-26 13:18:56 +00:00
|
|
|
parent::__construct( $query, $moduleName, 'us' );
|
2008-01-28 19:05:26 +00:00
|
|
|
}
|
2010-02-26 13:18:56 +00:00
|
|
|
|
2009-03-28 19:08:47 +00:00
|
|
|
/**
|
|
|
|
|
* Get an array mapping token names to their handler functions.
|
|
|
|
|
* The prototype for a token function is func($user)
|
|
|
|
|
* it should return a token or false (permission denied)
|
2014-08-08 16:56:07 +00:00
|
|
|
* @deprecated since 1.24
|
2014-04-15 18:12:09 +00:00
|
|
|
* @return array Array of tokenname => function
|
2009-03-28 19:08:47 +00:00
|
|
|
*/
|
|
|
|
|
protected function getTokenFunctions() {
|
|
|
|
|
// Don't call the hooks twice
|
2010-02-26 13:18:56 +00:00
|
|
|
if ( isset( $this->tokenFunctions ) ) {
|
2009-03-28 19:08:47 +00:00
|
|
|
return $this->tokenFunctions;
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2009-03-28 19:08:47 +00:00
|
|
|
|
2014-12-17 11:09:04 +00:00
|
|
|
// If we're in a mode that breaks the same-origin policy, no tokens can
|
|
|
|
|
// be obtained
|
|
|
|
|
if ( $this->lacksSameOriginSecurity() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [];
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2009-03-28 19:08:47 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->tokenFunctions = [
|
2018-01-13 00:02:09 +00:00
|
|
|
'userrights' => [ self::class, 'getUserrightsToken' ],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$this->getHookRunner()->onAPIQueryUsersTokens( $this->tokenFunctions );
|
2013-11-14 13:00:02 +00:00
|
|
|
|
2009-03-28 19:08:47 +00:00
|
|
|
return $this->tokenFunctions;
|
|
|
|
|
}
|
2010-02-26 13:18:56 +00:00
|
|
|
|
2012-05-02 13:48:02 +00:00
|
|
|
/**
|
2014-08-08 16:56:07 +00:00
|
|
|
* @deprecated since 1.24
|
2014-04-15 18:12:09 +00:00
|
|
|
* @param User $user
|
|
|
|
|
* @return string
|
2012-05-02 13:48:02 +00:00
|
|
|
*/
|
2010-02-26 13:18:56 +00:00
|
|
|
public static function getUserrightsToken( $user ) {
|
2009-03-28 19:08:47 +00:00
|
|
|
global $wgUser;
|
2013-11-14 13:00:02 +00:00
|
|
|
|
2009-03-28 19:08:47 +00:00
|
|
|
// Since the permissions check for userrights is non-trivial,
|
|
|
|
|
// don't bother with it here
|
2011-10-27 00:46:17 +00:00
|
|
|
return $wgUser->getEditToken( $user->getName() );
|
2009-03-28 19:08:47 +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 ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->prop = array_flip( $params['prop'] );
|
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 ) {
|
|
|
|
|
$n = User::getCanonicalName( $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 ) ) {
|
2017-10-06 17:03:55 +00:00
|
|
|
$userQuery = User::getQueryInfo();
|
|
|
|
|
$this->addTables( $userQuery['tables'] );
|
|
|
|
|
$this->addFields( $userQuery['fields'] );
|
|
|
|
|
$this->addJoinConds( $userQuery['joins'] );
|
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' ] );
|
|
|
|
|
$this->addFields( UserGroupMembership::selectFields() );
|
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
|
|
|
}
|
|
|
|
|
}
|
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 ) ) {
|
|
|
|
|
$user = User::newFromRow( $row );
|
|
|
|
|
} 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
|
|
|
}
|
2016-02-17 09:09:32 +00:00
|
|
|
$user = User::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'] ) ) {
|
2016-12-05 07:35:42 +00:00
|
|
|
$data[$key]['groups'] = $user->getEffectiveGroups();
|
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'] ) ) {
|
2017-06-26 16:35:31 +00:00
|
|
|
$data[$key]['groupmemberships'] = array_map( 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() ),
|
|
|
|
|
];
|
|
|
|
|
}, $user->getGroupMemberships() );
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-11 23:45:35 +00:00
|
|
|
if ( isset( $this->prop['implicitgroups'] ) ) {
|
2016-12-05 07:35:42 +00:00
|
|
|
$data[$key]['implicitgroups'] = $user->getAutomaticGroups();
|
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'] ) ) {
|
2009-06-03 15:36:44 +00:00
|
|
|
$gender = $user->getOption( 'gender' );
|
|
|
|
|
if ( strval( $gender ) === '' ) {
|
|
|
|
|
$gender = 'unknown';
|
|
|
|
|
}
|
2016-12-05 07:35:42 +00:00
|
|
|
$data[$key]['gender'] = $gender;
|
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']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $params['token'] !== null ) {
|
2009-03-28 19:08:47 +00:00
|
|
|
$tokenFunctions = $this->getTokenFunctions();
|
2010-02-26 13:18:56 +00:00
|
|
|
foreach ( $params['token'] as $t ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$val = call_user_func( $tokenFunctions[$t], $user );
|
2010-02-26 13:18:56 +00:00
|
|
|
if ( $val === false ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->addWarning( [ 'apiwarn-tokennotallowed', $t ] );
|
2010-02-26 13:18:56 +00:00
|
|
|
} else {
|
2016-12-05 07:35:42 +00:00
|
|
|
$data[$key][$t . 'token'] = $val;
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2009-03-28 19:08:47 +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
|
|
|
}
|
2008-01-28 19:05:26 +00:00
|
|
|
}
|
2011-03-12 22:23:43 +00:00
|
|
|
|
2013-05-24 13:58:54 +00:00
|
|
|
$context = $this->getContext();
|
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 ) {
|
|
|
|
|
$data[$u] = [ 'name' => $u ];
|
|
|
|
|
$urPage = new UserrightsPage;
|
|
|
|
|
$urPage->setContext( $context );
|
|
|
|
|
|
|
|
|
|
$iwUser = $urPage->fetchUser( $u );
|
|
|
|
|
|
|
|
|
|
if ( $iwUser instanceof UserRightsProxy ) {
|
|
|
|
|
$data[$u]['interwiki'] = true;
|
|
|
|
|
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $params['token'] !== null ) {
|
2016-12-05 07:35:42 +00:00
|
|
|
$tokenFunctions = $this->getTokenFunctions();
|
|
|
|
|
|
|
|
|
|
foreach ( $params['token'] as $t ) {
|
|
|
|
|
$val = call_user_func( $tokenFunctions[$t], $iwUser );
|
|
|
|
|
if ( $val === false ) {
|
|
|
|
|
$this->addWarning( [ 'apiwarn-tokennotallowed', $t ] );
|
|
|
|
|
} else {
|
|
|
|
|
$data[$u][$t . 'token'] = $val;
|
|
|
|
|
}
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2009-09-10 13:44:49 +00:00
|
|
|
}
|
2016-12-05 07:35:42 +00:00
|
|
|
} else {
|
|
|
|
|
$data[$u]['missing'] = true;
|
|
|
|
|
if ( isset( $this->prop['cancreate'] ) ) {
|
2020-03-31 19:06:26 +00:00
|
|
|
$status = MediaWikiServices::getInstance()->getAuthManager()
|
|
|
|
|
->canCreateAccount( $u );
|
2016-12-05 07:35:42 +00:00
|
|
|
$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 ) {
|
2014-04-22 01:45:42 +00:00
|
|
|
if ( isset( $params['token'] ) ) {
|
|
|
|
|
return 'private';
|
|
|
|
|
} elseif ( array_diff( (array)$params['prop'], static::$publicProps ) ) {
|
|
|
|
|
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' => [
|
2010-02-26 13:18:56 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
ApiBase::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' => [
|
2010-02-26 13:18:56 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2016-12-05 07:35:42 +00:00
|
|
|
'userids' => [
|
|
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
|
|
|
|
],
|
2016-02-17 09:09:32 +00:00
|
|
|
'token' => [
|
2014-08-08 16:56:07 +00:00
|
|
|
ApiBase::PARAM_DEPRECATED => true,
|
2010-02-26 13:18:56 +00:00
|
|
|
ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
|
|
|
|
|
ApiBase::PARAM_ISMULTI => true
|
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
|
|
|
}
|