r77664 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77663‎ | r77664 | r77665 >
Date:15:32, 3 December 2010
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
*(bug 26061) CodeReview API need to give info for a list of revisions
Modified paths:
  • /trunk/extensions/CodeReview/api/ApiQueryCodeRevisions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/api/ApiQueryCodeRevisions.php
@@ -42,27 +42,47 @@
4343
4444 $this->props = array_flip( $params['prop'] );
4545
46 - $listview = new CodeRevisionListView( $params['repo'] );
47 - if ( is_null( $listview->getRepo() ) ) {
 46+ $repo = CodeRepository::newFromName( $params['repo'] );
 47+
 48+ if ( !$repo ) {
4849 $this->dieUsage( "Invalid repo ``{$params['repo']}''", 'invalidrepo' );
4950 }
 51+
 52+ $data = array();
 53+
 54+ $listview = new CodeRevisionListView( $repo );
5055 $pager = $listview->getPager();
5156
52 - if ( !is_null( $params['start'] ) ) {
53 - $pager->setOffset( $this->getDB()->timestamp( $params['start'] ) );
54 - }
55 - $limit = $params['limit'];
56 - $pager->setLimit( $limit );
 57+ $revsSet = count( $params['revs'] );
5758
58 - $pager->doQuery();
 59+ if ( $revsSet ) {
 60+ $db = wfGetDB( DB_SLAVE );
5961
60 - $revisions = $pager->getResult();
61 - $data = array();
 62+ $list = $db->makeList( $params['revs'] );
6263
 64+ $query = $pager->getQueryInfo();
 65+
 66+ $query['conds'][] = 'cr_id IN ( ' . $list . ' )';
 67+
 68+ $revisions = $db->select( $query['tables'], $query['fields'], $query['conds'],
 69+ __METHOD__, $query['options'], $query['join_conds'] );
 70+
 71+ } else {
 72+ if ( !is_null( $params['start'] ) ) {
 73+ $pager->setOffset( $this->getDB()->timestamp( $params['start'] ) );
 74+ }
 75+ $limit = $params['limit'];
 76+ $pager->setLimit( $limit );
 77+
 78+ $pager->doQuery();
 79+
 80+ $revisions = $pager->getResult();
 81+ }
 82+
6383 $count = 0;
6484 $lastTimestamp = 0;
6585 foreach ( $revisions as $row ) {
66 - if ( $count == $limit ) {
 86+ if ( !$revsSet && $count == $limit ) {
6787 $this->setContinueEnumParameter( 'start',
6888 wfTimestamp( TS_ISO_8601, $lastTimestamp ) );
6989 break;
@@ -72,7 +92,6 @@
7393 $lastTimestamp = $row->cr_timestamp;
7494 $count++;
7595 }
76 - $revisions->free();
7796
7897 $result = $this->getResult();
7998 $result->setIndexedTagName( $data, 'revision' );
@@ -102,7 +121,6 @@
103122 if ( isset( $this->props['timestamp'] ) ) {
104123 $item['timestamp'] = wfTimestamp( TS_ISO_8601, $row->cr_timestamp );
105124 }
106 -
107125 return $item;
108126 }
109127
@@ -122,9 +140,14 @@
123141 'start' => array(
124142 ApiBase::PARAM_TYPE => 'timestamp'
125143 ),
 144+ 'revs' => array(
 145+ ApiBase::PARAM_ISMULTI => true,
 146+ ApiBase::PARAM_TYPE => 'integer',
 147+ ApiBase::PARAM_MIN => 1,
 148+ ),
126149 'prop' => array(
127150 ApiBase::PARAM_ISMULTI => true,
128 - ApiBase::PARAM_DFLT => 'revid|author|status|timestamp',
 151+ ApiBase::PARAM_DFLT => 'revid|status|author|timestamp',
129152 ApiBase::PARAM_TYPE => array(
130153 'revid',
131154 'status',
@@ -139,10 +162,12 @@
140163 }
141164
142165 public function getParamDescription() {
 166+ $p = $this->getModulePrefix();
143167 return array(
144168 'repo' => 'Name of the repository',
145169 'limit' => 'How many revisions to return',
146170 'start' => 'Timestamp to start listing at',
 171+ 'revs' => "List of revisions to get information about. Overrides {$p}start",
147172 'prop' => 'Which properties to return',
148173 );
149174 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r77665r77664, Whitespace, DIE IN A FIREreedy15:40, 3 December 2010
r77686Followup r77664, no need to build the list myselfreedy22:40, 3 December 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r77634Add CodeRevision->getCommentCount() function...reedy02:05, 3 December 2010

Comments

#Comment by Nikerabbit (talk | contribs)   22:29, 3 December 2010

+ $query['conds'][] = 'cr_id IN ( ' . $list . ' )'; Why are making the list manually?

#Comment by Reedy (talk | contribs)   22:32, 3 December 2010

Oh ffs.

array( 'cr_id' => $params['revs'] )

Would've done it, right?

#Comment by Catrope (talk | contribs)   22:32, 3 December 2010

Exactly

Status & tagging log