2015-11-11 02:23:03 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
|
2022-11-02 21:15:29 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Special\SpecialNotificationsMarkRead;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\Html\Html;
|
|
|
|
use MediaWiki\Output\OutputPage;
|
|
|
|
use MediaWiki\Utils\MWTimestamp;
|
2022-11-01 22:01:23 +00:00
|
|
|
use OOUI\IconWidget;
|
|
|
|
|
2015-11-11 02:23:03 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
$markAsReadIcon = new 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' ],
|
2022-11-12 06:37:37 +00:00
|
|
|
// First submission attempt
|
|
|
|
$markAsReadForm->prepareForm()->getHTML( false )
|
2016-05-28 00:02:55 +00:00
|
|
|
);
|
|
|
|
|
2024-04-19 18:41:40 +00:00
|
|
|
$html = Html::rawElement(
|
2022-11-01 21:39:23 +00:00
|
|
|
'div',
|
|
|
|
[ 'class' => 'mw-echo-title' ],
|
|
|
|
$model->getHeaderMessage()->parse()
|
|
|
|
) . "\n";
|
2015-11-11 02:23:03 +00:00
|
|
|
|
|
|
|
$body = $model->getBodyMessage();
|
|
|
|
if ( $body ) {
|
2024-04-19 18:41:40 +00:00
|
|
|
$html .= Html::element(
|
2022-11-01 21:39:23 +00:00
|
|
|
'div',
|
|
|
|
[ 'class' => 'mw-echo-payload' ],
|
2024-04-19 18:41:40 +00:00
|
|
|
$body->text()
|
2022-11-01 21:39:23 +00:00
|
|
|
) . "\n";
|
2015-11-11 02:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$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();
|
2024-04-19 18:41:40 +00:00
|
|
|
$html .= Html::rawElement(
|
2015-11-11 02:23:03 +00:00
|
|
|
'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";
|
|
|
|
|
2024-04-19 18:41:40 +00:00
|
|
|
return Html::rawElement( 'div', [ 'class' => 'mw-echo-state' ],
|
|
|
|
$markAsReadButton .
|
|
|
|
$icon .
|
|
|
|
Html::rawElement( 'div', [ 'class' => 'mw-echo-content' ], $html )
|
|
|
|
);
|
2015-11-11 02:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getIconURL( EchoEventPresentationModel $model ) {
|
2016-07-20 14:53:36 +00:00
|
|
|
return EchoIcon::getUrl(
|
2022-11-01 21:39:23 +00:00
|
|
|
$model->getIconType(),
|
|
|
|
$this->language->getDir()
|
2015-11-11 02:23:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|