mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-11 07:26:29 +00:00
cf71009638
Followup to I639b9d9906d3ff37021cb9b5ed3cb401354b5bd9 * Remove deprecated formatter * Log a warning and fail gracefully when an event type does not support Echo presentation model. Bug: T121612 Change-Id: Ic5712c4ce265b6faabce7a4028b4294fe3c73f18
72 lines
1.8 KiB
PHP
72 lines
1.8 KiB
PHP
<?php
|
|
use MediaWiki\Logger\LoggerFactory;
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
/**
|
|
* @param EchoEvent $event
|
|
* @return string|array|bool Output format depends on implementation, false if it cannot be formatted
|
|
*/
|
|
final public function format( EchoEvent $event ) {
|
|
// Deleted events should have been filtered out before getting there.
|
|
// This is just to be sure.
|
|
if ( $event->isDeleted() ) {
|
|
return false;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
$model = EchoEventPresentationModel::factory( $event, $this->language, $this->user );
|
|
if ( !$model->canRender() ) {
|
|
return false;
|
|
}
|
|
|
|
return $this->formatModel( $model );
|
|
}
|
|
|
|
/**
|
|
* @param EchoEventPresentationModel $model
|
|
* @return string|array
|
|
*/
|
|
abstract protected function formatModel( EchoEventPresentationModel $model );
|
|
}
|