http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89588
Revision: 89588
Author: reedy
Date: 2011-06-06 19:01:47 +0000 (Mon, 06 Jun 2011)
Log Message:
-----------
* (bug 29287) Path searching input need a suggest list
Adding API module to do code paths like a given prefix
Modified Paths:
--------------
trunk/extensions/CodeReview/CodeReview.php
Added Paths:
-----------
trunk/extensions/CodeReview/api/ApiQueryCodePaths.php
Modified: trunk/extensions/CodeReview/CodeReview.php
===================================================================
--- trunk/extensions/CodeReview/CodeReview.php 2011-06-06 19:00:36 UTC (rev
89587)
+++ trunk/extensions/CodeReview/CodeReview.php 2011-06-06 19:01:47 UTC (rev
89588)
@@ -41,6 +41,7 @@
$wgAutoloadClasses['ApiCodeDiff'] = $dir . 'api/ApiCodeDiff.php';
$wgAutoloadClasses['ApiRevisionUpdate'] = $dir . 'api/ApiRevisionUpdate.php';
$wgAutoloadClasses['ApiQueryCodeComments'] = $dir .
'api/ApiQueryCodeComments.php';
+$wgAutoloadClasses['ApiQueryCodePaths'] = $dir . 'api/ApiQueryCodePaths.php';
$wgAutoloadClasses['ApiQueryCodeRevisions'] = $dir .
'api/ApiQueryCodeRevisions.php';
$wgAutoloadClasses['ApiQueryCodeTags'] = $dir . 'api/ApiQueryCodeTags.php';
$wgAutoloadClasses['CodeRevisionCommitterApi'] = $dir .
'api/CodeRevisionCommitterApi.php';
@@ -96,6 +97,7 @@
$wgAPIModules['codediff'] = 'ApiCodeDiff';
$wgAPIModules['coderevisionupdate'] ='ApiRevisionUpdate';
$wgAPIListModules['codecomments'] = 'ApiQueryCodeComments';
+$wgAPIListModules['codepaths'] = 'ApiQueryCodePaths';
$wgAPIListModules['coderevisions'] = 'ApiQueryCodeRevisions';
$wgAPIListModules['codetags'] = 'ApiQueryCodeTags';
Copied: trunk/extensions/CodeReview/api/ApiQueryCodePaths.php (from rev 89577,
trunk/extensions/CodeReview/api/ApiQueryCodeTags.php)
===================================================================
--- trunk/extensions/CodeReview/api/ApiQueryCodePaths.php
(rev 0)
+++ trunk/extensions/CodeReview/api/ApiQueryCodePaths.php 2011-06-06
19:01:47 UTC (rev 89588)
@@ -0,0 +1,105 @@
+<?php
+
+/**
+ * Created on 6th June 2011
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+class ApiQueryCodePaths extends ApiQueryBase {
+ public function __construct( $query, $moduleName ) {
+ parent::__construct( $query, $moduleName, 'cp' );
+ }
+
+ public function execute() {
+ global $wgUser;
+ // Before doing anything at all, let's check permissions
+ if ( !$wgUser->isAllowed( 'codereview-use' ) ) {
+ $this->dieUsage( 'You don\'t have permission to view
code tags', 'permissiondenied' );
+ }
+ $params = $this->extractRequestParams();
+
+ $repo = CodeRepository::newFromName( $params['repo'] );
+ if ( !$repo instanceof CodeRepository ) {
+ $this->dieUsage( "Invalid repo ``{$params['repo']}''",
'invalidrepo' );
+ }
+
+ $this->addTables( 'code_paths' );
+ $this->addFields( 'cp_path' );
+ $this->addWhere( array( 'cp_repo_id' => $repo->getId() ) );
+ $db = $this->getDB();
+
+ $this->addWhere( 'cp_path ' . $db->buildLike( $params['path'],
$db->anyString() ) );
+
+ $this->addOption( 'LIMIT', 10 );
+
+ $res = $this->select( __METHOD__ );
+
+ $result = $this->getResult();
+
+ $data = array();
+
+ foreach ( $res as $row ) {
+ $item = array();
+ ApiResult::setContent( $item, $row->cp_path );
+ $data[] = $item;
+ }
+
+ $result->setIndexedTagName( $data, 'paths' );
+ $result->addValue( 'query', $this->getModuleName(), $data );
+ }
+
+ public function getAllowedParams() {
+ return array(
+ 'repo' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ 'path' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ );
+ }
+
+ public function getParamDescription() {
+ return array(
+ 'repo' => 'Name of the repository',
+ 'path' => 'Path prefix to filter on',
+ );
+ }
+
+ public function getDescription() {
+ return 'Get a list of 10 paths in a given repository, based on
the input path prefix';
+ }
+
+ public function getPossibleErrors() {
+ return array_merge( parent::getPossibleErrors(), array(
+ array( 'code' => 'permissiondenied', 'info' => 'You
don\'t have permission to view code comments' ),
+ array( 'code' => 'invalidrepo', 'info' => "Invalid repo
``repo''" ),
+ ) );
+ }
+
+ public function getExamples() {
+ return array(
+
'api.php?action=query&list=codepaths&cprepo=MediaWiki&cppath=/trunk/phase3',
+ );
+ }
+
+ public function getVersion() {
+ return __CLASS__ . ': $Id$';
+ }
+}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs