36 parent::__construct(
$query, $moduleName,
'rc' );
57 if ( isset( $this->tokenFunctions ) ) {
67 $this->tokenFunctions = [
68 'patrol' => [
'ApiQueryRecentChanges',
'getPatrolToken' ]
70 Hooks::run(
'APIQueryRecentChangesTokens', [ &$this->tokenFunctions ] );
85 $validTokenUser =
false;
88 if ( (
$wgUser->useRCPatrol() && $rc->getAttribute(
'rc_type' ) ==
RC_EDIT ) ||
89 (
$wgUser->useNPPatrol() && $rc->getAttribute(
'rc_type' ) ==
RC_NEW )
91 $validTokenUser =
true;
94 $validTokenUser =
true;
97 if ( $validTokenUser ) {
99 static $cachedPatrolToken =
null;
101 if ( is_null( $cachedPatrolToken ) ) {
102 $cachedPatrolToken =
$wgUser->getEditToken(
'patrol' );
105 return $cachedPatrolToken;
116 $this->fld_comment = isset( $prop[
'comment'] );
117 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
118 $this->fld_user = isset( $prop[
'user'] );
119 $this->fld_userid = isset( $prop[
'userid'] );
120 $this->fld_flags = isset( $prop[
'flags'] );
121 $this->fld_timestamp = isset( $prop[
'timestamp'] );
122 $this->fld_title = isset( $prop[
'title'] );
123 $this->fld_ids = isset( $prop[
'ids'] );
124 $this->fld_sizes = isset( $prop[
'sizes'] );
125 $this->fld_redirect = isset( $prop[
'redirect'] );
126 $this->fld_patrolled = isset( $prop[
'patrolled'] );
127 $this->fld_loginfo = isset( $prop[
'loginfo'] );
128 $this->fld_tags = isset( $prop[
'tags'] );
129 $this->fld_sha1 = isset( $prop[
'sha1'] );
137 $this->
run( $resultPageSet );
145 public function run( $resultPageSet =
null ) {
157 if ( !is_null(
$params[
'continue'] ) ) {
158 $cont = explode(
'|',
$params[
'continue'] );
160 $db = $this->
getDB();
161 $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
162 $id = intval( $cont[1] );
164 $op =
$params[
'dir'] ===
'older' ?
'<' :
'>';
166 "rc_timestamp $op $timestamp OR " .
167 "(rc_timestamp = $timestamp AND " .
172 $order =
$params[
'dir'] ===
'older' ?
'DESC' :
'ASC';
174 "rc_timestamp $order",
180 if ( !is_null(
$params[
'type'] ) ) {
183 }
catch ( Exception
$e ) {
188 if ( !is_null(
$params[
'show'] ) ) {
189 $show = array_flip(
$params[
'show'] );
192 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
193 || ( isset( $show[
'bot'] ) && isset( $show[
'!bot'] ) )
194 || ( isset( $show[
'anon'] ) && isset( $show[
'!anon'] ) )
195 || ( isset( $show[
'redirect'] ) && isset( $show[
'!redirect'] ) )
196 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
197 || ( isset( $show[
'patrolled'] ) && isset( $show[
'unpatrolled'] ) )
198 || ( isset( $show[
'!patrolled'] ) && isset( $show[
'unpatrolled'] ) )
205 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
206 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
211 $this->
addWhereIf(
'rc_minor = 0', isset( $show[
'!minor'] ) );
212 $this->
addWhereIf(
'rc_minor != 0', isset( $show[
'minor'] ) );
213 $this->
addWhereIf(
'rc_bot = 0', isset( $show[
'!bot'] ) );
214 $this->
addWhereIf(
'rc_bot != 0', isset( $show[
'bot'] ) );
215 $this->
addWhereIf(
'rc_user = 0', isset( $show[
'anon'] ) );
216 $this->
addWhereIf(
'rc_user != 0', isset( $show[
'!anon'] ) );
217 $this->
addWhereIf(
'rc_patrolled = 0', isset( $show[
'!patrolled'] ) );
218 $this->
addWhereIf(
'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->
addWhere(
'rc_patrolled = 0' );
225 } elseif ( $user->useNPPatrol() ) {
226 $this->
addWhere(
'rc_patrolled = 0' );
233 'page_is_redirect = 0 OR page_is_redirect IS NULL',
234 isset( $show[
'!redirect'] )
240 if ( !is_null(
$params[
'user'] ) ) {
244 if ( !is_null(
$params[
'excludeuser'] ) ) {
262 $showRedirects =
false;
264 if ( !is_null(
$params[
'prop'] ) ) {
265 $prop = array_flip(
$params[
'prop'] );
270 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
271 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
275 $this->
addFieldsIf( [
'rc_this_oldid',
'rc_last_oldid' ], $this->fld_ids );
276 $this->
addFieldsIf(
'rc_user', $this->fld_user || $this->fld_userid );
277 $this->
addFieldsIf(
'rc_user_text', $this->fld_user );
278 $this->
addFieldsIf( [
'rc_minor',
'rc_type',
'rc_bot' ], $this->fld_flags );
279 $this->
addFieldsIf( [
'rc_old_len',
'rc_new_len' ], $this->fld_sizes );
280 $this->
addFieldsIf( [
'rc_patrolled',
'rc_log_type' ], $this->fld_patrolled );
282 [
'rc_logid',
'rc_log_type',
'rc_log_action',
'rc_params' ],
285 $showRedirects = $this->fld_redirect || isset( $show[
'redirect'] )
286 || isset( $show[
'!redirect'] );
289 $resultPageSet &&
$params[
'generaterevisions'] );
291 if ( $this->fld_tags ) {
293 $this->
addJoinConds( [
'tag_summary' => [
'LEFT JOIN', [
'rc_id=ts_rc_id' ] ] ] );
297 if ( $this->fld_sha1 ) {
300 [
'rc_this_oldid=rev_id' ] ] ] );
301 $this->
addFields( [
'rev_sha1',
'rev_deleted' ] );
304 if (
$params[
'toponly'] || $showRedirects ) {
307 [
'rc_namespace=page_namespace',
'rc_title=page_title' ] ] ] );
311 $this->
addWhere(
'rc_this_oldid = page_latest' );
315 if ( !is_null(
$params[
'tag'] ) ) {
317 $this->
addJoinConds( [
'change_tag' => [
'INNER JOIN', [
'rc_id=ct_rc_id' ] ] ] );
322 if ( !is_null(
$params[
'user'] ) || !is_null(
$params[
'excludeuser'] ) ) {
323 if ( !$user->isAllowed(
'deletedhistory' ) ) {
325 } elseif ( !$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
331 $this->
addWhere( $this->
getDB()->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask" );
334 if ( $this->
getRequest()->getCheck(
'namespace' ) ) {
336 if ( !$user->isAllowed(
'deletedhistory' ) ) {
338 } elseif ( !$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
346 $this->
getDB()->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask",
351 $this->token =
$params[
'token'];
353 if ( $this->fld_comment || $this->fld_parsedcomment || $this->token ) {
355 $commentQuery = $this->commentStore->getJoin();
356 $this->
addTables( $commentQuery[
'tables'] );
357 $this->
addFields( $commentQuery[
'fields'] );
366 $res = $this->
select( __METHOD__, [], $hookData );
374 foreach (
$res as $row ) {
375 if ( $count === 0 && $resultPageSet !==
null ) {
379 $this,
'continue',
"$row->rc_timestamp|$row->rc_id"
382 if ( ++$count >
$params[
'limit'] ) {
389 if ( is_null( $resultPageSet ) ) {
394 $fit = $this->
processRow( $row, $vals, $hookData ) &&
395 $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
400 } elseif (
$params[
'generaterevisions'] ) {
401 $revid = (int)$row->rc_this_oldid;
406 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
410 if ( is_null( $resultPageSet ) ) {
412 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'rc' );
413 } elseif (
$params[
'generaterevisions'] ) {
414 $resultPageSet->populateFromRevisionIDs( $revids );
416 $resultPageSet->populateFromTitles(
$titles );
429 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
435 $type = intval( $row->rc_type );
441 if ( $this->fld_title || $this->fld_ids ) {
443 $vals[
'actionhidden'] =
true;
449 if ( $this->fld_title ) {
452 if ( $this->fld_ids ) {
453 $vals[
'pageid'] = intval( $row->rc_cur_id );
454 $vals[
'revid'] = intval( $row->rc_this_oldid );
455 $vals[
'old_revid'] = intval( $row->rc_last_oldid );
460 if ( $this->fld_ids ) {
461 $vals[
'rcid'] = intval( $row->rc_id );
465 if ( $this->fld_user || $this->fld_userid ) {
467 $vals[
'userhidden'] =
true;
471 if ( $this->fld_user ) {
472 $vals[
'user'] = $row->rc_user_text;
475 if ( $this->fld_userid ) {
476 $vals[
'userid'] = (int)$row->rc_user;
479 if ( !$row->rc_user ) {
480 $vals[
'anon'] =
true;
486 if ( $this->fld_flags ) {
487 $vals[
'bot'] = (bool)$row->rc_bot;
488 $vals[
'new'] = $row->rc_type ==
RC_NEW;
489 $vals[
'minor'] = (bool)$row->rc_minor;
493 if ( $this->fld_sizes ) {
494 $vals[
'oldlen'] = intval( $row->rc_old_len );
495 $vals[
'newlen'] = intval( $row->rc_new_len );
499 if ( $this->fld_timestamp ) {
500 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
504 if ( $this->fld_comment || $this->fld_parsedcomment ) {
506 $vals[
'commenthidden'] =
true;
510 $comment = $this->commentStore->getComment( $row )->text;
511 if ( $this->fld_comment ) {
512 $vals[
'comment'] = $comment;
515 if ( $this->fld_parsedcomment ) {
521 if ( $this->fld_redirect ) {
522 $vals[
'redirect'] = (bool)$row->page_is_redirect;
526 if ( $this->fld_patrolled ) {
527 $vals[
'patrolled'] = $row->rc_patrolled == 1;
531 if ( $this->fld_loginfo && $row->rc_type ==
RC_LOG ) {
533 $vals[
'actionhidden'] =
true;
537 $vals[
'logid'] = intval( $row->rc_logid );
538 $vals[
'logtype'] = $row->rc_log_type;
539 $vals[
'logaction'] = $row->rc_log_action;
544 if ( $this->fld_tags ) {
545 if ( $row->ts_tags ) {
546 $tags = explode(
',', $row->ts_tags );
548 $vals[
'tags'] = $tags;
554 if ( $this->fld_sha1 && $row->rev_sha1 !==
null ) {
556 $vals[
'sha1hidden'] =
true;
560 if ( $row->rev_sha1 !==
'' ) {
561 $vals[
'sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
568 if ( !is_null( $this->token ) ) {
570 foreach ( $this->token as
$t ) {
573 if ( $val ===
false ) {
574 $this->
addWarning( [
'apiwarn-tokennotallowed', $t ] );
576 $vals[
$t .
'token'] = $val;
582 $vals[
'suppressed'] =
true;
593 return isset( $flagsArray[
'patrolled'] ) ||
594 isset( $flagsArray[
'!patrolled'] ) ||
595 isset( $flagsArray[
'unpatrolled'] ) ||
596 isset( $flagsArray[
'autopatrolled'] ) ||
597 isset( $flagsArray[
'!autopatrolled'] );
601 if ( isset(
$params[
'show'] ) &&
606 if ( isset(
$params[
'token'] ) ) {
612 if ( !is_null(
$params[
'prop'] ) && in_array(
'parsedcomment',
$params[
'prop'] ) ) {
614 return 'anon-public-user-private';
706 'generaterevisions' =>
false,
712 'action=query&list=recentchanges'
713 =>
'apihelp-query+recentchanges-example-simple',
714 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
715 =>
'apihelp-query+recentchanges-example-generator',
720 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Recentchanges';
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a and you may at your option offer warranty protection in exchange for a fee You may modify your copy or copies of the Program or any portion of thus forming a work based on the and copy and distribute such modifications or work under the terms of Section provided that you also meet all of these that in whole or in part contains or is derived from the Program or any part to be licensed as a whole at no charge to all third parties under the terms of this License c If the modified program normally reads commands interactively when run
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
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_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
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 PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
const LIMIT_BIG1
Fast query, standard limit.
getResult()
Get the result object.
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
const PARAM_EXTRA_NAMESPACES
(int[]) When PARAM_TYPE is 'namespace', include these as additional possible values.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
const LIMIT_BIG2
Fast query, apihighlimits limit.
getModuleName()
Get the name of the module being executed by this instance.
getContinuationManager()
Get the continuation manager.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
lacksSameOriginSecurity()
Returns true if the current request breaks the same-origin policy.
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)
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(array($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.
includesPatrollingFlags(array $flagsArray)
__construct(ApiQuery $query, $moduleName)
static getPatrolToken( $pageid, $title, $rc=null)
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.
getTokenFunctions()
Get an array mapping token names to their handler functions.
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)
getUser()
Get the User object.
getRequest()
Get the WebRequest object.
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...
static userCanBitfield( $bitfield, $field, User $user=null)
Determine if the current user is allowed to view a particular field of this log row,...
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.
static userCanBitfield( $bitfield, $field, User $user=null, Title $title=null)
Determine if the current user is allowed to view a particular field of this revision,...
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like select() and insert() are usually more convenient. They take care of things like table prefixes and escaping for you. If you really need to make your own SQL
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
returning false will NOT prevent logging $e
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles