mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-30 18:45:07 +00:00
Move some boilerplate code into EchoEventFormatter
The conversion of EchoEvent into a EchoEventPresentationModel is now done by EchoFlyoutFormatter, instead of having each subclass do it. It also does the canRender() check so subclasses don't need to worry about it. The subclasses no longer have access to the underlying EchoEvent object, so the timestamp is exposed in EchoEventPresentationModel. Change-Id: I7f0a650373eebac7aa2231b1795b51a6d031ad67
This commit is contained in:
parent
a1282bcec0
commit
74b50cad30
|
@ -19,7 +19,20 @@ abstract class EchoEventFormatter {
|
|||
|
||||
/**
|
||||
* @param EchoEvent $event
|
||||
* @return string HTML
|
||||
* @return string|bool Output format depends on implementation, false if it cannot be formatted
|
||||
*/
|
||||
abstract public function format( EchoEvent $event );
|
||||
final public function format( EchoEvent $event ) {
|
||||
$model = EchoEventPresentationModel::factory( $event, $this->language, $this->user );
|
||||
if ( !$model->canRender() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->formatModel( $model );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EchoEventPresentationModel $model
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function formatModel( EchoEventPresentationModel $model );
|
||||
}
|
||||
|
|
|
@ -8,12 +8,7 @@
|
|||
* sending HTML for backwards compatibility.
|
||||
*/
|
||||
class EchoFlyoutFormatter extends EchoEventFormatter {
|
||||
public function format( EchoEvent $event ) {
|
||||
$model = EchoEventPresentationModel::factory( $event, $this->language, $this->user );
|
||||
if ( !$model->canRender() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function formatModel( EchoEventPresentationModel $model ) {
|
||||
$icon = Html::element(
|
||||
'img',
|
||||
array(
|
||||
|
@ -31,7 +26,7 @@ class EchoFlyoutFormatter extends EchoEventFormatter {
|
|||
// @todo body text
|
||||
|
||||
$ts = $this->language->getHumanTimestamp(
|
||||
new MWTimestamp( $event->getTimestamp() ),
|
||||
new MWTimestamp( $model->getTimestamp() ),
|
||||
null,
|
||||
$this->user
|
||||
);
|
||||
|
|
|
@ -85,6 +85,13 @@ abstract class EchoEventPresentationModel {
|
|||
*/
|
||||
abstract public function getIconType();
|
||||
|
||||
/**
|
||||
* @return string Timestamp the event occurred at
|
||||
*/
|
||||
final public function getTimestamp() {
|
||||
return $this->event->getTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for EchoEvent::userCan
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue