From 09928f1ed20035d36b02cfde0000b2951dbfbbfb Mon Sep 17 00:00:00 2001 From: Stephane Bisson Date: Wed, 10 Feb 2016 17:09:41 -0500 Subject: [PATCH] Add email body preview to emailuser notification when the subject line is left with the default generated value, we take the begining of the email content to add a preview in the notification. Bug: T121831 Change-Id: Ib7c646f6709c7100ef51186f84fe14807d6a211a --- Hooks.php | 11 ++++++++++- i18n/en.json | 2 +- i18n/qqq.json | 2 +- includes/formatters/EmailUserPresentationModel.php | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Hooks.php b/Hooks.php index f154bcb9c..e37695de7 100644 --- a/Hooks.php +++ b/Hooks.php @@ -1050,6 +1050,8 @@ class EchoHooks { * @return bool true in all cases */ public static function onEmailUserComplete( $address, $from, $subject, $text ) { + global $wgContLang; + if ( $from->name === $address->name ) { // nothing to notify return true; @@ -1057,11 +1059,18 @@ class EchoHooks { $userTo = User::newFromName( $address->name ); $userFrom = User::newFromName( $from->name ); + $autoSubject = wfMessage( 'defemailsubject', $from->name )->inContentLanguage()->text(); + if ( $subject === $autoSubject ) { + $preview = $wgContLang->truncate( $text, 125 ); + } else { + $preview = $subject; + } + EchoEvent::create( array( 'type' => 'emailuser', 'extra' => array( 'to-user-id' => $userTo->getId(), - 'subject' => $subject, + 'preview' => $preview, ), 'agent' => $userFrom, ) ); diff --git a/i18n/en.json b/i18n/en.json index a38b691ee..2142c0318 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -107,7 +107,7 @@ "notification-body-reverted": "$1", "notification-emailuser": "[[User:$1|$1]] {{GENDER:$1|sent}} you an email.", "notification-header-emailuser": "$1 {{GENDER:$2|sent}} you an email.", - "notification-body-email-user": "$1", + "notification-body-emailuser": "$1", "notification-edit-talk-page-email-subject2": "$1 {{GENDER:$1|left}} you a message on {{SITENAME}}", "notification-edit-talk-page-email-batch-body2": "$1 {{GENDER:$1|left}} a message on your talk page.", "notification-edit-talk-page-email-batch-body-with-section": "$1 {{GENDER:$1|left}} a message on your talk page in \"$2\".", diff --git a/i18n/qqq.json b/i18n/qqq.json index 07df54def..bfaf53dc2 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -128,7 +128,7 @@ "notification-body-reverted": "{{notranslate}}", "notification-emailuser": "Format for displaying notifications of a user has sent an email to another user. Parameters:\n* $1 - the username of the person the email, plain text. Can be used for GENDER.", "notification-header-emailuser": "Flyout-specific format for displaying notifications of user has sent an email to another user.\n\nParameters:\n* $1 - the formatted username of the person who sent the email.\n* $2 - the username for GENDER.", - "notification-body-email-user": "{{notranslate}}", + "notification-body-emailuser": "{{notranslate}}", "notification-edit-talk-page-email-subject2": "Email subject. Parameters:\n* $1 - a username which can be used for gender support", "notification-edit-talk-page-email-batch-body2": "First line of the email notification for a talk page edit. The following line completes it with the description of the message in question, that is its edit summary.\n\nParameters:\n* $1 - a username (which also links to the userpage of the user in question, in the HTML version)\nSee also:\n* {{msg-mw|Notification-edit-talk-page2}}\n* {{msg-mw|Notification-edit-talk-page-email-subject2}}\n* {{msg-mw|Notification-edit-talk-page-flyout2}}", "notification-edit-talk-page-email-batch-body-with-section": "Email notification for talk page edit with new section or new comment. Parameters:\n* $1 - a username\n* $2 - the raw section title text", diff --git a/includes/formatters/EmailUserPresentationModel.php b/includes/formatters/EmailUserPresentationModel.php index aef5fab1b..eeaf2a12c 100644 --- a/includes/formatters/EmailUserPresentationModel.php +++ b/includes/formatters/EmailUserPresentationModel.php @@ -15,7 +15,7 @@ class EchoEmailUserPresentationModel extends EchoEventPresentationModel { } public function getBodyMessage() { - $subject = $this->event->getExtraParam( 'subject' ); - return $subject ? $this->msg( 'notification-body-email-user' )->plaintextParams( $subject ) : false; + $preview = $this->event->getExtraParam( 'preview' ); + return $preview ? $this->msg( 'notification-body-emailuser' )->plaintextParams( $preview ) : false; } }