Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
ScoreException | |
0.00% |
0 / 12 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getHtml | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
getBox | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isTracked | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getStatsdKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /* |
3 | Score, a MediaWiki extension for rendering musical scores with LilyPond. |
4 | Copyright © 2011 Alexander Klauer |
5 | |
6 | This program is free software: you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation, either version 3 of the License, or |
9 | (at your option) any later version. |
10 | |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | |
19 | To contact the author: |
20 | <Graf.Zahl@gmx.net> |
21 | http://en.wikisource.org/wiki/User_talk:GrafZahl |
22 | https://github.com/TheCount/score |
23 | |
24 | */ |
25 | |
26 | namespace MediaWiki\Extension\Score; |
27 | |
28 | use Exception; |
29 | use MediaWiki\Html\Html; |
30 | use MediaWiki\Title\Title; |
31 | |
32 | /** |
33 | * Score exception |
34 | */ |
35 | class ScoreException extends Exception { |
36 | |
37 | /** @var array */ |
38 | private $args; |
39 | |
40 | /** |
41 | * @param string $message Message key of error message Should have one $1 parameter. |
42 | * @param array $args Parameters to the message |
43 | */ |
44 | public function __construct( $message, array $args = [] ) { |
45 | parent::__construct( $message ); |
46 | $this->args = $args; |
47 | } |
48 | |
49 | /** |
50 | * Auto-renders exception as HTML error message in the wiki's content |
51 | * language. |
52 | * |
53 | * @return string Error message HTML. |
54 | */ |
55 | public function getHtml() { |
56 | return $this->getBox( |
57 | wfMessage( $this->getMessage(), ...$this->args ) |
58 | ->inContentLanguage() |
59 | ->title( Title::makeTitle( NS_SPECIAL, 'Badtitle' ) ) |
60 | ->parse() |
61 | ); |
62 | } |
63 | |
64 | /** |
65 | * Get the error box. |
66 | * @param string $content Content of the box (raw HTML) |
67 | * @return string The error box (raw HTML) |
68 | */ |
69 | protected function getBox( string $content ): string { |
70 | return Html::errorBox( $content, '', 'mw-ext-score-error' ); |
71 | } |
72 | |
73 | /** |
74 | * Whether to add a tracking category |
75 | * |
76 | * @return bool |
77 | */ |
78 | public function isTracked() { |
79 | return true; |
80 | } |
81 | |
82 | /** |
83 | * Key for use in statsd metrics |
84 | * |
85 | * @return string|bool false if it shouldn't be recorded |
86 | */ |
87 | public function getStatsdKey() { |
88 | // Normalize message key into _ for statsd |
89 | return str_replace( '-', '_', $this->getMessage() ); |
90 | } |
91 | } |