summaryrefslogtreecommitdiff
path: root/includes/api/ApiQueryUserContributions.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiQueryUserContributions.php')
-rw-r--r--includes/api/ApiQueryUserContributions.php101
1 files changed, 76 insertions, 25 deletions
diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php
index be6c8bc4..24c73996 100644
--- a/includes/api/ApiQueryUserContributions.php
+++ b/includes/api/ApiQueryUserContributions.php
@@ -41,7 +41,8 @@ class ApiQueryContributions extends ApiQueryBase {
private $params, $username;
private $fld_ids = false, $fld_title = false, $fld_timestamp = false,
- $fld_comment = false, $fld_flags = false;
+ $fld_comment = false, $fld_flags = false,
+ $fld_patrolled = false;
public function execute() {
@@ -54,6 +55,7 @@ class ApiQueryContributions extends ApiQueryBase {
$this->fld_comment = isset($prop['comment']);
$this->fld_flags = isset($prop['flags']);
$this->fld_timestamp = isset($prop['timestamp']);
+ $this->fld_patrolled = isset($prop['patrolled']);
// TODO: if the query is going only against the revision table, should this be done?
$this->selectNamedDB('contributions', DB_SLAVE, 'contributions');
@@ -81,7 +83,6 @@ class ApiQueryContributions extends ApiQueryBase {
$res = $this->select( __METHOD__ );
//Initialise some variables
- $data = array ();
$count = 0;
$limit = $this->params['limit'];
@@ -97,16 +98,21 @@ class ApiQueryContributions extends ApiQueryBase {
}
$vals = $this->extractRowInfo($row);
- if ($vals)
- $data[] = $vals;
+ $fit = $this->getResult()->addValue(array('query', $this->getModuleName()), null, $vals);
+ if(!$fit)
+ {
+ if($this->multiUserMode)
+ $this->setContinueEnumParameter('continue', $this->continueStr($row));
+ else
+ $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->rev_timestamp));
+ break;
+ }
}
//Free the database record so the connection can get on with other stuff
$db->freeResult($res);
- //And send the whole shebang out as output.
- $this->getResult()->setIndexedTagName($data, 'item');
- $this->getResult()->addValue('query', $this->getModuleName(), $data);
+ $this->getResult()->setIndexedTagName_internal(array('query', $this->getModuleName()), 'item');
}
/**
@@ -132,12 +138,12 @@ class ApiQueryContributions extends ApiQueryBase {
* Prepares the query and returns the limit of rows requested
*/
private function prepareQuery() {
-
- //We're after the revision table, and the corresponding page row for
- //anything we retrieve.
- $this->addTables(array('revision', 'page'));
+ // We're after the revision table, and the corresponding page
+ // row for anything we retrieve. We may also need the
+ // recentchanges row.
+ $tables = array('page', 'revision'); // Order may change
$this->addWhere('page_id=rev_page');
-
+
// Handle continue parameter
if($this->multiUserMode && !is_null($this->params['continue']))
{
@@ -162,7 +168,8 @@ class ApiQueryContributions extends ApiQueryBase {
// ... and in the specified timeframe.
// Ensure the same sort order for rev_user_text and rev_timestamp
// so our query is indexed
- $this->addWhereRange('rev_user_text', $this->params['dir'], null, null);
+ if($this->multiUserMode)
+ $this->addWhereRange('rev_user_text', $this->params['dir'], null, null);
$this->addWhereRange('rev_timestamp',
$this->params['dir'], $this->params['start'], $this->params['end'] );
$this->addWhereFld('page_namespace', $this->params['namespace']);
@@ -170,14 +177,17 @@ class ApiQueryContributions extends ApiQueryBase {
$show = $this->params['show'];
if (!is_null($show)) {
$show = array_flip($show);
- if (isset ($show['minor']) && isset ($show['!minor']))
+ if ((isset($show['minor']) && isset($show['!minor']))
+ || (isset($show['patrolled']) && isset($show['!patrolled'])))
$this->dieUsage("Incorrect parameter - mutually exclusive values may not be supplied", 'show');
- $this->addWhereIf('rev_minor_edit = 0', isset ($show['!minor']));
- $this->addWhereIf('rev_minor_edit != 0', isset ($show['minor']));
+ $this->addWhereIf('rev_minor_edit = 0', isset($show['!minor']));
+ $this->addWhereIf('rev_minor_edit != 0', isset($show['minor']));
+ $this->addWhereIf('rc_patrolled = 0', isset($show['!patrolled']));
+ $this->addWhereIf('rc_patrolled != 0', isset($show['patrolled']));
}
$this->addOption('LIMIT', $this->params['limit'] + 1);
- $this->addOption( 'USE INDEX', array( 'revision' => 'usertext_timestamp' ) );
+ $index['revision'] = 'usertext_timestamp';
// Mandatory fields: timestamp allows request continuation
// ns+title checks if the user has access rights for this page
@@ -187,15 +197,49 @@ class ApiQueryContributions extends ApiQueryBase {
'page_namespace',
'page_title',
'rev_user_text',
- ));
+ ));
+
+ if(isset($show['patrolled']) || isset($show['!patrolled']) ||
+ $this->fld_patrolled)
+ {
+ global $wgUser;
+ if(!$wgUser->useRCPatrol() && !$wgUser->useNPPatrol())
+ $this->dieUsage("You need the patrol right to request the patrolled flag", 'permissiondenied');
+ // Use a redundant join condition on both
+ // timestamp and ID so we can use the timestamp
+ // index
+ $index['recentchanges'] = 'rc_user_text';
+ if(isset($show['patrolled']) || isset($show['!patrolled']))
+ {
+ // Put the tables in the right order for
+ // STRAIGHT_JOIN
+ $tables = array('revision', 'recentchanges', 'page');
+ $this->addOption('STRAIGHT_JOIN');
+ $this->addWhere('rc_user_text=rev_user_text');
+ $this->addWhere('rc_timestamp=rev_timestamp');
+ $this->addWhere('rc_this_oldid=rev_id');
+ }
+ else
+ {
+ $tables[] = 'recentchanges';
+ $this->addJoinConds(array('recentchanges' => array(
+ 'LEFT JOIN', array(
+ 'rc_user_text=rev_user_text',
+ 'rc_timestamp=rev_timestamp',
+ 'rc_this_oldid=rev_id'))));
+ }
+ }
+ $this->addTables($tables);
+ $this->addOption('USE INDEX', $index);
$this->addFieldsIf('rev_page', $this->fld_ids);
$this->addFieldsIf('rev_id', $this->fld_ids || $this->fld_flags);
$this->addFieldsIf('page_latest', $this->fld_flags);
// $this->addFieldsIf('rev_text_id', $this->fld_ids); // Should this field be exposed?
$this->addFieldsIf('rev_comment', $this->fld_comment);
$this->addFieldsIf('rev_minor_edit', $this->fld_flags);
- $this->addFieldsIf('page_is_new', $this->fld_flags);
+ $this->addFieldsIf('rev_parent_id', $this->fld_flags);
+ $this->addFieldsIf('rc_patrolled', $this->fld_patrolled);
}
/**
@@ -220,7 +264,7 @@ class ApiQueryContributions extends ApiQueryBase {
$vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->rev_timestamp);
if ($this->fld_flags) {
- if ($row->page_is_new)
+ if ($row->rev_parent_id == 0)
$vals['new'] = '';
if ($row->rev_minor_edit)
$vals['minor'] = '';
@@ -228,9 +272,12 @@ class ApiQueryContributions extends ApiQueryBase {
$vals['top'] = '';
}
- if ($this->fld_comment && isset( $row->rev_comment ) )
+ if ($this->fld_comment && isset($row->rev_comment))
$vals['comment'] = $row->rev_comment;
+ if ($this->fld_patrolled && $row->rc_patrolled)
+ $vals['patrolled'] = '';
+
return $vals;
}
@@ -279,7 +326,8 @@ class ApiQueryContributions extends ApiQueryBase {
'title',
'timestamp',
'comment',
- 'flags'
+ 'flags',
+ 'patrolled',
)
),
'show' => array (
@@ -287,6 +335,8 @@ class ApiQueryContributions extends ApiQueryBase {
ApiBase :: PARAM_TYPE => array (
'minor',
'!minor',
+ 'patrolled',
+ '!patrolled',
)
),
);
@@ -303,7 +353,8 @@ class ApiQueryContributions extends ApiQueryBase {
'dir' => 'The direction to search (older or newer).',
'namespace' => 'Only list contributions in these namespaces',
'prop' => 'Include additional pieces of information',
- 'show' => 'Show only items that meet this criteria, e.g. non minor edits only: show=!minor',
+ 'show' => array('Show only items that meet this criteria, e.g. non minor edits only: show=!minor',
+ 'NOTE: if show=patrolled or show=!patrolled is set, revisions older than $wgRCMaxAge won\'t be shown',),
);
}
@@ -319,6 +370,6 @@ class ApiQueryContributions extends ApiQueryBase {
}
public function getVersion() {
- return __CLASS__ . ': $Id: ApiQueryUserContributions.php 43271 2008-11-06 22:38:42Z siebrand $';
+ return __CLASS__ . ': $Id: ApiQueryUserContributions.php 47037 2009-02-09 14:07:18Z catrope $';
}
-}
+} \ No newline at end of file