45 private $commentStore;
48 private $commentFormatter;
51 private $changeTagDefStore;
54 private $slotRoleStore;
57 private $slotRoleRegistry;
59 private $formattedComments = [];
79 parent::__construct( $query, $moduleName,
'rc' );
80 $this->commentStore = $commentStore;
81 $this->commentFormatter = $commentFormatter;
82 $this->changeTagDefStore = $changeTagDefStore;
83 $this->slotRoleStore = $slotRoleStore;
84 $this->slotRoleRegistry = $slotRoleRegistry;
87 private $fld_comment =
false, $fld_parsedcomment =
false, $fld_user =
false, $fld_userid =
false,
88 $fld_flags =
false, $fld_timestamp =
false, $fld_title =
false, $fld_ids =
false,
89 $fld_sizes =
false, $fld_redirect =
false, $fld_patrolled =
false, $fld_loginfo =
false,
90 $fld_tags =
false, $fld_sha1 =
false;
97 $this->fld_comment = isset( $prop[
'comment'] );
98 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
99 $this->fld_user = isset( $prop[
'user'] );
100 $this->fld_userid = isset( $prop[
'userid'] );
101 $this->fld_flags = isset( $prop[
'flags'] );
102 $this->fld_timestamp = isset( $prop[
'timestamp'] );
103 $this->fld_title = isset( $prop[
'title'] );
104 $this->fld_ids = isset( $prop[
'ids'] );
105 $this->fld_sizes = isset( $prop[
'sizes'] );
106 $this->fld_redirect = isset( $prop[
'redirect'] );
107 $this->fld_patrolled = isset( $prop[
'patrolled'] );
108 $this->fld_loginfo = isset( $prop[
'loginfo'] );
109 $this->fld_tags = isset( $prop[
'tags'] );
110 $this->fld_sha1 = isset( $prop[
'sha1'] );
118 $this->
run( $resultPageSet );
126 public function run( $resultPageSet =
null ) {
138 if ( $params[
'continue'] !==
null ) {
140 $db = $this->
getDB();
141 $op = $params[
'dir'] ===
'older' ?
'<=' :
'>=';
142 $this->
addWhere( $db->buildComparison( $op, [
143 'rc_timestamp' => $db->timestamp( $cont[0] ),
148 $order = $params[
'dir'] ===
'older' ?
'DESC' :
'ASC';
150 "rc_timestamp $order",
154 if ( $params[
'type'] !==
null ) {
156 $this->
addWhereFld(
'rc_type', RecentChange::parseToRCType( $params[
'type'] ) );
157 }
catch ( Exception $e ) {
162 $title = $params[
'title'];
164 $titleObj = Title::newFromText(
$title );
165 if ( $titleObj ===
null || $titleObj->isExternal() ) {
167 } elseif ( $params[
'namespace'] && !in_array( $titleObj->getNamespace(), $params[
'namespace'] ) ) {
170 $this->
addWhereFld(
'rc_namespace', $titleObj->getNamespace() );
171 $this->
addWhereFld(
'rc_title', $titleObj->getDBkey() );
173 $this->
addWhereFld(
'rc_namespace', $params[
'namespace'] );
176 if ( $params[
'show'] !==
null ) {
177 $show = array_fill_keys( $params[
'show'],
true );
180 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
181 || ( isset( $show[
'bot'] ) && isset( $show[
'!bot'] ) )
182 || ( isset( $show[
'anon'] ) && isset( $show[
'!anon'] ) )
183 || ( isset( $show[
'redirect'] ) && isset( $show[
'!redirect'] ) )
184 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
185 || ( isset( $show[
'patrolled'] ) && isset( $show[
'unpatrolled'] ) )
186 || ( isset( $show[
'!patrolled'] ) && isset( $show[
'unpatrolled'] ) )
187 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!autopatrolled'] ) )
188 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'unpatrolled'] ) )
189 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!patrolled'] ) )
195 if ( $this->includesPatrollingFlags( $show ) && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
196 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
200 $this->
addWhereIf(
'rc_minor = 0', isset( $show[
'!minor'] ) );
201 $this->
addWhereIf(
'rc_minor != 0', isset( $show[
'minor'] ) );
202 $this->
addWhereIf(
'rc_bot = 0', isset( $show[
'!bot'] ) );
203 $this->
addWhereIf(
'rc_bot != 0', isset( $show[
'bot'] ) );
204 if ( isset( $show[
'anon'] ) || isset( $show[
'!anon'] ) ) {
206 $this->
addJoinConds( [
'actor' => [
'JOIN',
'actor_id=rc_actor' ] ] );
208 'actor_user IS NULL', isset( $show[
'anon'] )
211 'actor_user IS NOT NULL', isset( $show[
'!anon'] )
214 $this->
addWhereIf(
'rc_patrolled = 0', isset( $show[
'!patrolled'] ) );
215 $this->
addWhereIf(
'rc_patrolled != 0', isset( $show[
'patrolled'] ) );
216 $this->
addWhereIf(
'page_is_redirect = 1', isset( $show[
'redirect'] ) );
218 if ( isset( $show[
'unpatrolled'] ) ) {
220 if ( $user->useRCPatrol() ) {
221 $this->
addWhere(
'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
222 } elseif ( $user->useNPPatrol() ) {
223 $this->
addWhere(
'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
229 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
230 isset( $show[
'!autopatrolled'] )
233 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
234 isset( $show[
'autopatrolled'] )
239 'page_is_redirect = 0 OR page_is_redirect IS NULL',
240 isset( $show[
'!redirect'] )
246 if ( $params[
'prop'] !==
null ) {
247 $prop = array_fill_keys( $params[
'prop'],
true );
255 || $params[
'user'] !==
null
256 || $params[
'excludeuser'] !==
null
259 $this->
addFields( [
'actor_name',
'actor_user',
'rc_actor' ] );
260 $this->
addJoinConds( [
'actor' => [
'JOIN',
'actor_id=rc_actor' ] ] );
263 if ( $params[
'user'] !==
null ) {
264 $this->
addWhereFld(
'actor_name', $params[
'user'] );
267 if ( $params[
'excludeuser'] !==
null ) {
268 $this->
addWhere(
'actor_name<>' . $this->
getDB()->addQuotes( $params[
'excludeuser'] ) );
282 $showRedirects =
false;
284 if ( $params[
'prop'] !==
null ) {
285 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
286 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
290 $this->
addFieldsIf( [
'rc_this_oldid',
'rc_last_oldid' ], $this->fld_ids );
291 $this->
addFieldsIf( [
'rc_minor',
'rc_type',
'rc_bot' ], $this->fld_flags );
292 $this->
addFieldsIf( [
'rc_old_len',
'rc_new_len' ], $this->fld_sizes );
293 $this->
addFieldsIf( [
'rc_patrolled',
'rc_log_type' ], $this->fld_patrolled );
295 [
'rc_logid',
'rc_log_type',
'rc_log_action',
'rc_params' ],
298 $showRedirects = $this->fld_redirect || isset( $show[
'redirect'] )
299 || isset( $show[
'!redirect'] );
302 $resultPageSet && $params[
'generaterevisions'] );
304 if ( $this->fld_tags ) {
308 if ( $this->fld_sha1 ) {
311 [
'rc_this_oldid=rev_id' ] ] ] );
312 $this->
addFields( [
'rev_sha1',
'rev_deleted' ] );
315 if ( $params[
'toponly'] || $showRedirects ) {
318 [
'rc_namespace=page_namespace',
'rc_title=page_title' ] ] ] );
321 if ( $params[
'toponly'] ) {
322 $this->
addWhere(
'rc_this_oldid = page_latest' );
326 if ( $params[
'tag'] !==
null ) {
328 $this->
addJoinConds( [
'change_tag' => [
'JOIN', [
'rc_id=ct_rc_id' ] ] ] );
330 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
338 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
339 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
340 $bitmask = RevisionRecord::DELETED_USER;
341 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
342 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
347 $this->
addWhere( $this->
getDB()->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask" );
350 if ( $this->
getRequest()->getCheck(
'namespace' ) ) {
352 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
353 $bitmask = LogPage::DELETED_ACTION;
354 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
355 $bitmask = LogPage::DELETED_ACTION | LogPage::DELETED_RESTRICTED;
362 $this->
getDB()->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask",
367 if ( $this->fld_comment || $this->fld_parsedcomment ) {
368 $commentQuery = $this->commentStore->getJoin(
'rc_comment' );
369 $this->
addTables( $commentQuery[
'tables'] );
370 $this->
addFields( $commentQuery[
'fields'] );
374 if ( $params[
'slot'] !==
null ) {
376 $slotId = $this->slotRoleStore->getId( $params[
'slot'] );
377 }
catch ( Exception $e ) {
382 'slot' =>
'slots',
'parent_slot' =>
'slots'
385 'slot' => [
'LEFT JOIN', [
386 'rc_this_oldid = slot.slot_revision_id',
387 'slot.slot_role_id' => $slotId,
389 'parent_slot' => [
'LEFT JOIN', [
390 'rc_last_oldid = parent_slot.slot_revision_id',
391 'parent_slot.slot_role_id' => $slotId,
401 'slot.slot_origin = slot.slot_revision_id OR ' .
402 'slot.slot_content_id != parent_slot.slot_content_id OR ' .
403 '(slot.slot_content_id IS NULL AND parent_slot.slot_content_id IS NOT NULL) OR ' .
404 '(slot.slot_content_id IS NOT NULL AND parent_slot.slot_content_id IS NULL)'
407 $changeTypes = RecentChange::parseToRCType(
408 array_intersect( $params[
'type'], [
'new',
'edit' ] )
410 if ( count( $changeTypes ) ) {
415 $this->
addWhere(
'rc_type IS NULL' );
419 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
421 'MAX_EXECUTION_TIME',
422 $this->
getConfig()->
get( MainConfigNames::MaxExecutionTimeForExpensiveQueries )
428 $res = $this->
select( __METHOD__, [], $hookData );
431 if ( $this->fld_title && $resultPageSet ===
null ) {
434 if ( $this->fld_parsedcomment ) {
435 $this->formattedComments = $this->commentFormatter->formatItems(
436 $this->commentFormatter->rows(
$res )
437 ->indexField(
'rc_id' )
438 ->commentKey(
'rc_comment' )
439 ->namespaceField(
'rc_namespace' )
440 ->titleField(
'rc_title' )
450 foreach (
$res as $row ) {
451 if ( $count === 0 && $resultPageSet !==
null ) {
455 $this,
'continue',
"$row->rc_timestamp|$row->rc_id"
458 if ( ++$count > $params[
'limit'] ) {
465 if ( $resultPageSet ===
null ) {
470 $fit = $this->
processRow( $row, $vals, $hookData ) &&
471 $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
476 } elseif ( $params[
'generaterevisions'] ) {
477 $revid = (int)$row->rc_this_oldid;
482 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
486 if ( $resultPageSet ===
null ) {
488 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'rc' );
489 } elseif ( $params[
'generaterevisions'] ) {
490 $resultPageSet->populateFromRevisionIDs( $revids );
492 $resultPageSet->populateFromTitles( $titles );
504 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
510 $type = (int)$row->rc_type;
511 $vals[
'type'] = RecentChange::parseFromRCType(
$type );
516 if ( $this->fld_title || $this->fld_ids ) {
517 if (
$type ===
RC_LOG && ( $row->rc_deleted & LogPage::DELETED_ACTION ) ) {
518 $vals[
'actionhidden'] =
true;
522 LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user )
524 if ( $this->fld_title ) {
527 if ( $this->fld_ids ) {
528 $vals[
'pageid'] = (int)$row->rc_cur_id;
529 $vals[
'revid'] = (int)$row->rc_this_oldid;
530 $vals[
'old_revid'] = (int)$row->rc_last_oldid;
535 if ( $this->fld_ids ) {
536 $vals[
'rcid'] = (int)$row->rc_id;
540 if ( $this->fld_user || $this->fld_userid ) {
541 if ( $row->rc_deleted & RevisionRecord::DELETED_USER ) {
542 $vals[
'userhidden'] =
true;
545 if ( RevisionRecord::userCanBitfield( $row->rc_deleted, RevisionRecord::DELETED_USER, $user ) ) {
546 if ( $this->fld_user ) {
547 $vals[
'user'] = $row->actor_name;
550 if ( $this->fld_userid ) {
551 $vals[
'userid'] = (int)$row->actor_user;
554 if ( !$row->actor_user ) {
555 $vals[
'anon'] =
true;
561 if ( $this->fld_flags ) {
562 $vals[
'bot'] = (bool)$row->rc_bot;
563 $vals[
'new'] = $row->rc_type ==
RC_NEW;
564 $vals[
'minor'] = (bool)$row->rc_minor;
568 if ( $this->fld_sizes ) {
569 $vals[
'oldlen'] = (int)$row->rc_old_len;
570 $vals[
'newlen'] = (int)$row->rc_new_len;
574 if ( $this->fld_timestamp ) {
575 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
579 if ( $this->fld_comment || $this->fld_parsedcomment ) {
580 if ( $row->rc_deleted & RevisionRecord::DELETED_COMMENT ) {
581 $vals[
'commenthidden'] =
true;
584 if ( RevisionRecord::userCanBitfield(
585 $row->rc_deleted, RevisionRecord::DELETED_COMMENT, $user
587 if ( $this->fld_comment ) {
588 $vals[
'comment'] = $this->commentStore->getComment(
'rc_comment', $row )->text;
591 if ( $this->fld_parsedcomment ) {
592 $vals[
'parsedcomment'] = $this->formattedComments[$row->rc_id];
597 if ( $this->fld_redirect ) {
598 $vals[
'redirect'] = (bool)$row->page_is_redirect;
602 if ( $this->fld_patrolled ) {
603 $vals[
'patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
604 $vals[
'unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
605 $vals[
'autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
608 if ( $this->fld_loginfo && $row->rc_type ==
RC_LOG ) {
609 if ( $row->rc_deleted & LogPage::DELETED_ACTION ) {
610 $vals[
'actionhidden'] =
true;
613 if ( LogEventsList::userCanBitfield( $row->rc_deleted, LogPage::DELETED_ACTION, $user ) ) {
614 $vals[
'logid'] = (int)$row->rc_logid;
615 $vals[
'logtype'] = $row->rc_log_type;
616 $vals[
'logaction'] = $row->rc_log_action;
617 $vals[
'logparams'] = LogFormatter::newFromRow( $row )->formatParametersForApi();
621 if ( $this->fld_tags ) {
622 if ( $row->ts_tags ) {
623 $tags = explode(
',', $row->ts_tags );
624 ApiResult::setIndexedTagName( $tags,
'tag' );
625 $vals[
'tags'] = $tags;
631 if ( $this->fld_sha1 && $row->rev_sha1 !==
null ) {
632 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
633 $vals[
'sha1hidden'] =
true;
636 if ( RevisionRecord::userCanBitfield(
637 $row->rev_deleted, RevisionRecord::DELETED_TEXT, $user
639 if ( $row->rev_sha1 !==
'' ) {
640 $vals[
'sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
647 if ( $anyHidden && ( $row->rc_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
648 $vals[
'suppressed'] =
true;
658 private function includesPatrollingFlags( array $flagsArray ) {
659 return isset( $flagsArray[
'patrolled'] ) ||
660 isset( $flagsArray[
'!patrolled'] ) ||
661 isset( $flagsArray[
'unpatrolled'] ) ||
662 isset( $flagsArray[
'autopatrolled'] ) ||
663 isset( $flagsArray[
'!autopatrolled'] );
667 if ( isset( $params[
'show'] ) &&
668 $this->includesPatrollingFlags( array_fill_keys( $params[
'show'],
true ) )
675 if ( $params[
'prop'] !==
null && in_array(
'parsedcomment', $params[
'prop'] ) ) {
677 return 'anon-public-user-private';
684 $slotRoles = $this->slotRoleRegistry->getKnownRoles();
685 sort( $slotRoles, SORT_STRING );
689 ParamValidator::PARAM_TYPE =>
'timestamp'
692 ParamValidator::PARAM_TYPE =>
'timestamp'
695 ParamValidator::PARAM_DEFAULT =>
'older',
696 ParamValidator::PARAM_TYPE => [
702 'newer' =>
'api-help-paramvalue-direction-newer',
703 'older' =>
'api-help-paramvalue-direction-older',
707 ParamValidator::PARAM_ISMULTI =>
true,
708 ParamValidator::PARAM_TYPE =>
'namespace',
712 ParamValidator::PARAM_TYPE =>
'user',
713 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
716 ParamValidator::PARAM_TYPE =>
'user',
717 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
721 ParamValidator::PARAM_ISMULTI =>
true,
722 ParamValidator::PARAM_DEFAULT =>
'title|timestamp|ids',
723 ParamValidator::PARAM_TYPE => [
742 ParamValidator::PARAM_ISMULTI =>
true,
743 ParamValidator::PARAM_TYPE => [
760 ParamValidator::PARAM_DEFAULT => 10,
761 ParamValidator::PARAM_TYPE =>
'limit',
762 IntegerDef::PARAM_MIN => 1,
767 ParamValidator::PARAM_DEFAULT =>
'edit|new|log|categorize',
768 ParamValidator::PARAM_ISMULTI =>
true,
769 ParamValidator::PARAM_TYPE => RecentChange::getChangeTypes()
776 'generaterevisions' =>
false,
778 ParamValidator::PARAM_TYPE => $slotRoles
785 'action=query&list=recentchanges'
786 =>
'apihelp-query+recentchanges-example-simple',
787 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
788 =>
'apihelp-query+recentchanges-example-generator',
793 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Recentchanges';
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.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
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)
Die if more than one of a certain set of parameters is 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.
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, RowCommentFormatter $commentFormatter, NameTableStore $changeTagDefStore, NameTableStore $slotRoleStore, SlotRoleRegistry $slotRoleRegistry)
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.
This is the main query class.
A class containing constants representing the names of configuration variables.