2015-11-11 02:23:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A formatter for Special:Notifications
|
2016-03-09 20:13:48 +00:00
|
|
|
*
|
|
|
|
* This formatter uses OOUI libraries. Any calls to this formatter must
|
|
|
|
* also call OutputPage::enableOOUI() before calling this formatter.
|
2015-11-11 02:23:03 +00:00
|
|
|
*/
|
|
|
|
class SpecialNotificationsFormatter extends EchoEventFormatter {
|
|
|
|
protected function formatModel( EchoEventPresentationModel $model ) {
|
2016-05-28 00:02:55 +00:00
|
|
|
$markReadSpecialPage = new SpecialNotificationsMarkRead();
|
2016-03-09 20:13:48 +00:00
|
|
|
$id = $model->getEventId();
|
|
|
|
|
2015-11-11 02:23:03 +00:00
|
|
|
$icon = Html::element(
|
|
|
|
'img',
|
|
|
|
array(
|
|
|
|
'class' => 'mw-echo-icon',
|
|
|
|
'src' => $this->getIconURL( $model ),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2016-03-09 20:13:48 +00:00
|
|
|
OutputPage::setupOOUI();
|
2016-05-28 00:02:55 +00:00
|
|
|
|
|
|
|
$markAsReadIcon = new OOUI\IconWidget( array(
|
2016-03-09 20:13:48 +00:00
|
|
|
'icon' => 'close',
|
2016-05-28 00:02:55 +00:00
|
|
|
'title' => wfMessage( 'echo-notification-markasread' ),
|
2016-03-09 20:13:48 +00:00
|
|
|
) );
|
|
|
|
|
2016-05-28 00:02:55 +00:00
|
|
|
$markAsReadForm = $markReadSpecialPage->getMinimalForm(
|
|
|
|
$id,
|
|
|
|
$this->msg( 'echo-notification-markasread' )->text(),
|
|
|
|
false,
|
|
|
|
$markAsReadIcon->toString()
|
|
|
|
);
|
|
|
|
|
|
|
|
$markAsReadButton = Html::rawElement(
|
|
|
|
'div',
|
|
|
|
array( 'class' => 'mw-echo-markAsReadButton' ),
|
|
|
|
$markAsReadForm->prepareForm()->getHTML( /* First submission attempt */ false )
|
|
|
|
);
|
|
|
|
|
2015-11-11 02:23:03 +00:00
|
|
|
$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();
|
2016-05-03 01:56:13 +00:00
|
|
|
$primaryLink = $model->getPrimaryLinkWithMarkAsRead();
|
2015-11-11 02:23:03 +00:00
|
|
|
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 );
|
|
|
|
|
2016-03-09 20:13:48 +00:00
|
|
|
// 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 );
|
2015-11-11 02:23:03 +00:00
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getIconURL( EchoEventPresentationModel $model ) {
|
|
|
|
return EchoNotificationFormatter::getIconUrl(
|
|
|
|
$model->getIconType(),
|
|
|
|
$this->language->getDir()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|