Sbisson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/287078
Change subject: HTML email formatter using presentation model
......................................................................
HTML email formatter using presentation model
Bug: T121067
Change-Id: I77f466f0b507ffa49a9714ddba95bea8db1d8438
---
M autoload.php
M i18n/en.json
M i18n/qqq.json
M includes/EmailBatch.php
M includes/EmailFormatter.php
M includes/Notifier.php
M includes/formatters/BasicFormatter.php
A includes/formatters/EchoHtmlEmailFormatter.php
M includes/formatters/EchoPlainTextEmailFormatter.php
M includes/formatters/EditUserTalkPresentationModel.php
M tests/phpunit/EmailFormatterTest.php
11 files changed, 171 insertions(+), 23 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/78/287078/1
diff --git a/autoload.php b/autoload.php
index 2d5f7ab..02d4647 100644
--- a/autoload.php
+++ b/autoload.php
@@ -54,7 +54,7 @@
'EchoForeignNotifications' => __DIR__ .
'/includes/ForeignNotifications.php',
'EchoForeignPresentationModel' => __DIR__ .
'/includes/formatters/EchoForeignPresentationModel.php',
'EchoHTMLEmailDecorator' => __DIR__ . '/includes/EmailFormatter.php',
- 'EchoHTMLEmailFormatter' => __DIR__ . '/includes/EmailFormatter.php',
+ 'LegacyEchoHTMLEmailFormatter' => __DIR__ .
'/includes/EmailFormatter.php',
'EchoHooks' => __DIR__ . '/Hooks.php',
'EchoIteratorDecorator' => __DIR__ .
'/includes/iterator/IteratorDecorator.php',
'EchoLocalCache' => __DIR__ . '/includes/cache/LocalCache.php',
@@ -79,6 +79,7 @@
'EchoPresentationModelSectionTrait' => __DIR__ .
'/includes/formatters/PresentationModelSectionTrait.php',
'EchoPlainTextDigestEmailFormatter' => __DIR__ .
'/includes/formatters/EchoPlainTextDigestEmailFormatter.php',
'EchoPlainTextEmailFormatter' => __DIR__ .
'/includes/formatters/EchoPlainTextEmailFormatter.php',
+ 'EchoHtmlEmailFormatter' => __DIR__ .
'/includes/formatters/EchoHtmlEmailFormatter.php',
'EchoRevertedPresentationModel' => __DIR__ .
'/includes/formatters/RevertedPresentationModel.php',
'EchoRevisionLocalCache' => __DIR__ .
'/includes/cache/RevisionLocalCache.php',
'EchoSeenTime' => __DIR__ . '/includes/SeenTime.php',
diff --git a/i18n/en.json b/i18n/en.json
index 267c17b..dbcffd7 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -191,7 +191,7 @@
"echo-email-body-default": "You have a new notification at
{{SITENAME}}:\n\n$1",
"echo-email-batch-body-default": "You have a new notification.",
"echo-email-plain-footer": "To control which emails we send you, check
your preferences:",
- "echo-email-footer-default-html": "To control which emails we send you,
<a href=\"$2\" style=\"text-decoration:none; color: #3868B0;\">check your
preferences</a>.<br />\n$1",
+ "echo-email-html-footer": "To control which emails we send you, <a
href=\"$2\" style=\"text-decoration:none; color: #3868B0;\">check your
preferences</a>.<br />\n$1",
"echo-notification-alert": "{{PLURAL:$1|Alert ($1)|Alerts
($1)|100=Alerts (99+)}}",
"echo-notification-message": "{{PLURAL:$1|Message ($1)|Messages
($1)|100=Messages (99+)}}",
"echo-notification-alert-text-only": "Alerts",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 95f595f..7fbdf14 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -181,8 +181,8 @@
"echo-email-subject-default": "Default subject for Echo e-mail
notifications",
"echo-email-body-default": "Default message content for Echo email
notifications. Parameters:\n* $1 - a plain text description of the
notification",
"echo-email-batch-body-default": "Default message for Echo e-mail
digest notifications",
- "echo-email-plain-footer": "Footer content for Echo text e-mail
notifications.\n\nFor HTML version, see
{{msg-mw|echo-email-footer-default-html}}.",
- "echo-email-footer-default-html": "Default footer content for Echo html
e-mail notifications. Parameters:\n* $1 - the address of the organization that
sent the email\n* $2 - the URL to the notification preference page\nFor
plain-text version, see {{msg-mw|Echo-email-footer-default}}.",
+ "echo-email-plain-footer": "Footer content for Echo text e-mail
notifications.\n\nFor HTML version, see {{msg-mw|echo-email-html-footer}}.",
+ "echo-email-html-footer": "Default footer content for Echo html e-mail
notifications. Parameters:\n* $1 - the address of the organization that sent
the email\n* $2 - the URL to the notification preference page\nFor plain-text
version, see {{msg-mw|Echo-email-footer-default}}.",
"echo-notification-alert": "Label for alert notifications (= non
discussion notifications) tab in Echo overlay. Parameters:\n* $1 - the number
of unread alerts. The number cannot be higher than 100.\nSee also:\n*
{{msg-mw|Echo-notification-message}}\n{{Identical|Alert}}",
"echo-notification-message": "Label for message notifications (=
discussion notifications) tab in Echo overlay. Parameters:\n* $1 - the number
of unread messages. The number cannot be higher than 100.\nSee also:\n*
{{msg-mw|Echo-notification-alert}}\n{{Identical|Message}}",
"echo-notification-alert-text-only": "Label for alert notifications (=
non discussion notifications) tab in Echo overlay without alert notification
count next to it\n{{Identical|Alert}}",
diff --git a/includes/EmailBatch.php b/includes/EmailBatch.php
index 2635323..6329a8d 100644
--- a/includes/EmailBatch.php
+++ b/includes/EmailBatch.php
@@ -268,7 +268,7 @@
}
$emailDigest = new EchoEmailDigest( $this->mUser,
$formattedEvents, $frequency );
- $htmlEmailFormatter = new EchoHTMLEmailFormatter(
$emailDigest );
+ $htmlEmailFormatter = new LegacyEchoHTMLEmailFormatter(
$emailDigest );
$multipartBody = array(
'text' => $content['body'],
'html' => $htmlEmailFormatter->formatEmail(),
diff --git a/includes/EmailFormatter.php b/includes/EmailFormatter.php
index 1e65dc6..2b79bd1 100644
--- a/includes/EmailFormatter.php
+++ b/includes/EmailFormatter.php
@@ -66,7 +66,7 @@
/**
* Formatter class for formatting HTML email notification
*/
-class EchoHTMLEmailFormatter extends EchoEmailFormatter {
+class LegacyEchoHTMLEmailFormatter extends EchoEmailFormatter {
/**
* @param $emailMode EchoEmailMode
diff --git a/includes/Notifier.php b/includes/Notifier.php
index c93c997..965d562 100644
--- a/includes/Notifier.php
+++ b/includes/Notifier.php
@@ -121,13 +121,20 @@
*/
private static function generateEmail( EchoEvent $event, User $user ) {
$emailFormat = MWEchoNotifUser::newFromUser( $user
)->getEmailFormat();
- if ( $emailFormat === EchoHooks::EMAIL_FORMAT_PLAIN_TEXT ) {
- $lang = wfGetLangObj( $user->getOption( 'language' ) );
- $formatter = new EchoPlainTextEmailFormatter( $user,
$lang );
- return $formatter->format( $event );
- } else {
- // @todo get rid of this
- return EchoNotificationController::formatNotification(
$event, $user, 'email', 'email' );
+ $lang = wfGetLangObj( $user->getOption( 'language' ) );
+ $formatter = new EchoPlainTextEmailFormatter( $user, $lang );
+ $content = $formatter->format( $event );
+
+ if ( $emailFormat === EchoHooks::EMAIL_FORMAT_HTML ) {
+ $htmlEmailFormatter = new EchoHtmlEmailFormatter(
$user, $lang );
+ $htmlContent = $htmlEmailFormatter->format( $event );
+ $multipartBody = array(
+ 'text' => $content['body'],
+ 'html' => $htmlContent['body']
+ );
+ $content['body'] = $multipartBody;
}
+
+ return $content;
}
}
diff --git a/includes/formatters/BasicFormatter.php
b/includes/formatters/BasicFormatter.php
index a9b07ba..277a8ce 100644
--- a/includes/formatters/BasicFormatter.php
+++ b/includes/formatters/BasicFormatter.php
@@ -252,7 +252,7 @@
);
$format = MWEchoNotifUser::newFromUser( $user
)->getEmailFormat();
if ( $format == EchoHooks::EMAIL_FORMAT_HTML ) {
- $htmlEmailFormatter = new EchoHTMLEmailFormatter(
$emailSingle );
+ $htmlEmailFormatter = new LegacyEchoHTMLEmailFormatter(
$emailSingle );
$outputFormat = $this->outputFormat;
$this->setOutputFormat( 'htmlemail' );
// Add single email html body if user prefers html
format
diff --git a/includes/formatters/EchoHtmlEmailFormatter.php
b/includes/formatters/EchoHtmlEmailFormatter.php
new file mode 100644
index 0000000..2dcfe6c
--- /dev/null
+++ b/includes/formatters/EchoHtmlEmailFormatter.php
@@ -0,0 +1,136 @@
+<?php
+
+class EchoHtmlEmailFormatter extends EchoEventFormatter {
+
+ const PRIMARY_LINK_STYLE = 'cursor:pointer; text-align:center;
text-decoration:none; padding:.45em 0.6em .45em; color:#D9EEF7;
background:#3366BB; font-family: Arial, Helvetica, sans-serif;font-size: 13px;';
+ const SECONDARY_LINK_STYLE = 'text-decoration: none;font-size:
10px;font-family: Arial, Helvetica, sans-serif; color: #808184;';
+
+ protected function formatModel( EchoEventPresentationModel $model ) {
+
+ $subject = $model->getSubjectMessage()->parse();
+
+ $intro = $model->getHeaderMessage()->parse();
+
+ $summary = $model->getBodyMessage()->parse();
+
+ $actions = array();
+ $actions[] = $this->renderLink( $model->getPrimaryLink(),
self::PRIMARY_LINK_STYLE );
+ foreach ( $model->getSecondaryLinks() as $secondaryLink ) {
+ $actions[] = $this->renderLink( $secondaryLink,
self::SECONDARY_LINK_STYLE );
+ }
+
+ $iconUrl = EchoNotificationFormatter::getIconUrl(
$model->getIconType(), $this->language->getDir() );
+
+ $body = $this->renderBody(
+ $this->language,
+ $iconUrl,
+ $summary,
+ implode( " ", $actions ),
+ $intro,
+ $this->getFooter()
+ );
+
+ return array(
+ 'body' => $body,
+ 'subject' => $subject,
+ );
+ }
+
+ private function renderBody( Language $lang, $emailIcon, $summary,
$action, $intro, $footer ) {
+ $alignStart = $lang->alignStart();
+ $langCode = $lang->getCode();
+ $langDir = $lang->getDir();
+
+ return <<< EOF
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0"
/>
+ <style>
+ @media only screen and (max-width: 480px){
+ table[id="email-container"]{max-width:600px !important;
width:100% !important;}
+ }
+ </style>
+</head><body>
+<table cellspacing="0" cellpadding="0" border="0" width="100%" align="center"
lang="{$langCode}" dir="{$langDir}">
+<tr>
+ <td bgcolor="#E6E7E8"><center>
+ <br /><br />
+ <table cellspacing="0" cellpadding="0" border="0" width="600"
id="email-container">
+ <tr>
+ <td bgcolor="#FFFFFF" width="5%"> </td>
+ <td bgcolor="#FFFFFF" width="10%"> </td>
+ <td bgcolor="#FFFFFF" width="80%"
style="line-height:40px;"> </td>
+ <td bgcolor="#FFFFFF" width="5%"> </td>
+ </tr><tr>
+ <td bgcolor="#FFFFFF" rowspan="2"> </td>
+ <td bgcolor="#FFFFFF" align="center"
valign="top" rowspan="2"><img src="{$emailIcon}" alt="" height="30"
width="30"></td>
+ <td bgcolor="#FFFFFF" align="{$alignStart}"
style="font-family: Arial, Helvetica, sans-serif; font-size:13px;
line-height:20px; color:#6D6E70;">{$intro}</td>
+ <td bgcolor="#FFFFFF" rowspan="2"> </td>
+ </tr><tr>
+ <td bgcolor="#FFFFFF" align="{$alignStart}"
style="font-family: Arial, Helvetica, sans-serif; line-height: 20px;
font-weight: 600;">
+ <table cellspacing="0" cellpadding="0"
border="0">
+ <tr>
+ <td bgcolor="#FFFFFF"
align="{$alignStart}" style="font-family: Arial, Helvetica, sans-serif;
padding-top: 8px; font-size:13px; font-weight: bold; color: #58585B;">
+ {$summary}
+ </td>
+ </tr>
+ </table>
+ <table cellspacing="0" cellpadding="0"
border="0">
+ <tr>
+ <td bgcolor="#FFFFFF"
align="{$alignStart}" style="font-family: Arial, Helvetica, sans-serif;
font-size:14px; padding-top: 25px;">
+ {$action}
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr><tr>
+ <td bgcolor="#FFFFFF"> </td>
+ <td bgcolor="#FFFFFF"> </td>
+ <td bgcolor="#FFFFFF"
style="line-height:40px;"> </td>
+ <td bgcolor="#FFFFFF"> </td>
+ </tr><tr>
+ <td> </td>
+ <td> </td>
+ <td align="{$alignStart}" style="font-family:
Arial, Helvetica, sans-serif; font-size:10px; line-height:13px; color:#6D6E70;
padding:10px 20px;"><br />
+ {$footer}
+ <br /><br />
+ </td>
+ <td> </td>
+ </tr><tr>
+ <td colspan="4"> </td>
+ </tr>
+ </table>
+ <br><br></center>
+ </td>
+</tr>
+</table>
+</body></html>
+EOF;
+ }
+
+ /**
+ * @return string
+ */
+ public function getFooter() {
+ global $wgEchoEmailFooterAddress;
+
+ $prefsUrl = SpecialPage::getTitleFor( 'Preferences', false,
'mw-prefsection-echo' )
+ ->getFullURL( '', false, PROTO_CANONICAL );
+
+ return wfMessage( 'echo-email-html-footer' )
+ ->inLanguage( $this->language )
+ ->params( $wgEchoEmailFooterAddress, $prefsUrl )
+ ->text();
+ }
+
+ private function renderLink( $link, $style ) {
+ return Html::element(
+ 'a',
+ array(
+ 'href' => $link['url'],
+ 'style' => $style,
+ ),
+ $link['label']
+ );
+ }
+}
diff --git a/includes/formatters/EchoPlainTextEmailFormatter.php
b/includes/formatters/EchoPlainTextEmailFormatter.php
index 9d7d819..cd99ba1 100644
--- a/includes/formatters/EchoPlainTextEmailFormatter.php
+++ b/includes/formatters/EchoPlainTextEmailFormatter.php
@@ -5,31 +5,31 @@
$subject = EchoDiscussionParser::htmlToText(
$model->getSubjectMessage()->parse() );
- $text = EchoDiscussionParser::htmlToText(
$model->getHeaderMessage()->parse() );
+ $body = EchoDiscussionParser::htmlToText(
$model->getHeaderMessage()->parse() );
- $text .= "\n\n";
+ $body .= "\n\n";
$bodyMsg = $model->getBodyMessage();
if ( $bodyMsg ) {
- $text .= EchoDiscussionParser::htmlToText(
$bodyMsg->parse() );
+ $body .= EchoDiscussionParser::htmlToText(
$bodyMsg->parse() );
}
$primaryLink = $model->getPrimaryLink();
$primaryUrl = wfExpandUrl( $primaryLink['url'], PROTO_CANONICAL
);
$colon = $this->msg( 'colon-separator' )->text();
- $text .= "\n\n{$primaryLink['label']}$colon <$primaryUrl>";
+ $body .= "\n\n{$primaryLink['label']}$colon <$primaryUrl>";
foreach ( array_filter( $model->getSecondaryLinks() ) as
$secondaryLink ) {
$url = wfExpandUrl( $secondaryLink['url'],
PROTO_CANONICAL );
- $text .= "\n\n{$secondaryLink['label']}$colon <$url>";
+ $body .= "\n\n{$secondaryLink['label']}$colon <$url>";
}
// Footer
- $text .= "\n\n{$this->getFooter()}";
+ $body .= "\n\n{$this->getFooter()}";
return array(
- 'body' => $text,
+ 'body' => $body,
'subject' => $subject,
);
}
diff --git a/includes/formatters/EditUserTalkPresentationModel.php
b/includes/formatters/EditUserTalkPresentationModel.php
index 308161c..038f16a 100644
--- a/includes/formatters/EditUserTalkPresentationModel.php
+++ b/includes/formatters/EditUserTalkPresentationModel.php
@@ -82,4 +82,8 @@
$firstNotificationRevId = end( $events )->getExtraParam(
'revid' );
return $this->event->getTitle()->getPreviousRevisionID(
$firstNotificationRevId );
}
+
+ protected function getSubjectMessageKey() {
+ return 'notification-edit-talk-page-email-subject2';
+ }
}
diff --git a/tests/phpunit/EmailFormatterTest.php
b/tests/phpunit/EmailFormatterTest.php
index 75e2b70..2dd988f 100644
--- a/tests/phpunit/EmailFormatterTest.php
+++ b/tests/phpunit/EmailFormatterTest.php
@@ -39,7 +39,7 @@
$this->assertRegExp( $pattern,
$this->emailSingle->getTextTemplate() );
$this->assertEquals( 0, preg_match( $pattern,
$textFormatter->formatEmail() ) );
- $htmlFormatter = new EchoHTMLEmailFormatter( $this->emailSingle
);
+ $htmlFormatter = new LegacyEchoHTMLEmailFormatter(
$this->emailSingle );
$this->assertRegExp( $pattern,
$this->emailSingle->getHTMLTemplate() );
$this->assertEquals( 0, preg_match( $pattern,
$htmlFormatter->formatEmail() ) );
@@ -48,7 +48,7 @@
$this->assertRegExp( $pattern,
$this->emailSingle->getTextTemplate() );
$this->assertEquals( 0, preg_match( $pattern,
$textFormatter->formatEmail() ) );
- $htmlFormatter = new EchoHTMLEmailFormatter( $this->emailDigest
);
+ $htmlFormatter = new LegacyEchoHTMLEmailFormatter(
$this->emailDigest );
$this->assertRegExp( $pattern,
$this->emailSingle->getHTMLTemplate() );
$this->assertEquals( 0, preg_match( $pattern,
$htmlFormatter->formatEmail() ) );
}
--
To view, visit https://gerrit.wikimedia.org/r/287078
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I77f466f0b507ffa49a9714ddba95bea8db1d8438
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Sbisson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits