2015-08-19 20:22:45 +00:00
|
|
|
<?php
|
2016-07-20 14:53:36 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2015-08-19 20:22:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract class that each "formatter" should implement.
|
|
|
|
*
|
|
|
|
* A formatter is an output type, example formatters would be:
|
|
|
|
* * Special:Notifications
|
|
|
|
* * HTML email
|
|
|
|
* * plaintext email
|
|
|
|
*
|
|
|
|
* The formatter does not maintain any state except for the
|
|
|
|
* arguments passed in the constructor (user and language)
|
|
|
|
*/
|
|
|
|
abstract class EchoEventFormatter {
|
|
|
|
public function __construct( User $user, Language $language ) {
|
|
|
|
$this->user = $user;
|
|
|
|
$this->language = $language;
|
|
|
|
}
|
|
|
|
|
2015-10-29 21:14:35 +00:00
|
|
|
/**
|
|
|
|
* Equivalent to IContextSource::msg for the current
|
|
|
|
* language
|
|
|
|
*
|
|
|
|
* @return Message
|
|
|
|
*/
|
|
|
|
protected function msg( /* ,,, */ ) {
|
|
|
|
/**
|
|
|
|
* @var Message $msg
|
|
|
|
*/
|
|
|
|
$msg = call_user_func_array( 'wfMessage', func_get_args() );
|
|
|
|
$msg->inLanguage( $this->language );
|
|
|
|
|
|
|
|
return $msg;
|
|
|
|
}
|
|
|
|
|
2015-08-19 20:22:45 +00:00
|
|
|
/**
|
|
|
|
* @param EchoEvent $event
|
2015-10-29 21:14:35 +00:00
|
|
|
* @return string|array|bool Output format depends on implementation, false if it cannot be formatted
|
2015-08-19 20:22:45 +00:00
|
|
|
*/
|
2015-10-29 21:13:10 +00:00
|
|
|
final public function format( EchoEvent $event ) {
|
2016-03-04 19:23:02 +00:00
|
|
|
// Deleted events should have been filtered out before getting there.
|
|
|
|
// This is just to be sure.
|
|
|
|
if ( $event->isDeleted() ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-20 14:53:36 +00:00
|
|
|
if ( !EchoEventPresentationModel::supportsPresentationModel( $event->getType() ) ) {
|
|
|
|
LoggerFactory::getInstance( 'Echo' )->warning(
|
|
|
|
"Ignoring event type \"{type}\" since it does not support Echo presentation model.",
|
|
|
|
array(
|
|
|
|
'type' => $event->getType(),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-29 21:13:10 +00:00
|
|
|
$model = EchoEventPresentationModel::factory( $event, $this->language, $this->user );
|
|
|
|
if ( !$model->canRender() ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->formatModel( $model );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param EchoEventPresentationModel $model
|
2015-10-29 21:14:35 +00:00
|
|
|
* @return string|array
|
2015-10-29 21:13:10 +00:00
|
|
|
*/
|
|
|
|
abstract protected function formatModel( EchoEventPresentationModel $model );
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|