mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-24 07:54:13 +00:00
Merge "Special:Notifications formatter"
This commit is contained in:
commit
434a034120
|
@ -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',
|
||||
);
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -221,6 +221,7 @@ class ApiEchoNotifications extends ApiQueryBase {
|
|||
'flyout',
|
||||
'html',
|
||||
'model',
|
||||
'special',
|
||||
),
|
||||
),
|
||||
'limit' => array(
|
||||
|
|
71
includes/formatters/SpecialNotificationsFormatter.php
Normal file
71
includes/formatters/SpecialNotificationsFormatter.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* A formatter for Special:Notifications
|
||||
*/
|
||||
class SpecialNotificationsFormatter extends EchoEventFormatter {
|
||||
protected function formatModel( EchoEventPresentationModel $model ) {
|
||||
$icon = Html::element(
|
||||
'img',
|
||||
array(
|
||||
'class' => '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()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
apiData = {
|
||||
action: 'query',
|
||||
meta: 'notifications',
|
||||
notformat: 'html',
|
||||
notformat: 'special',
|
||||
notprop: 'index|list',
|
||||
notcontinue: this.notcontinue,
|
||||
notlimit: mw.config.get( 'wgEchoDisplayNum' ),
|
||||
|
|
Loading…
Reference in a new issue