summaryrefslogtreecommitdiff
path: root/includes/api/ApiQueryRecentChanges.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQueryRecentChanges.php')
-rw-r--r--includes/api/ApiQueryRecentChanges.php120
1 files changed, 90 insertions, 30 deletions
diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php
index 44093854..2b8c6a92 100644
--- a/includes/api/ApiQueryRecentChanges.php
+++ b/includes/api/ApiQueryRecentChanges.php
@@ -31,8 +31,8 @@ if (!defined('MEDIAWIKI')) {
/**
* A query action to enumerate the recent changes that were done to the wiki.
* Various filters are supported.
- *
- * @addtogroup API
+ *
+ * @ingroup API
*/
class ApiQueryRecentChanges extends ApiQueryBase {
@@ -43,26 +43,48 @@ class ApiQueryRecentChanges extends ApiQueryBase {
private $fld_comment = false, $fld_user = false, $fld_flags = false,
$fld_timestamp = false, $fld_title = false, $fld_ids = false,
$fld_sizes = false;
-
+
/**
* Generates and outputs the result of this query based upon the provided parameters.
*/
public function execute() {
/* Initialize vars */
- $limit = $prop = $namespace = $show = $type = $dir = $start = $end = null;
-
+ $limit = $prop = $namespace = $titles = $show = $type = $dir = $start = $end = null;
+
/* Get the parameters of the request. */
extract($this->extractRequestParams());
/* Build our basic query. Namely, something along the lines of:
- * SELECT * from recentchanges WHERE rc_timestamp > $start
- * AND rc_timestamp < $end AND rc_namespace = $namespace
+ * SELECT * FROM recentchanges WHERE rc_timestamp > $start
+ * AND rc_timestamp < $end AND rc_namespace = $namespace
* AND rc_deleted = '0'
*/
+ $db = $this->getDB();
$this->addTables('recentchanges');
+ $this->addOption('USE INDEX', array('recentchanges' => 'rc_timestamp'));
$this->addWhereRange('rc_timestamp', $dir, $start, $end);
$this->addWhereFld('rc_namespace', $namespace);
$this->addWhereFld('rc_deleted', 0);
+ if(!empty($titles))
+ {
+ $lb = new LinkBatch;
+ foreach($titles as $t)
+ {
+ $obj = Title::newFromText($t);
+ $lb->addObj($obj);
+ if($obj->getNamespace() < 0)
+ {
+ // LinkBatch refuses these, but we need them anyway
+ if(!array_key_exists($obj->getNamespace(), $lb->data))
+ $lb->data[$obj->getNamespace()] = array();
+ $lb->data[$obj->getNamespace()][$obj->getDbKey()] = 1;
+ }
+ }
+ $where = $lb->constructSet('rc', $this->getDb());
+ if($where != '')
+ $this->addWhere($where);
+ }
+
if(!is_null($type))
$this->addWhereFld('rc_type', $this->parseRCType($type));
@@ -70,12 +92,19 @@ class ApiQueryRecentChanges extends ApiQueryBase {
$show = array_flip($show);
/* Check for conflicting parameters. */
- if ((isset ($show['minor']) && isset ($show['!minor']))
- || (isset ($show['bot']) && isset ($show['!bot']))
- || (isset ($show['anon']) && isset ($show['!anon']))) {
-
+ if ((isset ($show['minor']) && isset ($show['!minor']))
+ || (isset ($show['bot']) && isset ($show['!bot']))
+ || (isset ($show['anon']) && isset ($show['!anon']))
+ || (isset ($show['redirect']) && isset ($show['!redirect']))
+ || (isset ($show['patrolled']) && isset ($show['!patrolled']))) {
+
$this->dieUsage("Incorrect parameter - mutually exclusive values may not be supplied", 'show');
}
+
+ // Check permissions
+ global $wgUser;
+ if((isset($show['patrolled']) || isset($show['!patrolled'])) && !$wgUser->isAllowed('patrol'))
+ $this->dieUsage("You need the patrol right to request the patrolled flag", 'permissiondenied');
/* Add additional conditions to query depending upon parameters. */
$this->addWhereIf('rc_minor = 0', isset ($show['!minor']));
@@ -84,6 +113,11 @@ class ApiQueryRecentChanges extends ApiQueryBase {
$this->addWhereIf('rc_bot != 0', isset ($show['bot']));
$this->addWhereIf('rc_user = 0', isset ($show['anon']));
$this->addWhereIf('rc_user != 0', isset ($show['!anon']));
+ $this->addWhereIf('rc_patrolled = 0', isset($show['!patrolled']));
+ $this->addWhereIf('rc_patrolled != 0', isset($show['patrolled']));
+ $this->addWhereIf('page_is_redirect = 1', isset ($show['redirect']));
+ // Don't throw log entries out the window here
+ $this->addWhereIf('page_is_redirect = 0 OR page_is_redirect IS NULL', isset ($show['!redirect']));
}
/* Add the fields we're concerned with to out query. */
@@ -108,13 +142,19 @@ class ApiQueryRecentChanges extends ApiQueryBase {
$this->fld_title = isset ($prop['title']);
$this->fld_ids = isset ($prop['ids']);
$this->fld_sizes = isset ($prop['sizes']);
+ $this->fld_redirect = isset($prop['redirect']);
+ $this->fld_patrolled = isset($prop['patrolled']);
+
+ global $wgUser;
+ if($this->fld_patrolled && !$wgUser->isAllowed('patrol'))
+ $this->dieUsage("You need the patrol right to request the patrolled flag", 'permissiondenied');
/* Add fields to our query if they are specified as a needed parameter. */
- $this->addFieldsIf('rc_id', $this->fld_ids);
- $this->addFieldsIf('rc_cur_id', $this->fld_ids);
- $this->addFieldsIf('rc_this_oldid', $this->fld_ids);
- $this->addFieldsIf('rc_last_oldid', $this->fld_ids);
- $this->addFieldsIf('rc_comment', $this->fld_comment);
+ $this->addFieldsIf('rc_id', $this->fld_ids);
+ $this->addFieldsIf('rc_cur_id', $this->fld_ids);
+ $this->addFieldsIf('rc_this_oldid', $this->fld_ids);
+ $this->addFieldsIf('rc_last_oldid', $this->fld_ids);
+ $this->addFieldsIf('rc_comment', $this->fld_comment);
$this->addFieldsIf('rc_user', $this->fld_user);
$this->addFieldsIf('rc_user_text', $this->fld_user);
$this->addFieldsIf('rc_minor', $this->fld_flags);
@@ -122,15 +162,18 @@ class ApiQueryRecentChanges extends ApiQueryBase {
$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('rc_patrolled', $this->fld_patrolled);
+ 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');
+ }
}
-
- /* Specify the limit for our query. It's $limit+1 because we (possibly) need to
+ /* Specify the limit for our query. It's $limit+1 because we (possibly) need to
* generate a "continue" parameter, to allow paging. */
$this->addOption('LIMIT', $limit +1);
- /* Specify the index to use in the query as rc_timestamp, instead of rc_revid (default). */
- $this->addOption('USE INDEX', 'rc_timestamp');
-
$data = array ();
$count = 0;
@@ -148,7 +191,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
/* Extract the data from a single row. */
$vals = $this->extractRowInfo($row);
-
+
/* Add that row's data to our final output. */
if($vals)
$data[] = $vals;
@@ -240,9 +283,17 @@ class ApiQueryRecentChanges extends ApiQueryBase {
$vals['comment'] = $row->rc_comment;
}
+ if ($this->fld_redirect)
+ if($row->page_is_redirect)
+ $vals['redirect'] = '';
+
+ /* Add the patrolled flag */
+ if ($this->fld_patrolled && $row->rc_patrolled == 1)
+ $vals['patrolled'] = '';
+
return $vals;
}
-
+
private function parseRCType($type)
{
if(is_array($type))
@@ -258,7 +309,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
case 'new': return RC_NEW;
case 'log': return RC_LOG;
}
- }
+ }
public function getAllowedParams() {
return array (
@@ -279,6 +330,9 @@ class ApiQueryRecentChanges extends ApiQueryBase {
ApiBase :: PARAM_ISMULTI => true,
ApiBase :: PARAM_TYPE => 'namespace'
),
+ 'titles' => array(
+ ApiBase :: PARAM_ISMULTI => true
+ ),
'prop' => array (
ApiBase :: PARAM_ISMULTI => true,
ApiBase :: PARAM_DFLT => 'title|timestamp|ids',
@@ -289,7 +343,9 @@ class ApiQueryRecentChanges extends ApiQueryBase {
'timestamp',
'title',
'ids',
- 'sizes'
+ 'sizes',
+ 'redirect',
+ 'patrolled'
)
),
'show' => array (
@@ -300,7 +356,11 @@ class ApiQueryRecentChanges extends ApiQueryBase {
'bot',
'!bot',
'anon',
- '!anon'
+ '!anon',
+ 'redirect',
+ '!redirect',
+ 'patrolled',
+ '!patrolled'
)
),
'limit' => array (
@@ -314,7 +374,7 @@ class ApiQueryRecentChanges extends ApiQueryBase {
ApiBase :: PARAM_ISMULTI => true,
ApiBase :: PARAM_TYPE => array (
'edit',
- 'new',
+ 'new',
'log'
)
)
@@ -327,13 +387,14 @@ class ApiQueryRecentChanges extends ApiQueryBase {
'end' => 'The timestamp to end enumerating.',
'dir' => 'In which direction to enumerate.',
'namespace' => 'Filter log entries to only this namespace(s)',
+ 'titles' => 'Filter log entries to only these page titles',
'prop' => 'Include additional pieces of information',
'show' => array (
'Show only items that meet this criteria.',
'For example, to see only minor edits done by logged-in users, set show=minor|!anon'
),
'type' => 'Which types of changes to show.',
- 'limit' => 'How many total pages to return.'
+ 'limit' => 'How many total changes to return.'
);
}
@@ -348,7 +409,6 @@ class ApiQueryRecentChanges extends ApiQueryBase {
}
public function getVersion() {
- return __CLASS__ . ': $Id: ApiQueryRecentChanges.php 30222 2008-01-28 19:05:26Z catrope $';
+ return __CLASS__ . ': $Id: ApiQueryRecentChanges.php 37909 2008-07-22 13:26:15Z catrope $';
}
}
-