mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 16:04:35 +00:00
fdc2b42b2b
Change-Id: Iaf4c2f7bb75896d3daafbb445f7b5f6341543f8e
61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Abstract class for formatters that process multiple events.
|
|
*
|
|
* The formatter does not maintain any state except for the
|
|
* arguments passed in the constructor (user and language)
|
|
*/
|
|
abstract class EchoEventDigestFormatter {
|
|
|
|
/** @var User */
|
|
protected $user;
|
|
|
|
/** @var Language */
|
|
protected $language;
|
|
|
|
public function __construct( User $user, Language $language ) {
|
|
$this->user = $user;
|
|
$this->language = $language;
|
|
}
|
|
|
|
/**
|
|
* Equivalent to IContextSource::msg for the current
|
|
* language
|
|
*
|
|
* @return Message
|
|
*/
|
|
protected function msg( /* ,,, */ ) {
|
|
/**
|
|
* @var Message $msg
|
|
*/
|
|
$msg = wfMessage( ...func_get_args() );
|
|
$msg->inLanguage( $this->language );
|
|
|
|
return $msg;
|
|
}
|
|
|
|
/**
|
|
* @param EchoEvent[] $events
|
|
* @param string $distributionType 'web' or 'email'
|
|
* @return string[]|false Output format depends on implementation, false if it cannot be formatted
|
|
*/
|
|
final public function format( array $events, $distributionType ) {
|
|
$models = [];
|
|
foreach ( $events as $event ) {
|
|
$model = EchoEventPresentationModel::factory( $event, $this->language, $this->user, $distributionType );
|
|
if ( $model->canRender() ) {
|
|
$models[] = $model;
|
|
}
|
|
}
|
|
|
|
return $models ? $this->formatModels( $models ) : false;
|
|
}
|
|
|
|
/**
|
|
* @param EchoEventPresentationModel[] $models
|
|
* @return string[]|string
|
|
*/
|
|
abstract protected function formatModels( array $models );
|
|
}
|