Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiQueryCodeTags
0.00% covered (danger)
0.00%
0 / 14
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 / 11
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 20 April 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 ApiQueryCodeTags extends ApiQueryBase {
30    public function __construct( $query, $moduleName ) {
31        parent::__construct( $query, $moduleName, 'ct' );
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        $data = [];
45        foreach ( $repo->getTagList( true ) as $tag => $count ) {
46            $data[] = [
47                'name' => $tag,
48                'revcount' => $count,
49            ];
50        }
51
52        $result = $this->getResult();
53        ApiResult::setIndexedTagName( $data, 'tag' );
54        $result->addValue( 'query', $this->getModuleName(), $data );
55    }
56
57    public function getAllowedParams() {
58        return [
59            'repo' => [
60                ParamValidator::PARAM_TYPE => 'string',
61                ParamValidator::PARAM_REQUIRED => true,
62            ],
63        ];
64    }
65
66    /**
67     * @inheritDoc
68     */
69    protected function getExamplesMessages() {
70        return [
71            'action=query&list=codetags&ctrepo=MediaWiki'
72                => 'apihelp-query+codetags-example-1',
73        ];
74    }
75}