43 private $commentStore;
46 private $commentFormatter;
49 private $changeTagDefStore;
52 private $slotRoleStore;
55 private $slotRoleRegistry;
57 private $formattedComments = [];
77 parent::__construct( $query, $moduleName,
'rc' );
78 $this->commentStore = $commentStore;
79 $this->commentFormatter = $commentFormatter;
80 $this->changeTagDefStore = $changeTagDefStore;
81 $this->slotRoleStore = $slotRoleStore;
82 $this->slotRoleRegistry = $slotRoleRegistry;
85 private $fld_comment =
false, $fld_parsedcomment =
false, $fld_user =
false, $fld_userid =
false,
86 $fld_flags =
false, $fld_timestamp =
false, $fld_title =
false, $fld_ids =
false,
87 $fld_sizes =
false, $fld_redirect =
false, $fld_patrolled =
false, $fld_loginfo =
false,
88 $fld_tags =
false, $fld_sha1 =
false;
95 $this->fld_comment = isset( $prop[
'comment'] );
96 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
97 $this->fld_user = isset( $prop[
'user'] );
98 $this->fld_userid = isset( $prop[
'userid'] );
99 $this->fld_flags = isset( $prop[
'flags'] );
100 $this->fld_timestamp = isset( $prop[
'timestamp'] );
101 $this->fld_title = isset( $prop[
'title'] );
102 $this->fld_ids = isset( $prop[
'ids'] );
103 $this->fld_sizes = isset( $prop[
'sizes'] );
104 $this->fld_redirect = isset( $prop[
'redirect'] );
105 $this->fld_patrolled = isset( $prop[
'patrolled'] );
106 $this->fld_loginfo = isset( $prop[
'loginfo'] );
107 $this->fld_tags = isset( $prop[
'tags'] );
108 $this->fld_sha1 = isset( $prop[
'sha1'] );
116 $this->
run( $resultPageSet );
124 public function run( $resultPageSet =
null ) {
136 if ( $params[
'continue'] !==
null ) {
137 $cont = explode(
'|', $params[
'continue'] );
139 $db = $this->
getDB();
140 $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
143 $op = $params[
'dir'] ===
'older' ?
'<' :
'>';
145 "rc_timestamp $op $timestamp OR " .
146 "(rc_timestamp = $timestamp AND " .
151 $order = $params[
'dir'] ===
'older' ?
'DESC' :
'ASC';
153 "rc_timestamp $order",
157 $this->
addWhereFld(
'rc_namespace', $params[
'namespace'] );
159 if ( $params[
'type'] !==
null ) {
161 $this->
addWhereFld(
'rc_type', RecentChange::parseToRCType( $params[
'type'] ) );
162 }
catch ( Exception $e ) {
167 $title = $params[
'title'];
169 $titleObj = Title::newFromText(
$title );
170 if ( $titleObj ===
null || $titleObj->isExternal() ) {
173 $this->
addWhereFld(
'rc_namespace', $titleObj->getNamespace() );
174 $this->
addWhereFld(
'rc_title', $titleObj->getDBkey() );
177 if ( $params[
'show'] !==
null ) {
178 $show = array_fill_keys( $params[
'show'],
true );
181 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
182 || ( isset( $show[
'bot'] ) && isset( $show[
'!bot'] ) )
183 || ( isset( $show[
'anon'] ) && isset( $show[
'!anon'] ) )
184 || ( isset( $show[
'redirect'] ) && isset( $show[
'!redirect'] ) )
185 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
186 || ( isset( $show[
'patrolled'] ) && isset( $show[
'unpatrolled'] ) )
187 || ( isset( $show[
'!patrolled'] ) && isset( $show[
'unpatrolled'] ) )
188 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!autopatrolled'] ) )
189 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'unpatrolled'] ) )
190 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!patrolled'] ) )
196 if ( $this->includesPatrollingFlags( $show ) && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
197 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
201 $this->
addWhereIf(
'rc_minor = 0', isset( $show[
'!minor'] ) );
202 $this->
addWhereIf(
'rc_minor != 0', isset( $show[
'minor'] ) );
203 $this->
addWhereIf(
'rc_bot = 0', isset( $show[
'!bot'] ) );
204 $this->
addWhereIf(
'rc_bot != 0', isset( $show[
'bot'] ) );
205 if ( isset( $show[
'anon'] ) || isset( $show[
'!anon'] ) ) {
207 $this->
addJoinConds( [
'actor' => [
'JOIN',
'actor_id=rc_actor' ] ] );
209 'actor_user IS NULL', isset( $show[
'anon'] )
212 'actor_user IS NOT NULL', isset( $show[
'!anon'] )
215 $this->
addWhereIf(
'rc_patrolled = 0', isset( $show[
'!patrolled'] ) );
216 $this->
addWhereIf(
'rc_patrolled != 0', isset( $show[
'patrolled'] ) );
217 $this->
addWhereIf(
'page_is_redirect = 1', isset( $show[
'redirect'] ) );
219 if ( isset( $show[
'unpatrolled'] ) ) {
221 if ( $user->useRCPatrol() ) {
222 $this->
addWhere(
'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
223 } elseif ( $user->useNPPatrol() ) {
224 $this->
addWhere(
'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
230 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
231 isset( $show[
'!autopatrolled'] )
234 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
235 isset( $show[
'autopatrolled'] )
240 'page_is_redirect = 0 OR page_is_redirect IS NULL',
241 isset( $show[
'!redirect'] )
247 if ( $params[
'prop'] !==
null ) {
248 $prop = array_fill_keys( $params[
'prop'],
true );
256 || $params[
'user'] !==
null
257 || $params[
'excludeuser'] !==
null
260 $this->
addFields( [
'actor_name',
'actor_user',
'rc_actor' ] );
261 $this->
addJoinConds( [
'actor' => [
'JOIN',
'actor_id=rc_actor' ] ] );
264 if ( $params[
'user'] !==
null ) {
265 $this->
addWhereFld(
'actor_name', $params[
'user'] );
268 if ( $params[
'excludeuser'] !==
null ) {
269 $this->
addWhere(
'actor_name<>' . $this->
getDB()->addQuotes( $params[
'excludeuser'] ) );
283 $showRedirects =
false;
285 if ( $params[
'prop'] !==
null ) {
286 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
287 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
291 $this->
addFieldsIf( [
'rc_this_oldid',
'rc_last_oldid' ], $this->fld_ids );
292 $this->
addFieldsIf( [
'rc_minor',
'rc_type',
'rc_bot' ], $this->fld_flags );
293 $this->
addFieldsIf( [
'rc_old_len',
'rc_new_len' ], $this->fld_sizes );
294 $this->
addFieldsIf( [
'rc_patrolled',
'rc_log_type' ], $this->fld_patrolled );
296 [
'rc_logid',
'rc_log_type',
'rc_log_action',
'rc_params' ],
299 $showRedirects = $this->fld_redirect || isset( $show[
'redirect'] )
300 || isset( $show[
'!redirect'] );
303 $resultPageSet && $params[
'generaterevisions'] );
305 if ( $this->fld_tags ) {
309 if ( $this->fld_sha1 ) {
312 [
'rc_this_oldid=rev_id' ] ] ] );
313 $this->
addFields( [
'rev_sha1',
'rev_deleted' ] );
316 if ( $params[
'toponly'] || $showRedirects ) {
319 [
'rc_namespace=page_namespace',
'rc_title=page_title' ] ] ] );
322 if ( $params[
'toponly'] ) {
323 $this->
addWhere(
'rc_this_oldid = page_latest' );
327 if ( $params[
'tag'] !==
null ) {
329 $this->
addJoinConds( [
'change_tag' => [
'JOIN', [
'rc_id=ct_rc_id' ] ] ] );
331 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
339 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
340 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
341 $bitmask = RevisionRecord::DELETED_USER;
342 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
343 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
348 $this->
addWhere( $this->
getDB()->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask" );
351 if ( $this->
getRequest()->getCheck(
'namespace' ) ) {
353 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
355 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
363 $this->
getDB()->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask",
368 if ( $this->fld_comment || $this->fld_parsedcomment ) {
369 $commentQuery = $this->commentStore->getJoin(
'rc_comment' );
370 $this->
addTables( $commentQuery[
'tables'] );
371 $this->
addFields( $commentQuery[
'fields'] );
375 if ( $params[
'slot'] !==
null ) {
377 $slotId = $this->slotRoleStore->getId( $params[
'slot'] );
378 }
catch ( Exception $e ) {
383 'slot' =>
'slots',
'parent_slot' =>
'slots'
386 'slot' => [
'LEFT JOIN', [
387 'rc_this_oldid = slot.slot_revision_id',
388 'slot.slot_role_id' => $slotId,
390 'parent_slot' => [
'LEFT JOIN', [
391 'rc_last_oldid = parent_slot.slot_revision_id',
392 'parent_slot.slot_role_id' => $slotId,
402 'slot.slot_origin = slot.slot_revision_id OR ' .
403 'slot.slot_content_id != parent_slot.slot_content_id OR ' .
404 '(slot.slot_content_id IS NULL AND parent_slot.slot_content_id IS NOT NULL) OR ' .
405 '(slot.slot_content_id IS NOT NULL AND parent_slot.slot_content_id IS NULL)'
408 $changeTypes = RecentChange::parseToRCType(
409 array_intersect( $params[
'type'], [
'new',
'edit' ] )
411 if ( count( $changeTypes ) ) {
416 $this->
addWhere(
'rc_type IS NULL' );
420 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
422 'MAX_EXECUTION_TIME',
423 $this->
getConfig()->
get( MainConfigNames::MaxExecutionTimeForExpensiveQueries )
429 $res = $this->
select( __METHOD__, [], $hookData );
432 if ( $this->fld_title && $resultPageSet ===
null ) {
435 if ( $this->fld_parsedcomment ) {
436 $this->formattedComments = $this->commentFormatter->formatItems(
437 $this->commentFormatter->rows(
$res )
438 ->indexField(
'rc_id' )
439 ->commentKey(
'rc_comment' )
440 ->namespaceField(
'rc_namespace' )
441 ->titleField(
'rc_title' )
451 foreach (
$res as $row ) {
452 if ( $count === 0 && $resultPageSet !==
null ) {
456 $this,
'continue',
"$row->rc_timestamp|$row->rc_id"
459 if ( ++$count > $params[
'limit'] ) {
466 if ( $resultPageSet ===
null ) {
471 $fit = $this->
processRow( $row, $vals, $hookData ) &&
472 $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
477 } elseif ( $params[
'generaterevisions'] ) {
478 $revid = (int)$row->rc_this_oldid;
483 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
487 if ( $resultPageSet ===
null ) {
489 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'rc' );
490 } elseif ( $params[
'generaterevisions'] ) {
491 $resultPageSet->populateFromRevisionIDs( $revids );
493 $resultPageSet->populateFromTitles( $titles );
505 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
511 $type = (int)$row->rc_type;
512 $vals[
'type'] = RecentChange::parseFromRCType(
$type );
517 if ( $this->fld_title || $this->fld_ids ) {
519 $vals[
'actionhidden'] =
true;
525 if ( $this->fld_title ) {
528 if ( $this->fld_ids ) {
529 $vals[
'pageid'] = (int)$row->rc_cur_id;
530 $vals[
'revid'] = (int)$row->rc_this_oldid;
531 $vals[
'old_revid'] = (int)$row->rc_last_oldid;
536 if ( $this->fld_ids ) {
537 $vals[
'rcid'] = (int)$row->rc_id;
541 if ( $this->fld_user || $this->fld_userid ) {
542 if ( $row->rc_deleted & RevisionRecord::DELETED_USER ) {
543 $vals[
'userhidden'] =
true;
546 if ( RevisionRecord::userCanBitfield( $row->rc_deleted, RevisionRecord::DELETED_USER, $user ) ) {
547 if ( $this->fld_user ) {
548 $vals[
'user'] = $row->actor_name;
551 if ( $this->fld_userid ) {
552 $vals[
'userid'] = (int)$row->actor_user;
555 if ( !$row->actor_user ) {
556 $vals[
'anon'] =
true;
562 if ( $this->fld_flags ) {
563 $vals[
'bot'] = (bool)$row->rc_bot;
564 $vals[
'new'] = $row->rc_type ==
RC_NEW;
565 $vals[
'minor'] = (bool)$row->rc_minor;
569 if ( $this->fld_sizes ) {
570 $vals[
'oldlen'] = (int)$row->rc_old_len;
571 $vals[
'newlen'] = (int)$row->rc_new_len;
575 if ( $this->fld_timestamp ) {
576 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
580 if ( $this->fld_comment || $this->fld_parsedcomment ) {
581 if ( $row->rc_deleted & RevisionRecord::DELETED_COMMENT ) {
582 $vals[
'commenthidden'] =
true;
585 if ( RevisionRecord::userCanBitfield(
586 $row->rc_deleted, RevisionRecord::DELETED_COMMENT, $user
588 if ( $this->fld_comment ) {
589 $vals[
'comment'] = $this->commentStore->getComment(
'rc_comment', $row )->text;
592 if ( $this->fld_parsedcomment ) {
593 $vals[
'parsedcomment'] = $this->formattedComments[$row->rc_id];
598 if ( $this->fld_redirect ) {
599 $vals[
'redirect'] = (bool)$row->page_is_redirect;
603 if ( $this->fld_patrolled ) {
604 $vals[
'patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
605 $vals[
'unpatrolled'] = ChangesList::isUnpatrolled( $row, $user );
606 $vals[
'autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
609 if ( $this->fld_loginfo && $row->rc_type ==
RC_LOG ) {
611 $vals[
'actionhidden'] =
true;
615 $vals[
'logid'] = (int)$row->rc_logid;
616 $vals[
'logtype'] = $row->rc_log_type;
617 $vals[
'logaction'] = $row->rc_log_action;
618 $vals[
'logparams'] = LogFormatter::newFromRow( $row )->formatParametersForApi();
622 if ( $this->fld_tags ) {
623 if ( $row->ts_tags ) {
624 $tags = explode(
',', $row->ts_tags );
625 ApiResult::setIndexedTagName( $tags,
'tag' );
626 $vals[
'tags'] = $tags;
632 if ( $this->fld_sha1 && $row->rev_sha1 !==
null ) {
633 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
634 $vals[
'sha1hidden'] =
true;
637 if ( RevisionRecord::userCanBitfield(
638 $row->rev_deleted, RevisionRecord::DELETED_TEXT, $user
640 if ( $row->rev_sha1 !==
'' ) {
641 $vals[
'sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
648 if ( $anyHidden && ( $row->rc_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
649 $vals[
'suppressed'] =
true;
659 private function includesPatrollingFlags( array $flagsArray ) {
660 return isset( $flagsArray[
'patrolled'] ) ||
661 isset( $flagsArray[
'!patrolled'] ) ||
662 isset( $flagsArray[
'unpatrolled'] ) ||
663 isset( $flagsArray[
'autopatrolled'] ) ||
664 isset( $flagsArray[
'!autopatrolled'] );
668 if ( isset( $params[
'show'] ) &&
669 $this->includesPatrollingFlags( array_fill_keys( $params[
'show'],
true ) )
676 if ( $params[
'prop'] !==
null && in_array(
'parsedcomment', $params[
'prop'] ) ) {
678 return 'anon-public-user-private';
685 $slotRoles = $this->slotRoleRegistry->getKnownRoles();
686 sort( $slotRoles, SORT_STRING );
690 ParamValidator::PARAM_TYPE =>
'timestamp'
693 ParamValidator::PARAM_TYPE =>
'timestamp'
696 ParamValidator::PARAM_DEFAULT =>
'older',
697 ParamValidator::PARAM_TYPE => [
703 'newer' =>
'api-help-paramvalue-direction-newer',
704 'older' =>
'api-help-paramvalue-direction-older',
708 ParamValidator::PARAM_ISMULTI =>
true,
709 ParamValidator::PARAM_TYPE =>
'namespace',
713 ParamValidator::PARAM_TYPE =>
'user',
714 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
717 ParamValidator::PARAM_TYPE =>
'user',
718 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
722 ParamValidator::PARAM_ISMULTI =>
true,
723 ParamValidator::PARAM_DEFAULT =>
'title|timestamp|ids',
724 ParamValidator::PARAM_TYPE => [
743 ParamValidator::PARAM_ISMULTI =>
true,
744 ParamValidator::PARAM_TYPE => [
761 ParamValidator::PARAM_DEFAULT => 10,
762 ParamValidator::PARAM_TYPE =>
'limit',
763 IntegerDef::PARAM_MIN => 1,
768 ParamValidator::PARAM_DEFAULT =>
'edit|new|log|categorize',
769 ParamValidator::PARAM_ISMULTI =>
true,
770 ParamValidator::PARAM_TYPE => RecentChange::getChangeTypes()
777 'generaterevisions' =>
false,
779 ParamValidator::PARAM_TYPE => $slotRoles
786 'action=query&list=recentchanges'
787 =>
'apihelp-query+recentchanges-example-simple',
788 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
789 =>
'apihelp-query+recentchanges-example-generator',
794 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.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
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.
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.