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',
|
2016-12-05 18:51:07 +00:00
|
|
|
[
|
2015-11-11 02:23:03 +00:00
|
|
|
'class' => 'mw-echo-icon',
|
|
|
|
'src' => $this->getIconURL( $model ),
|
2016-12-05 18:51:07 +00:00
|
|
|
]
|
2015-11-11 02:23:03 +00:00
|
|
|
);
|
|
|
|
|
2016-03-09 20:13:48 +00:00
|
|
|
OutputPage::setupOOUI();
|
2016-05-28 00:02:55 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
$markAsReadIcon = new OOUI\IconWidget( [
|
2016-03-09 20:13:48 +00:00
|
|
|
'icon' => 'close',
|
2018-08-21 12:16:22 +00:00
|
|
|
'title' => wfMessage( 'echo-notification-markasread' )->text(),
|
2016-12-05 18:51:07 +00:00
|
|
|
] );
|
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',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'class' => 'mw-echo-markAsReadButton' ],
|
2016-05-28 00:02:55 +00:00
|
|
|
$markAsReadForm->prepareForm()->getHTML( /* First submission attempt */ false )
|
|
|
|
);
|
|
|
|
|
2015-11-11 02:23:03 +00:00
|
|
|
$html = Xml::tags(
|
|
|
|
'div',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'class' => 'mw-echo-title' ],
|
2015-11-11 02:23:03 +00:00
|
|
|
$model->getHeaderMessage()->parse()
|
|
|
|
) . "\n";
|
|
|
|
|
|
|
|
$body = $model->getBodyMessage();
|
|
|
|
if ( $body ) {
|
|
|
|
$html .= Xml::tags(
|
|
|
|
'div',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ '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-12-05 18:51:07 +00:00
|
|
|
$footerItems = [ Html::element( 'span', [ '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
|
2016-12-05 18:51:07 +00:00
|
|
|
$links = [];
|
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-12-05 18:51:07 +00:00
|
|
|
$footerAttributes = [
|
2016-02-19 03:03:33 +00:00
|
|
|
'href' => $link['url'],
|
|
|
|
'class' => 'mw-echo-notification-footer-element',
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2016-02-19 03:03:33 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-08-13 08:23:49 +00:00
|
|
|
$pipe = wfMessage( 'pipe-separator' )->inLanguage( $this->language )->text();
|
2015-11-11 02:23:03 +00:00
|
|
|
$html .= Xml::tags(
|
|
|
|
'div',
|
2016-12-05 18:51:07 +00:00
|
|
|
[ 'class' => 'mw-echo-notification-footer' ],
|
2020-06-27 10:05:03 +00:00
|
|
|
implode(
|
|
|
|
Html::element( 'span', [ 'class' => 'mw-echo-notification-footer-element' ], $pipe ),
|
|
|
|
$footerItems
|
|
|
|
)
|
2015-11-11 02:23:03 +00:00
|
|
|
) . "\n";
|
|
|
|
|
|
|
|
// Wrap everything in mw-echo-content class
|
2016-12-05 18:51:07 +00:00
|
|
|
$html = Xml::tags( 'div', [ 'class' => 'mw-echo-content' ], $html );
|
2015-11-11 02:23:03 +00:00
|
|
|
|
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.
|
2016-12-05 18:51:07 +00:00
|
|
|
$html = Xml::tags( 'div', [ 'class' => 'mw-echo-state' ], $markAsReadButton . $icon . $html );
|
2015-11-11 02:23:03 +00:00
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getIconURL( EchoEventPresentationModel $model ) {
|
2016-07-20 14:53:36 +00:00
|
|
|
return EchoIcon::getUrl(
|
2015-11-11 02:23:03 +00:00
|
|
|
$model->getIconType(),
|
|
|
|
$this->language->getDir()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|