Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
77.78% |
7 / 9 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ApiHookHandler | |
77.78% |
7 / 9 |
|
0.00% |
0 / 2 |
4.18 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onAPIGetAllowedParams | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
3.02 |
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 | namespace MediaWiki\Extension\CentralAuth\Hooks\Handlers; |
22 | |
23 | use MediaWiki\Api\ApiBase; |
24 | use MediaWiki\Api\ApiMain; |
25 | use MediaWiki\Api\Hook\APIGetAllowedParamsHook; |
26 | use MediaWiki\Config\Config; |
27 | use MediaWiki\Extension\CentralAuth\Config\CAMainConfigNames; |
28 | use Wikimedia\ParamValidator\ParamValidator; |
29 | |
30 | class ApiHookHandler implements APIGetAllowedParamsHook { |
31 | |
32 | private Config $config; |
33 | |
34 | public function __construct( Config $config ) { |
35 | $this->config = $config; |
36 | } |
37 | |
38 | /** |
39 | * Inject the "centralauthtoken" parameter into the API |
40 | * @param ApiBase $module API module |
41 | * @param array &$params Array of parameter specifications |
42 | * @param int $flags |
43 | * @return bool |
44 | */ |
45 | public function onAPIGetAllowedParams( $module, &$params, $flags ) { |
46 | if ( !$this->config->get( CAMainConfigNames::CentralAuthCookies ) ) { |
47 | return true; |
48 | } |
49 | |
50 | if ( $module instanceof ApiMain ) { |
51 | $params['centralauthtoken'] = [ |
52 | ParamValidator::PARAM_TYPE => 'string', |
53 | ParamValidator::PARAM_SENSITIVE => true, |
54 | ]; |
55 | } |
56 | return true; |
57 | } |
58 | } |