2016-05-05 13:05:03 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
|
|
|
|
use Language;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Html\Html;
|
|
|
|
use MediaWiki\Parser\Sanitizer;
|
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
2022-11-01 22:01:23 +00:00
|
|
|
|
2016-05-05 13:05:03 +00:00
|
|
|
class EchoHtmlEmailFormatter extends EchoEventFormatter {
|
|
|
|
|
2022-03-26 23:15:55 +00:00
|
|
|
public const PRIMARY_LINK_STYLE =
|
|
|
|
'cursor: pointer;' .
|
|
|
|
'text-align: center;' .
|
|
|
|
'text-decoration: none;' .
|
2022-03-26 23:24:01 +00:00
|
|
|
'padding: 6px 10px;' .
|
|
|
|
'border-radius: 2px;' .
|
2022-03-26 23:15:55 +00:00
|
|
|
'color: #FFF;' .
|
|
|
|
'background: #36C;' .
|
|
|
|
'font-family: Arial, Helvetica, sans-serif;' .
|
2022-03-26 23:24:01 +00:00
|
|
|
'font-weight: bold;' .
|
2022-03-26 23:15:55 +00:00
|
|
|
'font-size: 13px;';
|
|
|
|
|
|
|
|
public const SECONDARY_LINK_STYLE =
|
|
|
|
'text-decoration: none;' .
|
|
|
|
'font-size: 10px;' .
|
|
|
|
'font-family: Arial, Helvetica, sans-serif;' .
|
|
|
|
'color: #72777D;';
|
2016-05-05 13:05:03 +00:00
|
|
|
|
|
|
|
protected function formatModel( EchoEventPresentationModel $model ) {
|
|
|
|
$subject = $model->getSubjectMessage()->parse();
|
|
|
|
|
|
|
|
$intro = $model->getHeaderMessage()->parse();
|
|
|
|
|
|
|
|
$bodyMsg = $model->getBodyMessage();
|
|
|
|
$summary = $bodyMsg ? $bodyMsg->parse() : '';
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$actions = [];
|
2016-05-05 13:05:03 +00:00
|
|
|
|
2016-06-09 22:15:22 +00:00
|
|
|
$primaryLink = $model->getPrimaryLinkWithMarkAsRead();
|
2016-05-05 13:05:03 +00:00
|
|
|
if ( $primaryLink ) {
|
|
|
|
$actions[] = $this->renderLink( $primaryLink, self::PRIMARY_LINK_STYLE );
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ( array_filter( $model->getSecondaryLinks() ) as $secondaryLink ) {
|
|
|
|
$actions[] = $this->renderLink( $secondaryLink, self::SECONDARY_LINK_STYLE );
|
|
|
|
}
|
|
|
|
|
2019-04-17 00:30:17 +00:00
|
|
|
$iconUrl = wfExpandUrl(
|
|
|
|
EchoIcon::getRasterizedUrl( $model->getIconType(), $this->language->getCode() ),
|
|
|
|
PROTO_CANONICAL
|
|
|
|
);
|
2016-05-05 13:05:03 +00:00
|
|
|
|
|
|
|
$body = $this->renderBody(
|
|
|
|
$this->language,
|
|
|
|
$iconUrl,
|
|
|
|
$summary,
|
|
|
|
implode( " ", $actions ),
|
|
|
|
$intro,
|
|
|
|
$this->getFooter()
|
|
|
|
);
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
2016-05-05 13:05:03 +00:00
|
|
|
'body' => $body,
|
|
|
|
'subject' => $subject,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2016-05-05 13:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderBody( Language $lang, $emailIcon, $summary, $action, $intro, $footer ) {
|
|
|
|
$alignStart = $lang->alignStart();
|
2017-11-09 10:43:16 +00:00
|
|
|
$langCode = $lang->getHtmlCode();
|
2016-05-05 13:05:03 +00:00
|
|
|
$langDir = $lang->getDir();
|
|
|
|
|
|
|
|
$iconImgSrc = Sanitizer::encodeAttribute( $emailIcon );
|
|
|
|
|
2017-09-20 01:50:12 +00:00
|
|
|
global $wgCanonicalServer;
|
2018-08-25 10:51:14 +00:00
|
|
|
// phpcs:disable Generic.Files.LineLength
|
2016-05-05 13:05:03 +00:00
|
|
|
return <<< EOF
|
|
|
|
<html><head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
2022-11-01 22:01:23 +00:00
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
2016-05-05 13:05:03 +00:00
|
|
|
<style>
|
|
|
|
@media only screen and (max-width: 480px){
|
|
|
|
table[id="email-container"]{max-width:600px !important; width:100% !important;}
|
|
|
|
}
|
|
|
|
</style>
|
2017-09-20 01:50:12 +00:00
|
|
|
<base href="{$wgCanonicalServer}">
|
2016-05-05 13:05:03 +00:00
|
|
|
</head><body>
|
|
|
|
<table cellspacing="0" cellpadding="0" border="0" width="100%" align="center" lang="{$langCode}" dir="{$langDir}">
|
|
|
|
<tr>
|
2016-11-25 19:24:12 +00:00
|
|
|
<td bgcolor="#EAECF0"><center>
|
2016-05-05 13:05:03 +00:00
|
|
|
<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="{$iconImgSrc}" alt="" height="30" width="30"></td>
|
2016-11-25 19:24:12 +00:00
|
|
|
<td bgcolor="#FFFFFF" align="{$alignStart}" style="font-family: Arial, Helvetica, sans-serif; font-size:13px; line-height:20px; color:#72777D;">{$intro}</td>
|
2016-05-05 13:05:03 +00:00
|
|
|
<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>
|
2016-11-25 19:24:12 +00:00
|
|
|
<td bgcolor="#FFFFFF" align="{$alignStart}" style="font-family: Arial, Helvetica, sans-serif; padding-top: 8px; font-size:13px; font-weight: bold; color: #54595D;">
|
2016-05-05 13:05:03 +00:00
|
|
|
{$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>
|
2016-11-25 19:24:12 +00:00
|
|
|
<td align="{$alignStart}" style="font-family: Arial, Helvetica, sans-serif; font-size:10px; line-height:13px; color:#72777D; padding:10px 20px;"><br />
|
2016-05-05 13:05:03 +00:00
|
|
|
{$footer}
|
|
|
|
<br /><br />
|
|
|
|
</td>
|
|
|
|
<td> </td>
|
|
|
|
</tr><tr>
|
|
|
|
<td colspan="4"> </td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<br><br></center>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</body></html>
|
|
|
|
EOF;
|
2018-08-25 10:51:14 +00:00
|
|
|
// phpcs:enable Generic.Files.LineLength
|
2016-05-05 13:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFooter() {
|
|
|
|
global $wgEchoEmailFooterAddress;
|
|
|
|
|
2016-05-18 20:59:30 +00:00
|
|
|
$preferenceLink = $this->renderLink(
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2018-08-25 10:51:14 +00:00
|
|
|
'label' => $this->msg( 'echo-email-html-footer-preference-link-text', $this->user )
|
|
|
|
->text(),
|
|
|
|
'url' => SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo' )
|
|
|
|
->getFullURL( '', false, PROTO_CANONICAL ),
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
2016-11-25 19:24:12 +00:00
|
|
|
'text-decoration: none; color: #36C;'
|
2016-05-18 20:59:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$footer = $this->msg( 'echo-email-html-footer-with-link' )
|
|
|
|
->rawParams( $preferenceLink )
|
2016-12-28 16:43:40 +00:00
|
|
|
->params( $this->user )
|
2016-05-18 20:59:30 +00:00
|
|
|
->parse();
|
|
|
|
|
|
|
|
if ( $wgEchoEmailFooterAddress ) {
|
|
|
|
$footer .= '<br />' . $wgEchoEmailFooterAddress;
|
|
|
|
}
|
2016-05-05 13:05:03 +00:00
|
|
|
|
2016-05-18 20:59:30 +00:00
|
|
|
return $footer;
|
2016-05-05 13:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderLink( $link, $style ) {
|
|
|
|
return Html::element(
|
|
|
|
'a',
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2016-05-18 14:57:01 +00:00
|
|
|
'href' => wfExpandUrl( $link['url'], PROTO_CANONICAL ),
|
2016-05-05 13:05:03 +00:00
|
|
|
'style' => $style,
|
2016-12-05 18:51:07 +00:00
|
|
|
],
|
2016-05-05 13:05:03 +00:00
|
|
|
$link['label']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|