35 private const MAX_PAGES = 100;
54 parent::__construct( $query, $moduleName,
'pc' );
55 $this->revisionStore = $revisionStore;
56 $this->actorMigration = $actorMigration;
57 $this->userGroupManager = $userGroupManager;
58 $this->groupPermissionsLookup = $groupPermissionsLookup;
59 $this->tempUserConfig = $tempUserConfig;
68 $pages = array_keys( $this->
getPageSet()->getGoodPages() );
71 if ( $params[
'continue'] !==
null ) {
73 $cont_page = (int)$cont[0];
74 $pages = array_filter( $pages,
static function ( $v ) use ( $cont_page ) {
75 return $v >= $cont_page;
78 if ( $pages === [] ) {
85 $continuePages =
null;
86 if ( count( $pages ) > self::MAX_PAGES ) {
87 $continuePages = $pages[self::MAX_PAGES] .
'|0';
88 $pages = array_slice( $pages, 0, self::MAX_PAGES );
92 $revQuery = $this->revisionStore->getQueryInfo();
93 $pageField =
'rev_page';
94 $idField =
'rev_actor';
95 $countField =
'rev_actor';
101 'page' => $pageField,
102 'anons' =>
"COUNT(DISTINCT $countField)",
105 $this->
addWhere( $this->actorMigration->isAnon( $revQuery[
'fields'][
'rev_user'] ) );
106 $this->
addWhere( [ $db->bitAnd(
'rev_deleted', RevisionRecord::DELETED_USER ) => 0 ] );
107 $this->
addOption(
'GROUP BY', $pageField );
108 $res = $this->
select( __METHOD__ );
109 foreach ( $res as $row ) {
110 $fit = $result->addValue( [
'query',
'pages', $row->page ],
111 'anoncontributors', (
int)$row->anons
118 $params[
'continue'] ??
'0|0'
130 'page' => $pageField,
133 'userid' =>
'MAX(' . $revQuery[
'fields'][
'rev_user'] .
')',
134 'username' =>
'MAX(' . $revQuery[
'fields'][
'rev_user_text'] .
')',
137 $this->
addWhere( $this->actorMigration->isNotAnon( $revQuery[
'fields'][
'rev_user'] ) );
138 $this->
addWhere( [ $db->bitAnd(
'rev_deleted', RevisionRecord::DELETED_USER ) => 0 ] );
139 $this->
addOption(
'GROUP BY', [ $pageField, $idField ] );
140 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
144 if ( count( $pages ) > 1 ) {
145 $this->
addOption(
'ORDER BY', [
'page',
'id' ] );
151 if ( $params[
'group'] ) {
152 $excludeGroups =
false;
153 $limitGroups = $params[
'group'];
154 } elseif ( $params[
'excludegroup'] ) {
155 $excludeGroups =
true;
156 $limitGroups = $params[
'excludegroup'];
157 } elseif ( $params[
'rights'] ) {
158 $excludeGroups =
false;
159 foreach ( $params[
'rights'] as $r ) {
160 $limitGroups = array_merge( $limitGroups,
161 $this->groupPermissionsLookup->getGroupsWithPermission( $r ) );
165 if ( !$limitGroups ) {
166 if ( $continuePages !==
null ) {
174 } elseif ( $params[
'excluderights'] ) {
175 $excludeGroups =
true;
176 foreach ( $params[
'excluderights'] as $r ) {
177 $limitGroups = array_merge( $limitGroups,
178 $this->groupPermissionsLookup->getGroupsWithPermission( $r ) );
182 if ( $limitGroups ) {
183 $limitGroups = array_unique( $limitGroups );
187 $excludeGroups ?
'LEFT JOIN' :
'JOIN',
189 'ug_user=' . $revQuery[
'fields'][
'rev_user'],
190 'ug_group' => $limitGroups,
191 $db->expr(
'ug_expiry',
'=',
null )->or(
'ug_expiry',
'>=', $db->timestamp() )
196 $this->
addWhereIf( [
'ug_user' =>
null ], $excludeGroups );
199 if ( $params[
'continue'] !==
null ) {
201 $this->
addWhere( $db->buildComparison(
'>=', [
202 $pageField => $cont[0],
203 $idField => $cont[1],
207 $res = $this->
select( __METHOD__ );
209 foreach ( $res as $row ) {
210 if ( ++$count > $params[
'limit'] ) {
218 [
'userid' => (
int)$row->userid,
'name' => $row->username ],
227 if ( $continuePages !==
null ) {
239 $userGroups = $this->userGroupManager->listAllGroups();
248 ParamValidator::PARAM_TYPE => $userGroups,
249 ParamValidator::PARAM_ISMULTI =>
true,
252 ParamValidator::PARAM_TYPE => $userGroups,
253 ParamValidator::PARAM_ISMULTI =>
true,
256 ParamValidator::PARAM_TYPE => $userRights,
257 ParamValidator::PARAM_ISMULTI =>
true,
260 ParamValidator::PARAM_TYPE => $userRights,
261 ParamValidator::PARAM_ISMULTI =>
true,
264 ParamValidator::PARAM_DEFAULT => 10,
265 ParamValidator::PARAM_TYPE =>
'limit',
266 IntegerDef::PARAM_MIN => 1,
278 $title = Title::newMainPage()->getPrefixedText();
279 $mp = rawurlencode( $title );
282 "action=query&prop=contributors&titles={$mp}"
283 =>
'apihelp-query+contributors-example-simple',
289 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Contributors';
294 if ( $this->tempUserConfig->isKnown() ) {
295 return 'apihelp-query+contributors-summary-tempusers-enabled';
297 return parent::getSummaryMessage();
302class_alias( ApiQueryContributors::class,
'ApiQueryContributors' );