Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -41,6 +41,7 @@ |
42 | 42 | $wgAutoloadClasses['ApiCodeDiff'] = $dir . 'api/ApiCodeDiff.php'; |
43 | 43 | $wgAutoloadClasses['ApiRevisionUpdate'] = $dir . 'api/ApiRevisionUpdate.php'; |
44 | 44 | $wgAutoloadClasses['ApiQueryCodeComments'] = $dir . 'api/ApiQueryCodeComments.php'; |
| 45 | +$wgAutoloadClasses['ApiQueryCodePaths'] = $dir . 'api/ApiQueryCodePaths.php'; |
45 | 46 | $wgAutoloadClasses['ApiQueryCodeRevisions'] = $dir . 'api/ApiQueryCodeRevisions.php'; |
46 | 47 | $wgAutoloadClasses['ApiQueryCodeTags'] = $dir . 'api/ApiQueryCodeTags.php'; |
47 | 48 | $wgAutoloadClasses['CodeRevisionCommitterApi'] = $dir . 'api/CodeRevisionCommitterApi.php'; |
— | — | @@ -96,6 +97,7 @@ |
97 | 98 | $wgAPIModules['codediff'] = 'ApiCodeDiff'; |
98 | 99 | $wgAPIModules['coderevisionupdate'] ='ApiRevisionUpdate'; |
99 | 100 | $wgAPIListModules['codecomments'] = 'ApiQueryCodeComments'; |
| 101 | +$wgAPIListModules['codepaths'] = 'ApiQueryCodePaths'; |
100 | 102 | $wgAPIListModules['coderevisions'] = 'ApiQueryCodeRevisions'; |
101 | 103 | $wgAPIListModules['codetags'] = 'ApiQueryCodeTags'; |
102 | 104 | |
Index: trunk/extensions/CodeReview/api/ApiQueryCodePaths.php |
— | — | @@ -0,0 +1,105 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Created on 6th June 2011 |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License along |
| 18 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | + * http://www.gnu.org/copyleft/gpl.html |
| 21 | + */ |
| 22 | + |
| 23 | +class ApiQueryCodePaths extends ApiQueryBase { |
| 24 | + public function __construct( $query, $moduleName ) { |
| 25 | + parent::__construct( $query, $moduleName, 'cp' ); |
| 26 | + } |
| 27 | + |
| 28 | + public function execute() { |
| 29 | + global $wgUser; |
| 30 | + // Before doing anything at all, let's check permissions |
| 31 | + if ( !$wgUser->isAllowed( 'codereview-use' ) ) { |
| 32 | + $this->dieUsage( 'You don\'t have permission to view code tags', 'permissiondenied' ); |
| 33 | + } |
| 34 | + $params = $this->extractRequestParams(); |
| 35 | + |
| 36 | + $repo = CodeRepository::newFromName( $params['repo'] ); |
| 37 | + if ( !$repo instanceof CodeRepository ) { |
| 38 | + $this->dieUsage( "Invalid repo ``{$params['repo']}''", 'invalidrepo' ); |
| 39 | + } |
| 40 | + |
| 41 | + $this->addTables( 'code_paths' ); |
| 42 | + $this->addFields( 'cp_path' ); |
| 43 | + $this->addWhere( array( 'cp_repo_id' => $repo->getId() ) ); |
| 44 | + $db = $this->getDB(); |
| 45 | + |
| 46 | + $this->addWhere( 'cp_path ' . $db->buildLike( $params['path'], $db->anyString() ) ); |
| 47 | + |
| 48 | + $this->addOption( 'LIMIT', 10 ); |
| 49 | + |
| 50 | + $res = $this->select( __METHOD__ ); |
| 51 | + |
| 52 | + $result = $this->getResult(); |
| 53 | + |
| 54 | + $data = array(); |
| 55 | + |
| 56 | + foreach ( $res as $row ) { |
| 57 | + $item = array(); |
| 58 | + ApiResult::setContent( $item, $row->cp_path ); |
| 59 | + $data[] = $item; |
| 60 | + } |
| 61 | + |
| 62 | + $result->setIndexedTagName( $data, 'paths' ); |
| 63 | + $result->addValue( 'query', $this->getModuleName(), $data ); |
| 64 | + } |
| 65 | + |
| 66 | + public function getAllowedParams() { |
| 67 | + return array( |
| 68 | + 'repo' => array( |
| 69 | + ApiBase::PARAM_TYPE => 'string', |
| 70 | + ApiBase::PARAM_REQUIRED => true, |
| 71 | + ), |
| 72 | + 'path' => array( |
| 73 | + ApiBase::PARAM_TYPE => 'string', |
| 74 | + ApiBase::PARAM_REQUIRED => true, |
| 75 | + ), |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + public function getParamDescription() { |
| 80 | + return array( |
| 81 | + 'repo' => 'Name of the repository', |
| 82 | + 'path' => 'Path prefix to filter on', |
| 83 | + ); |
| 84 | + } |
| 85 | + |
| 86 | + public function getDescription() { |
| 87 | + return 'Get a list of 10 paths in a given repository, based on the input path prefix'; |
| 88 | + } |
| 89 | + |
| 90 | + public function getPossibleErrors() { |
| 91 | + return array_merge( parent::getPossibleErrors(), array( |
| 92 | + array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to view code comments' ), |
| 93 | + array( 'code' => 'invalidrepo', 'info' => "Invalid repo ``repo''" ), |
| 94 | + ) ); |
| 95 | + } |
| 96 | + |
| 97 | + public function getExamples() { |
| 98 | + return array( |
| 99 | + 'api.php?action=query&list=codepaths&cprepo=MediaWiki&cppath=/trunk/phase3', |
| 100 | + ); |
| 101 | + } |
| 102 | + |
| 103 | + public function getVersion() { |
| 104 | + return __CLASS__ . ': $Id$'; |
| 105 | + } |
| 106 | +} |
Property changes on: trunk/extensions/CodeReview/api/ApiQueryCodePaths.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 107 | + native |
Added: svn:keywords |
2 | 108 | + Id |