<?php
/**
- * API for MediaWiki 1.8+
+ *
*
* Created on Oct 19, 2006
*
*
* @ingroup API
*/
-class ApiQueryRecentChanges extends ApiQueryBase {
+class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'rc' );
}
- private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_flags = false,
- $fld_timestamp = false, $fld_title = false, $fld_ids = false,
- $fld_sizes = false;
+ private $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
+ $fld_flags = false, $fld_timestamp = false, $fld_title = false, $fld_ids = false,
+ $fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false,
+ $fld_tags = false, $token = array();
+
+ private $tokenFunctions;
+
/**
* Get an array mapping token names to their handler functions.
* The prototype for a token function is func($pageid, $title, $rc)
return $this->tokenFunctions;
}
+ /**
+ * @static
+ * @param $pageid
+ * @param $title
+ * @param $rc RecentChange
+ * @return bool|String
+ */
public static function getPatrolToken( $pageid, $title, $rc ) {
global $wgUser;
if ( !$wgUser->useRCPatrol() && ( !$wgUser->useNPPatrol() ||
// The patrol token is always the same, let's exploit that
static $cachedPatrolToken = null;
- if ( !is_null( $cachedPatrolToken ) ) {
- return $cachedPatrolToken;
+ if ( is_null( $cachedPatrolToken ) ) {
+ $cachedPatrolToken = $wgUser->editToken( 'patrol' );
}
- $cachedPatrolToken = $wgUser->editToken();
return $cachedPatrolToken;
}
/**
* Sets internal state to include the desired properties in the output.
- * @param $prop associative array of properties, only keys are used here
+ * @param $prop Array associative array of properties, only keys are used here
*/
public function initProperties( $prop ) {
$this->fld_comment = isset( $prop['comment'] );
$this->fld_parsedcomment = isset( $prop['parsedcomment'] );
$this->fld_user = isset( $prop['user'] );
+ $this->fld_userid = isset( $prop['userid'] );
$this->fld_flags = isset( $prop['flags'] );
$this->fld_timestamp = isset( $prop['timestamp'] );
$this->fld_title = isset( $prop['title'] );
$this->fld_tags = isset( $prop['tags'] );
}
+ public function execute() {
+ $this->run();
+ }
+
+ public function executeGenerator( $resultPageSet ) {
+ $this->run( $resultPageSet );
+ }
+
/**
* Generates and outputs the result of this query based upon the provided parameters.
+ *
+ * @param $resultPageSet ApiPageSet
*/
- public function execute() {
+ public function run( $resultPageSet = null ) {
global $wgUser;
/* Get the parameters of the request. */
$params = $this->extractRequestParams();
'rc_cur_id',
'rc_type',
'rc_moved_to_ns',
- 'rc_moved_to_title'
+ 'rc_moved_to_title',
+ 'rc_deleted'
) );
/* Determine what properties we need to display. */
$this->addFieldsIf( 'rc_last_oldid', $this->fld_ids );
$this->addFieldsIf( 'rc_comment', $this->fld_comment || $this->fld_parsedcomment );
$this->addFieldsIf( 'rc_user', $this->fld_user );
- $this->addFieldsIf( 'rc_user_text', $this->fld_user );
+ $this->addFieldsIf( 'rc_user_text', $this->fld_user || $this->fld_userid );
$this->addFieldsIf( 'rc_minor', $this->fld_flags );
$this->addFieldsIf( 'rc_bot', $this->fld_flags );
$this->addFieldsIf( 'rc_new', $this->fld_flags );
/* Perform the actual query. */
$res = $this->select( __METHOD__ );
+ $titles = array();
+
/* Iterate through the rows, adding data extracted from them to our query result. */
foreach ( $res as $row ) {
if ( ++ $count > $params['limit'] ) {
break;
}
- /* Extract the data from a single row. */
- $vals = $this->extractRowInfo( $row );
+ if ( is_null( $resultPageSet ) ) {
+ /* Extract the data from a single row. */
+ $vals = $this->extractRowInfo( $row );
- /* Add that row's data to our final output. */
- if ( !$vals ) {
- continue;
- }
- $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $vals );
- if ( !$fit ) {
- $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) );
- break;
+ /* Add that row's data to our final output. */
+ if ( !$vals ) {
+ continue;
+ }
+ $fit = $this->getResult()->addValue( array( 'query', $this->getModuleName() ), null, $vals );
+ if ( !$fit ) {
+ $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->rc_timestamp ) );
+ break;
+ }
+ } else {
+ $titles[] = Title::makeTitle( $row->rc_namespace, $row->rc_title );
}
}
- /* Format the result */
- $this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'rc' );
+ if ( is_null( $resultPageSet ) ) {
+ /* Format the result */
+ $this->getResult()->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'rc' );
+ } else {
+ $resultPageSet->populateFromTitles( $titles );
+ }
}
/**
public function extractRowInfo( $row ) {
/* If page was moved somewhere, get the title of the move target. */
$movedToTitle = false;
- if ( isset( $row->rc_moved_to_title ) && $row->rc_moved_to_title !== '' )
- {
+ if ( isset( $row->rc_moved_to_title ) && $row->rc_moved_to_title !== '' ) {
$movedToTitle = Title::makeTitle( $row->rc_moved_to_ns, $row->rc_moved_to_title );
}
}
/* Add user data and 'anon' flag, if use is anonymous. */
- if ( $this->fld_user ) {
- $vals['user'] = $row->rc_user_text;
+ if ( $this->fld_user || $this->fld_userid ) {
+
+ if ( $this->fld_user ) {
+ $vals['user'] = $row->rc_user_text;
+ }
+
+ if ( $this->fld_userid ) {
+ $vals['userid'] = $row->rc_user;
+ }
+
if ( !$row->rc_user ) {
$vals['anon'] = '';
}
ApiBase::PARAM_DFLT => 'title|timestamp|ids',
ApiBase::PARAM_TYPE => array(
'user',
+ 'userid',
'comment',
'parsedcomment',
'flags',
}
public function getParamDescription() {
+ $p = $this->getModulePrefix();
return array(
'start' => 'The timestamp to start enumerating from',
'end' => 'The timestamp to end enumerating',
- 'dir' => 'In which direction to enumerate',
+ 'dir' => $this->getDirectionDescription( $p ),
'namespace' => 'Filter log entries to only this namespace(s)',
'user' => 'Only list changes by this user',
'excludeuser' => 'Don\'t list changes by this user',
'prop' => array(
'Include additional pieces of information',
' user - Adds the user responsible for the edit and tags if they are an IP',
+ ' userid - Adds the user id responsible for the edit',
' comment - Adds the comment for the edit',
' parsedcomment - Adds the parsed comment for the edit',
' flags - Adds flags for the edit',
' timestamp - Adds timestamp of the edit',
' title - Adds the page title of the edit',
- ' ids - Adds the page id, recent changes id and the new and old revision id',
+ ' ids - Adds the page ID, recent changes ID and the new and old revision ID',
' sizes - Adds the new and old page length in bytes',
' redirect - Tags edit if page is a redirect',
- ' patrolled - Tags edits have have been patrolled',
+ ' patrolled - Tags edits that have been patrolled',
' loginfo - Adds log information (logid, logtype, etc) to log entries',
' tags - Lists tags for the entry',
),
'token' => 'Which tokens to obtain for each change',
'show' => array(
'Show only items that meet this criteria.',
- "For example, to see only minor edits done by logged-in users, set {$this->getModulePrefix()}show=minor|!anon"
+ "For example, to see only minor edits done by logged-in users, set {$p}show=minor|!anon"
),
'type' => 'Which types of changes to show',
'limit' => 'How many total changes to return',