Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 46 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
EchoHooks | |
0.00% |
0 / 46 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
onBeforeCreateEchoEvent | |
0.00% |
0 / 42 |
|
0.00% |
0 / 1 |
6 | |||
onEchoGetBundleRules | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace LoginNotify; |
4 | |
5 | use MediaWiki\Extension\Notifications\AttributeManager; |
6 | use MediaWiki\Extension\Notifications\Hooks\BeforeCreateEchoEventHook; |
7 | use MediaWiki\Extension\Notifications\Hooks\EchoGetBundleRulesHook; |
8 | use MediaWiki\Extension\Notifications\Model\Event; |
9 | use MediaWiki\Extension\Notifications\UserLocator; |
10 | |
11 | /** |
12 | * Hooks from Echo extension, |
13 | * which is optional to use with this extension. |
14 | */ |
15 | class EchoHooks implements |
16 | BeforeCreateEchoEventHook, |
17 | EchoGetBundleRulesHook |
18 | { |
19 | /** |
20 | * Add LoginNotify events to Echo |
21 | * |
22 | * @param string[] &$notifications Array of Echo notifications |
23 | * @param string[] &$notificationCategories Array of Echo notification categories |
24 | * @param string[] &$icons Array of icon details |
25 | */ |
26 | public function onBeforeCreateEchoEvent( |
27 | array &$notifications, |
28 | array &$notificationCategories, |
29 | array &$icons |
30 | ) { |
31 | global $wgLoginNotifyEnableOnSuccess, $wgNotifyTypeAvailabilityByCategory; |
32 | |
33 | $icons['LoginNotify-user-avatar'] = [ |
34 | 'path' => 'LoginNotify/UserAvatar.svg' |
35 | ]; |
36 | |
37 | $notificationCategories['login-fail'] = [ |
38 | 'priority' => 7, |
39 | 'tooltip' => 'echo-pref-tooltip-login-fail', |
40 | ]; |
41 | |
42 | $loginBase = [ |
43 | AttributeManager::ATTR_LOCATORS => [ |
44 | [ [ UserLocator::class, 'locateEventAgent' ] ], |
45 | ], |
46 | 'canNotifyAgent' => true, |
47 | 'category' => 'login-fail', |
48 | 'group' => 'negative', |
49 | 'presentation-model' => PresentationModel::class, |
50 | 'icon' => 'LoginNotify-user-avatar', |
51 | 'immediate' => true, |
52 | ]; |
53 | $notifications['login-fail-new'] = [ |
54 | 'bundle' => [ |
55 | 'web' => true, |
56 | 'expandable' => false |
57 | ] |
58 | ] + $loginBase; |
59 | $notifications['login-fail-known'] = [ |
60 | 'bundle' => [ |
61 | 'web' => true, |
62 | 'expandable' => false |
63 | ] |
64 | ] + $loginBase; |
65 | if ( $wgLoginNotifyEnableOnSuccess ) { |
66 | $notificationCategories['login-success'] = [ |
67 | 'priority' => 7, |
68 | 'tooltip' => 'echo-pref-tooltip-login-success', |
69 | ]; |
70 | $notifications['login-success'] = [ |
71 | 'category' => 'login-success', |
72 | ] + $loginBase; |
73 | $wgNotifyTypeAvailabilityByCategory['login-success'] = [ |
74 | 'web' => false, |
75 | 'email' => true, |
76 | ]; |
77 | } |
78 | } |
79 | |
80 | /** |
81 | * @param Event $event |
82 | * @param string &$bundleString |
83 | */ |
84 | public function onEchoGetBundleRules( Event $event, string &$bundleString ) { |
85 | switch ( $event->getType() ) { |
86 | case 'login-fail-new': |
87 | $bundleString = 'login-fail'; |
88 | break; |
89 | } |
90 | } |
91 | } |