Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/249884
Change subject: Move some boilerplate code into EchoEventFormatter
......................................................................
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,
sosure the timestamp is exposed in EchoEventPresentationModel.
Change-Id: I7f0a650373eebac7aa2231b1795b51a6d031ad67
---
M includes/formatters/EchoEventFormatter.php
M includes/formatters/EchoFlyoutFormatter.php
M includes/formatters/EventPresentationModel.php
3 files changed, 24 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo
refs/changes/84/249884/1
diff --git a/includes/formatters/EchoEventFormatter.php
b/includes/formatters/EchoEventFormatter.php
index d330f32..c7aef95 100644
--- a/includes/formatters/EchoEventFormatter.php
+++ b/includes/formatters/EchoEventFormatter.php
@@ -19,7 +19,20 @@
/**
* @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 );
}
diff --git a/includes/formatters/EchoFlyoutFormatter.php
b/includes/formatters/EchoFlyoutFormatter.php
index 7d013cc..3a3b6d6 100644
--- a/includes/formatters/EchoFlyoutFormatter.php
+++ b/includes/formatters/EchoFlyoutFormatter.php
@@ -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 @@
// @todo body text
$ts = $this->language->getHumanTimestamp(
- new MWTimestamp( $event->getTimestamp() ),
+ new MWTimestamp( $model->getTimestamp() ),
null,
$this->user
);
diff --git a/includes/formatters/EventPresentationModel.php
b/includes/formatters/EventPresentationModel.php
index 95ead33..e852eca 100644
--- a/includes/formatters/EventPresentationModel.php
+++ b/includes/formatters/EventPresentationModel.php
@@ -86,6 +86,13 @@
abstract public function getIconType();
/**
+ * @return string Timestamp the event occurred at
+ */
+ final public function getTimestamp() {
+ return $this->event->getTimestamp();
+ }
+
+ /**
* Helper for EchoEvent::userCan
*
* @param int $type Revision::DELETED_* constant
--
To view, visit https://gerrit.wikimedia.org/r/249884
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7f0a650373eebac7aa2231b1795b51a6d031ad67
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits