Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / htmlform / fields / HTMLInfoField.php
blobcedf2edcb23b78ea66e54d3dcc4e0f6452ec0a07
1 <?php
3 namespace MediaWiki\HTMLForm\Field;
5 use Closure;
6 use MediaWiki\HTMLForm\HTMLFormField;
8 /**
9 * An information field (text blob), not a proper input.
10 * @stable to extend
12 class HTMLInfoField extends HTMLFormField {
13 /**
14 * @stable to call
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.
24 public function __construct( $info ) {
25 $info['nodata'] = true;
27 parent::__construct( $info );
30 /**
31 * @inheritDoc
32 * @stable to override
34 public function getDefault() {
35 $default = parent::getDefault();
36 if ( $default instanceof Closure ) {
37 $default = $default( $this->mParams );
39 return $default;
42 /**
43 * @inheritDoc
44 * @stable to override
46 public function getInputHTML( $value ) {
47 return !empty( $this->mParams['raw'] ) ? $value : htmlspecialchars( $value );
50 /**
51 * @inheritDoc
52 * @stable to override
54 public function getInputOOUI( $value ) {
55 if ( !empty( $this->mParams['raw'] ) ) {
56 $value = new \OOUI\HtmlSnippet( $value );
59 return new \OOUI\LabelWidget( [
60 'label' => $value,
61 'id' => $this->mID
62 ] );
65 /**
66 * @inheritDoc
67 * @stable to override
69 public function getTableRow( $value ) {
70 if ( !empty( $this->mParams['rawrow'] ) ) {
71 return $value;
74 return parent::getTableRow( $value );
77 /**
78 * @stable to override
79 * @param string $value
80 * @return string
81 * @since 1.20
83 public function getDiv( $value ) {
84 if ( !empty( $this->mParams['rawrow'] ) ) {
85 return $value;
88 return parent::getDiv( $value );
91 /**
92 * @stable to override
93 * @param string $value
94 * @return string
95 * @since 1.20
97 public function getRaw( $value ) {
98 if ( !empty( $this->mParams['rawrow'] ) ) {
99 return $value;
102 return parent::getRaw( $value );
106 * @stable to override
107 * @param mixed $value If not FieldLayout or subclass has been deprecated.
108 * @return \OOUI\FieldLayout
109 * @since 1.32
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' );
118 return $value;
121 return parent::getOOUI( $value );
124 public function getCodex( $value ) {
125 if ( !empty( $this->mParams['rawrow'] ) ) {
126 return $value;
129 return parent::getCodex( $value );
133 * @inheritDoc
134 * @stable to override
136 protected function needsLabel() {
137 return false;
141 /** @deprecated class alias since 1.42 */
142 class_alias( HTMLInfoField::class, 'HTMLInfoField' );