2013-11-19 12:55:50 +00:00
|
|
|
<?php
|
2013-11-19 13:08:16 +00:00
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
/**
|
|
|
|
|
* An information field (text blob), not a proper input.
|
|
|
|
|
*/
|
|
|
|
|
class HTMLInfoField extends HTMLFormField {
|
2016-08-02 07:27:44 +00:00
|
|
|
/**
|
|
|
|
|
* @param array $info
|
|
|
|
|
* In adition to the usual HTMLFormField parameters, this can take the following fields:
|
|
|
|
|
* - default: the value (text) of the field. Unlike other form field types, HTMLInfoField can
|
|
|
|
|
* take a closure as a default value, which will be evaluated with $info as its only parameter.
|
|
|
|
|
* - raw: if true, the value won't be escaped.
|
|
|
|
|
* - rawrow: if true, the usual wrapping of form fields (e.g. into a table row + cell when
|
|
|
|
|
* display mode is table) will not happen and the value must contain it already.
|
|
|
|
|
*/
|
2013-11-19 12:55:50 +00:00
|
|
|
public function __construct( $info ) {
|
2013-11-19 13:08:16 +00:00
|
|
|
$info['nodata'] = true;
|
2013-11-19 12:55:50 +00:00
|
|
|
|
|
|
|
|
parent::__construct( $info );
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-04 10:40:42 +00:00
|
|
|
public function getDefault() {
|
2016-08-02 07:27:44 +00:00
|
|
|
$default = parent::getDefault();
|
|
|
|
|
if ( $default instanceof Closure ) {
|
2019-03-08 03:25:40 +00:00
|
|
|
$default = $default( $this->mParams );
|
2016-08-02 07:27:44 +00:00
|
|
|
}
|
|
|
|
|
return $default;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
public function getInputHTML( $value ) {
|
2013-11-19 13:08:16 +00:00
|
|
|
return !empty( $this->mParams['raw'] ) ? $value : htmlspecialchars( $value );
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-21 21:03:49 +00:00
|
|
|
public function getInputOOUI( $value ) {
|
|
|
|
|
if ( !empty( $this->mParams['raw'] ) ) {
|
|
|
|
|
$value = new OOUI\HtmlSnippet( $value );
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return new OOUI\LabelWidget( [
|
2015-04-21 21:03:49 +00:00
|
|
|
'label' => $value,
|
2016-02-17 09:09:32 +00:00
|
|
|
] );
|
2015-04-21 21:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
public function getTableRow( $value ) {
|
2013-11-19 13:08:16 +00:00
|
|
|
if ( !empty( $this->mParams['rawrow'] ) ) {
|
2013-11-19 12:55:50 +00:00
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parent::getTableRow( $value );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-08-14 18:22:52 +00:00
|
|
|
* @param string $value
|
|
|
|
|
* @return string
|
2013-11-19 12:55:50 +00:00
|
|
|
* @since 1.20
|
|
|
|
|
*/
|
|
|
|
|
public function getDiv( $value ) {
|
2013-11-19 13:08:16 +00:00
|
|
|
if ( !empty( $this->mParams['rawrow'] ) ) {
|
2013-11-19 12:55:50 +00:00
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parent::getDiv( $value );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-08-14 18:22:52 +00:00
|
|
|
* @param string $value
|
|
|
|
|
* @return string
|
2013-11-19 12:55:50 +00:00
|
|
|
* @since 1.20
|
|
|
|
|
*/
|
|
|
|
|
public function getRaw( $value ) {
|
2013-11-19 13:08:16 +00:00
|
|
|
if ( !empty( $this->mParams['rawrow'] ) ) {
|
2013-11-19 12:55:50 +00:00
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parent::getRaw( $value );
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-03 16:35:28 +00:00
|
|
|
/**
|
2019-06-13 10:59:01 +00:00
|
|
|
* @param mixed $value If not FieldLayout or subclass has been deprecated.
|
2018-09-03 16:35:28 +00:00
|
|
|
* @return OOUI\FieldLayout
|
|
|
|
|
* @since 1.32
|
|
|
|
|
*/
|
|
|
|
|
public function getOOUI( $value ) {
|
|
|
|
|
if ( !empty( $this->mParams['rawrow'] ) ) {
|
|
|
|
|
if ( !( $value instanceof OOUI\FieldLayout ) ) {
|
2019-06-13 10:59:01 +00:00
|
|
|
wfDeprecated( __METHOD__ . ": 'default' parameter as a string when using" .
|
|
|
|
|
"'rawrow' (must be a FieldLayout or subclass)", '1.32' );
|
2018-09-03 16:35:28 +00:00
|
|
|
}
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parent::getOOUI( $value );
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
protected function needsLabel() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-11-19 13:08:16 +00:00
|
|
|
}
|