From d7f69cbab065b1328a036e5c7564ad86cb8692d9 Mon Sep 17 00:00:00 2001 From: niharika29 Date: Fri, 7 Apr 2017 21:48:57 +0000 Subject: [PATCH] Bundle notifications and show a single header message Bug: T162104 Change-Id: I6056098de7947dc450efdbbce6e42638bec4e2fd --- LoginNotify.hooks.php | 22 ++++++++++++++++++++-- LoginNotifyPresentationModel.php | 21 +++++++++++++-------- extension.json | 3 +++ i18n/en.json | 9 +++++---- i18n/qqq.json | 9 +++++---- 5 files changed, 46 insertions(+), 18 deletions(-) diff --git a/LoginNotify.hooks.php b/LoginNotify.hooks.php index 0831d17..3c9c706 100644 --- a/LoginNotify.hooks.php +++ b/LoginNotify.hooks.php @@ -57,10 +57,18 @@ class LoginNotifyHooks { 'immediate' => true, ]; $notifications['login-fail-new'] = [ - 'email-body-batch-message' => 'notification-loginnotify-login-fail-new-emailbatch' + 'email-body-batch-message' => 'notification-loginnotify-login-fail-new-emailbatch', + 'bundle' => [ + 'web' => true, + 'expandable' => false + ] ] + $loginBase; $notifications['login-fail-known'] = [ - 'email-body-batch-message' => 'notification-loginnotify-login-fail-known-emailbatch' + 'email-body-batch-message' => 'notification-loginnotify-login-fail-known-emailbatch', + 'bundle' => [ + 'web' => true, + 'expandable' => false + ] ] + $loginBase; if ( $wgLoginNotifyEnableOnSuccess ) { $notificationCategories['login-success'] = [ @@ -79,6 +87,16 @@ class LoginNotifyHooks { return true; } + public static function onEchoGetBundleRules( $event, &$bundleString ) { + switch ( $event->getType() ) { + case 'login-fail-known': + case 'login-fail-new': + $bundleString = 'login-fail'; + break; + } + return true; + } + /** * Old hook for pre 1.27 or wikis with auth manager disabled. * diff --git a/LoginNotifyPresentationModel.php b/LoginNotifyPresentationModel.php index cf1e2cd..3997c63 100644 --- a/LoginNotifyPresentationModel.php +++ b/LoginNotifyPresentationModel.php @@ -22,17 +22,22 @@ class LoginNotifyPresentationModel extends EchoEventPresentationModel { /** * Include the number of attempts in the message * - * (For grep) This uses i18n messages: - * notification-header-login-fail-known - * notification-header-login-fail-new - * notification-header-login-success - * * @return Message */ public function getHeaderMessage() { - return parent::getHeaderMessage()->numParams( - $this->event->getExtraParam( 'count', 0 ) - ); + // Check if we got a bundled notification with a 'count' param + // 'count' param is set when we have a failed login attempt + if ( $this->isBundled() && ( $this->event->getExtraParam( 'count', 0 ) > 0 ) ) { + $msg = $this->msg( 'notification-bundled-header-login-fail' ); + $msg->params( $this->event->getExtraParam( 'count', 0 ) ); + return $msg; + } elseif ( $this->event->getExtraParam( 'count', 0 ) > 0 ) { + $msg = $this->msg( 'notification-unbundled-header-login-fail' ); + return $msg; + } else { + $msg = $this->msg( 'notification-header-login-success' ); + return $msg; + } } /** diff --git a/extension.json b/extension.json index fb3933e..305da8a 100644 --- a/extension.json +++ b/extension.json @@ -33,6 +33,9 @@ "BeforeCreateEchoEvent": [ "LoginNotifyHooks::onBeforeCreateEchoEvent" ], + "EchoGetBundleRules": [ + "LoginNotifyHooks::onEchoGetBundleRules" + ], "LoginAuthenticateAudit": [ "LoginNotifyHooks::onLoginAuthenticateAudit" ], diff --git a/i18n/en.json b/i18n/en.json index 61e5992..bc9d9f6 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -2,7 +2,8 @@ "@metadata": { "authors": [ "Brian Wolff", - "MusikAnimal" + "MusikAnimal", + "Niharika" ] }, "loginnotify-desc": "Notify users about suspicious logins", @@ -13,10 +14,10 @@ "loginnotify-login-fail": "There have been several failed attempts to log in to your account", "notification-loginnotify-login-fail-email-subject": "{{PLURAL:$2|Failed attempt|Multiple failed attempts}} to log in to {{SITENAME}} as $1", "notification-loginnotify-login-success-email-subject": "Login to {{SITENAME}} as $1 from a computer you have not recently used", - "notification-header-login-fail-known": "There {{PLURAL:$3|has been '''one failed attempt'''|have been '''$3 failed attempts'''}} to log in to your account since the last time you logged in. If this was you, then you can disregard this message. If it wasn't, please make sure your account has a strong password.", - "notification-header-login-fail-new": "There {{PLURAL:$3|has been '''one failed attempt'''|have been '''$3 failed attempts'''}} to log in to your account since the last time you logged in. If this was you, then you can disregard this message. If it wasn't, please make sure your account has a strong password.", "notification-header-login-success": "Someone has successfully logged into your account from a computer which you have not edited from recently.", "notification-loginnotify-login-fail-new-emailbatch": "There {{PLURAL:$2|has been a failed attempt|have been $2 failed attempts}} to log in to your account '$1' on {{SITENAME}}. If this was you, then you can disregard this message. If it wasn't, please make sure your account has a strong password.", "notification-loginnotify-login-fail-known-emailbatch": "There {{PLURAL:$2|has been a failed attempt|have been $2 failed attempts}} to log in to your account, '$1' on {{SITENAME}}. If this was you, then you can disregard this message. If it wasn't, please make sure your account has a strong password.", - "notification-loginnotify-login-success-emailbatch": "Someone has successfully logged into your account '$1' on {{SITENAME}} from a computer which you have not edited from recently." + "notification-loginnotify-login-success-emailbatch": "Someone has successfully logged into your account '$1' on {{SITENAME}} from a computer which you have not edited from recently.", + "notification-bundled-header-login-fail": "There have been '''$1 failed attempts''' to login to your account since the last time you logged in. If this was you, then you can disregard this message. If it wasn't, please make sure your account has a strong password.", + "notification-unbundled-header-login-fail": "There have been multiple failed login attempts to your account. Please make sure your account has a strong password." } diff --git a/i18n/qqq.json b/i18n/qqq.json index b6fe6f9..a38b862 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -1,7 +1,8 @@ { "@metadata": { "authors": [ - "Brian Wolff" + "Brian Wolff", + "Niharika" ] }, "loginnotify-desc": "{{desc|name=LoginNotify|url=https://www.mediawiki.org/wiki/Extension:LoginNotify}}", @@ -12,10 +13,10 @@ "loginnotify-login-fail": "FIXME I have no idea where this message is used.\n{{notranslate}}", "notification-loginnotify-login-fail-email-subject": "Email subject line for email notice that there have been failed login attempts for the user's account. $1 is the user in question.", "notification-loginnotify-login-success-email-subject": "Email subject line for email notice that someone has logged in to the user's account from a computer that has not previously been used. $1 is the user in question.", - "notification-header-login-fail-known": "Text of notification for failed login attempt from a known computer. This is shown in the user's echo notifications, and is emailed to the user.\n* $1 = Username for account, formatted for display\n* $2 = Username for account, unformatted for use in GENDER\n* $3 = Number of failed login attempts so far", - "notification-header-login-fail-new": "Text of notification for failed login attempt from a computeri that is not recognized. This is shown in the user's echo notifications, and is emailed to the user.\n* $1 = Username for account, formatted for display\n* $2 = Username for account, unformatted for use in GENDER\n* $3 = Number of failed login attempts so far", "notification-header-login-success": "Text of notification for when someone successfully logs in as the current account from a computer that has not been previously used by that account. This is shown in the user's echo notifications, and is possibly emailed to the user.\n* $1 = Username for account, formatted for display\n* $2 = Username for account, unformatted for use in GENDER", "notification-loginnotify-login-fail-new-emailbatch": "Body of email notification that someone from a computer not previously used by the user has attempted and failed to log into the user's account. Subject of Message is {{msg-mw|notification-loginnotify-login-fail-email-subject}}. $1 is account name. $2 is the number of attempts", "notification-loginnotify-login-fail-known-emailbatch": "Body of email notification that someone from a computer which has been previously used by the user has attempted and failed to log into the user's account. Subject of Message is {{msg-mw|notification-loginnotify-login-fail-email-subject}}. $1 is account name. $2 is the number of attempts", - "notification-loginnotify-login-success-emailbatch": "Body of email notification that someone from a computer not previously used by the user has succesfully logged into the user's account. Subject of Message is {{msg-mw|notification-loginnotify-login-success-email-subject}}. $1 is account name." + "notification-loginnotify-login-success-emailbatch": "Body of email notification that someone from a computer not previously used by the user has succesfully logged into the user's account. Subject of Message is {{msg-mw|notification-loginnotify-login-success-email-subject}}. $1 is account name.", + "notification-bundled-header-login-fail": "Message string shown for bundled notifications", + "notification-unbundled-header-login-fail": "Message string shown for individual notifications when the bundle disperses" }