53 private $formattedComments = [];
75 parent::__construct( $query, $moduleName,
'rc' );
76 $this->commentStore = $commentStore;
77 $this->commentFormatter = $commentFormatter;
78 $this->changeTagDefStore = $changeTagDefStore;
79 $this->slotRoleStore = $slotRoleStore;
80 $this->slotRoleRegistry = $slotRoleRegistry;
81 $this->userNameUtils = $userNameUtils;
84 private bool $fld_comment =
false;
85 private bool $fld_parsedcomment =
false;
86 private bool $fld_user =
false;
87 private bool $fld_userid =
false;
88 private bool $fld_flags =
false;
89 private bool $fld_timestamp =
false;
90 private bool $fld_title =
false;
91 private bool $fld_ids =
false;
92 private bool $fld_sizes =
false;
93 private bool $fld_redirect =
false;
94 private bool $fld_patrolled =
false;
95 private bool $fld_loginfo =
false;
96 private bool $fld_tags =
false;
97 private bool $fld_sha1 =
false;
104 $this->fld_comment = isset( $prop[
'comment'] );
105 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
106 $this->fld_user = isset( $prop[
'user'] );
107 $this->fld_userid = isset( $prop[
'userid'] );
108 $this->fld_flags = isset( $prop[
'flags'] );
109 $this->fld_timestamp = isset( $prop[
'timestamp'] );
110 $this->fld_title = isset( $prop[
'title'] );
111 $this->fld_ids = isset( $prop[
'ids'] );
112 $this->fld_sizes = isset( $prop[
'sizes'] );
113 $this->fld_redirect = isset( $prop[
'redirect'] );
114 $this->fld_patrolled = isset( $prop[
'patrolled'] );
115 $this->fld_loginfo = isset( $prop[
'loginfo'] );
116 $this->fld_tags = isset( $prop[
'tags'] );
117 $this->fld_sha1 = isset( $prop[
'sha1'] );
125 $this->
run( $resultPageSet );
133 public function run( $resultPageSet =
null ) {
134 $db = $this->
getDB();
146 if (
$params[
'continue'] !==
null ) {
148 $op =
$params[
'dir'] ===
'older' ?
'<=' :
'>=';
149 $this->
addWhere( $db->buildComparison( $op, [
150 'rc_timestamp' => $db->timestamp( $cont[0] ),
155 $order =
$params[
'dir'] ===
'older' ?
'DESC' :
'ASC';
157 "rc_timestamp $order",
161 if (
$params[
'type'] !==
null ) {
166 if ( $title !==
null ) {
167 $titleObj = Title::newFromText( $title );
168 if ( $titleObj ===
null || $titleObj->isExternal() ) {
170 } elseif (
$params[
'namespace'] && !in_array( $titleObj->getNamespace(),
$params[
'namespace'] ) ) {
173 $this->
addWhereFld(
'rc_namespace', $titleObj->getNamespace() );
174 $this->
addWhereFld(
'rc_title', $titleObj->getDBkey() );
179 if (
$params[
'show'] !==
null ) {
180 $show = array_fill_keys(
$params[
'show'],
true );
183 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
184 || ( isset( $show[
'bot'] ) && isset( $show[
'!bot'] ) )
185 || ( isset( $show[
'anon'] ) && isset( $show[
'!anon'] ) )
186 || ( isset( $show[
'redirect'] ) && isset( $show[
'!redirect'] ) )
187 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
188 || ( isset( $show[
'patrolled'] ) && isset( $show[
'unpatrolled'] ) )
189 || ( isset( $show[
'!patrolled'] ) && isset( $show[
'unpatrolled'] ) )
190 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!autopatrolled'] ) )
191 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'unpatrolled'] ) )
192 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!patrolled'] ) )
198 if ( $this->includesPatrollingFlags( $show ) && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
199 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
203 $this->
addWhereIf( [
'rc_minor' => 0 ], isset( $show[
'!minor'] ) );
204 $this->
addWhereIf( $db->expr(
'rc_minor',
'!=', 0 ), isset( $show[
'minor'] ) );
205 $this->
addWhereIf( [
'rc_bot' => 0 ], isset( $show[
'!bot'] ) );
206 $this->
addWhereIf( $db->expr(
'rc_bot',
'!=', 0 ), isset( $show[
'bot'] ) );
207 if ( isset( $show[
'anon'] ) || isset( $show[
'!anon'] ) ) {
209 $this->
addJoinConds( [
'actor' => [
'JOIN',
'actor_id=rc_actor' ] ] );
211 [
'actor_user' =>
null ], isset( $show[
'anon'] )
214 $db->expr(
'actor_user',
'!=',
null ), isset( $show[
'!anon'] )
217 $this->
addWhereIf( [
'rc_patrolled' => 0 ], isset( $show[
'!patrolled'] ) );
218 $this->
addWhereIf( $db->expr(
'rc_patrolled',
'!=', 0 ), isset( $show[
'patrolled'] ) );
219 $this->
addWhereIf( [
'page_is_redirect' => 1 ], isset( $show[
'redirect'] ) );
221 if ( isset( $show[
'unpatrolled'] ) ) {
223 if ( $user->useRCPatrol() ) {
224 $this->
addWhereFld(
'rc_patrolled', RecentChange::PRC_UNPATROLLED );
225 } elseif ( $user->useNPPatrol() ) {
226 $this->
addWhereFld(
'rc_patrolled', RecentChange::PRC_UNPATROLLED );
232 $db->expr(
'rc_patrolled',
'!=', RecentChange::PRC_AUTOPATROLLED ),
233 isset( $show[
'!autopatrolled'] )
236 [
'rc_patrolled' => RecentChange::PRC_AUTOPATROLLED ],
237 isset( $show[
'autopatrolled'] )
242 [
'page_is_redirect' => [ 0,
null ] ],
243 isset( $show[
'!redirect'] )
249 if (
$params[
'prop'] !==
null ) {
250 $prop = array_fill_keys(
$params[
'prop'],
true );
259 ||
$params[
'excludeuser'] !==
null
262 $this->
addFields( [
'actor_name',
'actor_user',
'rc_actor' ] );
263 $this->
addJoinConds( [
'actor' => [
'JOIN',
'actor_id=rc_actor' ] ] );
266 if (
$params[
'user'] !==
null ) {
270 if (
$params[
'excludeuser'] !==
null ) {
271 $this->
addWhere( $db->expr(
'actor_name',
'!=',
$params[
'excludeuser'] ) );
285 $showRedirects =
false;
287 if (
$params[
'prop'] !==
null ) {
288 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
289 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
293 $this->
addFieldsIf( [
'rc_this_oldid',
'rc_last_oldid' ], $this->fld_ids );
294 $this->
addFieldsIf( [
'rc_minor',
'rc_type',
'rc_bot' ], $this->fld_flags );
295 $this->
addFieldsIf( [
'rc_old_len',
'rc_new_len' ], $this->fld_sizes );
296 $this->
addFieldsIf( [
'rc_patrolled',
'rc_log_type' ], $this->fld_patrolled );
298 [
'rc_logid',
'rc_log_type',
'rc_log_action',
'rc_params' ],
301 $showRedirects = $this->fld_redirect || isset( $show[
'redirect'] )
302 || isset( $show[
'!redirect'] );
305 $resultPageSet &&
$params[
'generaterevisions'] );
307 if ( $this->fld_tags ) {
311 if ( $this->fld_sha1 ) {
314 [
'rc_this_oldid=rev_id' ] ] ] );
315 $this->
addFields( [
'rev_sha1',
'rev_deleted' ] );
318 if (
$params[
'toponly'] || $showRedirects ) {
321 [
'rc_namespace=page_namespace',
'rc_title=page_title' ] ] ] );
325 $this->
addWhere(
'rc_this_oldid = page_latest' );
329 if (
$params[
'tag'] !==
null ) {
331 $this->
addJoinConds( [
'change_tag' => [
'JOIN', [
'rc_id=ct_rc_id' ] ] ] );
341 if (
$params[
'user'] !==
null ||
$params[
'excludeuser'] !==
null ) {
342 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
343 $bitmask = RevisionRecord::DELETED_USER;
344 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
345 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
350 $this->
addWhere( $db->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask" );
353 if ( $this->
getRequest()->getCheck(
'namespace' ) ) {
355 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
356 $bitmask = LogPage::DELETED_ACTION;
357 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
358 $bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
364 $db->expr(
'rc_type',
'!=',
RC_LOG )
365 ->orExpr(
new RawSQLExpression( $db->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask" ) )
370 if ( $this->fld_comment || $this->fld_parsedcomment ) {
371 $commentQuery = $this->commentStore->getJoin(
'rc_comment' );
372 $this->
addTables( $commentQuery[
'tables'] );
373 $this->
addFields( $commentQuery[
'fields'] );
377 if (
$params[
'slot'] !==
null ) {
379 $slotId = $this->slotRoleStore->getId(
$params[
'slot'] );
380 }
catch ( Exception $e ) {
385 'slot' =>
'slots',
'parent_slot' =>
'slots'
388 'slot' => [
'LEFT JOIN', [
389 'rc_this_oldid = slot.slot_revision_id',
390 'slot.slot_role_id' => $slotId,
392 'parent_slot' => [
'LEFT JOIN', [
393 'rc_last_oldid = parent_slot.slot_revision_id',
394 'parent_slot.slot_role_id' => $slotId,
405 new RawSQLExpression(
'slot.slot_content_id != parent_slot.slot_content_id' ),
406 $db->expr(
'slot.slot_content_id',
'=',
null )->
and(
'parent_slot.slot_content_id',
'!=',
null ),
407 $db->expr(
'slot.slot_content_id',
'!=',
null )->and(
'parent_slot.slot_content_id',
'=',
null ),
410 $changeTypes = RecentChange::parseToRCType(
411 array_intersect(
$params[
'type'], [
'new',
'edit' ] )
413 if ( count( $changeTypes ) ) {
418 $this->
addWhere( [
'rc_type' =>
null ] );
424 'MAX_EXECUTION_TIME',
425 $this->
getConfig()->
get( MainConfigNames::MaxExecutionTimeForExpensiveQueries )
431 $res = $this->
select( __METHOD__, [], $hookData );
434 if ( $this->fld_title && $resultPageSet ===
null ) {
437 if ( $this->fld_parsedcomment ) {
438 $this->formattedComments = $this->commentFormatter->formatItems(
439 $this->commentFormatter->rows( $res )
440 ->indexField(
'rc_id' )
441 ->commentKey(
'rc_comment' )
442 ->namespaceField(
'rc_namespace' )
443 ->titleField(
'rc_title' )
453 foreach ( $res as $row ) {
454 if ( $count === 0 && $resultPageSet !==
null ) {
458 $this,
'continue',
"$row->rc_timestamp|$row->rc_id"
461 if ( ++$count >
$params[
'limit'] ) {
468 if ( $resultPageSet ===
null ) {
473 $fit = $this->
processRow( $row, $vals, $hookData ) &&
474 $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
479 } elseif (
$params[
'generaterevisions'] ) {
480 $revid = (int)$row->rc_this_oldid;
485 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
489 if ( $resultPageSet ===
null ) {
491 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'rc' );
492 } elseif (
$params[
'generaterevisions'] ) {
493 $resultPageSet->populateFromRevisionIDs( $revids );
495 $resultPageSet->populateFromTitles( $titles );
507 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
513 $type = (int)$row->rc_type;
514 $vals[
'type'] = RecentChange::parseFromRCType( $type );
519 if ( $this->fld_title || $this->fld_ids ) {
520 if ( $type ===
RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
521 $vals[
'actionhidden'] =
true;
525 LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user )
527 if ( $this->fld_title ) {
530 if ( $this->fld_ids ) {
531 $vals[
'pageid'] = (int)$row->rc_cur_id;
532 $vals[
'revid'] = (int)$row->rc_this_oldid;
533 $vals[
'old_revid'] = (int)$row->rc_last_oldid;
538 if ( $this->fld_ids ) {
539 $vals[
'rcid'] = (int)$row->rc_id;
543 if ( $this->fld_user || $this->fld_userid ) {
544 if ( $row->rc_deleted & RevisionRecord::DELETED_USER ) {
545 $vals[
'userhidden'] =
true;
548 if ( RevisionRecord::userCanBitfield( $row->rc_deleted, RevisionRecord::DELETED_USER, $user ) ) {
549 if ( $this->fld_user ) {
550 $vals[
'user'] = $row->actor_name;
553 if ( $this->fld_userid ) {
554 $vals[
'userid'] = (int)$row->actor_user;
557 if ( isset( $row->actor_name ) && $this->userNameUtils->isTemp( $row->actor_name ) ) {
558 $vals[
'temp'] =
true;
561 if ( !$row->actor_user ) {
562 $vals[
'anon'] =
true;
568 if ( $this->fld_flags ) {
569 $vals[
'bot'] = (bool)$row->rc_bot;
570 $vals[
'new'] = $row->rc_type ==
RC_NEW;
571 $vals[
'minor'] = (bool)$row->rc_minor;
575 if ( $this->fld_sizes ) {
576 $vals[
'oldlen'] = (int)$row->rc_old_len;
577 $vals[
'newlen'] = (int)$row->rc_new_len;
581 if ( $this->fld_timestamp ) {
582 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
586 if ( $this->fld_comment || $this->fld_parsedcomment ) {
587 if ( $row->rc_deleted & RevisionRecord::DELETED_COMMENT ) {
588 $vals[
'commenthidden'] =
true;
591 if ( RevisionRecord::userCanBitfield(
592 $row->rc_deleted, RevisionRecord::DELETED_COMMENT, $user
594 if ( $this->fld_comment ) {
595 $vals[
'comment'] = $this->commentStore->getComment(
'rc_comment', $row )->text;
598 if ( $this->fld_parsedcomment ) {
599 $vals[
'parsedcomment'] = $this->formattedComments[$row->rc_id];
604 if ( $this->fld_redirect ) {
605 $vals[
'redirect'] = (bool)$row->page_is_redirect;
609 if ( $this->fld_patrolled ) {
610 $vals[
'patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
611 $vals[
'unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
612 $vals[
'autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
615 if ( $this->fld_loginfo && $row->rc_type ==
RC_LOG ) {
616 if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
617 $vals[
'actionhidden'] =
true;
620 if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) {
621 $vals[
'logid'] = (int)$row->rc_logid;
622 $vals[
'logtype'] = $row->rc_log_type;
623 $vals[
'logaction'] = $row->rc_log_action;
624 $vals[
'logparams'] = LogFormatter::newFromRow( $row )->formatParametersForApi();
628 if ( $this->fld_tags ) {
629 if ( $row->ts_tags ) {
630 $tags = explode(
',', $row->ts_tags );
631 ApiResult::setIndexedTagName( $tags,
'tag' );
632 $vals[
'tags'] = $tags;
638 if ( $this->fld_sha1 && $row->rev_sha1 !==
null ) {
639 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
640 $vals[
'sha1hidden'] =
true;
643 if ( RevisionRecord::userCanBitfield(
644 $row->rev_deleted, RevisionRecord::DELETED_TEXT, $user
646 if ( $row->rev_sha1 !==
'' ) {
647 $vals[
'sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
654 if ( $anyHidden && ( $row->rc_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
655 $vals[
'suppressed'] =
true;
665 private function includesPatrollingFlags( array $flagsArray ) {
666 return isset( $flagsArray[
'patrolled'] ) ||
667 isset( $flagsArray[
'!patrolled'] ) ||
668 isset( $flagsArray[
'unpatrolled'] ) ||
669 isset( $flagsArray[
'autopatrolled'] ) ||
670 isset( $flagsArray[
'!autopatrolled'] );
674 if ( isset(
$params[
'show'] ) &&
675 $this->includesPatrollingFlags( array_fill_keys(
$params[
'show'],
true ) )
682 if (
$params[
'prop'] !==
null && in_array(
'parsedcomment',
$params[
'prop'] ) ) {
684 return 'anon-public-user-private';
691 $slotRoles = $this->slotRoleRegistry->getKnownRoles();
692 sort( $slotRoles, SORT_STRING );
696 ParamValidator::PARAM_TYPE =>
'timestamp'
699 ParamValidator::PARAM_TYPE =>
'timestamp'
702 ParamValidator::PARAM_DEFAULT =>
'older',
703 ParamValidator::PARAM_TYPE => [
709 'newer' =>
'api-help-paramvalue-direction-newer',
710 'older' =>
'api-help-paramvalue-direction-older',
714 ParamValidator::PARAM_ISMULTI =>
true,
715 ParamValidator::PARAM_TYPE =>
'namespace',
719 ParamValidator::PARAM_TYPE =>
'user',
720 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
723 ParamValidator::PARAM_TYPE =>
'user',
724 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
728 ParamValidator::PARAM_ISMULTI =>
true,
729 ParamValidator::PARAM_DEFAULT =>
'title|timestamp|ids',
730 ParamValidator::PARAM_TYPE => [
749 ParamValidator::PARAM_ISMULTI =>
true,
750 ParamValidator::PARAM_TYPE => [
767 ParamValidator::PARAM_DEFAULT => 10,
768 ParamValidator::PARAM_TYPE =>
'limit',
769 IntegerDef::PARAM_MIN => 1,
774 ParamValidator::PARAM_DEFAULT =>
'edit|new|log|categorize',
775 ParamValidator::PARAM_ISMULTI =>
true,
776 ParamValidator::PARAM_TYPE => RecentChange::getChangeTypes()
783 'generaterevisions' =>
false,
785 ParamValidator::PARAM_TYPE => $slotRoles
792 'action=query&list=recentchanges'
793 =>
'apihelp-query+recentchanges-example-simple',
794 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
795 =>
'apihelp-query+recentchanges-example-generator',
800 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Recentchanges';
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.
array $params
The job parameters.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
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.
requireMaxOneParameter( $params,... $required)
Dies if more than one parameter from a certain set of parameters are set and not false.
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.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
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.
userCanSeeRevDel()
Check whether the current user has permission to view revision-deleted fields.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
A query action to enumerate the recent changes that were done to the wiki.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
initProperties( $prop)
Sets internal state to include the desired properties in the output.
getExamplesMessages()
Returns usage examples for this module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
executeGenerator( $resultPageSet)
Execute this module as a generator.
run( $resultPageSet=null)
Generates and outputs the result of this query based upon the provided parameters.
getHelpUrls()
Return links to more detailed help pages about the module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
extractRowInfo( $row)
Extracts from a single sql row the data needed to describe one recent change.
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, RowCommentFormatter $commentFormatter, NameTableStore $changeTagDefStore, NameTableStore $slotRoleStore, SlotRoleRegistry $slotRoleRegistry, UserNameUtils $userNameUtils)
This is the main query class.
A class containing constants representing the names of configuration variables.