diff options
Diffstat (limited to 'includes/api/ApiQueryUserContributions.php')
-rw-r--r-- | includes/api/ApiQueryUserContributions.php | 100 |
1 files changed, 88 insertions, 12 deletions
diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index 8e2f20db..f30b1325 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -4,7 +4,7 @@ * * Created on Oct 16, 2006 * - * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com + * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com" * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,10 +35,10 @@ class ApiQueryContributions extends ApiQueryBase { parent::__construct( $query, $moduleName, 'uc' ); } - private $params, $prefixMode, $userprefix, $multiUserMode, $usernames; + private $params, $prefixMode, $userprefix, $multiUserMode, $usernames, $parentLens; private $fld_ids = false, $fld_title = false, $fld_timestamp = false, $fld_comment = false, $fld_parsedcomment = false, $fld_flags = false, - $fld_patrolled = false, $fld_tags = false, $fld_size = false; + $fld_patrolled = false, $fld_tags = false, $fld_size = false, $fld_sizediff = false; public function execute() { // Parse some parameters @@ -50,6 +50,7 @@ class ApiQueryContributions extends ApiQueryBase { $this->fld_comment = isset( $prop['comment'] ); $this->fld_parsedcomment = isset ( $prop['parsedcomment'] ); $this->fld_size = isset( $prop['size'] ); + $this->fld_sizediff = isset( $prop['sizediff'] ); $this->fld_flags = isset( $prop['flags'] ); $this->fld_timestamp = isset( $prop['timestamp'] ); $this->fld_patrolled = isset( $prop['patrolled'] ); @@ -82,6 +83,17 @@ class ApiQueryContributions extends ApiQueryBase { // Do the actual query. $res = $this->select( __METHOD__ ); + if( $this->fld_sizediff ) { + $revIds = array(); + foreach ( $res as $row ) { + if( $row->rev_parent_id ) { + $revIds[] = $row->rev_parent_id; + } + } + $this->parentLens = Revision::getParentLengths( $this->getDB(), $revIds ); + $res->rewind(); // reset + } + // Initialise some variables $count = 0; $limit = $this->params['limit']; @@ -152,13 +164,14 @@ class ApiQueryContributions extends ApiQueryBase { $this->dieUsage( 'Invalid continue param. You should pass the original ' . 'value returned by the previous query', '_badcontinue' ); } - $encUser = $this->getDB()->strencode( $continue[0] ); - $encTS = wfTimestamp( TS_MW, $continue[1] ); + $db = $this->getDB(); + $encUser = $db->addQuotes( $continue[0] ); + $encTS = $db->addQuotes( $db->timestamp( $continue[1] ) ); $op = ( $this->params['dir'] == 'older' ? '<' : '>' ); $this->addWhere( - "rev_user_text $op '$encUser' OR " . - "(rev_user_text = '$encUser' AND " . - "rev_timestamp $op= '$encTS')" + "rev_user_text $op $encUser OR " . + "(rev_user_text = $encUser AND " . + "rev_timestamp $op= $encTS)" ); } @@ -185,7 +198,7 @@ class ApiQueryContributions extends ApiQueryBase { if ( !is_null( $show ) ) { $show = array_flip( $show ); if ( ( isset( $show['minor'] ) && isset( $show['!minor'] ) ) - || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) ) ) { + || ( isset( $show['patrolled'] ) && isset( $show['!patrolled'] ) ) ) { $this->dieUsageMsg( 'show' ); } @@ -243,8 +256,9 @@ class ApiQueryContributions extends ApiQueryBase { $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->fld_parsedcomment ); - $this->addFieldsIf( 'rev_len', $this->fld_size ); - $this->addFieldsIf( array( 'rev_minor_edit', 'rev_parent_id' ), $this->fld_flags ); + $this->addFieldsIf( 'rev_len', $this->fld_size || $this->fld_sizediff ); + $this->addFieldsIf( 'rev_minor_edit', $this->fld_flags ); + $this->addFieldsIf( 'rev_parent_id', $this->fld_flags || $this->fld_sizediff ); $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled ); if ( $this->fld_tags ) { @@ -332,6 +346,11 @@ class ApiQueryContributions extends ApiQueryBase { $vals['size'] = intval( $row->rev_len ); } + if ( $this->fld_sizediff && !is_null( $row->rev_len ) && !is_null( $row->rev_parent_id ) ) { + $parentLen = isset( $this->parentLens[$row->rev_parent_id] ) ? $this->parentLens[$row->rev_parent_id] : 0; + $vals['sizediff'] = intval( $row->rev_len - $parentLen ); + } + if ( $this->fld_tags ) { if ( $row->ts_tags ) { $tags = explode( ',', $row->ts_tags ); @@ -397,6 +416,7 @@ class ApiQueryContributions extends ApiQueryBase { 'comment', 'parsedcomment', 'size', + 'sizediff', 'flags', 'patrolled', 'tags' @@ -435,7 +455,8 @@ class ApiQueryContributions extends ApiQueryBase { ' timestamp - Adds the timestamp of the edit', ' comment - Adds the comment of the edit', ' parsedcomment - Adds the parsed comment of the edit', - ' size - Adds the size of the page', + ' size - Adds the new size of the edit', + ' sizediff - Adds the size delta of the edit against its parent', ' flags - Adds flags of the edit', ' patrolled - Tags patrolled edits', ' tags - Lists tags for the edit', @@ -447,6 +468,61 @@ class ApiQueryContributions extends ApiQueryBase { ); } + public function getResultProperties() { + return array( + '' => array( + 'userid' => 'integer', + 'user' => 'string', + 'userhidden' => 'boolean' + ), + 'ids' => array( + 'pageid' => 'integer', + 'revid' => 'integer' + ), + 'title' => array( + 'ns' => 'namespace', + 'title' => 'string' + ), + 'timestamp' => array( + 'timestamp' => 'timestamp' + ), + 'flags' => array( + 'new' => 'boolean', + 'minor' => 'boolean', + 'top' => 'boolean' + ), + 'comment' => array( + 'commenthidden' => 'boolean', + 'comment' => array( + ApiBase::PROP_TYPE => 'string', + ApiBase::PROP_NULLABLE => true + ) + ), + 'parsedcomment' => array( + 'commenthidden' => 'boolean', + 'parsedcomment' => array( + ApiBase::PROP_TYPE => 'string', + ApiBase::PROP_NULLABLE => true + ) + ), + 'patrolled' => array( + 'patrolled' => 'boolean' + ), + 'size' => array( + 'size' => array( + ApiBase::PROP_TYPE => 'integer', + ApiBase::PROP_NULLABLE => true + ) + ), + 'sizediff' => array( + 'sizediff' => array( + ApiBase::PROP_TYPE => 'integer', + ApiBase::PROP_NULLABLE => true + ) + ) + ); + } + public function getDescription() { return 'Get all edits by a user'; } |