46 private const MAX_PAGES = 100;
71 parent::__construct( $query, $moduleName,
'pc' );
72 $this->revisionStore = $revisionStore;
73 $this->actorMigration = $actorMigration;
74 $this->userGroupManager = $userGroupManager;
75 $this->groupPermissionsLookup = $groupPermissionsLookup;
84 $pages = array_keys( $this->
getPageSet()->getGoodPages() );
87 if ( $params[
'continue'] !==
null ) {
89 $cont_page = (int)$cont[0];
90 $pages = array_filter( $pages,
static function ( $v ) use ( $cont_page ) {
91 return $v >= $cont_page;
94 if ( $pages === [] ) {
101 $continuePages =
null;
102 if ( count( $pages ) > self::MAX_PAGES ) {
103 $continuePages = $pages[self::MAX_PAGES] .
'|0';
104 $pages = array_slice( $pages, 0, self::MAX_PAGES );
108 $revQuery = $this->revisionStore->getQueryInfo();
109 $pageField =
'rev_page';
110 $idField =
'rev_actor';
111 $countField =
'rev_actor';
117 'page' => $pageField,
118 'anons' =>
"COUNT(DISTINCT $countField)",
121 $this->
addWhere( $this->actorMigration->isAnon( $revQuery[
'fields'][
'rev_user'] ) );
122 $this->
addWhere( [ $db->bitAnd(
'rev_deleted', RevisionRecord::DELETED_USER ) => 0 ] );
123 $this->
addOption(
'GROUP BY', $pageField );
124 $res = $this->
select( __METHOD__ );
125 foreach ( $res as $row ) {
126 $fit = $result->addValue( [
'query',
'pages', $row->page ],
127 'anoncontributors', (
int)$row->anons
134 $params[
'continue'] ??
'0|0'
146 'page' => $pageField,
149 'userid' =>
'MAX(' . $revQuery[
'fields'][
'rev_user'] .
')',
150 'username' =>
'MAX(' . $revQuery[
'fields'][
'rev_user_text'] .
')',
153 $this->
addWhere( $this->actorMigration->isNotAnon( $revQuery[
'fields'][
'rev_user'] ) );
154 $this->
addWhere( [ $db->bitAnd(
'rev_deleted', RevisionRecord::DELETED_USER ) => 0 ] );
155 $this->
addOption(
'GROUP BY', [ $pageField, $idField ] );
156 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
160 if ( count( $pages ) > 1 ) {
161 $this->
addOption(
'ORDER BY', [
'page',
'id' ] );
167 if ( $params[
'group'] ) {
168 $excludeGroups =
false;
169 $limitGroups = $params[
'group'];
170 } elseif ( $params[
'excludegroup'] ) {
171 $excludeGroups =
true;
172 $limitGroups = $params[
'excludegroup'];
173 } elseif ( $params[
'rights'] ) {
174 $excludeGroups =
false;
175 foreach ( $params[
'rights'] as $r ) {
176 $limitGroups = array_merge( $limitGroups,
177 $this->groupPermissionsLookup->getGroupsWithPermission( $r ) );
181 if ( !$limitGroups ) {
182 if ( $continuePages !==
null ) {
190 } elseif ( $params[
'excluderights'] ) {
191 $excludeGroups =
true;
192 foreach ( $params[
'excluderights'] as $r ) {
193 $limitGroups = array_merge( $limitGroups,
194 $this->groupPermissionsLookup->getGroupsWithPermission( $r ) );
198 if ( $limitGroups ) {
199 $limitGroups = array_unique( $limitGroups );
203 $excludeGroups ?
'LEFT JOIN' :
'JOIN',
205 'ug_user=' . $revQuery[
'fields'][
'rev_user'],
206 'ug_group' => $limitGroups,
207 'ug_expiry IS NULL OR ug_expiry >= ' . $db->addQuotes( $db->timestamp() )
212 $this->
addWhereIf( [
'ug_user' =>
null ], $excludeGroups );
215 if ( $params[
'continue'] !==
null ) {
217 $this->
addWhere( $db->buildComparison(
'>=', [
218 $pageField => $cont[0],
219 $idField => $cont[1],
223 $res = $this->
select( __METHOD__ );
225 foreach ( $res as $row ) {
226 if ( ++$count > $params[
'limit'] ) {
234 [
'userid' => (
int)$row->userid,
'name' => $row->username ],
243 if ( $continuePages !==
null ) {
253 $userGroups = $this->userGroupManager->listAllGroups();
262 ParamValidator::PARAM_TYPE => $userGroups,
263 ParamValidator::PARAM_ISMULTI =>
true,
266 ParamValidator::PARAM_TYPE => $userGroups,
267 ParamValidator::PARAM_ISMULTI =>
true,
270 ParamValidator::PARAM_TYPE => $userRights,
271 ParamValidator::PARAM_ISMULTI =>
true,
274 ParamValidator::PARAM_TYPE => $userRights,
275 ParamValidator::PARAM_ISMULTI =>
true,
278 ParamValidator::PARAM_DEFAULT => 10,
279 ParamValidator::PARAM_TYPE =>
'limit',
280 IntegerDef::PARAM_MIN => 1,
291 $title = Title::newMainPage()->getPrefixedText();
292 $mp = rawurlencode( $title );
295 "action=query&prop=contributors&titles={$mp}"
296 =>
'apihelp-query+contributors-example-simple',
301 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)
Dies if more than one parameter from a certain set of parameters are 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 this is set, the result could take longer to generate,...
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.