46 private const MAX_PAGES = 100;
49 private $revisionStore;
52 private $actorMigration;
55 private $userGroupManager;
58 private $groupPermissionsLookup;
78 parent::__construct( $query, $moduleName,
'pc' );
79 $this->revisionStore = $revisionStore;
80 $this->actorMigration = $actorMigration;
81 $this->userGroupManager = $userGroupManager;
82 $this->groupPermissionsLookup = $groupPermissionsLookup;
91 $pages = array_keys( $this->
getPageSet()->getGoodPages() );
94 if ( $params[
'continue'] !==
null ) {
96 $cont_page = (int)$cont[0];
97 $pages = array_filter( $pages,
static function ( $v ) use ( $cont_page ) {
98 return $v >= $cont_page;
101 if ( $pages === [] ) {
108 $continuePages =
null;
109 if ( count( $pages ) > self::MAX_PAGES ) {
110 $continuePages = $pages[self::MAX_PAGES] .
'|0';
111 $pages = array_slice( $pages, 0, self::MAX_PAGES );
115 $revQuery = $this->revisionStore->getQueryInfo();
116 $pageField =
'rev_page';
117 $idField =
'rev_actor';
118 $countField =
'rev_actor';
124 'page' => $pageField,
125 'anons' =>
"COUNT(DISTINCT $countField)",
128 $this->
addWhere( $this->actorMigration->isAnon(
$revQuery[
'fields'][
'rev_user'] ) );
129 $this->
addWhere( $db->bitAnd(
'rev_deleted', RevisionRecord::DELETED_USER ) .
' = 0' );
130 $this->
addOption(
'GROUP BY', $pageField );
132 foreach (
$res as $row ) {
133 $fit = $result->addValue( [
'query',
'pages', $row->page ],
134 'anoncontributors', (
int)$row->anons
141 $params[
'continue'] ??
'0|0'
153 'page' => $pageField,
156 'userid' =>
'MAX(' .
$revQuery[
'fields'][
'rev_user'] .
')',
157 'username' =>
'MAX(' .
$revQuery[
'fields'][
'rev_user_text'] .
')',
160 $this->
addWhere( $this->actorMigration->isNotAnon(
$revQuery[
'fields'][
'rev_user'] ) );
161 $this->
addWhere( $db->bitAnd(
'rev_deleted', RevisionRecord::DELETED_USER ) .
' = 0' );
162 $this->
addOption(
'GROUP BY', [ $pageField, $idField ] );
163 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
167 if ( count( $pages ) > 1 ) {
168 $this->
addOption(
'ORDER BY', [
'page',
'id' ] );
174 if ( $params[
'group'] ) {
175 $excludeGroups =
false;
176 $limitGroups = $params[
'group'];
177 } elseif ( $params[
'excludegroup'] ) {
178 $excludeGroups =
true;
179 $limitGroups = $params[
'excludegroup'];
180 } elseif ( $params[
'rights'] ) {
181 $excludeGroups =
false;
182 foreach ( $params[
'rights'] as $r ) {
183 $limitGroups = array_merge( $limitGroups,
184 $this->groupPermissionsLookup->getGroupsWithPermission( $r ) );
188 if ( !$limitGroups ) {
189 if ( $continuePages !==
null ) {
197 } elseif ( $params[
'excluderights'] ) {
198 $excludeGroups =
true;
199 foreach ( $params[
'excluderights'] as $r ) {
200 $limitGroups = array_merge( $limitGroups,
201 $this->groupPermissionsLookup->getGroupsWithPermission( $r ) );
205 if ( $limitGroups ) {
206 $limitGroups = array_unique( $limitGroups );
210 $excludeGroups ?
'LEFT JOIN' :
'JOIN',
212 'ug_user=' .
$revQuery[
'fields'][
'rev_user'],
213 'ug_group' => $limitGroups,
214 'ug_expiry IS NULL OR ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
219 $this->
addWhereIf(
'ug_user IS NULL', $excludeGroups );
222 if ( $params[
'continue'] !==
null ) {
224 $this->
addWhere( $db->buildComparison(
'>=', [
225 $pageField => $cont[0],
226 $idField => $cont[1],
232 foreach (
$res as $row ) {
233 if ( ++$count > $params[
'limit'] ) {
241 [
'userid' => (
int)$row->userid,
'name' => $row->username ],
250 if ( $continuePages !==
null ) {
260 $userGroups = $this->userGroupManager->listAllGroups();
269 ParamValidator::PARAM_TYPE => $userGroups,
270 ParamValidator::PARAM_ISMULTI =>
true,
273 ParamValidator::PARAM_TYPE => $userGroups,
274 ParamValidator::PARAM_ISMULTI =>
true,
277 ParamValidator::PARAM_TYPE => $userRights,
278 ParamValidator::PARAM_ISMULTI =>
true,
281 ParamValidator::PARAM_TYPE => $userRights,
282 ParamValidator::PARAM_ISMULTI =>
true,
285 ParamValidator::PARAM_DEFAULT => 10,
286 ParamValidator::PARAM_TYPE =>
'limit',
287 IntegerDef::PARAM_MIN => 1,
298 $title = Title::newMainPage()->getPrefixedText();
299 $mp = rawurlencode(
$title );
302 "action=query&prop=contributors&titles={$mp}"
303 =>
'apihelp-query+contributors-example-simple',
308 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Contributors';
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
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.