Index: trunk/extensions/CodeReview/api/ApiQueryCodeRevisions.php |
— | — | @@ -42,27 +42,47 @@ |
43 | 43 | |
44 | 44 | $this->props = array_flip( $params['prop'] ); |
45 | 45 | |
46 | | - $listview = new CodeRevisionListView( $params['repo'] ); |
47 | | - if ( is_null( $listview->getRepo() ) ) { |
| 46 | + $repo = CodeRepository::newFromName( $params['repo'] ); |
| 47 | + |
| 48 | + if ( !$repo ) { |
48 | 49 | $this->dieUsage( "Invalid repo ``{$params['repo']}''", 'invalidrepo' ); |
49 | 50 | } |
| 51 | + |
| 52 | + $data = array(); |
| 53 | + |
| 54 | + $listview = new CodeRevisionListView( $repo ); |
50 | 55 | $pager = $listview->getPager(); |
51 | 56 | |
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'] ); |
57 | 58 | |
58 | | - $pager->doQuery(); |
| 59 | + if ( $revsSet ) { |
| 60 | + $db = wfGetDB( DB_SLAVE ); |
59 | 61 | |
60 | | - $revisions = $pager->getResult(); |
61 | | - $data = array(); |
| 62 | + $list = $db->makeList( $params['revs'] ); |
62 | 63 | |
| 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 | + |
63 | 83 | $count = 0; |
64 | 84 | $lastTimestamp = 0; |
65 | 85 | foreach ( $revisions as $row ) { |
66 | | - if ( $count == $limit ) { |
| 86 | + if ( !$revsSet && $count == $limit ) { |
67 | 87 | $this->setContinueEnumParameter( 'start', |
68 | 88 | wfTimestamp( TS_ISO_8601, $lastTimestamp ) ); |
69 | 89 | break; |
— | — | @@ -72,7 +92,6 @@ |
73 | 93 | $lastTimestamp = $row->cr_timestamp; |
74 | 94 | $count++; |
75 | 95 | } |
76 | | - $revisions->free(); |
77 | 96 | |
78 | 97 | $result = $this->getResult(); |
79 | 98 | $result->setIndexedTagName( $data, 'revision' ); |
— | — | @@ -102,7 +121,6 @@ |
103 | 122 | if ( isset( $this->props['timestamp'] ) ) { |
104 | 123 | $item['timestamp'] = wfTimestamp( TS_ISO_8601, $row->cr_timestamp ); |
105 | 124 | } |
106 | | - |
107 | 125 | return $item; |
108 | 126 | } |
109 | 127 | |
— | — | @@ -122,9 +140,14 @@ |
123 | 141 | 'start' => array( |
124 | 142 | ApiBase::PARAM_TYPE => 'timestamp' |
125 | 143 | ), |
| 144 | + 'revs' => array( |
| 145 | + ApiBase::PARAM_ISMULTI => true, |
| 146 | + ApiBase::PARAM_TYPE => 'integer', |
| 147 | + ApiBase::PARAM_MIN => 1, |
| 148 | + ), |
126 | 149 | 'prop' => array( |
127 | 150 | ApiBase::PARAM_ISMULTI => true, |
128 | | - ApiBase::PARAM_DFLT => 'revid|author|status|timestamp', |
| 151 | + ApiBase::PARAM_DFLT => 'revid|status|author|timestamp', |
129 | 152 | ApiBase::PARAM_TYPE => array( |
130 | 153 | 'revid', |
131 | 154 | 'status', |
— | — | @@ -139,10 +162,12 @@ |
140 | 163 | } |
141 | 164 | |
142 | 165 | public function getParamDescription() { |
| 166 | + $p = $this->getModulePrefix(); |
143 | 167 | return array( |
144 | 168 | 'repo' => 'Name of the repository', |
145 | 169 | 'limit' => 'How many revisions to return', |
146 | 170 | 'start' => 'Timestamp to start listing at', |
| 171 | + 'revs' => "List of revisions to get information about. Overrides {$p}start", |
147 | 172 | 'prop' => 'Which properties to return', |
148 | 173 | ); |
149 | 174 | } |