Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -41,6 +41,7 @@ |
42 | 42 | $wgAutoloadClasses['ApiCodeDiff'] = $dir . 'api/ApiCodeDiff.php'; |
43 | 43 | $wgAutoloadClasses['ApiCodeComments'] = $dir . 'api/ApiCodeComments.php'; |
44 | 44 | $wgAutoloadClasses['ApiCodeTestUpload'] = $dir . 'api/ApiCodeTestUpload.php'; |
| 45 | +$wgAutoloadClasses['ApiCodeRevisions'] = $dir . 'api/ApiCodeRevisions.php'; |
45 | 46 | |
46 | 47 | $wgAutoloadClasses['SubversionAdaptor'] = $dir . 'backend/Subversion.php'; |
47 | 48 | $wgAutoloadClasses['CodeDiffHighlighter'] = $dir . 'backend/DiffHighlighter.php'; |
— | — | @@ -84,6 +85,7 @@ |
85 | 86 | $wgAPIModules['codediff'] = 'ApiCodeDiff'; |
86 | 87 | $wgAPIModules['codetestupload'] = 'ApiCodeTestUpload'; |
87 | 88 | $wgAPIListModules['codecomments'] = 'ApiCodeComments'; |
| 89 | +$wgAPIListModules['coderevisions'] = 'ApiCodeRevisions'; |
88 | 90 | |
89 | 91 | $wgExtensionMessagesFiles['CodeReview'] = $dir . 'CodeReview.i18n.php'; |
90 | 92 | $wgExtensionAliasesFiles['CodeReview'] = $dir . 'CodeReview.alias.php'; |
Index: trunk/extensions/CodeReview/api/ApiCodeRevisions.php |
— | — | @@ -0,0 +1,172 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Created on July 06, 2010 |
| 6 | + * |
| 7 | + * API for MediaWiki 1.8+ |
| 8 | + * |
| 9 | + * Copyright © 2010 Sam Reed |
| 10 | + * Copyright © 2008 Bryan Tong Minh <Bryan.TongMinh@Gmail.com> |
| 11 | + * |
| 12 | + * This program is free software; you can redistribute it and/or modify |
| 13 | + * it under the terms of the GNU General Public License as published by |
| 14 | + * the Free Software Foundation; either version 2 of the License, or |
| 15 | + * (at your option) any later version. |
| 16 | + * |
| 17 | + * This program is distributed in the hope that it will be useful, |
| 18 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | + * GNU General Public License for more details. |
| 21 | + * |
| 22 | + * You should have received a copy of the GNU General Public License along |
| 23 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 24 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 25 | + * http://www.gnu.org/copyleft/gpl.html |
| 26 | + */ |
| 27 | + |
| 28 | +class ApiCodeRevisions extends ApiQueryBase { |
| 29 | + public function __construct( $query, $moduleName ) { |
| 30 | + parent::__construct( $query, $moduleName, 'cr' ); |
| 31 | + } |
| 32 | + |
| 33 | + public function execute() { |
| 34 | + global $wgUser; |
| 35 | + // Before doing anything at all, let's check permissions |
| 36 | + if ( !$wgUser->isAllowed( 'codereview-use' ) ) { |
| 37 | + $this->dieUsage( 'You don\'t have permission to view code revisions', 'permissiondenied' ); |
| 38 | + } |
| 39 | + $params = $this->extractRequestParams(); |
| 40 | + if ( is_null( $params['repo'] ) ) { |
| 41 | + $this->dieUsageMsg( array( 'missingparam', 'repo' ) ); |
| 42 | + } |
| 43 | + $this->props = array_flip( $params['prop'] ); |
| 44 | + |
| 45 | + $listview = new CodeRevisionListView( $params['repo'] ); |
| 46 | + if ( is_null( $listview->getRepo() ) ) { |
| 47 | + $this->dieUsage( "Invalid repo ``{$params['repo']}''", 'invalidrepo' ); |
| 48 | + } |
| 49 | + $pager = $listview->getPager(); |
| 50 | + |
| 51 | + if ( !is_null( $params['start'] ) ) { |
| 52 | + $pager->setOffset( $this->getDB()->timestamp( $params['start'] ) ); |
| 53 | + } |
| 54 | + $limit = $params['limit']; |
| 55 | + $pager->setLimit( $limit ); |
| 56 | + |
| 57 | + $pager->doQuery(); |
| 58 | + |
| 59 | + $revisions = $pager->getResult(); |
| 60 | + $data = array(); |
| 61 | + |
| 62 | + $count = 0; |
| 63 | + $lastTimestamp = 0; |
| 64 | + while ( $row = $revisions->fetchObject() ) { |
| 65 | + if ( $count == $limit ) { |
| 66 | + $this->setContinueEnumParameter( 'start', |
| 67 | + wfTimestamp( TS_ISO_8601, $lastTimestamp ) ); |
| 68 | + break; |
| 69 | + } |
| 70 | + |
| 71 | + $data[] = $this->formatRow( $row ); |
| 72 | + $lastTimestamp = $row->cr_timestamp; |
| 73 | + $count++; |
| 74 | + } |
| 75 | + $revisions->free(); |
| 76 | + |
| 77 | + $result = $this->getResult(); |
| 78 | + $result->setIndexedTagName( $data, 'revision' ); |
| 79 | + $result->addValue( 'query', $this->getModuleName(), $data ); |
| 80 | + } |
| 81 | + |
| 82 | + private function formatRow( $row ) { |
| 83 | + $item = array(); |
| 84 | + if ( isset( $this->props['revid'] ) ) { |
| 85 | + $item['revid'] = $row->cr_rev_id; |
| 86 | + } |
| 87 | + if ( isset( $this->props['status'] ) ) { |
| 88 | + $item['status'] = $row->cr_status; |
| 89 | + } |
| 90 | + if ( isset( $this->props['commentcount'] ) ) { |
| 91 | + $item['commentcount'] = $row->comments; |
| 92 | + } |
| 93 | + if ( isset( $this->props['tests'] ) ) { |
| 94 | + $item['tests'] = $row->tests; |
| 95 | + } |
| 96 | + if ( isset( $this->props['path'] ) ) { |
| 97 | + $item['path'] = $row->cr_path; |
| 98 | + } |
| 99 | + if ( isset( $this->props['message'] ) ) { |
| 100 | + ApiResult::setContent( $item, $row->cr_message ); |
| 101 | + } |
| 102 | + if ( isset( $this->props['author'] ) ) { |
| 103 | + $item['author'] = $row->cr_author; |
| 104 | + } |
| 105 | + if ( isset( $this->props['timestamp'] ) ) { |
| 106 | + $item['timestamp'] = wfTimestamp( TS_ISO_8601, $row->cr_timestamp ); |
| 107 | + } |
| 108 | + |
| 109 | + return $item; |
| 110 | + } |
| 111 | + |
| 112 | + public function getAllowedParams() { |
| 113 | + return array( |
| 114 | + 'repo' => null, |
| 115 | + 'limit' => array( |
| 116 | + ApiBase::PARAM_DFLT => 10, |
| 117 | + ApiBase::PARAM_TYPE => 'limit', |
| 118 | + ApiBase::PARAM_MIN => 1, |
| 119 | + ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, |
| 120 | + ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 |
| 121 | + ), |
| 122 | + 'start' => array( |
| 123 | + ApiBase::PARAM_TYPE => 'timestamp' |
| 124 | + ), |
| 125 | + 'prop' => array( |
| 126 | + ApiBase::PARAM_ISMULTI => true, |
| 127 | + ApiBase::PARAM_DFLT => 'revid|author|status|timestamp', |
| 128 | + ApiBase::PARAM_TYPE => array( |
| 129 | + 'revid', |
| 130 | + 'status', |
| 131 | + 'commentcount', |
| 132 | + 'tests', |
| 133 | + 'path', |
| 134 | + 'message', |
| 135 | + 'author', |
| 136 | + 'timestamp', |
| 137 | + ), |
| 138 | + ), |
| 139 | + ); |
| 140 | + } |
| 141 | + |
| 142 | + public function getParamDescription() { |
| 143 | + return array( |
| 144 | + 'repo' => 'Name of the repository', |
| 145 | + 'limit' => 'How many revisions to return', |
| 146 | + 'start' => 'Timestamp to start listing at', |
| 147 | + 'prop' => 'Which properties to return', |
| 148 | + ); |
| 149 | + } |
| 150 | + |
| 151 | + public function getDescription() { |
| 152 | + return 'List revisions in CodeReview'; |
| 153 | + } |
| 154 | + |
| 155 | + public function getPossibleErrors() { |
| 156 | + return array_merge( parent::getPossibleErrors(), array( |
| 157 | + array( 'missingparam', 'repo' ), |
| 158 | + array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to view code revisions' ), |
| 159 | + array( 'code' => 'invalidrepo', 'info' => "Invalid repo ``repo''" ), |
| 160 | + ) ); |
| 161 | + } |
| 162 | + |
| 163 | + public function getExamples() { |
| 164 | + return array( |
| 165 | + 'api.php?action=query&list=coderevisions&crrepo=MediaWiki', |
| 166 | + 'api.php?action=query&list=coderevisions&crrepo=MediaWiki&crprop=revid|author|status|timestamp', |
| 167 | + ); |
| 168 | + } |
| 169 | + |
| 170 | + public function getVersion() { |
| 171 | + return __CLASS__ . ': $Id: ApiCodeComments.php 48777 2009-03-25 01:26:54Z aaron $'; |
| 172 | + } |
| 173 | +} |
Property changes on: trunk/extensions/CodeReview/api/ApiCodeRevisions.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 174 | + native |
Index: trunk/extensions/CodeReview/ui/CodeCommentsListView.php |
— | — | @@ -23,6 +23,7 @@ |
24 | 24 | function getPager() { |
25 | 25 | return new CodeCommentsTablePager( $this ); |
26 | 26 | } |
| 27 | + |
27 | 28 | function getRepo() { |
28 | 29 | return $this->mRepo; |
29 | 30 | } |
Index: trunk/extensions/CodeReview/ui/CodeStatusChangeListView.php |
— | — | @@ -23,6 +23,7 @@ |
24 | 24 | function getPager() { |
25 | 25 | return new CodeStatusChangeTablePager( $this ); |
26 | 26 | } |
| 27 | + |
27 | 28 | function getRepo() { |
28 | 29 | return $this->mRepo; |
29 | 30 | } |
Index: trunk/extensions/CodeReview/ui/CodeRevisionListView.php |
— | — | @@ -206,7 +206,10 @@ |
207 | 207 | function getSpecializedWhereClause( $dbr ) { |
208 | 208 | return array(); |
209 | 209 | } |
210 | | - |
| 210 | + |
| 211 | + function getRepo() { |
| 212 | + return $this->mRepo; |
| 213 | + } |
211 | 214 | } |
212 | 215 | |
213 | 216 | // Pager for CodeRevisionListView |