Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
TimelineException | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getStatsdKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getHtml | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Timeline; |
4 | |
5 | use Exception; |
6 | use MediaWiki\Html\Html; |
7 | use MediaWiki\Title\Title; |
8 | |
9 | /** |
10 | * Timeline exception |
11 | */ |
12 | class TimelineException extends Exception { |
13 | |
14 | /** @var array */ |
15 | private $args; |
16 | |
17 | /** |
18 | * @param string $message Message key |
19 | * @param array $args message arguments (optional) |
20 | */ |
21 | public function __construct( $message, array $args = [] ) { |
22 | parent::__construct( $message ); |
23 | $this->args = $args; |
24 | } |
25 | |
26 | /** |
27 | * Key for use in statsd metrics |
28 | * |
29 | * @return string |
30 | */ |
31 | public function getStatsdKey(): string { |
32 | // Normalize message key into _ for statsd |
33 | return str_replace( '-', '_', $this->getMessage() ); |
34 | } |
35 | |
36 | /** |
37 | * Get the exception as localized HTML |
38 | * |
39 | * TODO: inject context? |
40 | * |
41 | * @return string |
42 | */ |
43 | public function getHtml() { |
44 | return Html::rawElement( |
45 | 'div', |
46 | [ 'class' => [ 'error', 'timeline-error' ] ], |
47 | wfMessage( $this->message, ...$this->args ) |
48 | ->inContentLanguage() |
49 | ->title( Title::makeTitle( NS_SPECIAL, 'Badtitle' ) ) |
50 | ->parse() |
51 | ); |
52 | } |
53 | } |