Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
79.31% |
23 / 29 |
|
50.00% |
3 / 6 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryORES | |
79.31% |
23 / 29 |
|
50.00% |
3 / 6 |
9.72 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
95.00% |
19 / 20 |
|
0.00% |
0 / 1 |
4 | |||
getCacheMode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getAllowedParams | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | */ |
16 | |
17 | namespace ORES\Hooks\Api; |
18 | |
19 | use MediaWiki\Api\ApiQuery; |
20 | use MediaWiki\Api\ApiQueryBase; |
21 | use MediaWiki\Api\ApiResult; |
22 | use MediaWiki\Title\NamespaceInfo; |
23 | use MediaWiki\WikiMap\WikiMap; |
24 | use ORES\Hooks\Helpers; |
25 | use ORES\Services\ORESServices; |
26 | |
27 | /** |
28 | * A query action to return meta information about ORES models and |
29 | * configuration on the wiki. |
30 | * |
31 | * @ingroup API |
32 | */ |
33 | class ApiQueryORES extends ApiQueryBase { |
34 | private NamespaceInfo $namespaceInfo; |
35 | |
36 | public function __construct( |
37 | ApiQuery $query, |
38 | string $moduleName, |
39 | NamespaceInfo $namespaceInfo |
40 | ) { |
41 | parent::__construct( $query, $moduleName, 'ores' ); |
42 | $this->namespaceInfo = $namespaceInfo; |
43 | } |
44 | |
45 | public function execute() { |
46 | $enabledNamespaces = $this->getConfig()->get( 'OresEnabledNamespaces' ); |
47 | |
48 | $result = $this->getResult(); |
49 | $data = [ |
50 | 'baseurl' => $this->getConfig()->get( 'OresBaseUrl' ), |
51 | 'wikiid' => $this->getConfig()->get( 'OresWikiId' ) ?: WikiMap::getCurrentWikiId(), |
52 | 'models' => [], |
53 | 'excludebots' => (bool)$this->getConfig()->get( 'OresExcludeBots' ), |
54 | 'damagingthresholds' => Helpers::getDamagingThresholds(), |
55 | 'namespaces' => $enabledNamespaces |
56 | ? array_keys( array_filter( $enabledNamespaces ) ) |
57 | : $this->namespaceInfo->getValidNamespaces(), |
58 | ]; |
59 | ApiResult::setArrayType( $data['models'], 'assoc' ); |
60 | ApiResult::setIndexedTagName( $data['namespaces'], 'ns' ); |
61 | |
62 | $models = ORESServices::getModelLookup()->getModels(); |
63 | |
64 | foreach ( $models as $modelName => $modelData ) { |
65 | $data['models'][$modelName] = [ |
66 | 'version' => $modelData['version'], |
67 | ]; |
68 | } |
69 | |
70 | $result->addValue( [ 'query' ], 'ores', $data ); |
71 | } |
72 | |
73 | public function getCacheMode( $params ) { |
74 | return 'public'; |
75 | } |
76 | |
77 | public function getAllowedParams() { |
78 | return []; |
79 | } |
80 | |
81 | /** |
82 | * @inheritDoc |
83 | */ |
84 | protected function getExamplesMessages() { |
85 | return [ |
86 | 'action=query&meta=ores' |
87 | => 'apihelp-query+ores-example-simple', |
88 | ]; |
89 | } |
90 | |
91 | public function getHelpUrls() { |
92 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:ORES'; |
93 | } |
94 | |
95 | } |