| 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 |
|
| 13 |
|
| 14 |
|
| 15 |
class EchoHooks implements |
| 16 |
BeforeCreateEchoEventHook, |
| 17 |
EchoGetBundleRulesHook |
| 18 |
{ |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 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 |
|
| 82 |
|
| 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 |
} |