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 ApiBase; |
24 | use ApiMain; |
25 | use MediaWiki\Api\Hook\APIGetAllowedParamsHook; |
26 | use MediaWiki\Config\Config; |
27 | use Wikimedia\ParamValidator\ParamValidator; |
28 | |
29 | class ApiHookHandler implements |
30 | APIGetAllowedParamsHook |
31 | { |
32 | /** @var Config */ |
33 | private $config; |
34 | |
35 | /** |
36 | * @param Config $config |
37 | */ |
38 | public function __construct( Config $config ) { |
39 | $this->config = $config; |
40 | } |
41 | |
42 | /** |
43 | * Inject the "centralauthtoken" parameter into the API |
44 | * @param ApiBase $module API module |
45 | * @param array &$params Array of parameter specifications |
46 | * @param int $flags |
47 | * @return bool |
48 | */ |
49 | public function onAPIGetAllowedParams( $module, &$params, $flags ) { |
50 | if ( !$this->config->get( 'CentralAuthCookies' ) ) { |
51 | return true; |
52 | } |
53 | |
54 | if ( $module instanceof ApiMain ) { |
55 | $params['centralauthtoken'] = [ |
56 | ParamValidator::PARAM_TYPE => 'string', |
57 | ParamValidator::PARAM_SENSITIVE => true, |
58 | ]; |
59 | } |
60 | return true; |
61 | } |
62 | } |