Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 48
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
EchoFlyoutFormatter
0.00% covered (danger)
0.00%
0 / 48
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 1
 formatModel
0.00% covered (danger)
0.00%
0 / 44
0.00% covered (danger)
0.00%
0 / 1
20
 getIconURL
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Extension\Notifications\Formatters;
4
5use MediaWiki\Html\Html;
6use 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 */
15class 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}