80 parent::__construct( $query, $moduleName,
'uc' );
81 $this->commentStore = $commentStore;
82 $this->userIdentityLookup = $userIdentityLookup;
83 $this->userNameUtils = $userNameUtils;
84 $this->revisionStore = $revisionStore;
85 $this->changeTagDefStore = $changeTagDefStore;
86 $this->actorMigration = $actorMigration;
87 $this->commentFormatter = $commentFormatter;
90 private $params, $multiUserMode, $orderBy, $parentLens;
92 private $fld_ids =
false, $fld_title =
false, $fld_timestamp =
false,
93 $fld_comment =
false, $fld_parsedcomment =
false, $fld_flags =
false,
94 $fld_patrolled =
false, $fld_tags =
false, $fld_size =
false, $fld_sizediff =
false;
100 $prop = array_fill_keys( $this->params[
'prop'],
true );
101 $this->fld_ids = isset( $prop[
'ids'] );
102 $this->fld_title = isset( $prop[
'title'] );
103 $this->fld_comment = isset( $prop[
'comment'] );
104 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
105 $this->fld_size = isset( $prop[
'size'] );
106 $this->fld_sizediff = isset( $prop[
'sizediff'] );
107 $this->fld_flags = isset( $prop[
'flags'] );
108 $this->fld_timestamp = isset( $prop[
'timestamp'] );
109 $this->fld_patrolled = isset( $prop[
'patrolled'] );
110 $this->fld_tags = isset( $prop[
'tags'] );
112 $dbSecondary = $this->
getDB();
114 $sort = ( $this->params[
'dir'] ==
'newer' ?
115 SelectQueryBuilder::SORT_ASC : SelectQueryBuilder::SORT_DESC );
116 $op = ( $this->params[
'dir'] ==
'older' ?
'<=' :
'>=' );
122 if ( isset( $this->params[
'userprefix'] ) ) {
123 $this->multiUserMode =
true;
124 $this->orderBy =
'name';
130 $userIter = call_user_func(
function () use ( $dbSecondary, $sort, $op, $fname ) {
132 if ( $this->params[
'continue'] !==
null ) {
134 [
'string',
'string',
'string',
'int' ] );
136 $fromName = $continue[1];
141 $usersBatch = $this->userIdentityLookup
142 ->newSelectQueryBuilder()
145 ->whereUserNamePrefix( $this->params[
'userprefix'] )
146 ->where( $fromName !==
false
147 ? $dbSecondary->buildComparison( $op, [
'actor_name' => $fromName ] )
149 ->orderByName( $sort )
150 ->fetchUserIdentities();
154 foreach ( $usersBatch as $user ) {
155 if ( ++$count >= $limit ) {
156 $fromName = $user->getName();
161 }
while ( $fromName !==
false );
166 } elseif ( isset( $this->params[
'userids'] ) ) {
167 if ( $this->params[
'userids'] === [] ) {
169 $this->
dieWithError( [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName" );
173 foreach ( $this->params[
'userids'] as $uid ) {
175 $this->
dieWithError( [
'apierror-invaliduserid', $uid ],
'invaliduserid' );
180 $this->orderBy =
'actor';
181 $this->multiUserMode = count( $ids ) > 1;
184 if ( $this->multiUserMode && $this->params[
'continue'] !==
null ) {
186 [
'string',
'int',
'string',
'int' ] );
188 $fromId = $continue[1];
191 $userIter = $this->userIdentityLookup
192 ->newSelectQueryBuilder()
193 ->caller( __METHOD__ )
194 ->whereUserIds( $ids )
195 ->orderByUserId( $sort )
196 ->where( $fromId ? $dbSecondary->buildComparison( $op, [
'actor_id' => $fromId ] ) : [] )
197 ->fetchUserIdentities();
198 $batchSize = count( $ids );
199 } elseif ( isset( $this->params[
'iprange'] ) ) {
201 $ipRange = $this->params[
'iprange'];
202 $contribsCIDRLimit = $this->
getConfig()->get( MainConfigNames::RangeContributionsCIDRLimit );
203 if ( IPUtils::isIPv4( $ipRange ) ) {
205 $cidrLimit = $contribsCIDRLimit[
'IPv4'];
206 } elseif ( IPUtils::isIPv6( $ipRange ) ) {
208 $cidrLimit = $contribsCIDRLimit[
'IPv6'];
210 $this->
dieWithError( [
'apierror-invalidiprange', $ipRange ],
'invalidiprange' );
212 $range = IPUtils::parseCIDR( $ipRange )[1];
213 if ( $range ===
false ) {
214 $this->
dieWithError( [
'apierror-invalidiprange', $ipRange ],
'invalidiprange' );
215 } elseif ( $range < $cidrLimit ) {
216 $this->
dieWithError( [
'apierror-cidrtoobroad', $type, $cidrLimit ] );
219 $this->multiUserMode =
true;
220 $this->orderBy =
'name';
225 $userIter = call_user_func(
function () use ( $dbSecondary, $sort, $op, $fname, $ipRange ) {
226 [ $start, $end ] = IPUtils::parseRange( $ipRange );
227 if ( $this->params[
'continue'] !==
null ) {
229 [
'string',
'string',
'string',
'int' ] );
231 $fromName = $continue[1];
232 $fromIPHex = IPUtils::toHex( $fromName );
244 $res = $dbSecondary->newSelectQueryBuilder()
245 ->select(
'ipc_hex' )
246 ->from(
'ip_changes' )
247 ->where( [
'ipc_hex BETWEEN ' . $dbSecondary->addQuotes( $start ) .
248 ' AND ' . $dbSecondary->addQuotes( $end )
250 ->groupBy(
'ipc_hex' )
251 ->orderBy(
'ipc_hex', $sort )
258 foreach ( $res as $row ) {
259 $ipAddr = IPUtils::formatHex( $row->ipc_hex );
260 if ( ++$count >= $limit ) {
264 yield UserIdentityValue::newAnonymous( $ipAddr );
266 }
while ( $fromName !==
false );
273 if ( !count( $this->params[
'user'] ) ) {
276 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
279 foreach ( $this->params[
'user'] as $u ) {
283 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
287 if ( $this->userNameUtils->isIP( $u ) || ExternalUserNames::isExternal( $u ) ) {
290 $name = $this->userNameUtils->getCanonical( $u );
291 if ( $name ===
false ) {
294 [
'apierror-baduser', $encParamName,
wfEscapeWikiText( $u ) ],
"baduser_$encParamName"
297 $names[$name] =
null;
301 $this->orderBy =
'actor';
302 $this->multiUserMode = count( $names ) > 1;
305 if ( $this->multiUserMode && $this->params[
'continue'] !==
null ) {
307 [
'string',
'int',
'string',
'int' ] );
309 $fromId = $continue[1];
312 $userIter = $this->userIdentityLookup
313 ->newSelectQueryBuilder()
314 ->caller( __METHOD__ )
315 ->whereUserNames( array_keys( $names ) )
316 ->orderByName( $sort )
317 ->where( $fromId ? $dbSecondary->buildComparison( $op, [
'actor_id' => $fromId ] ) : [] )
318 ->fetchUserIdentities();
319 $batchSize = count( $names );
323 $limit = $this->params[
'limit'];
325 while ( $userIter->valid() ) {
327 while ( count( $users ) < $batchSize && $userIter->valid() ) {
328 $users[] = $userIter->current();
333 $this->prepareQuery( $users, $limit - $count );
334 $res = $this->
select( __METHOD__, [], $hookData );
336 if ( $this->fld_title ) {
340 if ( $this->fld_sizediff ) {
342 foreach ( $res as $row ) {
343 if ( $row->rev_parent_id ) {
344 $revIds[] = (int)$row->rev_parent_id;
347 $this->parentLens = $this->revisionStore->getRevisionSizes( $revIds );
350 foreach ( $res as $row ) {
351 if ( ++$count > $limit ) {
358 $vals = $this->extractRowInfo( $row );
359 $fit = $this->
processRow( $row, $vals, $hookData ) &&
376 private function prepareQuery( array $users, $limit ) {
378 $db = $this->
getDB();
380 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $db )->joinComment()->joinPage();
381 $revWhere = $this->actorMigration->getWhere( $db,
'rev_user', $users );
383 $orderUserField =
'rev_actor';
384 $userField = $this->orderBy ===
'actor' ?
'rev_actor' :
'actor_name';
385 $tsField =
'rev_timestamp';
389 $this->
addWhere( $revWhere[
'conds'] );
391 if ( isset( $revWhere[
'orconds'][
'newactor'] ) ) {
392 $this->
addOption(
'USE INDEX', [
'revision' =>
'rev_actor_timestamp' ] );
396 if ( $this->params[
'continue'] !==
null ) {
397 if ( $this->multiUserMode ) {
399 [
'string',
'string',
'timestamp',
'int' ] );
400 $modeFlag = array_shift( $continue );
402 $encUser = array_shift( $continue );
405 [
'timestamp',
'int' ] );
407 $op = ( $this->params[
'dir'] ==
'older' ?
'<=' :
'>=' );
408 if ( $this->multiUserMode ) {
409 $this->
addWhere( $db->buildComparison( $op, [
411 $userField => $encUser,
412 $tsField => $db->timestamp( $continue[0] ),
413 $idField => $continue[1],
416 $this->
addWhere( $db->buildComparison( $op, [
417 $tsField => $db->timestamp( $continue[0] ),
418 $idField => $continue[1],
425 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
426 $bitmask = RevisionRecord::DELETED_USER;
427 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
428 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
433 $this->
addWhere( $db->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
437 if ( count( $users ) > 1 ) {
438 $this->
addWhereRange( $orderUserField, $this->params[
'dir'],
null,
null );
443 $this->params[
'dir'], $this->params[
'start'], $this->params[
'end'] );
446 $this->
addWhereRange( $idField, $this->params[
'dir'],
null,
null );
448 $this->
addWhereFld(
'page_namespace', $this->params[
'namespace'] );
450 $show = $this->params[
'show'];
451 if ( $this->params[
'toponly'] ) {
454 if ( $show !==
null ) {
455 $show = array_fill_keys( $show,
true );
457 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
458 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
459 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!autopatrolled'] ) )
460 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!patrolled'] ) )
461 || ( isset( $show[
'top'] ) && isset( $show[
'!top'] ) )
462 || ( isset( $show[
'new'] ) && isset( $show[
'!new'] ) )
467 $this->
addWhereIf( [
'rev_minor_edit' => 0 ], isset( $show[
'!minor'] ) );
468 $this->
addWhereIf(
'rev_minor_edit != 0', isset( $show[
'minor'] ) );
470 [
'rc_patrolled' => RecentChange::PRC_UNPATROLLED ],
471 isset( $show[
'!patrolled'] )
474 'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED,
475 isset( $show[
'patrolled'] )
478 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
479 isset( $show[
'!autopatrolled'] )
482 [
'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED ],
483 isset( $show[
'autopatrolled'] )
485 $this->
addWhereIf( $idField .
' != page_latest', isset( $show[
'!top'] ) );
486 $this->
addWhereIf( $idField .
' = page_latest', isset( $show[
'top'] ) );
487 $this->
addWhereIf(
'rev_parent_id != 0', isset( $show[
'!new'] ) );
488 $this->
addWhereIf( [
'rev_parent_id' => 0 ], isset( $show[
'new'] ) );
492 if ( isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
493 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] ) || $this->fld_patrolled
496 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
497 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
500 $isFilterset = isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
501 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] );
504 $isFilterset ?
'JOIN' :
'LEFT JOIN',
505 [
'rc_this_oldid = ' . $idField ]
509 $this->
addFieldsIf(
'rc_patrolled', $this->fld_patrolled );
511 if ( $this->fld_tags ) {
515 if ( isset( $this->params[
'tag'] ) ) {
518 [
'change_tag' => [
'JOIN', [ $idField .
' = ct_rev_id' ] ] ]
521 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $this->params[
'tag'] ) );
528 'MAX_EXECUTION_TIME',
529 $this->
getConfig()->
get( MainConfigNames::MaxExecutionTimeForExpensiveQueries )
539 private function extractRowInfo( $row ) {
543 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
544 $vals[
'texthidden'] =
true;
549 $vals[
'userid'] = (int)$row->rev_user;
550 $vals[
'user'] = $row->rev_user_text;
551 if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
552 $vals[
'userhidden'] =
true;
555 if ( $this->fld_ids ) {
556 $vals[
'pageid'] = (int)$row->rev_page;
557 $vals[
'revid'] = (int)$row->rev_id;
559 if ( $row->rev_parent_id !==
null ) {
560 $vals[
'parentid'] = (int)$row->rev_parent_id;
564 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
566 if ( $this->fld_title ) {
570 if ( $this->fld_timestamp ) {
571 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
574 if ( $this->fld_flags ) {
575 $vals[
'new'] = $row->rev_parent_id == 0 && $row->rev_parent_id !==
null;
576 $vals[
'minor'] = (bool)$row->rev_minor_edit;
577 $vals[
'top'] = $row->page_latest == $row->rev_id;
580 if ( $this->fld_comment || $this->fld_parsedcomment ) {
581 if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
582 $vals[
'commenthidden'] =
true;
586 $userCanView = RevisionRecord::userCanBitfield(
588 RevisionRecord::DELETED_COMMENT, $this->getAuthority()
591 if ( $userCanView ) {
592 $comment = $this->commentStore->getComment(
'rev_comment', $row )->text;
593 if ( $this->fld_comment ) {
594 $vals[
'comment'] = $comment;
597 if ( $this->fld_parsedcomment ) {
598 $vals[
'parsedcomment'] = $this->commentFormatter->format( $comment, $title );
603 if ( $this->fld_patrolled ) {
608 if ( $this->fld_size && $row->rev_len !==
null ) {
609 $vals[
'size'] = (int)$row->rev_len;
612 if ( $this->fld_sizediff
613 && $row->rev_len !==
null
614 && $row->rev_parent_id !==
null
616 $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0;
617 $vals[
'sizediff'] = (int)$row->rev_len - $parentLen;
620 if ( $this->fld_tags ) {
621 if ( $row->ts_tags ) {
622 $tags = explode(
',', $row->ts_tags );
624 $vals[
'tags'] = $tags;
630 if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
631 $vals[
'suppressed'] =
true;
637 private function continueStr( $row ) {
638 if ( $this->multiUserMode ) {
639 switch ( $this->orderBy ) {
641 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
643 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
646 return "$row->rev_timestamp|$row->rev_id";
653 return 'anon-public-user-private';
659 ParamValidator::PARAM_DEFAULT => 10,
660 ParamValidator::PARAM_TYPE =>
'limit',
661 IntegerDef::PARAM_MIN => 1,
666 ParamValidator::PARAM_TYPE =>
'timestamp'
669 ParamValidator::PARAM_TYPE =>
'timestamp'
675 ParamValidator::PARAM_TYPE =>
'user',
676 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'interwiki' ],
677 ParamValidator::PARAM_ISMULTI => true
680 ParamValidator::PARAM_TYPE =>
'integer',
681 ParamValidator::PARAM_ISMULTI => true
683 'userprefix' =>
null,
686 ParamValidator::PARAM_DEFAULT =>
'older',
687 ParamValidator::PARAM_TYPE => [
693 'newer' =>
'api-help-paramvalue-direction-newer',
694 'older' =>
'api-help-paramvalue-direction-older',
698 ParamValidator::PARAM_ISMULTI =>
true,
699 ParamValidator::PARAM_TYPE =>
'namespace'
702 ParamValidator::PARAM_ISMULTI =>
true,
703 ParamValidator::PARAM_DEFAULT =>
'ids|title|timestamp|comment|size|flags',
704 ParamValidator::PARAM_TYPE => [
719 ParamValidator::PARAM_ISMULTI =>
true,
720 ParamValidator::PARAM_TYPE => [
733 'apihelp-query+usercontribs-param-show',
734 $this->
getConfig()->get( MainConfigNames::RCMaxAge )
739 ParamValidator::PARAM_DEFAULT =>
false,
740 ParamValidator::PARAM_DEPRECATED =>
true,
747 'action=query&list=usercontribs&ucuser=Example'
748 =>
'apihelp-query+usercontribs-example-user',
749 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
750 =>
'apihelp-query+usercontribs-example-ipprefix',
755 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
requireOnlyOneParameter( $params,... $required)
Die if 0 or more than one of a certain set of parameters is set and not false.
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
const LIMIT_BIG1
Fast query, standard limit.
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 LIMIT_BIG2
Fast query, apihighlimits limit.
getModuleName()
Get the name of the module being executed by this instance.
This is a base class for all Query modules.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
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.
addWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.
getQueryBuilder()
Get the SelectQueryBuilder.
addFields( $value)
Add a set of fields to select to the internal array.
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.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
getDB()
Get the Query database connection (read-only)
executeGenderCacheFromResultWrapper(IResultWrapper $res, $fname=__METHOD__, $fieldPrefix='page')
Preprocess the result set to fill the GenderCache with the necessary information before using self::a...
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
This query action adds a list of a specified user's contributions to the output.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getHelpUrls()
Return links to more detailed help pages about the module.
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, UserIdentityLookup $userIdentityLookup, UserNameUtils $userNameUtils, RevisionStore $revisionStore, NameTableStore $changeTagDefStore, ActorMigration $actorMigration, CommentFormatter $commentFormatter)
getExamplesMessages()
Returns usage examples for this module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
This is the main query class.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
A class containing constants representing the names of configuration variables.