Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ApiQueryBabel | |
0.00% |
0 / 24 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
getAllowedParams | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
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 2 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 along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | declare( strict_types = 1 ); |
22 | |
23 | namespace MediaWiki\Babel; |
24 | |
25 | use MediaWiki\Api\ApiQuery; |
26 | use MediaWiki\Api\ApiQueryBase; |
27 | use MediaWiki\Api\ApiResult; |
28 | use MediaWiki\User\UserIdentityLookup; |
29 | use Wikimedia\ParamValidator\ParamValidator; |
30 | |
31 | class ApiQueryBabel extends ApiQueryBase { |
32 | private UserIdentityLookup $userIdentityLookup; |
33 | |
34 | public function __construct( |
35 | ApiQuery $queryModule, |
36 | string $moduleName, |
37 | UserIdentityLookup $userIdentityLookup |
38 | ) { |
39 | parent::__construct( $queryModule, $moduleName, 'bab' ); |
40 | $this->userIdentityLookup = $userIdentityLookup; |
41 | } |
42 | |
43 | public function execute(): void { |
44 | $params = $this->extractRequestParams(); |
45 | $userName = $params['user']; |
46 | $user = $this->userIdentityLookup->getUserIdentityByName( $userName ); |
47 | if ( !$user || !$user->getId() ) { |
48 | $this->dieWithError( [ 'nosuchusershort', wfEscapeWikiText( $userName ) ], 'baduser' ); |
49 | } |
50 | |
51 | $data = Babel::getUserLanguageInfo( $user ); |
52 | // Force a JSON object |
53 | $data[ApiResult::META_TYPE] = 'assoc'; |
54 | |
55 | $this->getResult()->addValue( |
56 | 'query', |
57 | $this->getModuleName(), |
58 | $data |
59 | ); |
60 | } |
61 | |
62 | /** @inheritDoc */ |
63 | public function getAllowedParams(): array { |
64 | return [ |
65 | 'user' => [ |
66 | ParamValidator::PARAM_REQUIRED => true, |
67 | ParamValidator::PARAM_TYPE => 'user', |
68 | ] |
69 | ]; |
70 | } |
71 | |
72 | /** @inheritDoc */ |
73 | protected function getExamplesMessages(): array { |
74 | return [ |
75 | 'action=query&meta=babel&babuser=Example' |
76 | => 'apihelp-query+babel-example-1', |
77 | ]; |
78 | } |
79 | |
80 | } |