mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-25 00:05:29 +00:00
15a44768f4
Bug: T115528 Change-Id: I54dba5f86d28a069659d66dede5b7ab9981213aa
103 lines
2.8 KiB
PHP
103 lines
2.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 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 = SpecialPage::getTitleFor( 'NotificationsMarkRead' );
|
|
$id = $model->getEventId();
|
|
|
|
$icon = Html::element(
|
|
'img',
|
|
array(
|
|
'class' => 'mw-echo-icon',
|
|
'src' => $this->getIconURL( $model ),
|
|
)
|
|
);
|
|
|
|
OutputPage::setupOOUI();
|
|
$markAsReadButton = new OOUI\ButtonWidget( array(
|
|
'icon' => 'close',
|
|
'framed' => false,
|
|
'href' => $markReadSpecialPage->getLocalUrl() . '/' . $id,
|
|
'classes' => array( 'mw-echo-markAsReadButton' ),
|
|
'title' => wfMessage( 'echo-notification-markasread' )
|
|
) );
|
|
|
|
$html = Xml::tags(
|
|
'div',
|
|
array( 'class' => 'mw-echo-title' ),
|
|
$model->getHeaderMessage()->parse()
|
|
) . "\n";
|
|
|
|
$body = $model->getBodyMessage();
|
|
if ( $body ) {
|
|
$html .= Xml::tags(
|
|
'div',
|
|
array( 'class' => 'mw-echo-payload' ),
|
|
$body->escaped()
|
|
) . "\n";
|
|
}
|
|
|
|
$ts = $this->language->getHumanTimestamp(
|
|
new MWTimestamp( $model->getTimestamp() ),
|
|
null,
|
|
$this->user
|
|
);
|
|
|
|
$footerItems = array( Html::element( 'span', array( 'class' => 'mw-echo-notification-footer-element' ), $ts ) );
|
|
|
|
// Add links to the footer, primary goes first, then secondary ones
|
|
$links = array();
|
|
$primaryLink = $model->getPrimaryLinkWithMarkAsRead();
|
|
if ( $primaryLink !== false ) {
|
|
$links[] = $primaryLink;
|
|
}
|
|
$links = array_merge( $links, array_filter( $model->getSecondaryLinks() ) );
|
|
foreach ( $links as $link ) {
|
|
$footerAttributes = array(
|
|
'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 )->escaped();
|
|
$html .= Xml::tags(
|
|
'div',
|
|
array( 'class' => 'mw-echo-notification-footer' ),
|
|
implode( Html::element( 'span', array( 'class' => 'mw-echo-notification-footer-element' ), $pipe ), $footerItems )
|
|
) . "\n";
|
|
|
|
// Wrap everything in mw-echo-content class
|
|
$html = Xml::tags( 'div', array( 'class' => 'mw-echo-content' ), $html );
|
|
|
|
// And then add the mark as read button
|
|
// and the icon in front and wrap with
|
|
// mw-echo-state class.
|
|
$html = Xml::tags( 'div', array( 'class' => 'mw-echo-state' ), $markAsReadButton . $icon . $html );
|
|
|
|
return $html;
|
|
}
|
|
|
|
private function getIconURL( EchoEventPresentationModel $model ) {
|
|
return EchoNotificationFormatter::getIconUrl(
|
|
$model->getIconType(),
|
|
$this->language->getDir()
|
|
);
|
|
}
|
|
}
|