47 private const MAX_PAGES = 100;
75 parent::__construct( $query, $moduleName,
'pc' );
76 $this->revisionStore = $revisionStore;
77 $this->actorMigration = $actorMigration;
78 $this->userGroupManager = $userGroupManager;
79 $this->groupPermissionsLookup = $groupPermissionsLookup;
80 $this->tempUserConfig = $tempUserConfig;
89 $pages = array_keys( $this->
getPageSet()->getGoodPages() );
92 if (
$params[
'continue'] !==
null ) {
94 $cont_page = (int)$cont[0];
95 $pages = array_filter( $pages,
static function ( $v ) use ( $cont_page ) {
96 return $v >= $cont_page;
99 if ( $pages === [] ) {
106 $continuePages =
null;
107 if ( count( $pages ) > self::MAX_PAGES ) {
108 $continuePages = $pages[self::MAX_PAGES] .
'|0';
109 $pages = array_slice( $pages, 0, self::MAX_PAGES );
113 $revQuery = $this->revisionStore->getQueryInfo();
114 $pageField =
'rev_page';
115 $idField =
'rev_actor';
116 $countField =
'rev_actor';
122 'page' => $pageField,
123 'anons' =>
"COUNT(DISTINCT $countField)",
126 $this->
addWhere( $this->actorMigration->isAnon( $revQuery[
'fields'][
'rev_user'] ) );
127 $this->
addWhere( [ $db->bitAnd(
'rev_deleted', RevisionRecord::DELETED_USER ) => 0 ] );
128 $this->
addOption(
'GROUP BY', $pageField );
129 $res = $this->
select( __METHOD__ );
130 foreach ( $res as $row ) {
131 $fit = $result->addValue( [
'query',
'pages', $row->page ],
132 'anoncontributors', (
int)$row->anons
151 'page' => $pageField,
154 'userid' =>
'MAX(' . $revQuery[
'fields'][
'rev_user'] .
')',
155 'username' =>
'MAX(' . $revQuery[
'fields'][
'rev_user_text'] .
')',
158 $this->
addWhere( $this->actorMigration->isNotAnon( $revQuery[
'fields'][
'rev_user'] ) );
159 $this->
addWhere( [ $db->bitAnd(
'rev_deleted', RevisionRecord::DELETED_USER ) => 0 ] );
160 $this->
addOption(
'GROUP BY', [ $pageField, $idField ] );
165 if ( count( $pages ) > 1 ) {
166 $this->
addOption(
'ORDER BY', [
'page',
'id' ] );
173 $excludeGroups =
false;
174 $limitGroups =
$params[
'group'];
175 } elseif (
$params[
'excludegroup'] ) {
176 $excludeGroups =
true;
177 $limitGroups =
$params[
'excludegroup'];
178 } elseif (
$params[
'rights'] ) {
179 $excludeGroups =
false;
180 foreach (
$params[
'rights'] as $r ) {
181 $limitGroups = array_merge( $limitGroups,
182 $this->groupPermissionsLookup->getGroupsWithPermission( $r ) );
186 if ( !$limitGroups ) {
187 if ( $continuePages !==
null ) {
195 } elseif (
$params[
'excluderights'] ) {
196 $excludeGroups =
true;
197 foreach (
$params[
'excluderights'] as $r ) {
198 $limitGroups = array_merge( $limitGroups,
199 $this->groupPermissionsLookup->getGroupsWithPermission( $r ) );
203 if ( $limitGroups ) {
204 $limitGroups = array_unique( $limitGroups );
208 $excludeGroups ?
'LEFT JOIN' :
'JOIN',
210 'ug_user=' . $revQuery[
'fields'][
'rev_user'],
211 'ug_group' => $limitGroups,
212 $db->expr(
'ug_expiry',
'=',
null )->or(
'ug_expiry',
'>=', $db->timestamp() )
217 $this->
addWhereIf( [
'ug_user' =>
null ], $excludeGroups );
220 if (
$params[
'continue'] !==
null ) {
222 $this->
addWhere( $db->buildComparison(
'>=', [
223 $pageField => $cont[0],
224 $idField => $cont[1],
228 $res = $this->
select( __METHOD__ );
230 foreach ( $res as $row ) {
231 if ( ++$count >
$params[
'limit'] ) {
239 [
'userid' => (
int)$row->userid,
'name' => $row->username ],
248 if ( $continuePages !==
null ) {
258 $userGroups = $this->userGroupManager->listAllGroups();
267 ParamValidator::PARAM_TYPE => $userGroups,
268 ParamValidator::PARAM_ISMULTI =>
true,
271 ParamValidator::PARAM_TYPE => $userGroups,
272 ParamValidator::PARAM_ISMULTI =>
true,
275 ParamValidator::PARAM_TYPE => $userRights,
276 ParamValidator::PARAM_ISMULTI =>
true,
279 ParamValidator::PARAM_TYPE => $userRights,
280 ParamValidator::PARAM_ISMULTI =>
true,
283 ParamValidator::PARAM_DEFAULT => 10,
284 ParamValidator::PARAM_TYPE =>
'limit',
285 IntegerDef::PARAM_MIN => 1,
296 $title = Title::newMainPage()->getPrefixedText();
297 $mp = rawurlencode( $title );
300 "action=query&prop=contributors&titles={$mp}"
301 =>
'apihelp-query+contributors-example-simple',
306 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Contributors';
310 if ( $this->tempUserConfig->isEnabled() ) {
311 return 'apihelp-query+contributors-summary-tempusers-enabled';
313 return parent::getSummaryMessage();
array $params
The job parameters.
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.
__construct(ApiQuery $query, $moduleName, RevisionStore $revisionStore, ActorMigration $actorMigration, UserGroupManager $userGroupManager, GroupPermissionsLookup $groupPermissionsLookup, TempUserConfig $tempUserConfig)
getExamplesMessages()
Returns usage examples for this module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getAllowedParams( $flags=0)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getHelpUrls()
Return links to more detailed help pages about the module.
getSummaryMessage()
Return the summary message.
This is the main query class.