2015-10-29 21:14:35 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Parser\Sanitizer;
|
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
2022-11-01 22:01:23 +00:00
|
|
|
|
2015-10-29 21:14:35 +00:00
|
|
|
class EchoPlainTextEmailFormatter extends EchoEventFormatter {
|
|
|
|
protected function formatModel( EchoEventPresentationModel $model ) {
|
2017-07-07 23:55:51 +00:00
|
|
|
$subject = Sanitizer::stripAllTags( $model->getSubjectMessage()->parse() );
|
2015-10-29 21:14:35 +00:00
|
|
|
|
2017-07-07 23:55:51 +00:00
|
|
|
$text = Sanitizer::stripAllTags( $model->getHeaderMessage()->parse() );
|
2015-10-29 21:14:35 +00:00
|
|
|
|
|
|
|
$text .= "\n\n";
|
|
|
|
|
|
|
|
$bodyMsg = $model->getBodyMessage();
|
|
|
|
if ( $bodyMsg ) {
|
2017-07-07 23:55:51 +00:00
|
|
|
$text .= Sanitizer::stripAllTags( $bodyMsg->parse() );
|
2015-10-29 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 22:15:22 +00:00
|
|
|
$primaryLink = $model->getPrimaryLinkWithMarkAsRead();
|
2015-10-29 21:14:35 +00:00
|
|
|
$colon = $this->msg( 'colon-separator' )->text();
|
2022-07-09 16:31:23 +00:00
|
|
|
|
|
|
|
if ( $primaryLink ) {
|
|
|
|
$primaryUrl = wfExpandUrl( $primaryLink['url'], PROTO_CANONICAL );
|
|
|
|
$text .= "\n\n{$primaryLink['label']}$colon <$primaryUrl>";
|
|
|
|
}
|
2015-10-29 21:14:35 +00:00
|
|
|
|
|
|
|
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()}";
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
2015-10-29 21:14:35 +00:00
|
|
|
'body' => $text,
|
|
|
|
'subject' => $subject,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2015-10-29 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFooter() {
|
|
|
|
global $wgEchoEmailFooterAddress;
|
|
|
|
|
2016-12-28 16:43:40 +00:00
|
|
|
$footerMsg = $this->msg( 'echo-email-plain-footer', $this->user )->text();
|
2015-10-29 21:14:35 +00:00
|
|
|
$prefsUrl = SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo' )
|
|
|
|
->getFullURL( '', false, PROTO_CANONICAL );
|
|
|
|
$text = "--\n\n$footerMsg\n$prefsUrl";
|
|
|
|
|
2019-02-19 08:54:56 +00:00
|
|
|
if ( $wgEchoEmailFooterAddress !== '' ) {
|
2015-10-29 21:14:35 +00:00
|
|
|
$text .= "\n\n$wgEchoEmailFooterAddress";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
}
|