Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
EchoPlainTextEmailFormatter | |
0.00% |
0 / 27 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
formatModel | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
20 | |||
getFooter | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Notifications\Formatters; |
4 | |
5 | use MediaWiki\Parser\Sanitizer; |
6 | use MediaWiki\SpecialPage\SpecialPage; |
7 | |
8 | class EchoPlainTextEmailFormatter extends EchoEventFormatter { |
9 | protected function formatModel( EchoEventPresentationModel $model ) { |
10 | $subject = Sanitizer::stripAllTags( $model->getSubjectMessage()->parse() ); |
11 | |
12 | $text = Sanitizer::stripAllTags( $model->getHeaderMessage()->parse() ); |
13 | |
14 | $text .= "\n\n"; |
15 | |
16 | $bodyMsg = $model->getBodyMessage(); |
17 | if ( $bodyMsg ) { |
18 | $text .= Sanitizer::stripAllTags( $bodyMsg->parse() ); |
19 | } |
20 | |
21 | $primaryLink = $model->getPrimaryLinkWithMarkAsRead(); |
22 | $colon = $this->msg( 'colon-separator' )->text(); |
23 | |
24 | if ( $primaryLink ) { |
25 | $primaryUrl = wfExpandUrl( $primaryLink['url'], PROTO_CANONICAL ); |
26 | $text .= "\n\n{$primaryLink['label']}$colon <$primaryUrl>"; |
27 | } |
28 | |
29 | foreach ( array_filter( $model->getSecondaryLinks() ) as $secondaryLink ) { |
30 | $url = wfExpandUrl( $secondaryLink['url'], PROTO_CANONICAL ); |
31 | $text .= "\n\n{$secondaryLink['label']}$colon <$url>"; |
32 | } |
33 | |
34 | // Footer |
35 | $text .= "\n\n{$this->getFooter()}"; |
36 | |
37 | return [ |
38 | 'body' => $text, |
39 | 'subject' => $subject, |
40 | ]; |
41 | } |
42 | |
43 | /** |
44 | * @return string |
45 | */ |
46 | public function getFooter() { |
47 | global $wgEchoEmailFooterAddress; |
48 | |
49 | $footerMsg = $this->msg( 'echo-email-plain-footer', $this->user )->text(); |
50 | $prefsUrl = SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo' ) |
51 | ->getFullURL( '', false, PROTO_CANONICAL ); |
52 | $text = "--\n\n$footerMsg\n$prefsUrl"; |
53 | |
54 | if ( $wgEchoEmailFooterAddress !== '' ) { |
55 | $text .= "\n\n$wgEchoEmailFooterAddress"; |
56 | } |
57 | |
58 | return $text; |
59 | } |
60 | } |