Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
UserLogoutHookHandler | |
0.00% |
0 / 33 |
|
0.00% |
0 / 3 |
110 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onUserLogout | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
onUserLogoutComplete | |
0.00% |
0 / 23 |
|
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\Config\Config; |
24 | use MediaWiki\Context\RequestContext; |
25 | use MediaWiki\Deferred\DeferredUpdates; |
26 | use MediaWiki\Extension\CentralAuth\CentralAuthHooks; |
27 | use MediaWiki\Extension\CentralAuth\Config\CAMainConfigNames; |
28 | use MediaWiki\Extension\CentralAuth\User\CentralAuthUser; |
29 | use MediaWiki\Hook\UserLogoutCompleteHook; |
30 | use MediaWiki\User\Hook\UserLogoutHook; |
31 | use MediaWiki\User\User; |
32 | use MediaWiki\WikiMap\WikiMap; |
33 | |
34 | class UserLogoutHookHandler implements |
35 | UserLogoutCompleteHook, |
36 | UserLogoutHook |
37 | { |
38 | |
39 | private Config $config; |
40 | |
41 | public function __construct( Config $config ) { |
42 | $this->config = $config; |
43 | } |
44 | |
45 | /** |
46 | * @param User $user |
47 | * @return bool |
48 | */ |
49 | public function onUserLogout( $user ) { |
50 | if ( !$this->config->get( CAMainConfigNames::CentralAuthCookies ) ) { |
51 | // Use local sessions only. |
52 | return true; |
53 | } |
54 | |
55 | $username = $user->getName(); |
56 | DeferredUpdates::addCallableUpdate( static function () use ( $username ) { |
57 | $centralUser = CentralAuthUser::getPrimaryInstanceByName( $username ); |
58 | if ( $centralUser->exists() ) { |
59 | $centralUser->resetAuthToken(); |
60 | } |
61 | } ); |
62 | |
63 | return true; |
64 | } |
65 | |
66 | /** |
67 | * @param User $user |
68 | * @param string &$inject_html |
69 | * @param string $oldName Unused |
70 | * @return bool |
71 | */ |
72 | public function onUserLogoutComplete( $user, &$inject_html, $oldName ) { |
73 | if ( !$this->config->get( CAMainConfigNames::CentralAuthCookies ) ) { |
74 | return true; |
75 | } |
76 | |
77 | $wikis = CentralAuthHooks::getAutoLoginWikis(); |
78 | $loginWiki = $this->config->get( CAMainConfigNames::CentralAuthLoginWiki ); |
79 | if ( $loginWiki && $loginWiki !== WikiMap::getCurrentWikiId() ) { |
80 | $wikis[$loginWiki] = $loginWiki; |
81 | } |
82 | |
83 | $csp = RequestContext::getMain()->getOutput()->getCSP(); |
84 | // No other domains |
85 | if ( !$wikis ) { |
86 | $inject_html = wfMessage( 'centralauth-logout-no-others' )->escaped(); |
87 | } else { |
88 | $inject_html = '<div class="centralauth-logout-box"><p>' . |
89 | wfMessage( 'centralauth-logout-progress' ) |
90 | ->params( $user->getName() ) |
91 | ->numParams( count( $wikis ) ) |
92 | ->escaped() . "</p>\n<p>"; |
93 | foreach ( $wikis as $wikiID ) { |
94 | $params = [ |
95 | 'type' => 'icon', |
96 | ]; |
97 | $inject_html .= CentralAuthHooks::getAuthIconHtml( |
98 | $wikiID, 'Special:CentralAutoLogin/deleteCookies', $params, $csp |
99 | ); |
100 | } |
101 | $inject_html .= "</p></div>\n"; |
102 | } |
103 | |
104 | return true; |
105 | } |
106 | } |