Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 43 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
SpecialContributionsHookHandler | |
0.00% |
0 / 43 |
|
0.00% |
0 / 3 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
onContributionsToolLinks | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |||
onSpecialContributionsBeforeMainOutput | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
56 |
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 LogEventsList; |
24 | use MediaWiki\Extension\CentralAuth\User\CentralAuthUser; |
25 | use MediaWiki\Hook\ContributionsToolLinksHook; |
26 | use MediaWiki\Hook\SpecialContributionsBeforeMainOutputHook; |
27 | use MediaWiki\Html\Html; |
28 | use MediaWiki\SpecialPage\SpecialPage; |
29 | use MediaWiki\Title\NamespaceInfo; |
30 | use MediaWiki\Title\Title; |
31 | use MediaWiki\User\User; |
32 | use MediaWiki\User\UserFactory; |
33 | |
34 | class SpecialContributionsHookHandler implements |
35 | ContributionsToolLinksHook, |
36 | SpecialContributionsBeforeMainOutputHook |
37 | { |
38 | /** @var NamespaceInfo */ |
39 | private $namespaceInfo; |
40 | |
41 | /** @var UserFactory */ |
42 | private UserFactory $userFactory; |
43 | |
44 | /** |
45 | * @param NamespaceInfo $namespaceInfo |
46 | * @param UserFactory $userFactory |
47 | */ |
48 | public function __construct( NamespaceInfo $namespaceInfo, UserFactory $userFactory ) { |
49 | $this->namespaceInfo = $namespaceInfo; |
50 | $this->userFactory = $userFactory; |
51 | } |
52 | |
53 | /** |
54 | * @param int $id User ID |
55 | * @param Title $title User page title |
56 | * @param array &$tools Array of tool links |
57 | * @param SpecialPage $sp for context |
58 | * @return bool|void |
59 | */ |
60 | public function onContributionsToolLinks( $id, Title $title, array &$tools, SpecialPage $sp ) { |
61 | $user = $this->userFactory->newFromId( $id ); |
62 | if ( !$user->isRegistered() ) { |
63 | return true; |
64 | } |
65 | $centralUser = CentralAuthUser::getInstance( $user ); |
66 | if ( !$centralUser->exists() || !$centralUser->isAttached() ) { |
67 | return true; |
68 | } |
69 | $linkRenderer = $sp->getLinkRenderer(); |
70 | $tools['centralauth'] = $linkRenderer->makeKnownLink( |
71 | SpecialPage::getTitleFor( 'CentralAuth', $title->getText() ), |
72 | $sp->msg( 'centralauth-contribs-link' )->text(), |
73 | [ 'class' => 'mw-contributions-link-centralauth' ] |
74 | ); |
75 | } |
76 | |
77 | /** |
78 | * @param int $id User ID |
79 | * @param User $user |
80 | * @param SpecialPage $sp |
81 | * @return bool|void |
82 | */ |
83 | public function onSpecialContributionsBeforeMainOutput( $id, $user, $sp ) { |
84 | if ( !$user->isRegistered() ) { |
85 | return true; |
86 | } |
87 | |
88 | $centralUser = CentralAuthUser::getInstance( $user ); |
89 | if ( !$centralUser->exists() || !$centralUser->isAttached() |
90 | || !$centralUser->isLocked() || $centralUser->isHidden() |
91 | ) { |
92 | return true; |
93 | } |
94 | |
95 | $out = $sp->getOutput(); |
96 | $count = LogEventsList::showLogExtract( |
97 | $out, |
98 | [ 'globalauth' ], |
99 | $this->namespaceInfo->getCanonicalName( NS_USER ) . ":{$user}@global", |
100 | '', |
101 | [ |
102 | 'lim' => 1, |
103 | 'showIfEmpty' => false, |
104 | 'msgKey' => [ |
105 | 'centralauth-contribs-locked-log', |
106 | $user->getName() |
107 | ], |
108 | 'offset' => '', |
109 | ] |
110 | ); |
111 | |
112 | if ( $count === 0 ) { |
113 | // we couldn't load the log entry |
114 | $out->addHTML( |
115 | Html::warningBox( |
116 | $out->msg( 'centralauth-contribs-locked', $user )->parse(), |
117 | 'mw-warning-with-logexcerpt' |
118 | ) |
119 | ); |
120 | } |
121 | } |
122 | } |