49 private $commentStore;
52 private $userIdentityLookup;
55 private $userNameUtils;
58 private $revisionStore;
61 private $changeTagDefStore;
64 private $actorMigration;
67 private $commentFormatter;
91 parent::__construct( $query, $moduleName,
'uc' );
92 $this->commentStore = $commentStore;
93 $this->userIdentityLookup = $userIdentityLookup;
94 $this->userNameUtils = $userNameUtils;
95 $this->revisionStore = $revisionStore;
96 $this->changeTagDefStore = $changeTagDefStore;
97 $this->actorMigration = $actorMigration;
98 $this->commentFormatter = $commentFormatter;
101 private $params, $multiUserMode, $orderBy, $parentLens;
103 private $fld_ids =
false, $fld_title =
false, $fld_timestamp =
false,
104 $fld_comment =
false, $fld_parsedcomment =
false, $fld_flags =
false,
105 $fld_patrolled =
false, $fld_tags =
false, $fld_size =
false, $fld_sizediff =
false;
111 $prop = array_fill_keys( $this->params[
'prop'],
true );
112 $this->fld_ids = isset( $prop[
'ids'] );
113 $this->fld_title = isset( $prop[
'title'] );
114 $this->fld_comment = isset( $prop[
'comment'] );
115 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
116 $this->fld_size = isset( $prop[
'size'] );
117 $this->fld_sizediff = isset( $prop[
'sizediff'] );
118 $this->fld_flags = isset( $prop[
'flags'] );
119 $this->fld_timestamp = isset( $prop[
'timestamp'] );
120 $this->fld_patrolled = isset( $prop[
'patrolled'] );
121 $this->fld_tags = isset( $prop[
'tags'] );
123 $dbSecondary = $this->
getDB();
125 $sort = ( $this->params[
'dir'] ==
'newer' ?
126 SelectQueryBuilder::SORT_ASC : SelectQueryBuilder::SORT_DESC );
127 $op = ( $this->params[
'dir'] ==
'older' ?
'<=' :
'>=' );
133 if ( isset( $this->params[
'userprefix'] ) ) {
134 $this->multiUserMode =
true;
135 $this->orderBy =
'name';
141 $userIter = call_user_func(
function () use ( $dbSecondary, $sort, $op, $fname ) {
143 if ( $this->params[
'continue'] !==
null ) {
145 [
'string',
'string',
'string',
'int' ] );
147 $fromName = $continue[1];
152 $usersBatch = $this->userIdentityLookup
153 ->newSelectQueryBuilder()
156 ->whereUserNamePrefix( $this->params[
'userprefix'] )
157 ->where( $fromName ? $dbSecondary->buildComparison( $op, [
'actor_name' => $fromName ] ) : [] )
158 ->orderByName( $sort )
159 ->fetchUserIdentities();
163 foreach ( $usersBatch as $user ) {
164 if ( ++$count >= $limit ) {
165 $fromName = $user->getName();
170 }
while ( $fromName !==
false );
175 } elseif ( isset( $this->params[
'userids'] ) ) {
176 if ( $this->params[
'userids'] === [] ) {
178 $this->
dieWithError( [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName" );
182 foreach ( $this->params[
'userids'] as $uid ) {
184 $this->
dieWithError( [
'apierror-invaliduserid', $uid ],
'invaliduserid' );
189 $this->orderBy =
'actor';
190 $this->multiUserMode = count( $ids ) > 1;
193 if ( $this->multiUserMode && $this->params[
'continue'] !==
null ) {
195 [
'string',
'int',
'string',
'int' ] );
197 $fromId = $continue[1];
200 $userIter = $this->userIdentityLookup
201 ->newSelectQueryBuilder()
202 ->caller( __METHOD__ )
203 ->whereUserIds( $ids )
204 ->orderByUserId( $sort )
205 ->where( $fromId ? $dbSecondary->buildComparison( $op, [
'actor_id' => $fromId ] ) : [] )
206 ->fetchUserIdentities();
207 $batchSize = count( $ids );
208 } elseif ( isset( $this->params[
'iprange'] ) ) {
210 $ipRange = $this->params[
'iprange'];
211 $contribsCIDRLimit = $this->
getConfig()->get( MainConfigNames::RangeContributionsCIDRLimit );
212 if ( IPUtils::isIPv4( $ipRange ) ) {
214 $cidrLimit = $contribsCIDRLimit[
'IPv4'];
215 } elseif ( IPUtils::isIPv6( $ipRange ) ) {
217 $cidrLimit = $contribsCIDRLimit[
'IPv6'];
219 $this->
dieWithError( [
'apierror-invalidiprange', $ipRange ],
'invalidiprange' );
221 $range = IPUtils::parseCIDR( $ipRange )[1];
222 if ( $range ===
false ) {
223 $this->
dieWithError( [
'apierror-invalidiprange', $ipRange ],
'invalidiprange' );
224 } elseif ( $range < $cidrLimit ) {
228 $this->multiUserMode =
true;
229 $this->orderBy =
'name';
234 $userIter = call_user_func(
function () use ( $dbSecondary, $sort, $op, $fname, $ipRange ) {
235 [ $start, $end ] = IPUtils::parseRange( $ipRange );
236 if ( $this->params[
'continue'] !==
null ) {
238 [
'string',
'string',
'string',
'int' ] );
240 $fromName = $continue[1];
241 $fromIPHex = IPUtils::toHex( $fromName );
253 $res = $dbSecondary->newSelectQueryBuilder()
254 ->select(
'ipc_hex' )
255 ->from(
'ip_changes' )
256 ->where( [
'ipc_hex BETWEEN ' . $dbSecondary->addQuotes( $start ) .
257 ' AND ' . $dbSecondary->addQuotes( $end )
259 ->groupBy(
'ipc_hex' )
260 ->orderBy(
'ipc_hex', $sort )
267 foreach (
$res as $row ) {
268 $ipAddr = IPUtils::formatHex( $row->ipc_hex );
269 if ( ++$count >= $limit ) {
275 }
while ( $fromName !==
false );
282 if ( !count( $this->params[
'user'] ) ) {
285 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
288 foreach ( $this->params[
'user'] as $u ) {
292 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
296 if ( $this->userNameUtils->isIP( $u ) || ExternalUserNames::isExternal( $u ) ) {
299 $name = $this->userNameUtils->getCanonical( $u );
300 if ( $name ===
false ) {
303 [
'apierror-baduser', $encParamName,
wfEscapeWikiText( $u ) ],
"baduser_$encParamName"
306 $names[$name] =
null;
310 $this->orderBy =
'actor';
311 $this->multiUserMode = count( $names ) > 1;
314 if ( $this->multiUserMode && $this->params[
'continue'] !==
null ) {
316 [
'string',
'int',
'string',
'int' ] );
318 $fromId = $continue[1];
321 $userIter = $this->userIdentityLookup
322 ->newSelectQueryBuilder()
323 ->caller( __METHOD__ )
324 ->whereUserNames( array_keys( $names ) )
325 ->orderByName( $sort )
326 ->where( $fromId ? $dbSecondary->buildComparison( $op, [
'actor_id' => $fromId ] ) : [] )
327 ->fetchUserIdentities();
328 $batchSize = count( $names );
332 $limit = $this->params[
'limit'];
334 while ( $userIter->valid() ) {
336 while ( count( $users ) < $batchSize && $userIter->valid() ) {
337 $users[] = $userIter->current();
342 $this->prepareQuery( $users, $limit - $count );
343 $res = $this->
select( __METHOD__, [], $hookData );
345 if ( $this->fld_title ) {
349 if ( $this->fld_sizediff ) {
351 foreach (
$res as $row ) {
352 if ( $row->rev_parent_id ) {
353 $revIds[] = (int)$row->rev_parent_id;
356 $this->parentLens = $this->revisionStore->getRevisionSizes( $revIds );
359 foreach (
$res as $row ) {
360 if ( ++$count > $limit ) {
367 $vals = $this->extractRowInfo( $row );
368 $fit = $this->
processRow( $row, $vals, $hookData ) &&
385 private function prepareQuery( array $users, $limit ) {
387 $db = $this->
getDB();
389 $revQuery = $this->revisionStore->getQueryInfo( [
'page' ] );
390 $revWhere = $this->actorMigration->getWhere( $db,
'rev_user', $users );
392 $orderUserField =
'rev_actor';
393 $userField = $this->orderBy ===
'actor' ?
'rev_actor' :
'actor_name';
394 $tsField =
'rev_timestamp';
400 $this->
addWhere( $revWhere[
'conds'] );
402 if ( isset( $revWhere[
'orconds'][
'newactor'] ) ) {
403 $this->
addOption(
'USE INDEX', [
'revision' =>
'rev_actor_timestamp' ] );
407 if ( $this->params[
'continue'] !==
null ) {
408 if ( $this->multiUserMode ) {
410 [
'string',
'string',
'timestamp',
'int' ] );
411 $modeFlag = array_shift( $continue );
413 $encUser = array_shift( $continue );
416 [
'timestamp',
'int' ] );
418 $op = ( $this->params[
'dir'] ==
'older' ?
'<=' :
'>=' );
419 if ( $this->multiUserMode ) {
420 $this->
addWhere( $db->buildComparison( $op, [
422 $userField => $encUser,
423 $tsField => $db->timestamp( $continue[0] ),
424 $idField => $continue[1],
427 $this->
addWhere( $db->buildComparison( $op, [
428 $tsField => $db->timestamp( $continue[0] ),
429 $idField => $continue[1],
436 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
437 $bitmask = RevisionRecord::DELETED_USER;
438 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
439 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
444 $this->
addWhere( $db->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
448 if ( count( $users ) > 1 ) {
449 $this->
addWhereRange( $orderUserField, $this->params[
'dir'],
null,
null );
454 $this->params[
'dir'], $this->params[
'start'], $this->params[
'end'] );
457 $this->
addWhereRange( $idField, $this->params[
'dir'],
null,
null );
459 $this->
addWhereFld(
'page_namespace', $this->params[
'namespace'] );
461 $show = $this->params[
'show'];
462 if ( $this->params[
'toponly'] ) {
465 if ( $show !==
null ) {
466 $show = array_fill_keys( $show,
true );
468 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
469 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
470 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!autopatrolled'] ) )
471 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!patrolled'] ) )
472 || ( isset( $show[
'top'] ) && isset( $show[
'!top'] ) )
473 || ( isset( $show[
'new'] ) && isset( $show[
'!new'] ) )
478 $this->
addWhereIf(
'rev_minor_edit = 0', isset( $show[
'!minor'] ) );
479 $this->
addWhereIf(
'rev_minor_edit != 0', isset( $show[
'minor'] ) );
481 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED,
482 isset( $show[
'!patrolled'] )
485 'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED,
486 isset( $show[
'patrolled'] )
489 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
490 isset( $show[
'!autopatrolled'] )
493 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
494 isset( $show[
'autopatrolled'] )
496 $this->
addWhereIf( $idField .
' != page_latest', isset( $show[
'!top'] ) );
497 $this->
addWhereIf( $idField .
' = page_latest', isset( $show[
'top'] ) );
498 $this->
addWhereIf(
'rev_parent_id != 0', isset( $show[
'!new'] ) );
499 $this->
addWhereIf(
'rev_parent_id = 0', isset( $show[
'new'] ) );
503 if ( isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
504 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] ) || $this->fld_patrolled
507 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
508 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
511 $isFilterset = isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
512 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] );
515 $isFilterset ?
'JOIN' :
'LEFT JOIN',
516 [
'rc_this_oldid = ' . $idField ]
520 $this->
addFieldsIf(
'rc_patrolled', $this->fld_patrolled );
522 if ( $this->fld_tags ) {
526 if ( isset( $this->params[
'tag'] ) ) {
529 [
'change_tag' => [
'JOIN', [ $idField .
' = ct_rev_id' ] ] ]
532 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $this->params[
'tag'] ) );
539 'MAX_EXECUTION_TIME',
540 $this->
getConfig()->
get( MainConfigNames::MaxExecutionTimeForExpensiveQueries )
550 private function extractRowInfo( $row ) {
554 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
555 $vals[
'texthidden'] =
true;
560 $vals[
'userid'] = (int)$row->rev_user;
561 $vals[
'user'] = $row->rev_user_text;
562 if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
563 $vals[
'userhidden'] =
true;
566 if ( $this->fld_ids ) {
567 $vals[
'pageid'] = (int)$row->rev_page;
568 $vals[
'revid'] = (int)$row->rev_id;
570 if ( $row->rev_parent_id !==
null ) {
571 $vals[
'parentid'] = (int)$row->rev_parent_id;
575 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
577 if ( $this->fld_title ) {
581 if ( $this->fld_timestamp ) {
582 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
585 if ( $this->fld_flags ) {
586 $vals[
'new'] = $row->rev_parent_id == 0 && $row->rev_parent_id !==
null;
587 $vals[
'minor'] = (bool)$row->rev_minor_edit;
588 $vals[
'top'] = $row->page_latest == $row->rev_id;
591 if ( $this->fld_comment || $this->fld_parsedcomment ) {
592 if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
593 $vals[
'commenthidden'] =
true;
597 $userCanView = RevisionRecord::userCanBitfield(
599 RevisionRecord::DELETED_COMMENT, $this->getAuthority()
602 if ( $userCanView ) {
603 $comment = $this->commentStore->getComment(
'rev_comment', $row )->text;
604 if ( $this->fld_comment ) {
605 $vals[
'comment'] = $comment;
608 if ( $this->fld_parsedcomment ) {
609 $vals[
'parsedcomment'] = $this->commentFormatter->format( $comment,
$title );
614 if ( $this->fld_patrolled ) {
619 if ( $this->fld_size && $row->rev_len !==
null ) {
620 $vals[
'size'] = (int)$row->rev_len;
623 if ( $this->fld_sizediff
624 && $row->rev_len !==
null
625 && $row->rev_parent_id !==
null
627 $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0;
628 $vals[
'sizediff'] = (int)$row->rev_len - $parentLen;
631 if ( $this->fld_tags ) {
632 if ( $row->ts_tags ) {
633 $tags = explode(
',', $row->ts_tags );
635 $vals[
'tags'] = $tags;
641 if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
642 $vals[
'suppressed'] =
true;
648 private function continueStr( $row ) {
649 if ( $this->multiUserMode ) {
650 switch ( $this->orderBy ) {
652 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
654 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
657 return "$row->rev_timestamp|$row->rev_id";
664 return 'anon-public-user-private';
670 ParamValidator::PARAM_DEFAULT => 10,
671 ParamValidator::PARAM_TYPE =>
'limit',
672 IntegerDef::PARAM_MIN => 1,
677 ParamValidator::PARAM_TYPE =>
'timestamp'
680 ParamValidator::PARAM_TYPE =>
'timestamp'
686 ParamValidator::PARAM_TYPE =>
'user',
687 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'interwiki' ],
688 ParamValidator::PARAM_ISMULTI =>
true
691 ParamValidator::PARAM_TYPE =>
'integer',
692 ParamValidator::PARAM_ISMULTI =>
true
694 'userprefix' =>
null,
697 ParamValidator::PARAM_DEFAULT =>
'older',
698 ParamValidator::PARAM_TYPE => [
704 'newer' =>
'api-help-paramvalue-direction-newer',
705 'older' =>
'api-help-paramvalue-direction-older',
709 ParamValidator::PARAM_ISMULTI =>
true,
710 ParamValidator::PARAM_TYPE =>
'namespace'
713 ParamValidator::PARAM_ISMULTI =>
true,
714 ParamValidator::PARAM_DEFAULT =>
'ids|title|timestamp|comment|size|flags',
715 ParamValidator::PARAM_TYPE => [
730 ParamValidator::PARAM_ISMULTI =>
true,
731 ParamValidator::PARAM_TYPE => [
744 'apihelp-query+usercontribs-param-show',
745 $this->
getConfig()->get( MainConfigNames::RCMaxAge )
750 ParamValidator::PARAM_DEFAULT =>
false,
751 ParamValidator::PARAM_DEPRECATED =>
true,
758 'action=query&list=usercontribs&ucuser=Example'
759 =>
'apihelp-query+usercontribs-example-user',
760 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
761 =>
'apihelp-query+usercontribs-example-ipprefix',
766 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 none 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.
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.
static newFromName( $name, $validate='valid')