|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* An information field (text blob), not a proper input. |
|
5
|
|
|
*/ |
|
6
|
|
|
class HTMLInfoField extends HTMLFormField { |
|
7
|
|
|
/** |
|
8
|
|
|
* @param array $info |
|
9
|
|
|
* In adition to the usual HTMLFormField parameters, this can take the following fields: |
|
10
|
|
|
* - default: the value (text) of the field. Unlike other form field types, HTMLInfoField can |
|
11
|
|
|
* take a closure as a default value, which will be evaluated with $info as its only parameter. |
|
12
|
|
|
* - raw: if true, the value won't be escaped. |
|
13
|
|
|
* - rawrow: if true, the usual wrapping of form fields (e.g. into a table row + cell when |
|
14
|
|
|
* display mode is table) will not happen and the value must contain it already. |
|
15
|
|
|
*/ |
|
16
|
|
|
public function __construct( $info ) { |
|
17
|
|
|
$info['nodata'] = true; |
|
18
|
|
|
|
|
19
|
|
|
parent::__construct( $info ); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
function getDefault() { |
|
23
|
|
|
$default = parent::getDefault(); |
|
24
|
|
|
if ( $default instanceof Closure ) { |
|
25
|
|
|
$default = call_user_func( $default, $this->mParams ); |
|
26
|
|
|
} |
|
27
|
|
|
return $default; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function getInputHTML( $value ) { |
|
31
|
|
|
return !empty( $this->mParams['raw'] ) ? $value : htmlspecialchars( $value ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function getInputOOUI( $value ) { |
|
35
|
|
|
if ( !empty( $this->mParams['raw'] ) ) { |
|
36
|
|
|
$value = new OOUI\HtmlSnippet( $value ); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return new OOUI\LabelWidget( [ |
|
40
|
|
|
'label' => $value, |
|
41
|
|
|
] ); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getTableRow( $value ) { |
|
45
|
|
|
if ( !empty( $this->mParams['rawrow'] ) ) { |
|
46
|
|
|
return $value; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return parent::getTableRow( $value ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $value |
|
54
|
|
|
* @return string |
|
55
|
|
|
* @since 1.20 |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getDiv( $value ) { |
|
58
|
|
|
if ( !empty( $this->mParams['rawrow'] ) ) { |
|
59
|
|
|
return $value; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return parent::getDiv( $value ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param string $value |
|
67
|
|
|
* @return string |
|
68
|
|
|
* @since 1.20 |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getRaw( $value ) { |
|
71
|
|
|
if ( !empty( $this->mParams['rawrow'] ) ) { |
|
72
|
|
|
return $value; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return parent::getRaw( $value ); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
protected function needsLabel() { |
|
79
|
|
|
return false; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|