r89588 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89587‎ | r89588 | r89589 >
Date:19:01, 6 June 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
* (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 (modified) (history)
  • /trunk/extensions/CodeReview/api/ApiQueryCodePaths.php (added) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeReview.php
@@ -41,6 +41,7 @@
4242 $wgAutoloadClasses['ApiCodeDiff'] = $dir . 'api/ApiCodeDiff.php';
4343 $wgAutoloadClasses['ApiRevisionUpdate'] = $dir . 'api/ApiRevisionUpdate.php';
4444 $wgAutoloadClasses['ApiQueryCodeComments'] = $dir . 'api/ApiQueryCodeComments.php';
 45+$wgAutoloadClasses['ApiQueryCodePaths'] = $dir . 'api/ApiQueryCodePaths.php';
4546 $wgAutoloadClasses['ApiQueryCodeRevisions'] = $dir . 'api/ApiQueryCodeRevisions.php';
4647 $wgAutoloadClasses['ApiQueryCodeTags'] = $dir . 'api/ApiQueryCodeTags.php';
4748 $wgAutoloadClasses['CodeRevisionCommitterApi'] = $dir . 'api/CodeRevisionCommitterApi.php';
@@ -96,6 +97,7 @@
9798 $wgAPIModules['codediff'] = 'ApiCodeDiff';
9899 $wgAPIModules['coderevisionupdate'] ='ApiRevisionUpdate';
99100 $wgAPIListModules['codecomments'] = 'ApiQueryCodeComments';
 101+$wgAPIListModules['codepaths'] = 'ApiQueryCodePaths';
100102 $wgAPIListModules['coderevisions'] = 'ApiQueryCodeRevisions';
101103 $wgAPIListModules['codetags'] = 'ApiQueryCodeTags';
102104
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
1107 + native
Added: svn:keywords
2108 + Id

Follow-up revisions

RevisionCommit summaryAuthorDate
r89589* (bug 29287) Path searching input need a suggest list...reedy19:10, 6 June 2011
r89594Followup r89588, adding the DISTINCT keyword is somewhat helpfulreedy19:24, 6 June 2011
r89596Fixup error messagesreedy19:35, 6 June 2011
r89645Followup r89589, r89588...reedy13:43, 7 June 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   19:03, 6 June 2011
+			$this->dieUsage( 'You don\'t have permission to view code tags', 'permissiondenied' );
+			array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to view code comments' ),

Messages copied from other classes?

#Comment by Reedy (talk | contribs)   19:33, 6 June 2011
/trunk/extensions/CodeReview/api/ApiQueryCodePaths.php (from /trunk/extensions/CodeReview/api/ApiQueryCodeTags.php:89577) (added) (diff)

What do you think? ;P

#Comment by Brion VIBBER (talk | contribs)   21:16, 6 June 2011

I don't think that has anything to do with the messages about 'tags' and 'comments'.

Those are entries in the table describing files that have been copied; they should be recorded differently but our code doesn't know how to do so, which is a known bug. (Should add to Bugzilla if it's not in there.)

Status & tagging log