summaryrefslogtreecommitdiff
path: root/includes/api/ApiQueryRecentChanges.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2011-12-03 13:29:22 +0100
committerPierre Schmitz <pierre@archlinux.de>2011-12-03 13:29:22 +0100
commitca32f08966f1b51fcb19460f0996bb0c4048e6fe (patch)
treeec04cc15b867bc21eedca904cea9af0254531a11 /includes/api/ApiQueryRecentChanges.php
parenta22fbfc60f36f5f7ee10d5ae6fe347340c2ee67c (diff)
Update to MediaWiki 1.18.0
* also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing
Diffstat (limited to 'includes/api/ApiQueryRecentChanges.php')
-rw-r--r--includes/api/ApiQueryRecentChanges.php132
1 files changed, 84 insertions, 48 deletions
diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php
index fb0d42b8..b144a7cf 100644
--- a/includes/api/ApiQueryRecentChanges.php
+++ b/includes/api/ApiQueryRecentChanges.php
@@ -1,6 +1,6 @@
<?php
/**
- * API for MediaWiki 1.8+
+ *
*
* Created on Oct 19, 2006
*
@@ -35,7 +35,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
*
* @ingroup API
*/
-class ApiQueryRecentChanges extends ApiQueryBase {
+class ApiQueryRecentChanges extends ApiQueryGeneratorBase {
public function __construct( $query, $moduleName ) {
parent::__construct( $query, $moduleName, 'rc' );
@@ -43,7 +43,8 @@ class ApiQueryRecentChanges extends ApiQueryBase {
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;
+ $fld_sizes = false, $fld_redirect = false, $fld_patrolled = false, $fld_loginfo = false,
+ $fld_tags = false, $token = array();
private $tokenFunctions;
@@ -71,6 +72,12 @@ class ApiQueryRecentChanges extends ApiQueryBase {
return $this->tokenFunctions;
}
+ /**
+ * @param $pageid
+ * @param $title
+ * @param $rc RecentChange
+ * @return bool|String
+ */
public static function getPatrolToken( $pageid, $title, $rc ) {
global $wgUser;
if ( !$wgUser->useRCPatrol() && ( !$wgUser->useNPPatrol() ||
@@ -84,7 +91,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
if ( is_null( $cachedPatrolToken ) ) {
$cachedPatrolToken = $wgUser->editToken( 'patrol' );
}
-
+
return $cachedPatrolToken;
}
@@ -108,10 +115,20 @@ class ApiQueryRecentChanges extends ApiQueryBase {
$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();
@@ -123,7 +140,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
*/
$this->addTables( 'recentchanges' );
$index = array( 'recentchanges' => 'rc_timestamp' ); // May change
- $this->addWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] );
+ $this->addTimestampWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] );
$this->addWhereFld( 'rc_namespace', $params['namespace'] );
$this->addWhereFld( 'rc_deleted', 0 );
@@ -140,9 +157,8 @@ class ApiQueryRecentChanges extends ApiQueryBase {
|| ( isset( $show['anon'] ) && isset( $show['!anon'] ) )
|| ( isset( $show['redirect'] ) && isset( $show['!redirect'] ) )
|| ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) )
- )
- {
- $this->dieUsageMsg( array( 'show' ) );
+ ) {
+ $this->dieUsageMsg( 'show' );
}
// Check permissions
@@ -195,6 +211,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
'rc_deleted'
) );
+ $showRedirects = false;
/* Determine what properties we need to display. */
if ( !is_null( $params['prop'] ) ) {
$prop = array_flip( $params['prop'] );
@@ -207,27 +224,15 @@ class ApiQueryRecentChanges extends ApiQueryBase {
}
/* Add fields to our query if they are specified as a needed parameter. */
- $this->addFieldsIf( 'rc_id', $this->fld_ids );
- $this->addFieldsIf( 'rc_this_oldid', $this->fld_ids );
- $this->addFieldsIf( 'rc_last_oldid', $this->fld_ids );
+ $this->addFieldsIf( array( 'rc_id', 'rc_this_oldid', '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->fld_userid );
- $this->addFieldsIf( 'rc_minor', $this->fld_flags );
- $this->addFieldsIf( 'rc_bot', $this->fld_flags );
- $this->addFieldsIf( 'rc_new', $this->fld_flags );
- $this->addFieldsIf( 'rc_old_len', $this->fld_sizes );
- $this->addFieldsIf( 'rc_new_len', $this->fld_sizes );
+ $this->addFieldsIf( array( 'rc_minor', 'rc_new', 'rc_bot' ) , $this->fld_flags );
+ $this->addFieldsIf( array( 'rc_old_len', 'rc_new_len' ), $this->fld_sizes );
$this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
- $this->addFieldsIf( 'rc_logid', $this->fld_loginfo );
- $this->addFieldsIf( 'rc_log_type', $this->fld_loginfo );
- $this->addFieldsIf( 'rc_log_action', $this->fld_loginfo );
- $this->addFieldsIf( 'rc_params', $this->fld_loginfo );
- if ( $this->fld_redirect || isset( $show['redirect'] ) || isset( $show['!redirect'] ) ) {
- $this->addTables( 'page' );
- $this->addJoinConds( array( 'page' => array( 'LEFT JOIN', array( 'rc_namespace=page_namespace', 'rc_title=page_title' ) ) ) );
- $this->addFields( 'page_is_redirect' );
- }
+ $this->addFieldsIf( array( 'rc_logid', 'rc_log_type', 'rc_log_action', 'rc_params' ), $this->fld_loginfo );
+ $showRedirects = $this->fld_redirect || isset( $show['redirect'] ) || isset( $show['!redirect'] );
}
if ( $this->fld_tags ) {
@@ -236,6 +241,16 @@ class ApiQueryRecentChanges extends ApiQueryBase {
$this->addFields( 'ts_tags' );
}
+ if ( $params['toponly'] || $showRedirects ) {
+ $this->addTables( 'page' );
+ $this->addJoinConds( array( 'page' => array( 'LEFT JOIN', array( 'rc_namespace=page_namespace', 'rc_title=page_title' ) ) ) );
+ $this->addFields( 'page_is_redirect' );
+
+ if ( $params['toponly'] ) {
+ $this->addWhere( 'rc_this_oldid = page_latest' );
+ }
+ }
+
if ( !is_null( $params['tag'] ) ) {
$this->addTables( 'change_tag' );
$this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rc_id=ct_rc_id' ) ) ) );
@@ -252,6 +267,10 @@ class ApiQueryRecentChanges extends ApiQueryBase {
/* Perform the actual query. */
$res = $this->select( __METHOD__ );
+ $titles = array();
+
+ $result = $this->getResult();
+
/* Iterate through the rows, adding data extracted from them to our query result. */
foreach ( $res as $row ) {
if ( ++ $count > $params['limit'] ) {
@@ -260,22 +279,30 @@ class ApiQueryRecentChanges extends ApiQueryBase {
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 = $result->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 */
+ $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'rc' );
+ } else {
+ $resultPageSet->populateFromTitles( $titles );
+ }
}
/**
@@ -288,8 +315,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
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 );
}
@@ -405,8 +431,11 @@ class ApiQueryRecentChanges extends ApiQueryBase {
$vals['logaction'] = $row->rc_log_action;
ApiQueryLogEvents::addLogParams(
$this->getResult(),
- $vals, $row->rc_params,
- $row->rc_log_type, $row->rc_timestamp
+ $vals,
+ $row->rc_params,
+ $row->rc_log_action,
+ $row->rc_log_type,
+ $row->rc_timestamp
);
}
@@ -550,15 +579,17 @@ class ApiQueryRecentChanges extends ApiQueryBase {
'new',
'log'
)
- )
+ ),
+ 'toponly' => false,
);
}
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',
@@ -571,21 +602,22 @@ class ApiQueryRecentChanges extends ApiQueryBase {
' 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',
'tag' => 'Only list changes tagged with this tag',
+ 'toponly' => 'Only list changes which are the latest revision',
);
}
@@ -607,7 +639,11 @@ class ApiQueryRecentChanges extends ApiQueryBase {
);
}
+ public function getHelpUrls() {
+ return 'https://www.mediawiki.org/wiki/API:Recentchanges';
+ }
+
public function getVersion() {
- return __CLASS__ . ': $Id: ApiQueryRecentChanges.php 78437 2010-12-15 14:14:16Z catrope $';
+ return __CLASS__ . ': $Id: ApiQueryRecentChanges.php 104449 2011-11-28 15:52:04Z reedy $';
}
}