mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-25 00:05:29 +00:00
e649551e5e
* preg_match_all already returns the number of matches. We can just use this number instead of counting it. * Checking for a strlen() of 0 is a little tooo expressive, because we don't really care about the actual length of the string. Change-Id: I0537a7740e5d369b79364f24aecf71c4e8fa7db1
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
class EchoPlainTextEmailFormatter extends EchoEventFormatter {
|
|
protected function formatModel( EchoEventPresentationModel $model ) {
|
|
$subject = Sanitizer::stripAllTags( $model->getSubjectMessage()->parse() );
|
|
|
|
$text = Sanitizer::stripAllTags( $model->getHeaderMessage()->parse() );
|
|
|
|
$text .= "\n\n";
|
|
|
|
$bodyMsg = $model->getBodyMessage();
|
|
if ( $bodyMsg ) {
|
|
$text .= Sanitizer::stripAllTags( $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', $this->user )->text();
|
|
$prefsUrl = SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo' )
|
|
->getFullURL( '', false, PROTO_CANONICAL );
|
|
$text = "--\n\n$footerMsg\n$prefsUrl";
|
|
|
|
if ( $wgEchoEmailFooterAddress !== '' ) {
|
|
$text .= "\n\n$wgEchoEmailFooterAddress";
|
|
}
|
|
|
|
return $text;
|
|
}
|
|
}
|