mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-26 14:43:22 +00:00
14b06b78e5
Replaced all occurrences of "iconURL" in the extension's repo with "iconUrl" after spotting a typo in `mw.echo.dm.NotificationItem.js#13`, "iconUrl" (find the correct "iconURL" in `mw.echo.Controller.js#394` in the diff). Thankfully the typo was only in the documentation block, but given the casing of other config object properties like "primaryUrl" and "secondaryUrl", it would be best to make them all consistent to prevent any bug that could happen in the future. Change-Id: I56e6a1d2c7695204b35e767679a27ee22b3fe4bc
81 lines
2 KiB
PHP
81 lines
2 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
use MediaWiki\Html\Html;
|
|
use MediaWiki\Utils\MWTimestamp;
|
|
|
|
/**
|
|
* A formatter for the notification flyout popup
|
|
*
|
|
* Ideally we wouldn't need this, and we'd just pass the
|
|
* presentation model to the client, but we need to continue
|
|
* sending HTML for backwards compatibility.
|
|
*/
|
|
class EchoFlyoutFormatter extends EchoEventFormatter {
|
|
protected function formatModel( EchoEventPresentationModel $model ) {
|
|
$icon = Html::element(
|
|
'img',
|
|
[
|
|
'class' => 'mw-echo-icon',
|
|
'src' => $this->getIconUrl( $model ),
|
|
]
|
|
);
|
|
|
|
$html = Html::rawElement(
|
|
'div',
|
|
[ 'class' => 'mw-echo-title' ],
|
|
$model->getHeaderMessage()->parse()
|
|
) . "\n";
|
|
|
|
$body = $model->getBodyMessage();
|
|
if ( $body ) {
|
|
$html .= Html::rawElement(
|
|
'div',
|
|
[ 'class' => 'mw-echo-payload' ],
|
|
$body->parse()
|
|
) . "\n";
|
|
}
|
|
|
|
$ts = $this->language->getHumanTimestamp(
|
|
new MWTimestamp( $model->getTimestamp() ),
|
|
null,
|
|
$this->user
|
|
);
|
|
|
|
$footerItems = [ $ts ];
|
|
$secondaryLinks = array_filter( $model->getSecondaryLinks() );
|
|
foreach ( $secondaryLinks as $link ) {
|
|
$footerItems[] = Html::element( 'a', [ 'href' => $link['url'] ], $link['label'] );
|
|
}
|
|
$html .= Html::rawElement(
|
|
'div',
|
|
[ 'class' => 'mw-echo-notification-footer' ],
|
|
$this->language->pipeList( $footerItems )
|
|
) . "\n";
|
|
|
|
// Add the primary link afterwards, if it has one
|
|
$primaryLink = $model->getPrimaryLinkWithMarkAsRead();
|
|
if ( $primaryLink !== false ) {
|
|
$html .= Html::element(
|
|
'a',
|
|
[ 'class' => 'mw-echo-notification-primary-link', 'href' => $primaryLink['url'] ],
|
|
$primaryLink['label']
|
|
) . "\n";
|
|
}
|
|
|
|
return Html::rawElement( 'div', [ 'class' => 'mw-echo-state' ],
|
|
$icon .
|
|
Html::rawElement( 'div', [ 'class' => 'mw-echo-content' ], $html )
|
|
);
|
|
}
|
|
|
|
private function getIconUrl( EchoEventPresentationModel $model ) {
|
|
return EchoIcon::getUrl(
|
|
$model->getIconType(),
|
|
$this->language->getDir()
|
|
);
|
|
}
|
|
|
|
}
|