mediawiki-extensions-Echo/includes/formatters/EchoPlainTextEmailFormatter.php
Kunal Mehta b6f742bc46 Add plain text email formatter
Formatters based on presentation models for
individual event emails and digest (daily, weekly)
plain text emails.

Bug: T121067
Change-Id: I4eceaf521315adab7429a8a73ffca70ebcddab86
2016-05-04 13:35:37 -04:00

55 lines
1.4 KiB
PHP

<?php
class EchoPlainTextEmailFormatter extends EchoEventFormatter {
protected function formatModel( EchoEventPresentationModel $model ) {
$subject = EchoDiscussionParser::htmlToText( $model->getSubjectMessage()->parse() );
$text = EchoDiscussionParser::htmlToText( $model->getHeaderMessage()->parse() );
$text .= "\n\n";
$bodyMsg = $model->getBodyMessage();
if ( $bodyMsg ) {
$text .= 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>";
foreach ( array_filter( $model->getSecondaryLinks() ) as $secondaryLink ) {
$url = wfExpandUrl( $secondaryLink['url'], PROTO_CANONICAL );
$text .= "\n\n{$secondaryLink['label']}$colon <$url>";
}
// Footer
$text .= "\n\n{$this->getFooter()}";
return array(
'body' => $text,
'subject' => $subject,
);
}
/**
* @return string
*/
public function getFooter() {
global $wgEchoEmailFooterAddress;
$footerMsg = $this->msg( 'echo-email-plain-footer' )->text();
$prefsUrl = SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo' )
->getFullURL( '', false, PROTO_CANONICAL );
$text = "--\n\n$footerMsg\n$prefsUrl";
if ( strlen( $wgEchoEmailFooterAddress ) ) {
$text .= "\n\n$wgEchoEmailFooterAddress";
}
return $text;
}
}