78 parent::__construct( $query, $moduleName,
'uc' );
97 $prop = array_fill_keys( $this->params[
'prop'],
true );
98 $this->fld_ids = isset( $prop[
'ids'] );
99 $this->fld_title = isset( $prop[
'title'] );
100 $this->fld_comment = isset( $prop[
'comment'] );
101 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
102 $this->fld_size = isset( $prop[
'size'] );
103 $this->fld_sizediff = isset( $prop[
'sizediff'] );
104 $this->fld_flags = isset( $prop[
'flags'] );
105 $this->fld_timestamp = isset( $prop[
'timestamp'] );
106 $this->fld_patrolled = isset( $prop[
'patrolled'] );
107 $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 ) {
133 $continue = explode(
'|', $this->params[
'continue'] );
136 $fromName = $continue[1];
141 $from = $fromName ?
"$op= " . $dbSecondary->addQuotes( $fromName ) :
false;
142 $usersBatch = $this->userIdentityLookup
143 ->newSelectQueryBuilder()
146 ->whereUserNamePrefix( $this->params[
'userprefix'] )
147 ->where( $from ? [
"actor_name $from" ] : [] )
148 ->orderByName( $sort )
149 ->fetchUserIdentities();
153 foreach ( $usersBatch as $user ) {
154 if ( ++$count >= $limit ) {
155 $fromName = $user->getName();
160 }
while ( $fromName !==
false );
165 } elseif ( isset( $this->params[
'userids'] ) ) {
166 if ( $this->params[
'userids'] === [] ) {
168 $this->
dieWithError( [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName" );
172 foreach ( $this->params[
'userids'] as $uid ) {
174 $this->
dieWithError( [
'apierror-invaliduserid', $uid ],
'invaliduserid' );
179 $this->orderBy =
'id';
180 $this->multiUserMode = count( $ids ) > 1;
182 $from = $fromId =
false;
183 if ( $this->multiUserMode && $this->params[
'continue'] !==
null ) {
184 $continue = explode(
'|', $this->params[
'continue'] );
187 $fromId = (int)$continue[1];
189 $from =
"$op= $fromId";
192 $userIter = $this->userIdentityLookup
193 ->newSelectQueryBuilder()
194 ->caller( __METHOD__ )
195 ->whereUserIds( $ids )
196 ->orderByUserId( $sort )
197 ->where( $from ? [
"actor_id $from" ] : [] )
198 ->fetchUserIdentities();
199 $batchSize = count( $ids );
202 if ( !count( $this->params[
'user'] ) ) {
205 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
208 foreach ( $this->params[
'user'] as $u ) {
212 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
216 if ( $this->userNameUtils->isIP( $u ) || ExternalUserNames::isExternal( $u ) ) {
219 $name = $this->userNameUtils->getCanonical( $u );
220 if ( $name ===
false ) {
223 [
'apierror-baduser', $encParamName,
wfEscapeWikiText( $u ) ],
"baduser_$encParamName"
226 $names[$name] =
null;
230 $this->orderBy =
'name';
231 $this->multiUserMode = count( $names ) > 1;
233 $from = $fromName =
false;
234 if ( $this->multiUserMode && $this->params[
'continue'] !==
null ) {
235 $continue = explode(
'|', $this->params[
'continue'] );
238 $fromName = $continue[1];
239 $from =
"$op= " . $dbSecondary->addQuotes( $fromName );
242 $userIter = $this->userIdentityLookup
243 ->newSelectQueryBuilder()
244 ->caller( __METHOD__ )
245 ->whereUserNames( array_keys( $names ) )
246 ->where( $from ? [
"actor_id $from" ] : [] )
247 ->orderByName( $sort )
248 ->fetchUserIdentities();
249 $batchSize = count( $names );
253 if ( $batchSize > 1 ) {
254 $this->orderBy =
'actor';
258 $limit = $this->params[
'limit'];
260 while ( $userIter->valid() ) {
262 while ( count( $users ) < $batchSize && $userIter->valid() ) {
263 $users[] = $userIter->current();
269 $res = $this->
select( __METHOD__, [], $hookData );
271 if ( $this->fld_title ) {
275 if ( $this->fld_sizediff ) {
277 foreach (
$res as $row ) {
278 if ( $row->rev_parent_id ) {
279 $revIds[] = $row->rev_parent_id;
282 $this->parentLens = $this->revisionStore->getRevisionSizes( $revIds );
285 foreach (
$res as $row ) {
286 if ( ++$count > $limit ) {
294 $fit = $this->
processRow( $row, $vals, $hookData ) &&
315 $db = $this->
getDB();
317 $revQuery = $this->revisionStore->getQueryInfo( [
'page' ] );
318 $revWhere = $this->actorMigration->getWhere( $db,
'rev_user', $users );
321 $orderUserField =
'rev_actor';
322 $userField = $this->orderBy ===
'actor' ?
'revactor_actor' :
'actor_name';
323 $tsField =
'revactor_timestamp';
324 $idField =
'revactor_rev';
333 if ( count( $users ) > 1 && !isset( $this->params[
'tag'] ) ) {
335 unset(
$revQuery[
'joins'][
'temp_rev_user'] );
344 $orderUserField =
'rev_actor';
345 $userField = $this->orderBy ===
'actor' ?
'rev_actor' :
'actor_name';
346 $tsField =
'rev_timestamp';
353 $this->
addWhere( $revWhere[
'conds'] );
356 if ( $this->params[
'continue'] !==
null ) {
357 $continue = explode(
'|', $this->params[
'continue'] );
358 if ( $this->multiUserMode ) {
360 $modeFlag = array_shift( $continue );
362 $encUser = $db->addQuotes( array_shift( $continue ) );
366 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
367 $encId = (int)$continue[1];
369 $op = ( $this->params[
'dir'] ==
'older' ?
'<' :
'>' );
370 if ( $this->multiUserMode ) {
372 "$userField $op $encUser OR " .
373 "($userField = $encUser AND " .
374 "($tsField $op $encTS OR " .
375 "($tsField = $encTS AND " .
376 "$idField $op= $encId)))"
380 "$tsField $op $encTS OR " .
381 "($tsField = $encTS AND " .
382 "$idField $op= $encId)"
389 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
390 $bitmask = RevisionRecord::DELETED_USER;
391 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
392 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
397 $this->
addWhere( $db->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
401 if ( count( $users ) > 1 ) {
402 $this->
addWhereRange( $orderUserField, $this->params[
'dir'],
null,
null );
407 $this->params[
'dir'], $this->params[
'start'], $this->params[
'end'] );
410 $this->
addWhereRange( $idField, $this->params[
'dir'],
null,
null );
412 $this->
addWhereFld(
'page_namespace', $this->params[
'namespace'] );
414 $show = $this->params[
'show'];
415 if ( $this->params[
'toponly'] ) {
418 if ( $show !==
null ) {
419 $show = array_fill_keys( $show,
true );
421 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
422 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
423 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!autopatrolled'] ) )
424 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!patrolled'] ) )
425 || ( isset( $show[
'top'] ) && isset( $show[
'!top'] ) )
426 || ( isset( $show[
'new'] ) && isset( $show[
'!new'] ) )
431 $this->
addWhereIf(
'rev_minor_edit = 0', isset( $show[
'!minor'] ) );
432 $this->
addWhereIf(
'rev_minor_edit != 0', isset( $show[
'minor'] ) );
434 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED,
435 isset( $show[
'!patrolled'] )
438 'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED,
439 isset( $show[
'patrolled'] )
442 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
443 isset( $show[
'!autopatrolled'] )
446 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
447 isset( $show[
'autopatrolled'] )
449 $this->
addWhereIf( $idField .
' != page_latest', isset( $show[
'!top'] ) );
450 $this->
addWhereIf( $idField .
' = page_latest', isset( $show[
'top'] ) );
451 $this->
addWhereIf(
'rev_parent_id != 0', isset( $show[
'!new'] ) );
452 $this->
addWhereIf(
'rev_parent_id = 0', isset( $show[
'new'] ) );
456 if ( isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
457 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] ) || $this->fld_patrolled
460 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
461 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
464 $isFilterset = isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
465 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] );
468 $isFilterset ?
'JOIN' :
'LEFT JOIN',
469 [
'rc_this_oldid = ' . $idField ]
473 $this->
addFieldsIf(
'rc_patrolled', $this->fld_patrolled );
475 if ( $this->fld_tags ) {
479 if ( isset( $this->params[
'tag'] ) ) {
482 [
'change_tag' => [
'JOIN', [ $idField .
' = ct_rev_id' ] ] ]
485 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $this->params[
'tag'] ) );
492 'MAX_EXECUTION_TIME',
493 $this->
getConfig()->
get(
'MaxExecutionTimeForExpensiveQueries' )
507 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
508 $vals[
'texthidden'] =
true;
513 $vals[
'userid'] = (int)$row->rev_user;
514 $vals[
'user'] = $row->rev_user_text;
515 if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
516 $vals[
'userhidden'] =
true;
519 if ( $this->fld_ids ) {
520 $vals[
'pageid'] = (int)$row->rev_page;
521 $vals[
'revid'] = (int)$row->rev_id;
523 if ( $row->rev_parent_id !==
null ) {
524 $vals[
'parentid'] = (int)$row->rev_parent_id;
528 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
530 if ( $this->fld_title ) {
534 if ( $this->fld_timestamp ) {
535 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
538 if ( $this->fld_flags ) {
539 $vals[
'new'] = $row->rev_parent_id == 0 && $row->rev_parent_id !==
null;
540 $vals[
'minor'] = (bool)$row->rev_minor_edit;
541 $vals[
'top'] = $row->page_latest == $row->rev_id;
544 if ( $this->fld_comment || $this->fld_parsedcomment ) {
545 if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
546 $vals[
'commenthidden'] =
true;
550 $userCanView = RevisionRecord::userCanBitfield(
552 RevisionRecord::DELETED_COMMENT, $this->getUser()
555 if ( $userCanView ) {
556 $comment = $this->commentStore->getComment(
'rev_comment', $row )->text;
557 if ( $this->fld_comment ) {
558 $vals[
'comment'] = $comment;
561 if ( $this->fld_parsedcomment ) {
567 if ( $this->fld_patrolled ) {
568 $vals[
'patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
569 $vals[
'autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
572 if ( $this->fld_size && $row->rev_len !==
null ) {
573 $vals[
'size'] = (int)$row->rev_len;
576 if ( $this->fld_sizediff
577 && $row->rev_len !==
null
578 && $row->rev_parent_id !==
null
580 $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0;
581 $vals[
'sizediff'] = (int)$row->rev_len - $parentLen;
584 if ( $this->fld_tags ) {
585 if ( $row->ts_tags ) {
586 $tags = explode(
',', $row->ts_tags );
587 ApiResult::setIndexedTagName( $tags,
'tag' );
588 $vals[
'tags'] = $tags;
594 if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
595 $vals[
'suppressed'] =
true;
602 if ( $this->multiUserMode ) {
603 switch ( $this->orderBy ) {
605 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
607 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
609 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
612 return "$row->rev_timestamp|$row->rev_id";
619 return 'anon-public-user-private';
642 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'interwiki' ],
649 'userprefix' =>
null,
694 'apihelp-query+usercontribs-param-show',
708 'action=query&list=usercontribs&ucuser=Example'
709 =>
'apihelp-query+usercontribs-example-user',
710 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
711 =>
'apihelp-query+usercontribs-example-ipprefix',
716 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
724class_alias( ApiQueryUserContribs::class,
'ApiQueryContributions' );
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage, for migration from the temporary table revision_actor_temp to the...
const SCHEMA_COMPAT_READ_TEMP
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,...
This is not intended to be a long-term part of MediaWiki; it will be deprecated and removed once acto...
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.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
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...
ActorMigration $actorMigration
CommentStore $commentStore
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)
getExamplesMessages()
Returns usage examples for this module.
UserNameUtils $userNameUtils
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
prepareQuery(array $users, $limit)
Prepares the query and returns the limit of rows requested.
RevisionStore $revisionStore
extractRowInfo( $row)
Extract fields from the database row and append them to a result array.
UserIdentityLookup $userIdentityLookup
NameTableStore $changeTagDefStore
This is the main query class.
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...