2015-10-29 21:14:35 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
|
|
|
|
use Language;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Parser\Sanitizer;
|
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
|
|
|
use MediaWiki\User\User;
|
2022-11-01 22:01:23 +00:00
|
|
|
|
2015-10-29 21:14:35 +00:00
|
|
|
class EchoPlainTextDigestEmailFormatter extends EchoEventDigestFormatter {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string 'daily' or 'weekly'
|
|
|
|
*/
|
|
|
|
protected $digestMode;
|
|
|
|
|
|
|
|
public function __construct( User $user, Language $language, $digestMode ) {
|
|
|
|
parent::__construct( $user, $language );
|
|
|
|
$this->digestMode = $digestMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param EchoEventPresentationModel[] $models
|
2018-08-13 07:25:22 +00:00
|
|
|
* @return string[] Array of the following format:
|
2015-10-29 21:14:35 +00:00
|
|
|
* [ 'body' => formatted email body,
|
|
|
|
* 'subject' => formatted email subject ]
|
|
|
|
*/
|
|
|
|
protected function formatModels( array $models ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$content = [];
|
2015-10-29 21:14:35 +00:00
|
|
|
foreach ( $models as $model ) {
|
2017-07-07 23:55:51 +00:00
|
|
|
$content[$model->getCategory()][] = Sanitizer::stripAllTags( $model->getHeaderMessage()->parse() );
|
2015-10-29 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ksort( $content );
|
|
|
|
|
|
|
|
// echo-email-batch-body-intro-daily
|
|
|
|
// echo-email-batch-body-intro-weekly
|
|
|
|
$text = $this->msg( 'echo-email-batch-body-intro-' . $this->digestMode )
|
|
|
|
->params( $this->user->getName() )->text();
|
|
|
|
|
|
|
|
// Does this need to be a message?
|
|
|
|
$bullet = $this->msg( 'echo-email-batch-bullet' )->text();
|
|
|
|
|
|
|
|
foreach ( $content as $type => $items ) {
|
|
|
|
$text .= "\n\n--\n\n";
|
|
|
|
$text .= $this->getCategoryTitle( $type, count( $items ) );
|
|
|
|
$text .= "\n";
|
|
|
|
foreach ( $items as $item ) {
|
|
|
|
$text .= "\n$bullet $item";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$colon = $this->msg( 'colon-separator' )->text();
|
|
|
|
$text .= "\n\n--\n\n";
|
|
|
|
$viewAll = $this->msg( 'echo-email-batch-link-text-view-all-notifications' )->text();
|
|
|
|
$link = SpecialPage::getTitleFor( 'Notifications' )->getFullURL( '', false, PROTO_CANONICAL );
|
|
|
|
$text .= "$viewAll$colon <$link>";
|
|
|
|
|
|
|
|
$plainTextFormatter = new EchoPlainTextEmailFormatter( $this->user, $this->language );
|
|
|
|
|
|
|
|
$text .= "\n\n{$plainTextFormatter->getFooter()}";
|
|
|
|
|
|
|
|
// echo-email-batch-subject-daily
|
|
|
|
// echo-email-batch-subject-weekly
|
|
|
|
$subject = $this->msg( 'echo-email-batch-subject-' . $this->digestMode )
|
|
|
|
->numParams( count( $models ), count( $models ) )
|
|
|
|
->text();
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
return [
|
2015-10-29 21:14:35 +00:00
|
|
|
'subject' => $subject,
|
|
|
|
'body' => $text,
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2015-10-29 21:14:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $type Notification type
|
|
|
|
* @param int $count Number of notifications in this type's section
|
|
|
|
* @return string Formatted category section title
|
|
|
|
*/
|
|
|
|
private function getCategoryTitle( $type, $count ) {
|
|
|
|
return $this->msg( "echo-category-title-$type" )
|
|
|
|
->numParams( $count )
|
|
|
|
->text();
|
|
|
|
}
|
|
|
|
}
|