| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\Notifications\Formatters; |
| 4 |
|
| 5 |
use MediaWiki\Extension\Notifications\Special\SpecialNotificationsMarkRead; |
| 6 |
use MediaWiki\Html\Html; |
| 7 |
use MediaWiki\Output\OutputPage; |
| 8 |
use MediaWiki\Utils\MWTimestamp; |
| 9 |
use OOUI\IconWidget; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class SpecialNotificationsFormatter extends EchoEventFormatter { |
| 18 |
protected function formatModel( EchoEventPresentationModel $model ) { |
| 19 |
$markReadSpecialPage = new SpecialNotificationsMarkRead(); |
| 20 |
$id = $model->getEventId(); |
| 21 |
|
| 22 |
$icon = Html::element( |
| 23 |
'img', |
| 24 |
[ |
| 25 |
'class' => 'mw-echo-icon', |
| 26 |
'src' => $this->getIconUrl( $model ), |
| 27 |
] |
| 28 |
); |
| 29 |
|
| 30 |
OutputPage::setupOOUI(); |
| 31 |
|
| 32 |
$markAsReadIcon = new IconWidget( [ |
| 33 |
'icon' => 'close', |
| 34 |
'title' => wfMessage( 'echo-notification-markasread' )->text(), |
| 35 |
] ); |
| 36 |
|
| 37 |
$markAsReadForm = $markReadSpecialPage->getMinimalForm( |
| 38 |
$id, |
| 39 |
$this->msg( 'echo-notification-markasread' )->text(), |
| 40 |
false, |
| 41 |
$markAsReadIcon->toString() |
| 42 |
); |
| 43 |
|
| 44 |
$markAsReadButton = Html::rawElement( |
| 45 |
'div', |
| 46 |
[ 'class' => 'mw-echo-markAsReadButton' ], |
| 47 |
|
| 48 |
$markAsReadForm->prepareForm()->getHTML( false ) |
| 49 |
); |
| 50 |
|
| 51 |
$html = Html::rawElement( |
| 52 |
'div', |
| 53 |
[ 'class' => 'mw-echo-title' ], |
| 54 |
$model->getHeaderMessage()->parse() |
| 55 |
) . "\n"; |
| 56 |
|
| 57 |
$body = $model->getBodyMessage(); |
| 58 |
if ( $body ) { |
| 59 |
$html .= Html::element( |
| 60 |
'div', |
| 61 |
[ 'class' => 'mw-echo-payload' ], |
| 62 |
$body->text() |
| 63 |
) . "\n"; |
| 64 |
} |
| 65 |
|
| 66 |
$ts = $this->language->getHumanTimestamp( |
| 67 |
new MWTimestamp( $model->getTimestamp() ), |
| 68 |
null, |
| 69 |
$this->user |
| 70 |
); |
| 71 |
|
| 72 |
$footerItems = [ Html::element( 'span', [ 'class' => 'mw-echo-notification-footer-element' ], $ts ) ]; |
| 73 |
|
| 74 |
|
| 75 |
$links = []; |
| 76 |
$primaryLink = $model->getPrimaryLinkWithMarkAsRead(); |
| 77 |
if ( $primaryLink !== false ) { |
| 78 |
$links[] = $primaryLink; |
| 79 |
} |
| 80 |
$links = array_merge( $links, array_filter( $model->getSecondaryLinks() ) ); |
| 81 |
foreach ( $links as $link ) { |
| 82 |
$footerAttributes = [ |
| 83 |
'href' => $link['url'], |
| 84 |
'class' => 'mw-echo-notification-footer-element', |
| 85 |
]; |
| 86 |
|
| 87 |
if ( isset( $link['tooltip'] ) ) { |
| 88 |
$footerAttributes['title'] = $link['tooltip']; |
| 89 |
} |
| 90 |
|
| 91 |
$footerItems[] = Html::element( |
| 92 |
'a', |
| 93 |
$footerAttributes, |
| 94 |
$link['label'] |
| 95 |
); |
| 96 |
} |
| 97 |
|
| 98 |
$pipe = wfMessage( 'pipe-separator' )->inLanguage( $this->language )->text(); |
| 99 |
$html .= Html::rawElement( |
| 100 |
'div', |
| 101 |
[ 'class' => 'mw-echo-notification-footer' ], |
| 102 |
implode( |
| 103 |
Html::element( 'span', [ 'class' => 'mw-echo-notification-footer-element' ], $pipe ), |
| 104 |
$footerItems |
| 105 |
) |
| 106 |
) . "\n"; |
| 107 |
|
| 108 |
return Html::rawElement( 'div', [ 'class' => 'mw-echo-state' ], |
| 109 |
$markAsReadButton . |
| 110 |
$icon . |
| 111 |
Html::rawElement( 'div', [ 'class' => 'mw-echo-content' ], $html ) |
| 112 |
); |
| 113 |
} |
| 114 |
|
| 115 |
private function getIconUrl( EchoEventPresentationModel $model ) { |
| 116 |
return EchoIcon::getUrl( |
| 117 |
$model->getIconType(), |
| 118 |
$this->language->getDir() |
| 119 |
); |
| 120 |
} |
| 121 |
} |