2013-11-19 12:55:50 +00:00
|
|
|
<?php
|
2013-11-19 13:08:16 +00:00
|
|
|
|
2020-07-10 19:23:59 +00:00
|
|
|
/*
|
|
|
|
|
* @stable to extend
|
|
|
|
|
*/
|
2013-11-19 12:55:50 +00:00
|
|
|
class HTMLTextAreaField extends HTMLFormField {
|
2020-05-15 22:07:42 +00:00
|
|
|
protected const DEFAULT_COLS = 80;
|
|
|
|
|
protected const DEFAULT_ROWS = 25;
|
2013-11-19 12:55:50 +00:00
|
|
|
|
2016-04-01 12:06:49 +00:00
|
|
|
protected $mPlaceholder = '';
|
2018-01-03 17:31:34 +00:00
|
|
|
protected $mUseEditFont = false;
|
2016-04-01 12:06:49 +00:00
|
|
|
|
|
|
|
|
/**
|
2020-07-10 19:23:59 +00:00
|
|
|
* @stable to call
|
|
|
|
|
*
|
2016-04-01 12:06:49 +00:00
|
|
|
* @param array $params
|
|
|
|
|
* - cols, rows: textarea size
|
|
|
|
|
* - placeholder/placeholder-message: set HTML placeholder attribute
|
|
|
|
|
* - spellcheck: set HTML spellcheck attribute
|
2018-01-03 17:31:34 +00:00
|
|
|
* - useeditfont: add CSS classes to use the same font as the wikitext editor
|
2016-04-01 12:06:49 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct( $params ) {
|
|
|
|
|
parent::__construct( $params );
|
|
|
|
|
|
|
|
|
|
if ( isset( $params['placeholder-message'] ) ) {
|
2017-12-07 01:42:24 +00:00
|
|
|
$this->mPlaceholder = $this->getMessage( $params['placeholder-message'] )->text();
|
2016-04-01 12:06:49 +00:00
|
|
|
} elseif ( isset( $params['placeholder'] ) ) {
|
|
|
|
|
$this->mPlaceholder = $params['placeholder'];
|
|
|
|
|
}
|
2018-01-03 17:31:34 +00:00
|
|
|
|
|
|
|
|
if ( isset( $params['useeditfont'] ) ) {
|
|
|
|
|
$this->mUseEditFont = $params['useeditfont'];
|
|
|
|
|
}
|
2016-04-01 12:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
2016-11-04 10:40:42 +00:00
|
|
|
public function getCols() {
|
2017-10-06 22:17:58 +00:00
|
|
|
return $this->mParams['cols'] ?? static::DEFAULT_COLS;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-11-04 10:40:42 +00:00
|
|
|
public function getRows() {
|
2017-10-06 22:17:58 +00:00
|
|
|
return $this->mParams['rows'] ?? static::DEFAULT_ROWS;
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
|
|
|
|
|
2016-11-04 10:40:42 +00:00
|
|
|
public function getSpellCheck() {
|
2017-10-06 22:17:58 +00:00
|
|
|
$val = $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.
|
2021-08-17 19:52:34 +00:00
|
|
|
return $val ? 'true' : 'false';
|
2015-05-18 22:35:15 +00:00
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 19:23:59 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
* @stable to override
|
|
|
|
|
*/
|
2016-11-04 10:40:42 +00:00
|
|
|
public function getInputHTML( $value ) {
|
2018-01-03 17:31:34 +00:00
|
|
|
$classes = [];
|
|
|
|
|
|
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 !== '' ) {
|
2018-01-03 17:31:34 +00:00
|
|
|
array_push( $classes, $this->mClass );
|
|
|
|
|
}
|
|
|
|
|
if ( $this->mUseEditFont ) {
|
|
|
|
|
// The following classes can be used here:
|
|
|
|
|
// * mw-editfont-monospace
|
|
|
|
|
// * mw-editfont-sans-serif
|
|
|
|
|
// * mw-editfont-serif
|
|
|
|
|
array_push(
|
|
|
|
|
$classes,
|
|
|
|
|
'mw-editfont-' . $this->mParent->getUser()->getOption( 'editfont' )
|
|
|
|
|
);
|
|
|
|
|
$this->mParent->getOutput()->addModuleStyles( 'mediawiki.editfont.styles' );
|
2013-11-19 12:55:50 +00:00
|
|
|
}
|
2016-04-01 12:06:49 +00:00
|
|
|
if ( $this->mPlaceholder !== '' ) {
|
|
|
|
|
$attribs['placeholder'] = $this->mPlaceholder;
|
|
|
|
|
}
|
2020-09-08 14:16:47 +00:00
|
|
|
if ( $classes ) {
|
|
|
|
|
$attribs['class'] = $classes;
|
2018-01-03 17:31:34 +00:00
|
|
|
}
|
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
|
|
|
|
2020-07-10 19:23:59 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
* @stable to override
|
|
|
|
|
*/
|
2020-05-11 00:55:41 +00:00
|
|
|
public function getInputOOUI( $value ) {
|
2018-01-03 17:31:34 +00:00
|
|
|
$classes = [];
|
|
|
|
|
|
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" );
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-22 19:30:03 +00:00
|
|
|
$attribs = $this->getTooltipAndAccessKeyOOUI();
|
2015-04-21 21:03:49 +00:00
|
|
|
|
|
|
|
|
if ( $this->mClass !== '' ) {
|
2018-01-03 17:31:34 +00:00
|
|
|
array_push( $classes, $this->mClass );
|
|
|
|
|
}
|
|
|
|
|
if ( $this->mUseEditFont ) {
|
|
|
|
|
// The following classes can be used here:
|
|
|
|
|
// * mw-editfont-monospace
|
|
|
|
|
// * mw-editfont-sans-serif
|
|
|
|
|
// * mw-editfont-serif
|
|
|
|
|
array_push(
|
|
|
|
|
$classes,
|
|
|
|
|
'mw-editfont-' . $this->mParent->getUser()->getOption( 'editfont' )
|
|
|
|
|
);
|
|
|
|
|
$this->mParent->getOutput()->addModuleStyles( 'mediawiki.editfont.styles' );
|
2015-04-21 21:03:49 +00:00
|
|
|
}
|
2016-04-01 12:06:49 +00:00
|
|
|
if ( $this->mPlaceholder !== '' ) {
|
|
|
|
|
$attribs['placeholder'] = $this->mPlaceholder;
|
|
|
|
|
}
|
2018-01-03 17:31:34 +00:00
|
|
|
if ( count( $classes ) ) {
|
|
|
|
|
$attribs['classes'] = $classes;
|
|
|
|
|
}
|
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
|
|
|
|
2017-10-12 21:36:40 +00:00
|
|
|
return new OOUI\MultilineTextInputWidget( [
|
2015-04-21 21:03:49 +00:00
|
|
|
'id' => $this->mID,
|
|
|
|
|
'name' => $this->mName,
|
|
|
|
|
'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
|
|
|
}
|