mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/LoginNotify
synced 2024-11-28 00:40:38 +00:00
c524ee65a4
Bug: T344785 Change-Id: I71f4433896b2758d1a5d8984192bf06fddc89468
100 lines
2.6 KiB
PHP
100 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace LoginNotify;
|
|
|
|
use EchoAttributeManager;
|
|
use EchoEvent;
|
|
use EchoUserLocator;
|
|
use MediaWiki\Extension\Notifications\Hooks\BeforeCreateEchoEventHook;
|
|
use MediaWiki\Extension\Notifications\Hooks\EchoGetBundleRulesHook;
|
|
|
|
/**
|
|
* Hooks from Echo extension,
|
|
* which is optional to use with this extension.
|
|
*/
|
|
class EchoHooks implements
|
|
BeforeCreateEchoEventHook,
|
|
EchoGetBundleRulesHook
|
|
{
|
|
/**
|
|
* Add LoginNotify events to Echo
|
|
*
|
|
* @param string[] &$notifications Array of Echo notifications
|
|
* @param string[] &$notificationCategories Array of Echo notification categories
|
|
* @param string[] &$icons Array of icon details
|
|
*/
|
|
public function onBeforeCreateEchoEvent(
|
|
array &$notifications,
|
|
array &$notificationCategories,
|
|
array &$icons
|
|
) {
|
|
global $wgLoginNotifyEnableOnSuccess, $wgNotifyTypeAvailabilityByCategory;
|
|
|
|
$icons['LoginNotify-user-avatar'] = [
|
|
'path' => 'LoginNotify/UserAvatar.svg'
|
|
];
|
|
|
|
$notificationCategories['login-fail'] = [
|
|
'priority' => 7,
|
|
'tooltip' => 'echo-pref-tooltip-login-fail',
|
|
];
|
|
|
|
$loginBase = [
|
|
EchoAttributeManager::ATTR_LOCATORS => [
|
|
[ [ EchoUserLocator::class, 'locateEventAgent' ] ],
|
|
],
|
|
'canNotifyAgent' => true,
|
|
'category' => 'login-fail',
|
|
'group' => 'negative',
|
|
'presentation-model' => PresentationModel::class,
|
|
// fixme, what does this actually do?
|
|
'title-message' => 'loginnotify-login-fail',
|
|
'title-params' => [],
|
|
// FIXME Should count be a parameter
|
|
'email-subject-params' => [ 'agent', 'count' ],
|
|
'email-body-batch-params' => [ 'agent', 'count' ],
|
|
// FIXME is it ok not to set batch email messages, since
|
|
// we have immediate flag?
|
|
'icon' => 'LoginNotify-user-avatar',
|
|
'immediate' => true,
|
|
];
|
|
$notifications['login-fail-new'] = [
|
|
'bundle' => [
|
|
'web' => true,
|
|
'expandable' => false
|
|
]
|
|
] + $loginBase;
|
|
$notifications['login-fail-known'] = [
|
|
'bundle' => [
|
|
'web' => true,
|
|
'expandable' => false
|
|
]
|
|
] + $loginBase;
|
|
if ( $wgLoginNotifyEnableOnSuccess ) {
|
|
$notificationCategories['login-success'] = [
|
|
'priority' => 7,
|
|
'tooltip' => 'echo-pref-tooltip-login-success',
|
|
];
|
|
$notifications['login-success'] = [
|
|
'category' => 'login-success',
|
|
] + $loginBase;
|
|
$wgNotifyTypeAvailabilityByCategory['login-success'] = [
|
|
'web' => false,
|
|
'email' => true,
|
|
];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param EchoEvent $event
|
|
* @param string &$bundleString
|
|
*/
|
|
public function onEchoGetBundleRules( EchoEvent $event, string &$bundleString ) {
|
|
switch ( $event->getType() ) {
|
|
case 'login-fail-new':
|
|
$bundleString = 'login-fail';
|
|
break;
|
|
}
|
|
}
|
|
}
|