Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiQueryCodePaths
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 1
12
 getAllowedParams
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getExamplesMessages
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\CodeReview\Api;
4
5use ApiQueryBase;
6use ApiResult;
7use MediaWiki\Extension\CodeReview\Backend\CodeRepository;
8use Wikimedia\ParamValidator\ParamValidator;
9
10/**
11 * Created on 6th June 2011
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 * http://www.gnu.org/copyleft/gpl.html
27 */
28
29class ApiQueryCodePaths extends ApiQueryBase {
30    public function __construct( $query, $moduleName ) {
31        parent::__construct( $query, $moduleName, 'cp' );
32    }
33
34    public function execute() {
35        $this->checkUserRightsAny( 'codereview-use' );
36
37        $params = $this->extractRequestParams();
38
39        $repo = CodeRepository::newFromName( $params['repo'] );
40        if ( !$repo instanceof CodeRepository ) {
41            $this->dieWithError( [ 'apierror-invalidrepo', wfEscapeWikiText( $params['repo'] ) ] );
42        }
43
44        $this->addTables( 'code_paths' );
45        $this->addFields( 'DISTINCT cp_path' );
46        $this->addWhere( [ 'cp_repo_id' => $repo->getId() ] );
47        $db = $this->getDB();
48
49        $this->addWhere( 'cp_path ' . $db->buildLike( $params['path'], $db->anyString() ) );
50        $this->addOption( 'USE INDEX', 'repo_path' );
51
52        $this->addOption( 'LIMIT', 10 );
53
54        $res = $this->select( __METHOD__ );
55
56        $result = $this->getResult();
57
58        $data = [];
59
60        foreach ( $res as $row ) {
61            $item = [];
62            ApiResult::setContentValue( $item, 'path', $row->cp_path );
63            $data[] = $item;
64        }
65
66        ApiResult::setIndexedTagName( $data, 'paths' );
67        $result->addValue( 'query', $this->getModuleName(), $data );
68    }
69
70    public function getAllowedParams() {
71        return [
72            'repo' => [
73                ParamValidator::PARAM_TYPE => 'string',
74                ParamValidator::PARAM_REQUIRED => true,
75            ],
76            'path' => [
77                ParamValidator::PARAM_TYPE => 'string',
78                ParamValidator::PARAM_REQUIRED => true,
79            ],
80        ];
81    }
82
83    /**
84     * @inheritDoc
85     */
86    protected function getExamplesMessages() {
87        return [
88            'action=query&list=codepaths&cprepo=MediaWiki&cppath=/trunk/phase3'
89                => 'apihelp-query+codepaths-example-1',
90        ];
91    }
92}