Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
| HTMLInfoField | |
0.00% |
0 / 36 |
|
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 / 9 |
|
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 | // In case the information text contains any form elements, avoid treating it |
| 64 | // as a clickable label (T428359). Maybe it shouldn't be a `<label>` in the first place⦠|
| 65 | ->setAttributes( [ 'for' => '' ] ); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @inheritDoc |
| 70 | * @stable to override |
| 71 | */ |
| 72 | public function getTableRow( $value ) { |
| 73 | if ( !empty( $this->mParams['rawrow'] ) ) { |
| 74 | return $value; |
| 75 | } |
| 76 | |
| 77 | return parent::getTableRow( $value ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @stable to override |
| 82 | * @param string $value |
| 83 | * @return string |
| 84 | * @since 1.20 |
| 85 | */ |
| 86 | public function getDiv( $value ) { |
| 87 | if ( !empty( $this->mParams['rawrow'] ) ) { |
| 88 | return $value; |
| 89 | } |
| 90 | |
| 91 | return parent::getDiv( $value ); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @stable to override |
| 96 | * @param string $value |
| 97 | * @return string |
| 98 | * @since 1.20 |
| 99 | */ |
| 100 | public function getRaw( $value ) { |
| 101 | if ( !empty( $this->mParams['rawrow'] ) ) { |
| 102 | return $value; |
| 103 | } |
| 104 | |
| 105 | return parent::getRaw( $value ); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @stable to override |
| 110 | * @param mixed $value If not FieldLayout or subclass has been deprecated. |
| 111 | * @return \OOUI\FieldLayout |
| 112 | * @since 1.32 |
| 113 | */ |
| 114 | public function getOOUI( $value ) { |
| 115 | if ( !empty( $this->mParams['rawrow'] ) ) { |
| 116 | if ( !( $value instanceof \OOUI\FieldLayout ) ) { |
| 117 | wfDeprecatedMsg( __METHOD__ . ": 'default' parameter as a string when using " . |
| 118 | "'rawrow' was deprecated in MediaWiki 1.32 (must be a FieldLayout or subclass)", |
| 119 | '1.32' ); |
| 120 | } |
| 121 | return $value; |
| 122 | } |
| 123 | |
| 124 | return parent::getOOUI( $value ); |
| 125 | } |
| 126 | |
| 127 | /** @inheritDoc */ |
| 128 | public function getCodex( $value ) { |
| 129 | if ( !empty( $this->mParams['rawrow'] ) ) { |
| 130 | return $value; |
| 131 | } |
| 132 | |
| 133 | return parent::getCodex( $value ); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * @inheritDoc |
| 138 | * @stable to override |
| 139 | */ |
| 140 | protected function needsLabel() { |
| 141 | return false; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /** @deprecated class alias since 1.42 */ |
| 146 | class_alias( HTMLInfoField::class, 'HTMLInfoField' ); |