50 private $formattedComments = [];
70 parent::__construct( $query, $moduleName,
'rc' );
71 $this->commentStore = $commentStore;
72 $this->commentFormatter = $commentFormatter;
73 $this->changeTagDefStore = $changeTagDefStore;
74 $this->slotRoleStore = $slotRoleStore;
75 $this->slotRoleRegistry = $slotRoleRegistry;
88 $this->fld_comment = isset( $prop[
'comment'] );
89 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
90 $this->fld_user = isset( $prop[
'user'] );
91 $this->fld_userid = isset( $prop[
'userid'] );
92 $this->fld_flags = isset( $prop[
'flags'] );
93 $this->fld_timestamp = isset( $prop[
'timestamp'] );
94 $this->fld_title = isset( $prop[
'title'] );
95 $this->fld_ids = isset( $prop[
'ids'] );
96 $this->fld_sizes = isset( $prop[
'sizes'] );
97 $this->fld_redirect = isset( $prop[
'redirect'] );
98 $this->fld_patrolled = isset( $prop[
'patrolled'] );
99 $this->fld_loginfo = isset( $prop[
'loginfo'] );
100 $this->fld_tags = isset( $prop[
'tags'] );
101 $this->fld_sha1 = isset( $prop[
'sha1'] );
109 $this->
run( $resultPageSet );
117 public function run( $resultPageSet =
null ) {
129 if ( $params[
'continue'] !==
null ) {
131 $db = $this->
getDB();
132 $op = $params[
'dir'] ===
'older' ?
'<=' :
'>=';
133 $this->
addWhere( $db->buildComparison( $op, [
134 'rc_timestamp' => $db->timestamp( $cont[0] ),
139 $order = $params[
'dir'] ===
'older' ?
'DESC' :
'ASC';
141 "rc_timestamp $order",
145 if ( $params[
'type'] !==
null ) {
148 }
catch ( Exception $e ) {
153 $title = $params[
'title'];
154 if ( $title !==
null ) {
155 $titleObj = Title::newFromText( $title );
156 if ( $titleObj ===
null || $titleObj->isExternal() ) {
158 } elseif ( $params[
'namespace'] && !in_array( $titleObj->getNamespace(), $params[
'namespace'] ) ) {
161 $this->
addWhereFld(
'rc_namespace', $titleObj->getNamespace() );
162 $this->
addWhereFld(
'rc_title', $titleObj->getDBkey() );
164 $this->
addWhereFld(
'rc_namespace', $params[
'namespace'] );
167 if ( $params[
'show'] !==
null ) {
168 $show = array_fill_keys( $params[
'show'],
true );
171 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
172 || ( isset( $show[
'bot'] ) && isset( $show[
'!bot'] ) )
173 || ( isset( $show[
'anon'] ) && isset( $show[
'!anon'] ) )
174 || ( isset( $show[
'redirect'] ) && isset( $show[
'!redirect'] ) )
175 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
176 || ( isset( $show[
'patrolled'] ) && isset( $show[
'unpatrolled'] ) )
177 || ( isset( $show[
'!patrolled'] ) && isset( $show[
'unpatrolled'] ) )
178 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!autopatrolled'] ) )
179 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'unpatrolled'] ) )
180 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!patrolled'] ) )
186 if ( $this->includesPatrollingFlags( $show ) && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
187 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
191 $this->
addWhereIf( [
'rc_minor' => 0 ], isset( $show[
'!minor'] ) );
192 $this->
addWhereIf(
'rc_minor != 0', isset( $show[
'minor'] ) );
193 $this->
addWhereIf( [
'rc_bot' => 0 ], isset( $show[
'!bot'] ) );
194 $this->
addWhereIf(
'rc_bot != 0', isset( $show[
'bot'] ) );
195 if ( isset( $show[
'anon'] ) || isset( $show[
'!anon'] ) ) {
197 $this->
addJoinConds( [
'actor' => [
'JOIN',
'actor_id=rc_actor' ] ] );
199 [
'actor_user' =>
null ], isset( $show[
'anon'] )
202 'actor_user IS NOT NULL', isset( $show[
'!anon'] )
205 $this->
addWhereIf( [
'rc_patrolled' => 0 ], isset( $show[
'!patrolled'] ) );
206 $this->
addWhereIf(
'rc_patrolled != 0', isset( $show[
'patrolled'] ) );
207 $this->
addWhereIf( [
'page_is_redirect' => 1 ], isset( $show[
'redirect'] ) );
209 if ( isset( $show[
'unpatrolled'] ) ) {
211 if ( $user->useRCPatrol() ) {
213 } elseif ( $user->useNPPatrol() ) {
221 isset( $show[
'!autopatrolled'] )
225 isset( $show[
'autopatrolled'] )
230 [
'page_is_redirect' => [ 0,
null ] ],
231 isset( $show[
'!redirect'] )
237 if ( $params[
'prop'] !==
null ) {
238 $prop = array_fill_keys( $params[
'prop'],
true );
246 || $params[
'user'] !==
null
247 || $params[
'excludeuser'] !==
null
250 $this->
addFields( [
'actor_name',
'actor_user',
'rc_actor' ] );
251 $this->
addJoinConds( [
'actor' => [
'JOIN',
'actor_id=rc_actor' ] ] );
254 if ( $params[
'user'] !==
null ) {
255 $this->
addWhereFld(
'actor_name', $params[
'user'] );
258 if ( $params[
'excludeuser'] !==
null ) {
259 $this->
addWhere(
'actor_name<>' . $this->
getDB()->addQuotes( $params[
'excludeuser'] ) );
273 $showRedirects =
false;
275 if ( $params[
'prop'] !==
null ) {
276 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
277 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
281 $this->
addFieldsIf( [
'rc_this_oldid',
'rc_last_oldid' ], $this->fld_ids );
282 $this->
addFieldsIf( [
'rc_minor',
'rc_type',
'rc_bot' ], $this->fld_flags );
283 $this->
addFieldsIf( [
'rc_old_len',
'rc_new_len' ], $this->fld_sizes );
284 $this->
addFieldsIf( [
'rc_patrolled',
'rc_log_type' ], $this->fld_patrolled );
286 [
'rc_logid',
'rc_log_type',
'rc_log_action',
'rc_params' ],
289 $showRedirects = $this->fld_redirect || isset( $show[
'redirect'] )
290 || isset( $show[
'!redirect'] );
293 $resultPageSet && $params[
'generaterevisions'] );
295 if ( $this->fld_tags ) {
299 if ( $this->fld_sha1 ) {
302 [
'rc_this_oldid=rev_id' ] ] ] );
303 $this->
addFields( [
'rev_sha1',
'rev_deleted' ] );
306 if ( $params[
'toponly'] || $showRedirects ) {
309 [
'rc_namespace=page_namespace',
'rc_title=page_title' ] ] ] );
312 if ( $params[
'toponly'] ) {
313 $this->
addWhere(
'rc_this_oldid = page_latest' );
317 if ( $params[
'tag'] !==
null ) {
319 $this->
addJoinConds( [
'change_tag' => [
'JOIN', [
'rc_id=ct_rc_id' ] ] ] );
321 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
329 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
330 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
331 $bitmask = RevisionRecord::DELETED_USER;
332 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
333 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
338 $this->
addWhere( $this->
getDB()->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask" );
341 if ( $this->
getRequest()->getCheck(
'namespace' ) ) {
343 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
345 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
353 $this->
getDB()->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask",
358 if ( $this->fld_comment || $this->fld_parsedcomment ) {
359 $commentQuery = $this->commentStore->getJoin(
'rc_comment' );
360 $this->
addTables( $commentQuery[
'tables'] );
361 $this->
addFields( $commentQuery[
'fields'] );
365 if ( $params[
'slot'] !==
null ) {
367 $slotId = $this->slotRoleStore->getId( $params[
'slot'] );
368 }
catch ( Exception $e ) {
373 'slot' =>
'slots',
'parent_slot' =>
'slots'
376 'slot' => [
'LEFT JOIN', [
377 'rc_this_oldid = slot.slot_revision_id',
378 'slot.slot_role_id' => $slotId,
380 'parent_slot' => [
'LEFT JOIN', [
381 'rc_last_oldid = parent_slot.slot_revision_id',
382 'parent_slot.slot_role_id' => $slotId,
392 'slot.slot_origin = slot.slot_revision_id OR ' .
393 'slot.slot_content_id != parent_slot.slot_content_id OR ' .
394 '(slot.slot_content_id IS NULL AND parent_slot.slot_content_id IS NOT NULL) OR ' .
395 '(slot.slot_content_id IS NOT NULL AND parent_slot.slot_content_id IS NULL)'
399 array_intersect( $params[
'type'], [
'new',
'edit' ] )
401 if ( count( $changeTypes ) ) {
406 $this->
addWhere( [
'rc_type' =>
null ] );
410 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
412 'MAX_EXECUTION_TIME',
413 $this->
getConfig()->
get( MainConfigNames::MaxExecutionTimeForExpensiveQueries )
419 $res = $this->
select( __METHOD__, [], $hookData );
422 if ( $this->fld_title && $resultPageSet ===
null ) {
425 if ( $this->fld_parsedcomment ) {
426 $this->formattedComments = $this->commentFormatter->formatItems(
427 $this->commentFormatter->rows( $res )
428 ->indexField(
'rc_id' )
429 ->commentKey(
'rc_comment' )
430 ->namespaceField(
'rc_namespace' )
431 ->titleField(
'rc_title' )
441 foreach ( $res as $row ) {
442 if ( $count === 0 && $resultPageSet !==
null ) {
446 $this,
'continue',
"$row->rc_timestamp|$row->rc_id"
449 if ( ++$count > $params[
'limit'] ) {
456 if ( $resultPageSet ===
null ) {
461 $fit = $this->
processRow( $row, $vals, $hookData ) &&
462 $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
467 } elseif ( $params[
'generaterevisions'] ) {
468 $revid = (int)$row->rc_this_oldid;
473 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
477 if ( $resultPageSet ===
null ) {
479 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'rc' );
480 } elseif ( $params[
'generaterevisions'] ) {
481 $resultPageSet->populateFromRevisionIDs( $revids );
483 $resultPageSet->populateFromTitles( $titles );
495 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
501 $type = (int)$row->rc_type;
507 if ( $this->fld_title || $this->fld_ids ) {
509 $vals[
'actionhidden'] =
true;
515 if ( $this->fld_title ) {
518 if ( $this->fld_ids ) {
519 $vals[
'pageid'] = (int)$row->rc_cur_id;
520 $vals[
'revid'] = (
int)$row->rc_this_oldid;
521 $vals[
'old_revid'] = (int)$row->rc_last_oldid;
526 if ( $this->fld_ids ) {
527 $vals[
'rcid'] = (int)$row->rc_id;
531 if ( $this->fld_user || $this->fld_userid ) {
532 if ( $row->rc_deleted & RevisionRecord::DELETED_USER ) {
533 $vals[
'userhidden'] =
true;
536 if ( RevisionRecord::userCanBitfield( $row->rc_deleted, RevisionRecord::DELETED_USER, $user ) ) {
537 if ( $this->fld_user ) {
538 $vals[
'user'] = $row->actor_name;
541 if ( $this->fld_userid ) {
542 $vals[
'userid'] = (int)$row->actor_user;
545 if ( !$row->actor_user ) {
546 $vals[
'anon'] =
true;
552 if ( $this->fld_flags ) {
553 $vals[
'bot'] = (bool)$row->rc_bot;
554 $vals[
'new'] = $row->rc_type ==
RC_NEW;
555 $vals[
'minor'] = (
bool)$row->rc_minor;
559 if ( $this->fld_sizes ) {
560 $vals[
'oldlen'] = (int)$row->rc_old_len;
561 $vals[
'newlen'] = (
int)$row->rc_new_len;
565 if ( $this->fld_timestamp ) {
566 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
570 if ( $this->fld_comment || $this->fld_parsedcomment ) {
571 if ( $row->rc_deleted & RevisionRecord::DELETED_COMMENT ) {
572 $vals[
'commenthidden'] =
true;
575 if ( RevisionRecord::userCanBitfield(
576 $row->rc_deleted, RevisionRecord::DELETED_COMMENT, $user
578 if ( $this->fld_comment ) {
579 $vals[
'comment'] = $this->commentStore->getComment(
'rc_comment', $row )->text;
582 if ( $this->fld_parsedcomment ) {
583 $vals[
'parsedcomment'] = $this->formattedComments[$row->rc_id];
588 if ( $this->fld_redirect ) {
589 $vals[
'redirect'] = (bool)$row->page_is_redirect;
593 if ( $this->fld_patrolled ) {
599 if ( $this->fld_loginfo && $row->rc_type ==
RC_LOG ) {
601 $vals[
'actionhidden'] =
true;
605 $vals[
'logid'] = (int)$row->rc_logid;
606 $vals[
'logtype'] = $row->rc_log_type;
607 $vals[
'logaction'] = $row->rc_log_action;
612 if ( $this->fld_tags ) {
613 if ( $row->ts_tags ) {
614 $tags = explode(
',', $row->ts_tags );
616 $vals[
'tags'] = $tags;
622 if ( $this->fld_sha1 && $row->rev_sha1 !==
null ) {
623 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
624 $vals[
'sha1hidden'] =
true;
627 if ( RevisionRecord::userCanBitfield(
628 $row->rev_deleted, RevisionRecord::DELETED_TEXT, $user
630 if ( $row->rev_sha1 !==
'' ) {
631 $vals[
'sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
638 if ( $anyHidden && ( $row->rc_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
639 $vals[
'suppressed'] =
true;
649 private function includesPatrollingFlags( array $flagsArray ) {
650 return isset( $flagsArray[
'patrolled'] ) ||
651 isset( $flagsArray[
'!patrolled'] ) ||
652 isset( $flagsArray[
'unpatrolled'] ) ||
653 isset( $flagsArray[
'autopatrolled'] ) ||
654 isset( $flagsArray[
'!autopatrolled'] );
658 if ( isset( $params[
'show'] ) &&
659 $this->includesPatrollingFlags( array_fill_keys( $params[
'show'],
true ) )
666 if ( $params[
'prop'] !==
null && in_array(
'parsedcomment', $params[
'prop'] ) ) {
668 return 'anon-public-user-private';
675 $slotRoles = $this->slotRoleRegistry->getKnownRoles();
676 sort( $slotRoles, SORT_STRING );
680 ParamValidator::PARAM_TYPE =>
'timestamp'
683 ParamValidator::PARAM_TYPE =>
'timestamp'
686 ParamValidator::PARAM_DEFAULT =>
'older',
687 ParamValidator::PARAM_TYPE => [
693 'newer' =>
'api-help-paramvalue-direction-newer',
694 'older' =>
'api-help-paramvalue-direction-older',
698 ParamValidator::PARAM_ISMULTI =>
true,
699 ParamValidator::PARAM_TYPE =>
'namespace',
703 ParamValidator::PARAM_TYPE =>
'user',
704 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
707 ParamValidator::PARAM_TYPE =>
'user',
708 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
712 ParamValidator::PARAM_ISMULTI =>
true,
713 ParamValidator::PARAM_DEFAULT =>
'title|timestamp|ids',
714 ParamValidator::PARAM_TYPE => [
733 ParamValidator::PARAM_ISMULTI =>
true,
734 ParamValidator::PARAM_TYPE => [
751 ParamValidator::PARAM_DEFAULT => 10,
752 ParamValidator::PARAM_TYPE =>
'limit',
753 IntegerDef::PARAM_MIN => 1,
758 ParamValidator::PARAM_DEFAULT =>
'edit|new|log|categorize',
759 ParamValidator::PARAM_ISMULTI =>
true,
767 'generaterevisions' =>
false,
769 ParamValidator::PARAM_TYPE => $slotRoles
776 'action=query&list=recentchanges'
777 =>
'apihelp-query+recentchanges-example-simple',
778 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
779 =>
'apihelp-query+recentchanges-example-generator',
784 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,...
if(!defined('MW_SETUP_CALLBACK'))
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)
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.
__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.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static isUnpatrolled( $rc, User $user)
static userCanBitfield( $bitfield, $field, Authority $performer)
Determine if the current user is allowed to view a particular field of this log row,...
A class containing constants representing the names of configuration variables.
static parseToRCType( $type)
Parsing text to RC_* constants.
static getChangeTypes()
Get an array of all change types.
static parseFromRCType( $rcType)
Parsing RC_* constants to human-readable test.