Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryBetaFeatures | |
0.00% |
0 / 34 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
20 | |||
getAllowedParams | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getHelpUrls | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * This file is part of the MediaWiki extension BetaFeatures. |
5 | * |
6 | * BetaFeatures is free software: you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation, either version 2 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * BetaFeatures is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with BetaFeatures. If not, see <http://www.gnu.org/licenses/>. |
18 | * |
19 | * Query module to list all available BetaFeatures |
20 | * |
21 | * @ingroup API |
22 | * @file |
23 | * @author Kunal Mehta <legoktm@gmail.com> |
24 | * @license GPL-2.0-or-later |
25 | */ |
26 | |
27 | namespace MediaWiki\Extension\BetaFeatures; |
28 | |
29 | use MediaWiki\Api\ApiQuery; |
30 | use MediaWiki\Api\ApiQueryBase; |
31 | use MediaWiki\Extension\BetaFeatures\Hooks\HookRunner; |
32 | use MediaWiki\HookContainer\HookContainer; |
33 | use MediaWiki\User\User; |
34 | use Wikimedia\Rdbms\IConnectionProvider; |
35 | |
36 | class ApiQueryBetaFeatures extends ApiQueryBase { |
37 | private IConnectionProvider $dbProvider; |
38 | private HookContainer $hookContainer; |
39 | |
40 | public function __construct( |
41 | ApiQuery $query, |
42 | string $moduleName, |
43 | IConnectionProvider $dbProvider, |
44 | HookContainer $hookContainer |
45 | ) { |
46 | parent::__construct( $query, $moduleName, 'bf' ); |
47 | $this->dbProvider = $dbProvider; |
48 | $this->hookContainer = $hookContainer; |
49 | } |
50 | |
51 | public function execute() { |
52 | $params = $this->extractRequestParams(); |
53 | |
54 | $prefs = $this->getConfig()->get( 'BetaFeatures' ); |
55 | $user = User::newFromName( 'MediaWiki default' ); |
56 | ( new HookRunner( $this->hookContainer ) ) |
57 | ->onGetBetaFeaturePreferences( $user, $prefs ); |
58 | |
59 | $counts = isset( $params['counts'] ) |
60 | ? Hooks::getUserCounts( array_keys( $prefs ), $this->dbProvider ) |
61 | : []; |
62 | foreach ( $prefs as $key => $info ) { |
63 | $path = [ 'query', $this->getModuleName(), $key ]; |
64 | $this->getResult()->addValue( |
65 | $path, |
66 | 'name', |
67 | $key |
68 | ); |
69 | if ( isset( $counts[$key] ) ) { |
70 | $count = (int)$counts[$key]; |
71 | } else { |
72 | $count = 0; |
73 | } |
74 | $this->getResult()->addValue( |
75 | $path, |
76 | 'count', |
77 | $count |
78 | ); |
79 | } |
80 | } |
81 | |
82 | /** @inheritDoc */ |
83 | public function getAllowedParams() { |
84 | return [ |
85 | 'counts' => null, |
86 | ]; |
87 | } |
88 | |
89 | /** |
90 | * @see ApiBase::getExamplesMessages() |
91 | * @return array |
92 | */ |
93 | protected function getExamplesMessages() { |
94 | return [ |
95 | 'action=query&list=betafeatures&bfcounts=' |
96 | => 'apihelp-query+betafeatures-example-1', |
97 | ]; |
98 | } |
99 | |
100 | /** @inheritDoc */ |
101 | public function getHelpUrls() { |
102 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:BetaFeatures'; |
103 | } |
104 | } |