Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
SecurePollHookHandler | |
0.00% |
0 / 20 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onSecurePoll_GetUserParams | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
42 |
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\Extension\CentralAuth\User\CentralAuthUser; |
24 | use MediaWiki\Extension\SecurePoll\Hooks\SecurePoll_GetUserParamsHook; |
25 | use MediaWiki\Extension\SecurePoll\User\LocalAuth; |
26 | use MediaWiki\Title\NamespaceInfo; |
27 | use MediaWiki\User\User; |
28 | use MediaWiki\WikiMap\WikiMap; |
29 | |
30 | class SecurePollHookHandler implements SecurePoll_GetUserParamsHook { |
31 | |
32 | private NamespaceInfo $namespaceInfo; |
33 | |
34 | public function __construct( NamespaceInfo $namespaceInfo ) { |
35 | $this->namespaceInfo = $namespaceInfo; |
36 | } |
37 | |
38 | /** |
39 | * @param LocalAuth $localAuth Unused |
40 | * @param User $user |
41 | * @param array &$params |
42 | * @return bool |
43 | */ |
44 | public function onSecurePoll_GetUserParams( LocalAuth $localAuth, User $user, array &$params ) { |
45 | if ( !$user->isRegistered() ) { |
46 | return true; |
47 | } |
48 | |
49 | $centralUser = CentralAuthUser::getInstance( $user ); |
50 | if ( !( $centralUser->exists() && $centralUser->isAttached() ) ) { |
51 | return true; |
52 | } |
53 | |
54 | $wikiID = $centralUser->getHomeWiki(); |
55 | if ( strval( $wikiID ) === '' ) { |
56 | return true; |
57 | } |
58 | |
59 | $wiki = WikiMap::getWiki( $wikiID ); |
60 | $wikiUrl = $wiki->getUrl( '' ); |
61 | $parts = explode( '/', $wikiUrl ); |
62 | if ( isset( $parts[2] ) ) { |
63 | $params['properties']['ca-local-domain'] = $params['domain']; |
64 | $params['domain'] = $parts[2]; |
65 | } |
66 | |
67 | $params['properties']['ca-local-url'] = $params['url']; |
68 | $params['url'] = $wiki->getUrl( |
69 | $this->namespaceInfo->getCanonicalName( NS_USER ) . ':' . $user->getTitleKey() |
70 | ); |
71 | return true; |
72 | } |
73 | } |