Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
HTMLInfoField | |
0.00% |
0 / 33 |
|
0.00% |
0 / 10 |
380 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getDefault | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getInputHTML | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
getInputOOUI | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
getTableRow | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getDiv | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getRaw | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getOOUI | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
getCodex | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
needsLabel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\HTMLForm\Field; |
4 | |
5 | use Closure; |
6 | use MediaWiki\HTMLForm\HTMLFormField; |
7 | |
8 | /** |
9 | * An information field (text blob), not a proper input. |
10 | * @stable to extend |
11 | */ |
12 | class HTMLInfoField extends HTMLFormField { |
13 | /** |
14 | * @stable to call |
15 | * |
16 | * @param array $info |
17 | * In addition to the usual HTMLFormField parameters, this can take the following fields: |
18 | * - default: the value (text) of the field. Unlike other form field types, HTMLInfoField can |
19 | * take a closure as a default value, which will be evaluated with $info as its only parameter. |
20 | * - raw: if true, the value won't be escaped. |
21 | * - rawrow: if true, the usual wrapping of form fields (e.g. into a table row + cell when |
22 | * display mode is table) will not happen and the value must contain it already. |
23 | */ |
24 | public function __construct( $info ) { |
25 | $info['nodata'] = true; |
26 | |
27 | parent::__construct( $info ); |
28 | } |
29 | |
30 | /** |
31 | * @inheritDoc |
32 | * @stable to override |
33 | */ |
34 | public function getDefault() { |
35 | $default = parent::getDefault(); |
36 | if ( $default instanceof Closure ) { |
37 | $default = $default( $this->mParams ); |
38 | } |
39 | return $default; |
40 | } |
41 | |
42 | /** |
43 | * @inheritDoc |
44 | * @stable to override |
45 | */ |
46 | public function getInputHTML( $value ) { |
47 | return !empty( $this->mParams['raw'] ) ? $value : htmlspecialchars( $value ); |
48 | } |
49 | |
50 | /** |
51 | * @inheritDoc |
52 | * @stable to override |
53 | */ |
54 | public function getInputOOUI( $value ) { |
55 | if ( !empty( $this->mParams['raw'] ) ) { |
56 | $value = new \OOUI\HtmlSnippet( $value ); |
57 | } |
58 | |
59 | return new \OOUI\LabelWidget( [ |
60 | 'label' => $value, |
61 | 'id' => $this->mID |
62 | ] ); |
63 | } |
64 | |
65 | /** |
66 | * @inheritDoc |
67 | * @stable to override |
68 | */ |
69 | public function getTableRow( $value ) { |
70 | if ( !empty( $this->mParams['rawrow'] ) ) { |
71 | return $value; |
72 | } |
73 | |
74 | return parent::getTableRow( $value ); |
75 | } |
76 | |
77 | /** |
78 | * @stable to override |
79 | * @param string $value |
80 | * @return string |
81 | * @since 1.20 |
82 | */ |
83 | public function getDiv( $value ) { |
84 | if ( !empty( $this->mParams['rawrow'] ) ) { |
85 | return $value; |
86 | } |
87 | |
88 | return parent::getDiv( $value ); |
89 | } |
90 | |
91 | /** |
92 | * @stable to override |
93 | * @param string $value |
94 | * @return string |
95 | * @since 1.20 |
96 | */ |
97 | public function getRaw( $value ) { |
98 | if ( !empty( $this->mParams['rawrow'] ) ) { |
99 | return $value; |
100 | } |
101 | |
102 | return parent::getRaw( $value ); |
103 | } |
104 | |
105 | /** |
106 | * @stable to override |
107 | * @param mixed $value If not FieldLayout or subclass has been deprecated. |
108 | * @return \OOUI\FieldLayout |
109 | * @since 1.32 |
110 | */ |
111 | public function getOOUI( $value ) { |
112 | if ( !empty( $this->mParams['rawrow'] ) ) { |
113 | if ( !( $value instanceof \OOUI\FieldLayout ) ) { |
114 | wfDeprecatedMsg( __METHOD__ . ": 'default' parameter as a string when using " . |
115 | "'rawrow' was deprecated in MediaWiki 1.32 (must be a FieldLayout or subclass)", |
116 | '1.32' ); |
117 | } |
118 | return $value; |
119 | } |
120 | |
121 | return parent::getOOUI( $value ); |
122 | } |
123 | |
124 | public function getCodex( $value ) { |
125 | if ( !empty( $this->mParams['rawrow'] ) ) { |
126 | return $value; |
127 | } |
128 | |
129 | return parent::getCodex( $value ); |
130 | } |
131 | |
132 | /** |
133 | * @inheritDoc |
134 | * @stable to override |
135 | */ |
136 | protected function needsLabel() { |
137 | return false; |
138 | } |
139 | } |
140 | |
141 | /** @deprecated class alias since 1.42 */ |
142 | class_alias( HTMLInfoField::class, 'HTMLInfoField' ); |