36 parent::__construct(
$query, $moduleName,
'rc' );
57 if ( isset( $this->tokenFunctions ) ) {
67 $this->tokenFunctions = [
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;
93 } elseif ( $wgUser->useRCPatrol() || $wgUser->useNPPatrol() ) {
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 ) {
159 if ( !is_null(
$params[
'continue'] ) ) {
160 $cont = explode(
'|',
$params[
'continue'] );
162 $db = $this->
getDB();
163 $timestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
164 $id = intval( $cont[1] );
166 $op =
$params[
'dir'] ===
'older' ?
'<' :
'>';
168 "rc_timestamp $op $timestamp OR " .
169 "(rc_timestamp = $timestamp AND " .
174 $order =
$params[
'dir'] ===
'older' ?
'DESC' :
'ASC';
176 "rc_timestamp $order",
182 if ( !is_null(
$params[
'type'] ) ) {
185 }
catch ( Exception
$e ) {
191 if ( !is_null( $title ) ) {
192 $titleObj = Title::newFromText( $title );
193 if ( is_null( $titleObj ) ) {
196 $this->
addWhereFld(
'rc_namespace', $titleObj->getNamespace() );
197 $this->
addWhereFld(
'rc_title', $titleObj->getDBkey() );
200 if ( !is_null(
$params[
'show'] ) ) {
201 $show = array_flip(
$params[
'show'] );
204 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
205 || ( isset( $show[
'bot'] ) && isset( $show[
'!bot'] ) )
206 || ( isset( $show[
'anon'] ) && isset( $show[
'!anon'] ) )
207 || ( isset( $show[
'redirect'] ) && isset( $show[
'!redirect'] ) )
208 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
209 || ( isset( $show[
'patrolled'] ) && isset( $show[
'unpatrolled'] ) )
210 || ( isset( $show[
'!patrolled'] ) && isset( $show[
'unpatrolled'] ) )
211 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!autopatrolled'] ) )
212 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'unpatrolled'] ) )
213 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!patrolled'] ) )
220 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
221 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
226 $this->
addWhereIf(
'rc_minor = 0', isset( $show[
'!minor'] ) );
227 $this->
addWhereIf(
'rc_minor != 0', isset( $show[
'minor'] ) );
228 $this->
addWhereIf(
'rc_bot = 0', isset( $show[
'!bot'] ) );
229 $this->
addWhereIf(
'rc_bot != 0', isset( $show[
'bot'] ) );
230 if ( isset( $show[
'anon'] ) || isset( $show[
'!anon'] ) ) {
231 $actorMigration = ActorMigration::newMigration();
232 $actorQuery = $actorMigration->getJoin(
'rc_user' );
233 $this->
addTables( $actorQuery[
'tables'] );
236 $actorMigration->isAnon( $actorQuery[
'fields'][
'rc_user'] ), isset( $show[
'anon'] )
239 $actorMigration->isNotAnon( $actorQuery[
'fields'][
'rc_user'] ), isset( $show[
'!anon'] )
242 $this->
addWhereIf(
'rc_patrolled = 0', isset( $show[
'!patrolled'] ) );
243 $this->
addWhereIf(
'rc_patrolled != 0', isset( $show[
'patrolled'] ) );
244 $this->
addWhereIf(
'page_is_redirect = 1', isset( $show[
'redirect'] ) );
246 if ( isset( $show[
'unpatrolled'] ) ) {
248 if ( $user->useRCPatrol() ) {
249 $this->
addWhere(
'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
250 } elseif ( $user->useNPPatrol() ) {
251 $this->
addWhere(
'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED );
257 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
258 isset( $show[
'!autopatrolled'] )
261 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
262 isset( $show[
'autopatrolled'] )
267 'page_is_redirect = 0 OR page_is_redirect IS NULL',
268 isset( $show[
'!redirect'] )
274 if ( !is_null(
$params[
'user'] ) ) {
276 $actorQuery = ActorMigration::newMigration()
278 $this->
addTables( $actorQuery[
'tables'] );
280 $this->
addWhere( $actorQuery[
'conds'] );
283 if ( !is_null(
$params[
'excludeuser'] ) ) {
285 $actorQuery = ActorMigration::newMigration()
287 $this->
addTables( $actorQuery[
'tables'] );
289 $this->
addWhere(
'NOT(' . $actorQuery[
'conds'] .
')' );
303 $showRedirects =
false;
305 if ( !is_null(
$params[
'prop'] ) ) {
306 $prop = array_flip(
$params[
'prop'] );
311 if ( $this->fld_patrolled && !$user->useRCPatrol() && !$user->useNPPatrol() ) {
312 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
316 $this->
addFieldsIf( [
'rc_this_oldid',
'rc_last_oldid' ], $this->fld_ids );
317 if ( $this->fld_user || $this->fld_userid ) {
318 $actorQuery = ActorMigration::newMigration()->getJoin(
'rc_user' );
319 $this->
addTables( $actorQuery[
'tables'] );
320 $this->
addFields( $actorQuery[
'fields'] );
323 $this->
addFieldsIf( [
'rc_minor',
'rc_type',
'rc_bot' ], $this->fld_flags );
324 $this->
addFieldsIf( [
'rc_old_len',
'rc_new_len' ], $this->fld_sizes );
325 $this->
addFieldsIf( [
'rc_patrolled',
'rc_log_type' ], $this->fld_patrolled );
327 [
'rc_logid',
'rc_log_type',
'rc_log_action',
'rc_params' ],
330 $showRedirects = $this->fld_redirect || isset( $show[
'redirect'] )
331 || isset( $show[
'!redirect'] );
334 $resultPageSet &&
$params[
'generaterevisions'] );
336 if ( $this->fld_tags ) {
338 $this->
addJoinConds( [
'tag_summary' => [
'LEFT JOIN', [
'rc_id=ts_rc_id' ] ] ] );
342 if ( $this->fld_sha1 ) {
345 [
'rc_this_oldid=rev_id' ] ] ] );
346 $this->
addFields( [
'rev_sha1',
'rev_deleted' ] );
349 if (
$params[
'toponly'] || $showRedirects ) {
352 [
'rc_namespace=page_namespace',
'rc_title=page_title' ] ] ] );
356 $this->
addWhere(
'rc_this_oldid = page_latest' );
360 if ( !is_null(
$params[
'tag'] ) ) {
362 $this->
addJoinConds( [
'change_tag' => [
'INNER JOIN', [
'rc_id=ct_rc_id' ] ] ] );
364 $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
377 if ( !is_null(
$params[
'user'] ) || !is_null(
$params[
'excludeuser'] ) ) {
378 if ( !$user->isAllowed(
'deletedhistory' ) ) {
379 $bitmask = RevisionRecord::DELETED_USER;
380 } elseif ( !$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
381 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
386 $this->
addWhere( $this->
getDB()->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask" );
389 if ( $this->
getRequest()->getCheck(
'namespace' ) ) {
391 if ( !$user->isAllowed(
'deletedhistory' ) ) {
393 } elseif ( !$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
401 $this->
getDB()->bitAnd(
'rc_deleted', $bitmask ) .
" != $bitmask",
406 $this->token =
$params[
'token'];
408 if ( $this->fld_comment || $this->fld_parsedcomment || $this->token ) {
409 $this->commentStore = CommentStore::getStore();
410 $commentQuery = $this->commentStore->getJoin(
'rc_comment' );
411 $this->
addTables( $commentQuery[
'tables'] );
412 $this->
addFields( $commentQuery[
'fields'] );
421 $res = $this->
select( __METHOD__, [], $hookData );
429 foreach (
$res as $row ) {
430 if ( $count === 0 && $resultPageSet !==
null ) {
434 $this,
'continue',
"$row->rc_timestamp|$row->rc_id"
437 if ( ++$count >
$params[
'limit'] ) {
444 if ( is_null( $resultPageSet ) ) {
449 $fit = $this->
processRow( $row, $vals, $hookData ) &&
450 $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
455 } elseif (
$params[
'generaterevisions'] ) {
456 $revid = (int)$row->rc_this_oldid;
461 $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
465 if ( is_null( $resultPageSet ) ) {
467 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'rc' );
468 } elseif (
$params[
'generaterevisions'] ) {
469 $resultPageSet->populateFromRevisionIDs( $revids );
471 $resultPageSet->populateFromTitles(
$titles );
484 $title = Title::makeTitle( $row->rc_namespace, $row->rc_title );
490 $type = intval( $row->rc_type );
491 $vals[
'type'] = RecentChange::parseFromRCType(
$type );
496 if ( $this->fld_title || $this->fld_ids ) {
498 $vals[
'actionhidden'] =
true;
504 if ( $this->fld_title ) {
507 if ( $this->fld_ids ) {
508 $vals[
'pageid'] = intval( $row->rc_cur_id );
509 $vals[
'revid'] = intval( $row->rc_this_oldid );
510 $vals[
'old_revid'] = intval( $row->rc_last_oldid );
515 if ( $this->fld_ids ) {
516 $vals[
'rcid'] = intval( $row->rc_id );
520 if ( $this->fld_user || $this->fld_userid ) {
521 if ( $row->rc_deleted & RevisionRecord::DELETED_USER ) {
522 $vals[
'userhidden'] =
true;
525 if ( RevisionRecord::userCanBitfield( $row->rc_deleted, RevisionRecord::DELETED_USER, $user ) ) {
526 if ( $this->fld_user ) {
527 $vals[
'user'] = $row->rc_user_text;
530 if ( $this->fld_userid ) {
531 $vals[
'userid'] = (int)$row->rc_user;
534 if ( !$row->rc_user ) {
535 $vals[
'anon'] =
true;
541 if ( $this->fld_flags ) {
542 $vals[
'bot'] = (bool)$row->rc_bot;
543 $vals[
'new'] = $row->rc_type ==
RC_NEW;
544 $vals[
'minor'] = (bool)$row->rc_minor;
548 if ( $this->fld_sizes ) {
549 $vals[
'oldlen'] = intval( $row->rc_old_len );
550 $vals[
'newlen'] = intval( $row->rc_new_len );
554 if ( $this->fld_timestamp ) {
555 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rc_timestamp );
559 if ( $this->fld_comment || $this->fld_parsedcomment ) {
560 if ( $row->rc_deleted & RevisionRecord::DELETED_COMMENT ) {
561 $vals[
'commenthidden'] =
true;
564 if ( RevisionRecord::userCanBitfield(
565 $row->rc_deleted, RevisionRecord::DELETED_COMMENT, $user
567 $comment = $this->commentStore->getComment(
'rc_comment', $row )->text;
568 if ( $this->fld_comment ) {
569 $vals[
'comment'] = $comment;
572 if ( $this->fld_parsedcomment ) {
578 if ( $this->fld_redirect ) {
579 $vals[
'redirect'] = (bool)$row->page_is_redirect;
583 if ( $this->fld_patrolled ) {
584 $vals[
'patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
586 $vals[
'autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
589 if ( $this->fld_loginfo && $row->rc_type ==
RC_LOG ) {
591 $vals[
'actionhidden'] =
true;
595 $vals[
'logid'] = intval( $row->rc_logid );
596 $vals[
'logtype'] = $row->rc_log_type;
597 $vals[
'logaction'] = $row->rc_log_action;
602 if ( $this->fld_tags ) {
603 if ( $row->ts_tags ) {
604 $tags = explode(
',', $row->ts_tags );
606 $vals[
'tags'] = $tags;
612 if ( $this->fld_sha1 && $row->rev_sha1 !==
null ) {
613 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
614 $vals[
'sha1hidden'] =
true;
617 if ( RevisionRecord::userCanBitfield(
618 $row->rev_deleted, RevisionRecord::DELETED_TEXT, $user
620 if ( $row->rev_sha1 !==
'' ) {
621 $vals[
'sha1'] = Wikimedia\base_convert( $row->rev_sha1, 36, 16, 40 );
628 if ( !is_null( $this->token ) ) {
630 foreach ( $this->token as
$t ) {
632 $title, RecentChange::newFromRow( $row ) );
633 if ( $val ===
false ) {
634 $this->
addWarning( [
'apiwarn-tokennotallowed', $t ] );
636 $vals[
$t .
'token'] = $val;
641 if ( $anyHidden && ( $row->rc_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
642 $vals[
'suppressed'] =
true;
653 return isset( $flagsArray[
'patrolled'] ) ||
654 isset( $flagsArray[
'!patrolled'] ) ||
655 isset( $flagsArray[
'unpatrolled'] ) ||
656 isset( $flagsArray[
'autopatrolled'] ) ||
657 isset( $flagsArray[
'!autopatrolled'] );
661 if ( isset(
$params[
'show'] ) &&
666 if ( isset(
$params[
'token'] ) ) {
672 if ( !is_null(
$params[
'prop'] ) && in_array(
'parsedcomment',
$params[
'prop'] ) ) {
674 return 'anon-public-user-private';
769 'generaterevisions' =>
false,
775 'action=query&list=recentchanges'
776 =>
'apihelp-query+recentchanges-example-simple',
777 'action=query&generator=recentchanges&grcshow=!patrolled&prop=info'
778 =>
'apihelp-query+recentchanges-example-generator',
783 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
int $wgChangeTagsSchemaMigrationStage
change_tag table schema migration stage.
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,...
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.
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.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
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
const MIGRATION_WRITE_BOTH
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))