Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ApiQueryBetaFeatures | |
0.00% |
0 / 22 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
| 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 | |
| 38 | public function __construct( |
| 39 | ApiQuery $query, |
| 40 | string $moduleName, |
| 41 | private readonly IConnectionProvider $dbProvider, |
| 42 | private readonly HookContainer $hookContainer |
| 43 | ) { |
| 44 | parent::__construct( $query, $moduleName, 'bf' ); |
| 45 | } |
| 46 | |
| 47 | public function execute() { |
| 48 | $params = $this->extractRequestParams(); |
| 49 | |
| 50 | $prefs = $this->getConfig()->get( 'BetaFeatures' ); |
| 51 | $user = User::newFromName( 'MediaWiki default' ); |
| 52 | ( new HookRunner( $this->hookContainer ) ) |
| 53 | ->onGetBetaFeaturePreferences( $user, $prefs ); |
| 54 | |
| 55 | $counts = isset( $params['counts'] ) |
| 56 | ? Hooks::getUserCounts( array_keys( $prefs ), $this->dbProvider ) |
| 57 | : []; |
| 58 | foreach ( $prefs as $key => $info ) { |
| 59 | $path = [ 'query', $this->getModuleName(), $key ]; |
| 60 | $this->getResult()->addValue( $path, 'name', $key ); |
| 61 | $count = (int)( $counts[$key] ?? 0 ); |
| 62 | $this->getResult()->addValue( $path, 'count', $count ); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /** @inheritDoc */ |
| 67 | public function getAllowedParams() { |
| 68 | return [ |
| 69 | 'counts' => null, |
| 70 | ]; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @see ApiBase::getExamplesMessages() |
| 75 | * @return array |
| 76 | */ |
| 77 | protected function getExamplesMessages() { |
| 78 | return [ |
| 79 | 'action=query&list=betafeatures&bfcounts=' |
| 80 | => 'apihelp-query+betafeatures-example-1', |
| 81 | ]; |
| 82 | } |
| 83 | |
| 84 | /** @inheritDoc */ |
| 85 | public function getHelpUrls() { |
| 86 | return 'https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:BetaFeatures'; |
| 87 | } |
| 88 | } |