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
|
|
|
class HTMLTextAreaField extends HTMLFormField {
|
|
|
|
|
const DEFAULT_COLS = 80;
|
|
|
|
|
const DEFAULT_ROWS = 25;
|
|
|
|
|
|
2016-04-01 12:06:49 +00:00
|
|
|
protected $mPlaceholder = '';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $params
|
|
|
|
|
* - cols, rows: textarea size
|
|
|
|
|
* - placeholder/placeholder-message: set HTML placeholder attribute
|
|
|
|
|
* - spellcheck: set HTML spellcheck attribute
|
|
|
|
|
*/
|
|
|
|
|
public function __construct( $params ) {
|
|
|
|
|
parent::__construct( $params );
|
|
|
|
|
|
|
|
|
|
if ( isset( $params['placeholder-message'] ) ) {
|
|
|
|
|
$this->mPlaceholder = $this->getMessage( $params['placeholder-message'] )->parse();
|
|
|
|
|
} elseif ( isset( $params['placeholder'] ) ) {
|
|
|
|
|
$this->mPlaceholder = $params['placeholder'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
function getCols() {
|
2013-11-19 13:08:16 +00:00
|
|
|
return isset( $this->mParams['cols'] ) ? $this->mParams['cols'] : static::DEFAULT_COLS;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getRows() {
|
2013-11-19 13:08:16 +00:00
|
|
|
return isset( $this->mParams['rows'] ) ? $this->mParams['rows'] : static::DEFAULT_ROWS;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
2015-05-18 22:35:15 +00:00
|
|
|
function getSpellCheck() {
|
|
|
|
|
$val = isset( $this->mParams['spellcheck'] ) ? $this->mParams['spellcheck'] : null;
|
2015-06-26 05:32:28 +00:00
|
|
|
if ( is_bool( $val ) ) {
|
2015-05-18 22:35:15 +00:00
|
|
|
// "spellcheck" attribute literally requires "true" or "false" to work.
|
|
|
|
|
return $val === true ? 'true' : 'false';
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-19 12:55:50 +00:00
|
|
|
function getInputHTML( $value ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$attribs = [
|
2013-11-19 12:55:50 +00:00
|
|
|
'id' => $this->mID,
|
|
|
|
|
'cols' => $this->getCols(),
|
|
|
|
|
'rows' => $this->getRows(),
|
2015-05-18 22:35:15 +00:00
|
|
|
'spellcheck' => $this->getSpellCheck(),
|
2016-02-17 09:09:32 +00:00
|
|
|
] + $this->getTooltipAndAccessKey();
|
2013-11-19 12:55:50 +00:00
|
|
|
|
|
|
|
|
if ( $this->mClass !== '' ) {
|
2013-11-19 13:08:16 +00:00
|
|
|
$attribs['class'] = $this->mClass;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
2016-04-01 12:06:49 +00:00
|
|
|
if ( $this->mPlaceholder !== '' ) {
|
|
|
|
|
$attribs['placeholder'] = $this->mPlaceholder;
|
|
|
|
|
}
|
2013-11-19 12:55:50 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$allowedParams = [
|
2013-05-02 18:27:44 +00:00
|
|
|
'tabindex',
|
|
|
|
|
'disabled',
|
|
|
|
|
'readonly',
|
|
|
|
|
'required',
|
|
|
|
|
'autofocus'
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2013-05-02 18:27:44 +00:00
|
|
|
|
|
|
|
|
$attribs += $this->getAttributes( $allowedParams );
|
2014-07-30 17:56:25 +00:00
|
|
|
return Html::textarea( $this->mName, $value, $attribs );
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
2015-04-21 21:03:49 +00:00
|
|
|
|
|
|
|
|
function getInputOOUI( $value ) {
|
2015-07-08 01:27:03 +00:00
|
|
|
if ( isset( $this->mParams['cols'] ) ) {
|
|
|
|
|
throw new Exception( "OOUIHTMLForm does not support the 'cols' parameter for textareas" );
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 21:03:49 +00:00
|
|
|
$attribs = $this->getTooltipAndAccessKey();
|
|
|
|
|
|
|
|
|
|
if ( $this->mClass !== '' ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$attribs['classes'] = [ $this->mClass ];
|
2015-04-21 21:03:49 +00:00
|
|
|
}
|
2016-04-01 12:06:49 +00:00
|
|
|
if ( $this->mPlaceholder !== '' ) {
|
|
|
|
|
$attribs['placeholder'] = $this->mPlaceholder;
|
|
|
|
|
}
|
2015-04-21 21:03:49 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$allowedParams = [
|
2015-04-21 21:03:49 +00:00
|
|
|
'tabindex',
|
|
|
|
|
'disabled',
|
|
|
|
|
'readonly',
|
|
|
|
|
'required',
|
|
|
|
|
'autofocus',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2015-04-21 21:03:49 +00:00
|
|
|
|
2016-03-02 19:09:53 +00:00
|
|
|
$attribs += OOUI\Element::configFromHtmlAttributes(
|
|
|
|
|
$this->getAttributes( $allowedParams )
|
|
|
|
|
);
|
2015-04-21 21:03:49 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
return new OOUI\TextInputWidget( [
|
2015-04-21 21:03:49 +00:00
|
|
|
'id' => $this->mID,
|
|
|
|
|
'name' => $this->mName,
|
|
|
|
|
'multiline' => true,
|
|
|
|
|
'value' => $value,
|
2015-07-08 01:27:03 +00:00
|
|
|
'rows' => $this->getRows(),
|
2016-02-17 09:09:32 +00:00
|
|
|
] + $attribs );
|
2015-04-21 21:03:49 +00:00
|
|
|
}
|
2013-11-19 13:08:16 +00:00
|
|
|
}
|