diff --git a/autoload.php b/autoload.php index 38bcab2f3..ddb80dd57 100644 --- a/autoload.php +++ b/autoload.php @@ -109,5 +109,6 @@ $wgAutoloadClasses += array( 'NotificationControllerTest' => __DIR__ . '/tests/phpunit/controller/NotificationControllerTest.php', 'NotificationsTest' => __DIR__ . '/tests/NotificationsTest.php', 'SpecialNotifications' => __DIR__ . '/includes/special/SpecialNotifications.php', + 'SpecialNotificationsFormatter' => __DIR__ . '/includes/formatters/SpecialNotificationsFormatter.php', 'SuppressionMaintenanceTest' => __DIR__ . '/tests/phpunit/maintenance/SupressionMaintenanceTest.php', ); diff --git a/includes/DataOutputFormatter.php b/includes/DataOutputFormatter.php index 3855d5653..8009be6db 100644 --- a/includes/DataOutputFormatter.php +++ b/includes/DataOutputFormatter.php @@ -11,6 +11,15 @@ class EchoDataOutputFormatter { protected static $formatters = array( 'flyout' => 'EchoFlyoutFormatter', 'model' => 'EchoModelFormatter', + 'special' => 'SpecialNotificationsFormatter', + ); + + /** + * @var array Mapping of new formatter to old formatter type + */ + protected static $legacyMapping = array( + 'flyout' => 'flyout', + 'special' => 'html', ); /** @@ -137,8 +146,9 @@ class EchoDataOutputFormatter { $formatter = new self::$formatters[$format]( $user, $lang ); return $formatter->format( $event ); } else { + $legacyFormat = self::$legacyMapping[$format]; // Legacy b/c - return EchoNotificationController::formatNotification( $event, $user, $format ); + return EchoNotificationController::formatNotification( $event, $user, $legacyFormat ); } } diff --git a/includes/api/ApiEchoNotifications.php b/includes/api/ApiEchoNotifications.php index acef4ea7e..7e41579e2 100644 --- a/includes/api/ApiEchoNotifications.php +++ b/includes/api/ApiEchoNotifications.php @@ -221,6 +221,7 @@ class ApiEchoNotifications extends ApiQueryBase { 'flyout', 'html', 'model', + 'special', ), ), 'limit' => array( diff --git a/includes/formatters/SpecialNotificationsFormatter.php b/includes/formatters/SpecialNotificationsFormatter.php new file mode 100644 index 000000000..aa1d2a8a8 --- /dev/null +++ b/includes/formatters/SpecialNotificationsFormatter.php @@ -0,0 +1,71 @@ + 'mw-echo-icon', + 'src' => $this->getIconURL( $model ), + ) + ); + + $html = Xml::tags( + 'div', + array( 'class' => 'mw-echo-title' ), + $model->getHeaderMessage()->parse() + ) . "\n"; + + $body = $model->getBodyMessage(); + if ( $body ) { + $html .= Xml::tags( + 'div', + null, + $body->parse() + ) . "\n"; + } + + $ts = $this->language->getHumanTimestamp( + new MWTimestamp( $model->getTimestamp() ), + null, + $this->user + ); + + $footerItems = array( $ts ); + + // Add links to the footer, primary goes first, then secondary ones + $links = array(); + $primaryLink = $model->getPrimaryLink(); + if ( $primaryLink !== false ) { + $links[$primaryLink[0]] = $primaryLink[1]; + } + $links += $model->getSecondaryLinks(); + foreach ( $links as $target => $text ) { + $footerItems[] = Html::element( 'a', array( 'href' => $target ), $text ); + } + + $html .= Xml::tags( + 'div', + array( 'class' => 'mw-echo-notification-footer' ), + $this->language->pipeList( $footerItems ) + ) . "\n"; + + // Wrap everything in mw-echo-content class + $html = Xml::tags( 'div', array( 'class' => 'mw-echo-content' ), $html ); + + // And then add the icon in front and wrap with mw-echo-state class. + $html = Xml::tags( 'div', array( 'class' => 'mw-echo-state' ), $icon . $html ); + + return $html; + } + + private function getIconURL( EchoEventPresentationModel $model ) { + return EchoNotificationFormatter::getIconUrl( + $model->getIconType(), + $this->language->getDir() + ); + } +} diff --git a/includes/special/SpecialNotifications.php b/includes/special/SpecialNotifications.php index e0a1d05cf..a67090acb 100644 --- a/includes/special/SpecialNotifications.php +++ b/includes/special/SpecialNotifications.php @@ -59,7 +59,7 @@ class SpecialNotifications extends SpecialPage { } foreach ( $notifications as $notification ) { - $output = EchoDataOutputFormatter::formatOutput( $notification, 'html', $user, $this->getLanguage() ); + $output = EchoDataOutputFormatter::formatOutput( $notification, 'special', $user, $this->getLanguage() ); if ( $output ) { $notif[] = $output; } diff --git a/modules/special/ext.echo.special.js b/modules/special/ext.echo.special.js index dd2bb572b..6e495dacc 100644 --- a/modules/special/ext.echo.special.js +++ b/modules/special/ext.echo.special.js @@ -67,7 +67,7 @@ apiData = { action: 'query', meta: 'notifications', - notformat: 'html', + notformat: 'special', notprop: 'index|list', notcontinue: this.notcontinue, notlimit: mw.config.get( 'wgEchoDisplayNum' ),