Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -40,6 +40,7 @@ |
41 | 41 | |
42 | 42 | $wgAutoloadClasses['ApiCodeUpdate'] = $dir . 'ApiCodeUpdate.php'; |
43 | 43 | $wgAutoloadClasses['ApiCodeDiff'] = $dir . 'ApiCodeDiff.php'; |
| 44 | +$wgAutoloadClasses['ApiCodeComments'] = $dir . 'ApiCodeComments.php'; |
44 | 45 | $wgAutoloadClasses['CodeDiffHighlighter'] = $dir . 'DiffHighlighter.php'; |
45 | 46 | $wgAutoloadClasses['CodeRepository'] = $dir . 'CodeRepository.php'; |
46 | 47 | $wgAutoloadClasses['CodeRepoListView'] = $dir . 'CodeRepoListView.php'; |
— | — | @@ -69,6 +70,7 @@ |
70 | 71 | |
71 | 72 | $wgAPIModules['codeupdate'] = 'ApiCodeUpdate'; |
72 | 73 | $wgAPIModules['codediff'] = 'ApiCodeDiff'; |
| 74 | +$wgAPIListModules['codecomments'] = 'ApiCodeComments'; |
73 | 75 | |
74 | 76 | $wgExtensionMessagesFiles['CodeReview'] = $dir . 'CodeReview.i18n.php'; |
75 | 77 | $wgExtensionAliasesFiles['CodeReview'] = $dir . 'CodeReview.alias.php'; |
Index: trunk/extensions/CodeReview/ApiCodeComments.php |
— | — | @@ -0,0 +1,110 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on Oct 29, 2008 |
| 6 | + * |
| 7 | + * API for MediaWiki 1.8+ |
| 8 | + * |
| 9 | + * Copyright (C) 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 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 24 | + * http://www.gnu.org/copyleft/gpl.html |
| 25 | + */ |
| 26 | + |
| 27 | +class ApiCodeComments extends ApiQueryBase { |
| 28 | + public function __construct( $query, $moduleName ) { |
| 29 | + parent::__construct( $query, $moduleName, 'cc' ); |
| 30 | + } |
| 31 | + |
| 32 | + public function execute() { |
| 33 | + $params = $this->extractRequestParams(); |
| 34 | + if ( is_null( $params['repo'] ) ) |
| 35 | + $this->dieUsageMsg( array( 'missingparam', 'repo' ) ); |
| 36 | + $this->props = array_flip( $params['prop'] ); |
| 37 | + |
| 38 | + $listview = new CodeCommentsListView( $params['repo'] ); |
| 39 | + $pager = $listview->getPager(); |
| 40 | + |
| 41 | + if ( !is_null( $params['start'] ) ) |
| 42 | + $pager->setOffset( $params['start'] ); |
| 43 | + $limit = $params['limit']; |
| 44 | + $pager->setLimit( $limit ); |
| 45 | + |
| 46 | + $pager->doQuery(); |
| 47 | + |
| 48 | + $comments = $pager->getResult(); |
| 49 | + $data = array(); |
| 50 | + |
| 51 | + $count = 0; |
| 52 | + $lastTimestamp = 0; // Stop Eclipse from whining |
| 53 | + while ( $row = $comments->fetchObject() ) { |
| 54 | + if ( $count == $limit ) { |
| 55 | + $this->setContinueEnumParameter( 'start', $lastTimestamp ); |
| 56 | + break; |
| 57 | + } |
| 58 | + |
| 59 | + $data[] = self::formatRow( $row ); |
| 60 | + $lastTimestamp = $row->cc_timestamp; |
| 61 | + $count++; |
| 62 | + } |
| 63 | + $comments->free(); |
| 64 | + |
| 65 | + $result = $this->getMain()->getResult(); |
| 66 | + $result->setIndexedTagName( $data, 'comment' ); |
| 67 | + $result->addValue( 'query', $this->getModuleName(), $data ); |
| 68 | + } |
| 69 | + private function formatRow( $row ) { |
| 70 | + $item = array(); |
| 71 | + if ( isset( $this->props['timestamp'] ) ) |
| 72 | + $item['timestamp'] = $row->cc_timestamp; |
| 73 | + if ( isset( $this->props['user'] ) ) |
| 74 | + $item['user'] = $row->cc_user_text; |
| 75 | + if ( isset( $this->props['revision'] ) ) |
| 76 | + $item['status'] = $row->cr_status; |
| 77 | + if ( isset( $this->props['text'] ) ) |
| 78 | + ApiResult::setContent( $item, $row->cc_text ); |
| 79 | + return $item; |
| 80 | + } |
| 81 | + |
| 82 | + public function getAllowedParams() { |
| 83 | + return array ( |
| 84 | + 'repo' => null, |
| 85 | + 'limit' => array ( |
| 86 | + ApiBase :: PARAM_DFLT => 10, |
| 87 | + ApiBase :: PARAM_TYPE => 'limit', |
| 88 | + ApiBase :: PARAM_MIN => 1, |
| 89 | + ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1, |
| 90 | + ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2 |
| 91 | + ), |
| 92 | + 'start' => array( |
| 93 | + ApiBase :: PARAM_TYPE => 'timestamp' |
| 94 | + ), |
| 95 | + 'prop' => array ( |
| 96 | + ApiBase :: PARAM_ISMULTI => true, |
| 97 | + ApiBase :: PARAM_DFLT => 'timestamp|user|revision', |
| 98 | + ApiBase :: PARAM_TYPE => array ( |
| 99 | + 'timestamp', |
| 100 | + 'user', |
| 101 | + 'revision', |
| 102 | + 'text', |
| 103 | + ), |
| 104 | + ), |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + public function getVersion() { |
| 109 | + return __CLASS__ . ': $Id:$'; |
| 110 | + } |
| 111 | +} |
Property changes on: trunk/extensions/CodeReview/ApiCodeComments.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 112 | + native |