Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ScribuntoException | |
0.00% |
0 / 28 |
|
0.00% |
0 / 4 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
72 | |||
getMessageName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toStatus | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getScriptTraceHtml | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\Scribunto; |
4 | |
5 | use Exception; |
6 | use MediaWiki\Status\Status; |
7 | use MediaWiki\Title\Title; |
8 | |
9 | /** |
10 | * An exception class which represents an error in the script. This does not |
11 | * normally abort the request, instead it is caught and shown to the user. |
12 | */ |
13 | class ScribuntoException extends Exception { |
14 | /** |
15 | * @var string |
16 | */ |
17 | public $messageName; |
18 | |
19 | /** |
20 | * @var array |
21 | */ |
22 | public $messageArgs; |
23 | |
24 | /** |
25 | * @var array |
26 | */ |
27 | public $params; |
28 | |
29 | /** |
30 | * @param string $messageName |
31 | * @param array $params |
32 | */ |
33 | public function __construct( $messageName, $params = [] ) { |
34 | $this->messageArgs = $params['args'] ?? []; |
35 | if ( isset( $params['module'] ) && isset( $params['line'] ) ) { |
36 | $codeLocation = false; |
37 | if ( isset( $params['title'] ) ) { |
38 | $moduleTitle = Title::newFromText( $params['module'] ); |
39 | if ( $moduleTitle && $moduleTitle->equals( $params['title'] ) ) { |
40 | $codeLocation = wfMessage( 'scribunto-line', $params['line'] )->inContentLanguage()->text(); |
41 | } |
42 | } |
43 | if ( $codeLocation === false ) { |
44 | $codeLocation = wfMessage( |
45 | 'scribunto-module-line', |
46 | $params['module'], |
47 | $params['line'] |
48 | )->inContentLanguage()->text(); |
49 | } |
50 | } else { |
51 | $codeLocation = '[UNKNOWN]'; |
52 | } |
53 | array_unshift( $this->messageArgs, $codeLocation ); |
54 | $msg = wfMessage( $messageName ) |
55 | ->params( $this->messageArgs ) |
56 | ->inContentLanguage(); |
57 | if ( isset( $params['title'] ) ) { |
58 | $msg = $msg->page( $params['title'] ); |
59 | } |
60 | parent::__construct( $msg->text() ); |
61 | |
62 | $this->messageName = $messageName; |
63 | $this->params = $params; |
64 | } |
65 | |
66 | /** |
67 | * @return string |
68 | */ |
69 | public function getMessageName() { |
70 | return $this->messageName; |
71 | } |
72 | |
73 | public function toStatus() { |
74 | $status = Status::newFatal( $this->messageName, ...$this->messageArgs ); |
75 | $status->value = $this; |
76 | return $status; |
77 | } |
78 | |
79 | /** |
80 | * Get the backtrace as HTML, or false if there is none available. |
81 | * @param array $options |
82 | * @return bool|string |
83 | */ |
84 | public function getScriptTraceHtml( $options = [] ) { |
85 | return false; |
86 | } |
87 | } |