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 | /** @var NamespaceInfo */ |
32 | private $namespaceInfo; |
33 | |
34 | /** |
35 | * @param NamespaceInfo $namespaceInfo |
36 | */ |
37 | public function __construct( NamespaceInfo $namespaceInfo ) { |
38 | $this->namespaceInfo = $namespaceInfo; |
39 | } |
40 | |
41 | /** |
42 | * @param LocalAuth $localAuth Unused |
43 | * @param User $user |
44 | * @param array &$params |
45 | * @return bool |
46 | */ |
47 | public function onSecurePoll_GetUserParams( LocalAuth $localAuth, User $user, array &$params ) { |
48 | if ( !$user->isRegistered() ) { |
49 | return true; |
50 | } |
51 | |
52 | $centralUser = CentralAuthUser::getInstance( $user ); |
53 | if ( !( $centralUser->exists() && $centralUser->isAttached() ) ) { |
54 | return true; |
55 | } |
56 | |
57 | $wikiID = $centralUser->getHomeWiki(); |
58 | if ( strval( $wikiID ) === '' ) { |
59 | return true; |
60 | } |
61 | |
62 | $wiki = WikiMap::getWiki( $wikiID ); |
63 | $wikiUrl = $wiki->getUrl( '' ); |
64 | $parts = explode( '/', $wikiUrl ); |
65 | if ( isset( $parts[2] ) ) { |
66 | $params['properties']['ca-local-domain'] = $params['domain']; |
67 | $params['domain'] = $parts[2]; |
68 | } |
69 | |
70 | $params['properties']['ca-local-url'] = $params['url']; |
71 | $params['url'] = $wiki->getUrl( |
72 | $this->namespaceInfo->getCanonicalName( NS_USER ) . ':' . $user->getTitleKey() |
73 | ); |
74 | return true; |
75 | } |
76 | } |