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 ? $dbSecondary->buildComparison( $op, [
'actor_name' => $fromName ] ) : [] )
147 ->orderByName( $sort )
148 ->fetchUserIdentities();
152 foreach ( $usersBatch as $user ) {
153 if ( ++$count >= $limit ) {
154 $fromName = $user->getName();
159 }
while ( $fromName !==
false );
164 } elseif ( isset( $this->params[
'userids'] ) ) {
165 if ( $this->params[
'userids'] === [] ) {
167 $this->
dieWithError( [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName" );
171 foreach ( $this->params[
'userids'] as $uid ) {
173 $this->
dieWithError( [
'apierror-invaliduserid', $uid ],
'invaliduserid' );
178 $this->orderBy =
'actor';
179 $this->multiUserMode = count( $ids ) > 1;
182 if ( $this->multiUserMode && $this->params[
'continue'] !==
null ) {
184 [
'string',
'int',
'string',
'int' ] );
186 $fromId = $continue[1];
189 $userIter = $this->userIdentityLookup
190 ->newSelectQueryBuilder()
191 ->caller( __METHOD__ )
192 ->whereUserIds( $ids )
193 ->orderByUserId( $sort )
194 ->where( $fromId ? $dbSecondary->buildComparison( $op, [
'actor_id' => $fromId ] ) : [] )
195 ->fetchUserIdentities();
196 $batchSize = count( $ids );
197 } elseif ( isset( $this->params[
'iprange'] ) ) {
199 $ipRange = $this->params[
'iprange'];
200 $contribsCIDRLimit = $this->
getConfig()->get( MainConfigNames::RangeContributionsCIDRLimit );
201 if ( IPUtils::isIPv4( $ipRange ) ) {
203 $cidrLimit = $contribsCIDRLimit[
'IPv4'];
204 } elseif ( IPUtils::isIPv6( $ipRange ) ) {
206 $cidrLimit = $contribsCIDRLimit[
'IPv6'];
208 $this->
dieWithError( [
'apierror-invalidiprange', $ipRange ],
'invalidiprange' );
210 $range = IPUtils::parseCIDR( $ipRange )[1];
211 if ( $range ===
false ) {
212 $this->
dieWithError( [
'apierror-invalidiprange', $ipRange ],
'invalidiprange' );
213 } elseif ( $range < $cidrLimit ) {
214 $this->
dieWithError( [
'apierror-cidrtoobroad', $type, $cidrLimit ] );
217 $this->multiUserMode =
true;
218 $this->orderBy =
'name';
223 $userIter = call_user_func(
function () use ( $dbSecondary, $sort, $op, $fname, $ipRange ) {
224 [ $start, $end ] = IPUtils::parseRange( $ipRange );
225 if ( $this->params[
'continue'] !==
null ) {
227 [
'string',
'string',
'string',
'int' ] );
229 $fromName = $continue[1];
230 $fromIPHex = IPUtils::toHex( $fromName );
242 $res = $dbSecondary->newSelectQueryBuilder()
243 ->select(
'ipc_hex' )
244 ->from(
'ip_changes' )
245 ->where( [
'ipc_hex BETWEEN ' . $dbSecondary->addQuotes( $start ) .
246 ' AND ' . $dbSecondary->addQuotes( $end )
248 ->groupBy(
'ipc_hex' )
249 ->orderBy(
'ipc_hex', $sort )
256 foreach ( $res as $row ) {
257 $ipAddr = IPUtils::formatHex( $row->ipc_hex );
258 if ( ++$count >= $limit ) {
262 yield UserIdentityValue::newAnonymous( $ipAddr );
264 }
while ( $fromName !==
false );
271 if ( !count( $this->params[
'user'] ) ) {
274 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
277 foreach ( $this->params[
'user'] as $u ) {
281 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
285 if ( $this->userNameUtils->isIP( $u ) || ExternalUserNames::isExternal( $u ) ) {
288 $name = $this->userNameUtils->getCanonical( $u );
289 if ( $name ===
false ) {
292 [
'apierror-baduser', $encParamName,
wfEscapeWikiText( $u ) ],
"baduser_$encParamName"
295 $names[$name] =
null;
299 $this->orderBy =
'actor';
300 $this->multiUserMode = count( $names ) > 1;
303 if ( $this->multiUserMode && $this->params[
'continue'] !==
null ) {
305 [
'string',
'int',
'string',
'int' ] );
307 $fromId = $continue[1];
310 $userIter = $this->userIdentityLookup
311 ->newSelectQueryBuilder()
312 ->caller( __METHOD__ )
313 ->whereUserNames( array_keys( $names ) )
314 ->orderByName( $sort )
315 ->where( $fromId ? $dbSecondary->buildComparison( $op, [
'actor_id' => $fromId ] ) : [] )
316 ->fetchUserIdentities();
317 $batchSize = count( $names );
321 $limit = $this->params[
'limit'];
323 while ( $userIter->valid() ) {
325 while ( count( $users ) < $batchSize && $userIter->valid() ) {
326 $users[] = $userIter->current();
331 $this->prepareQuery( $users, $limit - $count );
332 $res = $this->
select( __METHOD__, [], $hookData );
334 if ( $this->fld_title ) {
338 if ( $this->fld_sizediff ) {
340 foreach ( $res as $row ) {
341 if ( $row->rev_parent_id ) {
342 $revIds[] = (int)$row->rev_parent_id;
345 $this->parentLens = $this->revisionStore->getRevisionSizes( $revIds );
348 foreach ( $res as $row ) {
349 if ( ++$count > $limit ) {
356 $vals = $this->extractRowInfo( $row );
357 $fit = $this->
processRow( $row, $vals, $hookData ) &&
374 private function prepareQuery( array $users, $limit ) {
376 $db = $this->
getDB();
378 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $db )->joinComment()->joinPage();
379 $revWhere = $this->actorMigration->getWhere( $db,
'rev_user', $users );
381 $orderUserField =
'rev_actor';
382 $userField = $this->orderBy ===
'actor' ?
'rev_actor' :
'actor_name';
383 $tsField =
'rev_timestamp';
387 $this->
addWhere( $revWhere[
'conds'] );
389 if ( isset( $revWhere[
'orconds'][
'newactor'] ) ) {
390 $this->
addOption(
'USE INDEX', [
'revision' =>
'rev_actor_timestamp' ] );
394 if ( $this->params[
'continue'] !==
null ) {
395 if ( $this->multiUserMode ) {
397 [
'string',
'string',
'timestamp',
'int' ] );
398 $modeFlag = array_shift( $continue );
400 $encUser = array_shift( $continue );
403 [
'timestamp',
'int' ] );
405 $op = ( $this->params[
'dir'] ==
'older' ?
'<=' :
'>=' );
406 if ( $this->multiUserMode ) {
407 $this->
addWhere( $db->buildComparison( $op, [
409 $userField => $encUser,
410 $tsField => $db->timestamp( $continue[0] ),
411 $idField => $continue[1],
414 $this->
addWhere( $db->buildComparison( $op, [
415 $tsField => $db->timestamp( $continue[0] ),
416 $idField => $continue[1],
423 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
424 $bitmask = RevisionRecord::DELETED_USER;
425 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
426 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
431 $this->
addWhere( $db->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
435 if ( count( $users ) > 1 ) {
436 $this->
addWhereRange( $orderUserField, $this->params[
'dir'],
null,
null );
441 $this->params[
'dir'], $this->params[
'start'], $this->params[
'end'] );
444 $this->
addWhereRange( $idField, $this->params[
'dir'],
null,
null );
446 $this->
addWhereFld(
'page_namespace', $this->params[
'namespace'] );
448 $show = $this->params[
'show'];
449 if ( $this->params[
'toponly'] ) {
452 if ( $show !==
null ) {
453 $show = array_fill_keys( $show,
true );
455 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
456 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
457 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!autopatrolled'] ) )
458 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!patrolled'] ) )
459 || ( isset( $show[
'top'] ) && isset( $show[
'!top'] ) )
460 || ( isset( $show[
'new'] ) && isset( $show[
'!new'] ) )
465 $this->
addWhereIf( [
'rev_minor_edit' => 0 ], isset( $show[
'!minor'] ) );
466 $this->
addWhereIf(
'rev_minor_edit != 0', isset( $show[
'minor'] ) );
468 [
'rc_patrolled' => RecentChange::PRC_UNPATROLLED ],
469 isset( $show[
'!patrolled'] )
472 'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED,
473 isset( $show[
'patrolled'] )
476 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
477 isset( $show[
'!autopatrolled'] )
480 [
'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED ],
481 isset( $show[
'autopatrolled'] )
483 $this->
addWhereIf( $idField .
' != page_latest', isset( $show[
'!top'] ) );
484 $this->
addWhereIf( $idField .
' = page_latest', isset( $show[
'top'] ) );
485 $this->
addWhereIf(
'rev_parent_id != 0', isset( $show[
'!new'] ) );
486 $this->
addWhereIf( [
'rev_parent_id' => 0 ], isset( $show[
'new'] ) );
490 if ( isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
491 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] ) || $this->fld_patrolled
494 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
495 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
498 $isFilterset = isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
499 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] );
502 $isFilterset ?
'JOIN' :
'LEFT JOIN',
503 [
'rc_this_oldid = ' . $idField ]
507 $this->
addFieldsIf(
'rc_patrolled', $this->fld_patrolled );
509 if ( $this->fld_tags ) {
513 if ( isset( $this->params[
'tag'] ) ) {
516 [
'change_tag' => [
'JOIN', [ $idField .
' = ct_rev_id' ] ] ]
519 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $this->params[
'tag'] ) );
526 'MAX_EXECUTION_TIME',
527 $this->
getConfig()->
get( MainConfigNames::MaxExecutionTimeForExpensiveQueries )
537 private function extractRowInfo( $row ) {
541 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
542 $vals[
'texthidden'] =
true;
547 $vals[
'userid'] = (int)$row->rev_user;
548 $vals[
'user'] = $row->rev_user_text;
549 if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
550 $vals[
'userhidden'] =
true;
553 if ( $this->fld_ids ) {
554 $vals[
'pageid'] = (int)$row->rev_page;
555 $vals[
'revid'] = (int)$row->rev_id;
557 if ( $row->rev_parent_id !==
null ) {
558 $vals[
'parentid'] = (int)$row->rev_parent_id;
562 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
564 if ( $this->fld_title ) {
568 if ( $this->fld_timestamp ) {
569 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
572 if ( $this->fld_flags ) {
573 $vals[
'new'] = $row->rev_parent_id == 0 && $row->rev_parent_id !==
null;
574 $vals[
'minor'] = (bool)$row->rev_minor_edit;
575 $vals[
'top'] = $row->page_latest == $row->rev_id;
578 if ( $this->fld_comment || $this->fld_parsedcomment ) {
579 if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
580 $vals[
'commenthidden'] =
true;
584 $userCanView = RevisionRecord::userCanBitfield(
586 RevisionRecord::DELETED_COMMENT, $this->getAuthority()
589 if ( $userCanView ) {
590 $comment = $this->commentStore->getComment(
'rev_comment', $row )->text;
591 if ( $this->fld_comment ) {
592 $vals[
'comment'] = $comment;
595 if ( $this->fld_parsedcomment ) {
596 $vals[
'parsedcomment'] = $this->commentFormatter->format( $comment, $title );
601 if ( $this->fld_patrolled ) {
606 if ( $this->fld_size && $row->rev_len !==
null ) {
607 $vals[
'size'] = (int)$row->rev_len;
610 if ( $this->fld_sizediff
611 && $row->rev_len !==
null
612 && $row->rev_parent_id !==
null
614 $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0;
615 $vals[
'sizediff'] = (int)$row->rev_len - $parentLen;
618 if ( $this->fld_tags ) {
619 if ( $row->ts_tags ) {
620 $tags = explode(
',', $row->ts_tags );
622 $vals[
'tags'] = $tags;
628 if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
629 $vals[
'suppressed'] =
true;
635 private function continueStr( $row ) {
636 if ( $this->multiUserMode ) {
637 switch ( $this->orderBy ) {
639 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
641 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
644 return "$row->rev_timestamp|$row->rev_id";
651 return 'anon-public-user-private';
657 ParamValidator::PARAM_DEFAULT => 10,
658 ParamValidator::PARAM_TYPE =>
'limit',
659 IntegerDef::PARAM_MIN => 1,
664 ParamValidator::PARAM_TYPE =>
'timestamp'
667 ParamValidator::PARAM_TYPE =>
'timestamp'
673 ParamValidator::PARAM_TYPE =>
'user',
674 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'interwiki' ],
675 ParamValidator::PARAM_ISMULTI =>
true
678 ParamValidator::PARAM_TYPE =>
'integer',
679 ParamValidator::PARAM_ISMULTI =>
true
681 'userprefix' =>
null,
684 ParamValidator::PARAM_DEFAULT =>
'older',
685 ParamValidator::PARAM_TYPE => [
691 'newer' =>
'api-help-paramvalue-direction-newer',
692 'older' =>
'api-help-paramvalue-direction-older',
696 ParamValidator::PARAM_ISMULTI =>
true,
697 ParamValidator::PARAM_TYPE =>
'namespace'
700 ParamValidator::PARAM_ISMULTI =>
true,
701 ParamValidator::PARAM_DEFAULT =>
'ids|title|timestamp|comment|size|flags',
702 ParamValidator::PARAM_TYPE => [
717 ParamValidator::PARAM_ISMULTI =>
true,
718 ParamValidator::PARAM_TYPE => [
731 'apihelp-query+usercontribs-param-show',
732 $this->
getConfig()->get( MainConfigNames::RCMaxAge )
737 ParamValidator::PARAM_DEFAULT =>
false,
738 ParamValidator::PARAM_DEPRECATED =>
true,
745 'action=query&list=usercontribs&ucuser=Example'
746 =>
'apihelp-query+usercontribs-example-user',
747 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
748 =>
'apihelp-query+usercontribs-example-ipprefix',
753 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
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.