2015-11-11 02:23:03 +00:00
|
|
|
<?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',
|
2015-12-18 20:56:32 +00:00
|
|
|
array( 'class' => 'mw-echo-payload' ),
|
2016-02-25 18:19:19 +00:00
|
|
|
$body->escaped()
|
2015-11-11 02:23:03 +00:00
|
|
|
) . "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$ts = $this->language->getHumanTimestamp(
|
|
|
|
new MWTimestamp( $model->getTimestamp() ),
|
|
|
|
null,
|
|
|
|
$this->user
|
|
|
|
);
|
|
|
|
|
2016-01-20 21:19:54 +00:00
|
|
|
$footerItems = array( Html::element( 'span', array( 'class' => 'mw-echo-notification-footer-element' ), $ts ) );
|
2015-11-11 02:23:03 +00:00
|
|
|
|
|
|
|
// Add links to the footer, primary goes first, then secondary ones
|
|
|
|
$links = array();
|
|
|
|
$primaryLink = $model->getPrimaryLink();
|
|
|
|
if ( $primaryLink !== false ) {
|
2016-01-12 21:54:05 +00:00
|
|
|
$links[] = $primaryLink;
|
2015-11-11 02:23:03 +00:00
|
|
|
}
|
2016-01-12 21:54:05 +00:00
|
|
|
$links = array_merge( $links, array_filter( $model->getSecondaryLinks() ) );
|
2015-12-03 15:52:46 +00:00
|
|
|
foreach ( $links as $link ) {
|
2016-02-19 03:03:33 +00:00
|
|
|
$footerAttributes = array(
|
|
|
|
'href' => $link['url'],
|
|
|
|
'class' => 'mw-echo-notification-footer-element',
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( isset( $link['tooltip'] ) ) {
|
|
|
|
$footerAttributes['title'] = $link['tooltip'];
|
|
|
|
}
|
|
|
|
|
2016-02-17 17:27:49 +00:00
|
|
|
$footerItems[] = Html::element(
|
|
|
|
'a',
|
2016-02-19 03:03:33 +00:00
|
|
|
$footerAttributes,
|
2016-02-17 17:27:49 +00:00
|
|
|
$link['label']
|
|
|
|
);
|
2015-11-11 02:23:03 +00:00
|
|
|
}
|
|
|
|
|
2016-01-20 21:19:54 +00:00
|
|
|
$pipe = wfMessage( 'pipe-separator' )->inLanguage( $this->language )->escaped();
|
2015-11-11 02:23:03 +00:00
|
|
|
$html .= Xml::tags(
|
|
|
|
'div',
|
|
|
|
array( 'class' => 'mw-echo-notification-footer' ),
|
2016-01-20 21:19:54 +00:00
|
|
|
implode( Html::element( 'span', array( 'class' => 'mw-echo-notification-footer-element' ), $pipe ), $footerItems )
|
2015-11-11 02:23:03 +00:00
|
|
|
) . "\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()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|