mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-12-24 13:44:40 +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
122 lines
3 KiB
PHP
122 lines
3 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
use MediaWiki\Extension\Notifications\Special\SpecialNotificationsMarkRead;
|
|
use MediaWiki\Html\Html;
|
|
use MediaWiki\Output\OutputPage;
|
|
use MediaWiki\Utils\MWTimestamp;
|
|
use OOUI\IconWidget;
|
|
|
|
/**
|
|
* A formatter for Special:Notifications
|
|
*
|
|
* This formatter uses OOUI libraries. Any calls to this formatter must
|
|
* also call OutputPage::enableOOUI() before calling this formatter.
|
|
*/
|
|
class SpecialNotificationsFormatter extends EchoEventFormatter {
|
|
protected function formatModel( EchoEventPresentationModel $model ) {
|
|
$markReadSpecialPage = new SpecialNotificationsMarkRead();
|
|
$id = $model->getEventId();
|
|
|
|
$icon = Html::element(
|
|
'img',
|
|
[
|
|
'class' => 'mw-echo-icon',
|
|
'src' => $this->getIconUrl( $model ),
|
|
]
|
|
);
|
|
|
|
OutputPage::setupOOUI();
|
|
|
|
$markAsReadIcon = new IconWidget( [
|
|
'icon' => 'close',
|
|
'title' => wfMessage( 'echo-notification-markasread' )->text(),
|
|
] );
|
|
|
|
$markAsReadForm = $markReadSpecialPage->getMinimalForm(
|
|
$id,
|
|
$this->msg( 'echo-notification-markasread' )->text(),
|
|
false,
|
|
$markAsReadIcon->toString()
|
|
);
|
|
|
|
$markAsReadButton = Html::rawElement(
|
|
'div',
|
|
[ 'class' => 'mw-echo-markAsReadButton' ],
|
|
// First submission attempt
|
|
$markAsReadForm->prepareForm()->getHTML( false )
|
|
);
|
|
|
|
$html = Html::rawElement(
|
|
'div',
|
|
[ 'class' => 'mw-echo-title' ],
|
|
$model->getHeaderMessage()->parse()
|
|
) . "\n";
|
|
|
|
$body = $model->getBodyMessage();
|
|
if ( $body ) {
|
|
$html .= Html::element(
|
|
'div',
|
|
[ 'class' => 'mw-echo-payload' ],
|
|
$body->text()
|
|
) . "\n";
|
|
}
|
|
|
|
$ts = $this->language->getHumanTimestamp(
|
|
new MWTimestamp( $model->getTimestamp() ),
|
|
null,
|
|
$this->user
|
|
);
|
|
|
|
$footerItems = [ Html::element( 'span', [ 'class' => 'mw-echo-notification-footer-element' ], $ts ) ];
|
|
|
|
// Add links to the footer, primary goes first, then secondary ones
|
|
$links = [];
|
|
$primaryLink = $model->getPrimaryLinkWithMarkAsRead();
|
|
if ( $primaryLink !== false ) {
|
|
$links[] = $primaryLink;
|
|
}
|
|
$links = array_merge( $links, array_filter( $model->getSecondaryLinks() ) );
|
|
foreach ( $links as $link ) {
|
|
$footerAttributes = [
|
|
'href' => $link['url'],
|
|
'class' => 'mw-echo-notification-footer-element',
|
|
];
|
|
|
|
if ( isset( $link['tooltip'] ) ) {
|
|
$footerAttributes['title'] = $link['tooltip'];
|
|
}
|
|
|
|
$footerItems[] = Html::element(
|
|
'a',
|
|
$footerAttributes,
|
|
$link['label']
|
|
);
|
|
}
|
|
|
|
$pipe = wfMessage( 'pipe-separator' )->inLanguage( $this->language )->text();
|
|
$html .= Html::rawElement(
|
|
'div',
|
|
[ 'class' => 'mw-echo-notification-footer' ],
|
|
implode(
|
|
Html::element( 'span', [ 'class' => 'mw-echo-notification-footer-element' ], $pipe ),
|
|
$footerItems
|
|
)
|
|
) . "\n";
|
|
|
|
return Html::rawElement( 'div', [ 'class' => 'mw-echo-state' ],
|
|
$markAsReadButton .
|
|
$icon .
|
|
Html::rawElement( 'div', [ 'class' => 'mw-echo-content' ], $html )
|
|
);
|
|
}
|
|
|
|
private function getIconUrl( EchoEventPresentationModel $model ) {
|
|
return EchoIcon::getUrl(
|
|
$model->getIconType(),
|
|
$this->language->getDir()
|
|
);
|
|
}
|
|
}
|