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