44 private const MAX_PAGES = 100;
47 private $revisionStore;
50 private $actorMigration;
53 private $userGroupManager;
56 private $groupPermissionsLookup;
76 parent::__construct( $query, $moduleName,
'pc' );
77 $this->revisionStore = $revisionStore;
78 $this->actorMigration = $actorMigration;
79 $this->userGroupManager = $userGroupManager;
80 $this->groupPermissionsLookup = $groupPermissionsLookup;
89 $pages = array_keys( $this->
getPageSet()->getGoodPages() );
92 if ( $params[
'continue'] !==
null ) {
93 $cont = explode(
'|', $params[
'continue'] );
95 $cont_page = (int)$cont[0];
96 $pages = array_filter( $pages,
static function ( $v ) use ( $cont_page ) {
97 return $v >= $cont_page;
100 if ( $pages === [] ) {
107 $continuePages =
null;
108 if ( count( $pages ) > self::MAX_PAGES ) {
109 $continuePages = $pages[self::MAX_PAGES] .
'|0';
110 $pages = array_slice( $pages, 0, self::MAX_PAGES );
114 $revQuery = $this->revisionStore->getQueryInfo();
115 $pageField =
'rev_page';
116 $idField =
'rev_actor';
117 $countField =
'rev_actor';
123 'page' => $pageField,
124 'anons' =>
"COUNT(DISTINCT $countField)",
127 $this->
addWhere( $this->actorMigration->isAnon(
$revQuery[
'fields'][
'rev_user'] ) );
128 $this->
addWhere( $db->bitAnd(
'rev_deleted', RevisionRecord::DELETED_USER ) .
' = 0' );
129 $this->
addOption(
'GROUP BY', $pageField );
131 foreach (
$res as $row ) {
132 $fit = $result->addValue( [
'query',
'pages', $row->page ],
133 'anoncontributors', (
int)$row->anons
140 $params[
'continue'] ??
'0|0'
152 'page' => $pageField,
155 'userid' =>
'MAX(' .
$revQuery[
'fields'][
'rev_user'] .
')',
156 'username' =>
'MAX(' .
$revQuery[
'fields'][
'rev_user_text'] .
')',
159 $this->
addWhere( $this->actorMigration->isNotAnon(
$revQuery[
'fields'][
'rev_user'] ) );
160 $this->
addWhere( $db->bitAnd(
'rev_deleted', RevisionRecord::DELETED_USER ) .
' = 0' );
161 $this->
addOption(
'GROUP BY', [ $pageField, $idField ] );
162 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
166 if ( count( $pages ) > 1 ) {
167 $this->
addOption(
'ORDER BY', [
'page',
'id' ] );
173 if ( $params[
'group'] ) {
174 $excludeGroups =
false;
175 $limitGroups = $params[
'group'];
176 } elseif ( $params[
'excludegroup'] ) {
177 $excludeGroups =
true;
178 $limitGroups = $params[
'excludegroup'];
179 } elseif ( $params[
'rights'] ) {
180 $excludeGroups =
false;
181 foreach ( $params[
'rights'] as $r ) {
182 $limitGroups = array_merge( $limitGroups,
183 $this->groupPermissionsLookup->getGroupsWithPermission( $r ) );
187 if ( !$limitGroups ) {
188 if ( $continuePages !==
null ) {
196 } elseif ( $params[
'excluderights'] ) {
197 $excludeGroups =
true;
198 foreach ( $params[
'excluderights'] as $r ) {
199 $limitGroups = array_merge( $limitGroups,
200 $this->groupPermissionsLookup->getGroupsWithPermission( $r ) );
204 if ( $limitGroups ) {
205 $limitGroups = array_unique( $limitGroups );
209 $excludeGroups ?
'LEFT JOIN' :
'JOIN',
211 'ug_user=' .
$revQuery[
'fields'][
'rev_user'],
212 'ug_group' => $limitGroups,
213 'ug_expiry IS NULL OR ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
218 $this->
addWhereIf(
'ug_user IS NULL', $excludeGroups );
221 if ( $params[
'continue'] !==
null ) {
222 $cont = explode(
'|', $params[
'continue'] );
224 $cont_page = (int)$cont[0];
225 $cont_id = (int)$cont[1];
227 "$pageField > $cont_page OR " .
228 "($pageField = $cont_page AND " .
229 "$idField >= $cont_id)"
235 foreach (
$res as $row ) {
236 if ( ++$count > $params[
'limit'] ) {
244 [
'userid' => (
int)$row->userid,
'name' => $row->username ],
253 if ( $continuePages !==
null ) {
263 $userGroups = $this->userGroupManager->listAllGroups();
272 ParamValidator::PARAM_TYPE => $userGroups,
273 ParamValidator::PARAM_ISMULTI =>
true,
276 ParamValidator::PARAM_TYPE => $userGroups,
277 ParamValidator::PARAM_ISMULTI =>
true,
280 ParamValidator::PARAM_TYPE => $userRights,
281 ParamValidator::PARAM_ISMULTI =>
true,
284 ParamValidator::PARAM_TYPE => $userRights,
285 ParamValidator::PARAM_ISMULTI =>
true,
288 ParamValidator::PARAM_DEFAULT => 10,
289 ParamValidator::PARAM_TYPE =>
'limit',
290 IntegerDef::PARAM_MIN => 1,
301 $title = Title::newMainPage()->getPrefixedText();
302 $mp = rawurlencode(
$title );
305 "action=query&prop=contributors&titles={$mp}"
306 =>
'apihelp-query+contributors-example-simple',
311 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Contributors';
This is not intended to be a long-term part of MediaWiki; it will be deprecated and removed once acto...
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
const LIMIT_BIG1
Fast query, standard limit.
requireMaxOneParameter( $params,... $required)
Die if more than one of a certain set of parameters is set and not false.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const GET_VALUES_FOR_HELP
getAllowedParams() flag: When set, the result could take longer to generate, but should be more thoro...
const LIMIT_BIG2
Fast query, apihighlimits limit.
This is a base class for all Query modules.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
resetQueryParams()
Blank the internal arrays with query parameters.
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
addFields( $value)
Add a set of fields to select to the internal array.
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
getDB()
Get the Query database connection (read-only)
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
getPageSet()
Get the PageSet object to work on.
addWhere( $value)
Add a set of WHERE clauses to the internal array.
A query module to show contributors to a page.
getExamplesMessages()
Returns usage examples for this module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getAllowedParams( $flags=0)
__construct(ApiQuery $query, $moduleName, RevisionStore $revisionStore, ActorMigration $actorMigration, UserGroupManager $userGroupManager, GroupPermissionsLookup $groupPermissionsLookup)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getHelpUrls()
Return links to more detailed help pages about the module.
This is the main query class.