2015-08-19 20:22:45 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Html\Html;
|
|
|
|
use MediaWiki\Utils\MWTimestamp;
|
2022-11-01 22:01:23 +00:00
|
|
|
|
2015-08-19 20:22:45 +00:00
|
|
|
/**
|
|
|
|
* A formatter for the notification flyout popup
|
|
|
|
*
|
2022-11-01 22:01:23 +00:00
|
|
|
* Ideally we wouldn't need this, and we'd just pass the
|
2015-08-19 20:22:45 +00:00
|
|
|
* presentation model to the client, but we need to continue
|
|
|
|
* sending HTML for backwards compatibility.
|
|
|
|
*/
|
|
|
|
class EchoFlyoutFormatter extends EchoEventFormatter {
|
2015-10-29 21:13:10 +00:00
|
|
|
protected function formatModel( EchoEventPresentationModel $model ) {
|
2015-08-19 20:22:45 +00:00
|
|
|
$icon = Html::element(
|
|
|
|
'img',
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2015-08-19 20:22:45 +00:00
|
|
|
'class' => 'mw-echo-icon',
|
2024-08-16 22:09:41 +00:00
|
|
|
'src' => $this->getIconUrl( $model ),
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
2015-08-19 20:22:45 +00:00
|
|
|
);
|
|
|
|
|
2024-04-19 18:41:40 +00:00
|
|
|
$html = Html::rawElement(
|
2022-11-01 21:39:23 +00:00
|
|
|
'div',
|
|
|
|
[ 'class' => 'mw-echo-title' ],
|
|
|
|
$model->getHeaderMessage()->parse()
|
|
|
|
) . "\n";
|
2015-08-19 20:22:45 +00:00
|
|
|
|
2015-11-04 20:41:29 +00:00
|
|
|
$body = $model->getBodyMessage();
|
|
|
|
if ( $body ) {
|
2024-04-19 18:41:40 +00:00
|
|
|
$html .= Html::rawElement(
|
2022-11-01 21:39:23 +00:00
|
|
|
'div',
|
|
|
|
[ 'class' => 'mw-echo-payload' ],
|
|
|
|
$body->parse()
|
|
|
|
) . "\n";
|
2015-11-04 20:41:29 +00:00
|
|
|
}
|
2015-08-19 20:22:45 +00:00
|
|
|
|
|
|
|
$ts = $this->language->getHumanTimestamp(
|
2015-10-29 21:13:10 +00:00
|
|
|
new MWTimestamp( $model->getTimestamp() ),
|
2015-08-19 20:22:45 +00:00
|
|
|
null,
|
|
|
|
$this->user
|
|
|
|
);
|
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$footerItems = [ $ts ];
|
2016-01-12 21:54:05 +00:00
|
|
|
$secondaryLinks = array_filter( $model->getSecondaryLinks() );
|
2015-11-19 15:41:18 +00:00
|
|
|
foreach ( $secondaryLinks as $link ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$footerItems[] = Html::element( 'a', [ 'href' => $link['url'] ], $link['label'] );
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
2024-04-19 18:41:40 +00:00
|
|
|
$html .= Html::rawElement(
|
2015-08-19 20:22:45 +00:00
|
|
|
'div',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'class' => 'mw-echo-notification-footer' ],
|
2015-08-19 20:22:45 +00:00
|
|
|
$this->language->pipeList( $footerItems )
|
|
|
|
) . "\n";
|
|
|
|
|
2015-11-02 23:55:17 +00:00
|
|
|
// Add the primary link afterwards, if it has one
|
2016-05-03 01:56:13 +00:00
|
|
|
$primaryLink = $model->getPrimaryLinkWithMarkAsRead();
|
2015-11-02 23:55:17 +00:00
|
|
|
if ( $primaryLink !== false ) {
|
|
|
|
$html .= Html::element(
|
|
|
|
'a',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'class' => 'mw-echo-notification-primary-link', 'href' => $primaryLink['url'] ],
|
2015-11-19 15:41:18 +00:00
|
|
|
$primaryLink['label']
|
2015-11-02 23:55:17 +00:00
|
|
|
) . "\n";
|
|
|
|
}
|
2015-08-19 20:22:45 +00:00
|
|
|
|
2024-04-19 18:41:40 +00:00
|
|
|
return Html::rawElement( 'div', [ 'class' => 'mw-echo-state' ],
|
|
|
|
$icon .
|
|
|
|
Html::rawElement( 'div', [ 'class' => 'mw-echo-content' ], $html )
|
|
|
|
);
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
|
|
|
|
2024-08-16 22:09:41 +00:00
|
|
|
private function getIconUrl( EchoEventPresentationModel $model ) {
|
2016-07-20 14:53:36 +00:00
|
|
|
return EchoIcon::getUrl(
|
2022-11-01 21:39:23 +00:00
|
|
|
$model->getIconType(),
|
|
|
|
$this->language->getDir()
|
2015-08-19 20:22:45 +00:00
|
|
|
);
|
|
|
|
}
|
2015-11-19 15:41:18 +00:00
|
|
|
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|