mediawiki-extensions-Echo/includes/formatters/EchoPlainTextEmailFormatter.php
James D. Forrester 8c810dff48 build: Update mediawiki/mediawiki-codesniffer to 0.7.1
Also added "composer fix" command.

Change-Id: I25cb61b3b92798f1259d1575a336e2b056d5764f
2016-12-05 15:54:30 -08:00

55 lines
1.5 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->getPrimaryLinkWithMarkAsRead();
$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 [
'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;
}
}