Debian Codegraph @

extensions/Echo/includes/Formatters/EchoFlyoutFormatter.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Notifications\Formatters;
4
5 use MediaWiki\Html\Html;
6 use MediaWiki\Utils\MWTimestamp;
7
8 /**
9 * A formatter for the notification flyout popup
10 *
11 * Ideally we wouldn't need this, and we'd just pass the
12 * presentation model to the client, but we need to continue
13 * sending HTML for backwards compatibility.
14 */
15 class EchoFlyoutFormatter extends EchoEventFormatter {
16 protected function formatModel( EchoEventPresentationModel $model ) {
17 $icon = Html::element(
18 'img',
19 [
20 'class' => 'mw-echo-icon',
21 'src' => $this->getIconUrl( $model ),
22 ]
23 );
24
25 $html = Html::rawElement(
26 'div',
27 [ 'class' => 'mw-echo-title' ],
28 $model->getHeaderMessage()->parse()
29 ) . "\n";
30
31 $body = $model->getBodyMessage();
32 if ( $body ) {
33 $html .= Html::rawElement(
34 'div',
35 [ 'class' => 'mw-echo-payload' ],
36 $body->parse()
37 ) . "\n";
38 }
39
40 $ts = $this->language->getHumanTimestamp(
41 new MWTimestamp( $model->getTimestamp() ),
42 null,
43 $this->user
44 );
45
46 $footerItems = [ $ts ];
47 $secondaryLinks = array_filter( $model->getSecondaryLinks() );
48 foreach ( $secondaryLinks as $link ) {
49 $footerItems[] = Html::element( 'a', [ 'href' => $link['url'] ], $link['label'] );
50 }
51 $html .= Html::rawElement(
52 'div',
53 [ 'class' => 'mw-echo-notification-footer' ],
54 $this->language->pipeList( $footerItems )
55 ) . "\n";
56
57 // Add the primary link afterwards, if it has one
58 $primaryLink = $model->getPrimaryLinkWithMarkAsRead();
59 if ( $primaryLink !== false ) {
60 $html .= Html::element(
61 'a',
62 [ 'class' => 'mw-echo-notification-primary-link', 'href' => $primaryLink['url'] ],
63 $primaryLink['label']
64 ) . "\n";
65 }
66
67 return Html::rawElement( 'div', [ 'class' => 'mw-echo-state' ],
68 $icon .
69 Html::rawElement( 'div', [ 'class' => 'mw-echo-content' ], $html )
70 );
71 }
72
73 private function getIconUrl( EchoEventPresentationModel $model ) {
74 return EchoIcon::getUrl(
75 $model->getIconType(),
76 $this->language->getDir()
77 );
78 }
79
80 }