| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Notifications\Formatters; |
| 4 |
|
| 5 |
use MediaWiki\Language\Language; |
| 6 |
use MediaWiki\Parser\Sanitizer; |
| 7 |
use MediaWiki\SpecialPage\SpecialPage; |
| 8 |
use MediaWiki\User\User; |
| 9 |
|
| 10 |
class EchoPlainTextDigestEmailFormatter extends EchoEventDigestFormatter { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
protected $digestMode; |
| 16 |
|
| 17 |
public function __construct( User $user, Language $language, $digestMode ) { |
| 18 |
parent::__construct( $user, $language ); |
| 19 |
$this->digestMode = $digestMode; |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
protected function formatModels( array $models ) { |
| 29 |
$content = []; |
| 30 |
foreach ( $models as $model ) { |
| 31 |
$content[$model->getCategory()][] = Sanitizer::stripAllTags( $model->getHeaderMessage()->parse() ); |
| 32 |
} |
| 33 |
|
| 34 |
ksort( $content ); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
$text = $this->msg( 'echo-email-batch-body-intro-' . $this->digestMode ) |
| 39 |
->params( $this->user->getName() )->text(); |
| 40 |
|
| 41 |
|
| 42 |
$bullet = $this->msg( 'echo-email-batch-bullet' )->text(); |
| 43 |
|
| 44 |
foreach ( $content as $type => $items ) { |
| 45 |
$text .= "\n\n--\n\n"; |
| 46 |
$text .= $this->getCategoryTitle( $type, count( $items ) ); |
| 47 |
$text .= "\n"; |
| 48 |
foreach ( $items as $item ) { |
| 49 |
$text .= "\n$bullet $item"; |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
$colon = $this->msg( 'colon-separator' )->text(); |
| 54 |
$text .= "\n\n--\n\n"; |
| 55 |
$viewAll = $this->msg( 'echo-email-batch-link-text-view-all-notifications' )->text(); |
| 56 |
$link = SpecialPage::getTitleFor( 'Notifications' )->getFullURL( '', false, PROTO_CANONICAL ); |
| 57 |
$text .= "$viewAll$colon <$link>"; |
| 58 |
|
| 59 |
$plainTextFormatter = new EchoPlainTextEmailFormatter( $this->user, $this->language ); |
| 60 |
|
| 61 |
$text .= "\n\n{$plainTextFormatter->getFooter()}"; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
$subject = $this->msg( 'echo-email-batch-subject-' . $this->digestMode ) |
| 66 |
->numParams( count( $models ), count( $models ) ) |
| 67 |
->text(); |
| 68 |
|
| 69 |
return [ |
| 70 |
'subject' => $subject, |
| 71 |
'body' => $text, |
| 72 |
]; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
private function getCategoryTitle( $type, $count ) { |
| 81 |
return $this->msg( "echo-category-title-$type" ) |
| 82 |
->numParams( $count ) |
| 83 |
->text(); |
| 84 |
} |
| 85 |
} |