32 parent::__construct(
$query, $moduleName,
'rc' );
53 if ( isset( $this->tokenFunctions ) ) {
63 $this->tokenFunctions = [
66 Hooks::run(
'APIQueryRecentChangesTokens', [ &$this->tokenFunctions ] );
81 $validTokenUser =
false;
84 if ( (
$wgUser->useRCPatrol() && $rc->getAttribute(
'rc_type' ) ==
RC_EDIT ) ||
85 (
$wgUser->useNPPatrol() && $rc->getAttribute(
'rc_type' ) ==
RC_NEW )
87 $validTokenUser =
true;
90 $validTokenUser =
true;
93 if ( $validTokenUser ) {
95 static $cachedPatrolToken =
null;
97 if ( is_null( $cachedPatrolToken ) ) {
98 $cachedPatrolToken =
$wgUser->getEditToken(
'patrol' );
101 return $cachedPatrolToken;
112 $this->fld_comment = isset( $prop[
'comment'] );
113 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
114 $this->fld_user = isset( $prop[
'user'] );
115 $this->fld_userid = isset( $prop[
'userid'] );
116 $this->fld_flags = isset( $prop[
'flags'] );
117 $this->fld_timestamp = isset( $prop[
'timestamp'] );
118 $this->fld_title = isset( $prop[
'title'] );
119 $this->fld_ids = isset( $prop[
'ids'] );
120 $this->fld_sizes = isset( $prop[
'sizes'] );
121 $this->fld_redirect = isset( $prop[
'redirect'] );
122 $this->fld_patrolled = isset( $prop[
'patrolled'] );
123 $this->fld_loginfo = isset( $prop[
'loginfo'] );
124 $this->fld_tags = isset( $prop[
'tags'] );
125 $this->fld_sha1 = isset( $prop[
'sha1'] );
133 $this->
run( $resultPageSet );
141 public function run( $resultPageSet =
null ) {
153 if ( !is_null(
$params[
'continue'] ) ) {
154 $cont = explode(
'|',
$params[
'continue'] );
156 $db = $this->
getDB();
157 $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
158 $id = intval( $cont[1] );
160 $op =
$params[
'dir'] ===
'older' ?
'<' :
'>';
162 "rc_timestamp $op $timestamp OR " .
163 "(rc_timestamp = $timestamp AND " .
168 $order =
$params[
'dir'] ===
'older' ?
'DESC' :
'ASC';
170 "rc_timestamp $order",
176 if ( !is_null(
$params[
'type'] ) ) {
179 }
catch ( Exception
$e ) {
184 if ( !is_null(
$params[
'show'] ) ) {
185 $show = array_flip(
$params[
'show'] );
188 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
189 || ( isset( $show[
'bot'] ) && isset( $show[
'!bot'] ) )
190 || ( isset( $show[
'anon'] ) && isset( $show[
'!anon'] ) )
191 || ( isset( $show[
'redirect'] ) && isset( $show[
'!redirect'] ) )
192 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
193 || ( isset( $show[
'patrolled'] ) && isset( $show[
'unpatrolled'] ) )
194 || ( isset( $show[
'!patrolled'] ) && isset( $show[
'unpatrolled'] ) )
195 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!autopatrolled'] ) )
196 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'unpatrolled'] ) )
197 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!patrolled'] ) )
204 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
205 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
210 $this->
addWhereIf(
'rc_minor = 0', isset( $show[
'!minor'] ) );
211 $this->
addWhereIf(
'rc_minor != 0', isset( $show[
'minor'] ) );
212 $this->
addWhereIf(
'rc_bot = 0', isset( $show[
'!bot'] ) );
213 $this->
addWhereIf(
'rc_bot != 0', isset( $show[
'bot'] ) );
214 if ( isset( $show[
'anon'] ) || isset( $show[
'!anon'] ) ) {
215 $actorMigration = ActorMigration::newMigration();
216 $actorQuery = $actorMigration->getJoin(
'rc_user' );
217 $this->
addTables( $actorQuery[
'tables'] );
220 $actorMigration->isAnon( $actorQuery[
'fields'][
'rc_user'] ), isset( $show[
'anon'] )
223 $actorMigration->isNotAnon( $actorQuery[
'fields'][
'rc_user'] ), isset( $show[
'!anon'] )
226 $this->
addWhereIf(
'rc_patrolled = 0', isset( $show[
'!patrolled'] ) );
227 $this->
addWhereIf(
'rc_patrolled != 0', isset( $show[
'patrolled'] ) );
228 $this->
addWhereIf(
'page_is_redirect = 1', isset( $show[
'redirect'] ) );
230 if ( isset( $show[
'unpatrolled'] ) ) {
232 if ( $user->useRCPatrol() ) {
233 $this->
addWhere(
'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
234 } elseif ( $user->useNPPatrol() ) {
235 $this->
addWhere(
'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
241 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
242 isset( $show[
'!autopatrolled'] )
245 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
246 isset( $show[
'autopatrolled'] )
251 'page_is_redirect = 0 OR page_is_redirect IS NULL',
252 isset( $show[
'!redirect'] )
258 if ( !is_null(
$params[
'user'] ) ) {
260 $actorQuery = ActorMigration::newMigration()
262 $this->
addTables( $actorQuery[
'tables'] );
264 $this->
addWhere( $actorQuery[
'conds'] );
267 if ( !is_null(
$params[
'excludeuser'] ) ) {
269 $actorQuery = ActorMigration::newMigration()
271 $this->
addTables( $actorQuery[
'tables'] );
273 $this->
addWhere(
'NOT(' . $actorQuery[
'conds'] .
')' );
287 $showRedirects =
false;
289 if ( !is_null(
$params[
'prop'] ) ) {
290 $prop = array_flip(
$params[
'prop'] );
295 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
296 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
300 $this->
addFieldsIf( [
'rc_this_oldid',
'rc_last_oldid' ], $this->fld_ids );
301 if ( $this->fld_user || $this->fld_userid ) {
302 $actorQuery = ActorMigration::newMigration()->getJoin(
'rc_user' );
303 $this->
addTables( $actorQuery[
'tables'] );
304 $this->
addFields( $actorQuery[
'fields'] );
307 $this->
addFieldsIf( [
'rc_minor',
'rc_type',
'rc_bot' ], $this->fld_flags );
308 $this->
addFieldsIf( [
'rc_old_len',
'rc_new_len' ], $this->fld_sizes );
309 $this->
addFieldsIf( [
'rc_patrolled',
'rc_log_type' ], $this->fld_patrolled );
311 [
'rc_logid',
'rc_log_type',
'rc_log_action',
'rc_params' ],
314 $showRedirects = $this->fld_redirect || isset( $show[
'redirect'] )
315 || isset( $show[
'!redirect'] );
318 $resultPageSet &&
$params[
'generaterevisions'] );
320 if ( $this->fld_tags ) {
322 $this->
addJoinConds( [
'tag_summary' => [
'LEFT JOIN', [
'rc_id=ts_rc_id' ] ] ] );
326 if ( $this->fld_sha1 ) {
329 [
'rc_this_oldid=rev_id' ] ] ] );
330 $this->
addFields( [
'rev_sha1',
'rev_deleted' ] );
333 if (
$params[
'toponly'] || $showRedirects ) {
336 [
'rc_namespace=page_namespace',
'rc_title=page_title' ] ] ] );
340 $this->
addWhere(
'rc_this_oldid = page_latest' );
344 if ( !is_null(
$params[
'tag'] ) ) {
346 $this->
addJoinConds( [
'change_tag' => [
'INNER JOIN', [
'rc_id=ct_rc_id' ] ] ] );
351 if ( !is_null(
$params[
'user'] ) || !is_null(
$params[
'excludeuser'] ) ) {
352 if ( !$user->isAllowed(
'deletedhistory' ) ) {
353 $bitmask = Revision::DELETED_USER;
354 } elseif ( !$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
355 $bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
360 $this->
addWhere( $this->
getDB()->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask" );
363 if ( $this->
getRequest()->getCheck(
'namespace' ) ) {
365 if ( !$user->isAllowed(
'deletedhistory' ) ) {
367 } elseif ( !$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
375 $this->
getDB()->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask",
380 $this->token =
$params[
'token'];
382 if ( $this->fld_comment || $this->fld_parsedcomment || $this->token ) {
383 $this->commentStore = CommentStore::getStore();
384 $commentQuery = $this->commentStore->getJoin(
'rc_comment' );
385 $this->
addTables( $commentQuery[
'tables'] );
386 $this->
addFields( $commentQuery[
'fields'] );
395 $res = $this->
select( __METHOD__, [], $hookData );
403 foreach (
$res as $row ) {
404 if ( $count === 0 && $resultPageSet !==
null ) {
408 $this,
'continue',
"$row->rc_timestamp|$row->rc_id"
411 if ( ++$count >
$params[
'limit'] ) {
418 if ( is_null( $resultPageSet ) ) {
423 $fit = $this->
processRow( $row, $vals, $hookData ) &&
424 $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
429 } elseif (
$params[
'generaterevisions'] ) {
430 $revid = (int)$row->rc_this_oldid;
435 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
439 if ( is_null( $resultPageSet ) ) {
441 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'rc' );
442 } elseif (
$params[
'generaterevisions'] ) {
443 $resultPageSet->populateFromRevisionIDs( $revids );
445 $resultPageSet->populateFromTitles(
$titles );
458 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
464 $type = intval( $row->rc_type );
465 $vals[
'type'] = RecentChange::parseFromRCType(
$type );
470 if ( $this->fld_title || $this->fld_ids ) {
472 $vals[
'actionhidden'] =
true;
478 if ( $this->fld_title ) {
481 if ( $this->fld_ids ) {
482 $vals[
'pageid'] = intval( $row->rc_cur_id );
483 $vals[
'revid'] = intval( $row->rc_this_oldid );
484 $vals[
'old_revid'] = intval( $row->rc_last_oldid );
489 if ( $this->fld_ids ) {
490 $vals[
'rcid'] = intval( $row->rc_id );
494 if ( $this->fld_user || $this->fld_userid ) {
495 if ( $row->rc_deleted & Revision::DELETED_USER ) {
496 $vals[
'userhidden'] =
true;
499 if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_USER, $user ) ) {
500 if ( $this->fld_user ) {
501 $vals[
'user'] = $row->rc_user_text;
504 if ( $this->fld_userid ) {
505 $vals[
'userid'] = (int)$row->rc_user;
508 if ( !$row->rc_user ) {
509 $vals[
'anon'] =
true;
515 if ( $this->fld_flags ) {
516 $vals[
'bot'] = (bool)$row->rc_bot;
517 $vals[
'new'] = $row->rc_type ==
RC_NEW;
518 $vals[
'minor'] = (bool)$row->rc_minor;
522 if ( $this->fld_sizes ) {
523 $vals[
'oldlen'] = intval( $row->rc_old_len );
524 $vals[
'newlen'] = intval( $row->rc_new_len );
528 if ( $this->fld_timestamp ) {
529 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
533 if ( $this->fld_comment || $this->fld_parsedcomment ) {
534 if ( $row->rc_deleted & Revision::DELETED_COMMENT ) {
535 $vals[
'commenthidden'] =
true;
538 if ( Revision::userCanBitfield( $row->rc_deleted, Revision::DELETED_COMMENT, $user ) ) {
539 $comment = $this->commentStore->getComment(
'rc_comment', $row )->text;
540 if ( $this->fld_comment ) {
541 $vals[
'comment'] = $comment;
544 if ( $this->fld_parsedcomment ) {
550 if ( $this->fld_redirect ) {
551 $vals[
'redirect'] = (bool)$row->page_is_redirect;
555 if ( $this->fld_patrolled ) {
556 $vals[
'patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
558 $vals[
'autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
561 if ( $this->fld_loginfo && $row->rc_type ==
RC_LOG ) {
563 $vals[
'actionhidden'] =
true;
567 $vals[
'logid'] = intval( $row->rc_logid );
568 $vals[
'logtype'] = $row->rc_log_type;
569 $vals[
'logaction'] = $row->rc_log_action;
574 if ( $this->fld_tags ) {
575 if ( $row->ts_tags ) {
576 $tags = explode(
',', $row->ts_tags );
578 $vals[
'tags'] = $tags;
584 if ( $this->fld_sha1 && $row->rev_sha1 !==
null ) {
585 if ( $row->rev_deleted & Revision::DELETED_TEXT ) {
586 $vals[
'sha1hidden'] =
true;
589 if ( Revision::userCanBitfield( $row->rev_deleted, Revision::DELETED_TEXT, $user ) ) {
590 if ( $row->rev_sha1 !==
'' ) {
591 $vals[
'sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
598 if ( !is_null( $this->token ) ) {
600 foreach ( $this->token as
$t ) {
602 $title, RecentChange::newFromRow( $row ) );
603 if ( $val ===
false ) {
604 $this->
addWarning( [
'apiwarn-tokennotallowed', $t ] );
606 $vals[
$t .
'token'] = $val;
611 if ( $anyHidden && ( $row->rc_deleted & Revision::DELETED_RESTRICTED ) ) {
612 $vals[
'suppressed'] =
true;
623 return isset( $flagsArray[
'patrolled'] ) ||
624 isset( $flagsArray[
'!patrolled'] ) ||
625 isset( $flagsArray[
'unpatrolled'] ) ||
626 isset( $flagsArray[
'autopatrolled'] ) ||
627 isset( $flagsArray[
'!autopatrolled'] );
631 if ( isset(
$params[
'show'] ) &&
636 if ( isset(
$params[
'token'] ) ) {
642 if ( !is_null(
$params[
'prop'] ) && in_array(
'parsedcomment',
$params[
'prop'] ) ) {
644 return 'anon-public-user-private';
738 'generaterevisions' =>
false,
744 'action=query&list=recentchanges'
745 =>
'apihelp-query+recentchanges-example-simple',
746 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
747 =>
'apihelp-query+recentchanges-example-generator',
752 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)
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 newFromName( $name, $validate='valid')
Static factory method for creation from username.
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
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class