Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
30.00% |
3 / 10 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ScoreException | |
30.00% |
3 / 10 |
|
60.00% |
3 / 5 |
13.57 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getHtml | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| getBox | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isTracked | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getStatsdKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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 | /** |
| 38 | * @param string $message Message key of error message Should have one $1 parameter. |
| 39 | * @param array $args Parameters to the message |
| 40 | */ |
| 41 | public function __construct( |
| 42 | string $message, |
| 43 | private readonly array $args = [], |
| 44 | ) { |
| 45 | parent::__construct( $message ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Auto-renders exception as HTML error message in the wiki's content |
| 50 | * language. |
| 51 | * |
| 52 | * @return string Error message HTML. |
| 53 | */ |
| 54 | public function getHtml() { |
| 55 | return $this->getBox( |
| 56 | wfMessage( $this->getMessage(), ...$this->args ) |
| 57 | ->inContentLanguage() |
| 58 | ->title( Title::makeTitle( NS_SPECIAL, 'Badtitle' ) ) |
| 59 | ->parse() |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Get the error box. |
| 65 | * @param string $content Content of the box (raw HTML) |
| 66 | * @return string The error box (raw HTML) |
| 67 | */ |
| 68 | protected function getBox( string $content ): string { |
| 69 | return Html::errorBox( $content, '', 'mw-ext-score-error' ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Whether to add a tracking category |
| 74 | * |
| 75 | * @return bool |
| 76 | */ |
| 77 | public function isTracked() { |
| 78 | return true; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Key for use in statsd metrics |
| 83 | * |
| 84 | * @return string|bool false if it shouldn't be recorded |
| 85 | */ |
| 86 | public function getStatsdKey() { |
| 87 | // Normalize message key into _ for statsd |
| 88 | return str_replace( '-', '_', $this->getMessage() ); |
| 89 | } |
| 90 | } |