3 class HTMLTextAreaField
extends HTMLFormField
{
4 const DEFAULT_COLS
= 80;
5 const DEFAULT_ROWS
= 25;
7 protected $mPlaceholder = '';
8 protected $mUseEditFont = false;
11 * @param array $params
12 * - cols, rows: textarea size
13 * - placeholder/placeholder-message: set HTML placeholder attribute
14 * - spellcheck: set HTML spellcheck attribute
15 * - useeditfont: add CSS classes to use the same font as the wikitext editor
17 public function __construct( $params ) {
18 parent
::__construct( $params );
20 if ( isset( $params['placeholder-message'] ) ) {
21 $this->mPlaceholder
= $this->getMessage( $params['placeholder-message'] )->text();
22 } elseif ( isset( $params['placeholder'] ) ) {
23 $this->mPlaceholder
= $params['placeholder'];
26 if ( isset( $params['useeditfont'] ) ) {
27 $this->mUseEditFont
= $params['useeditfont'];
31 public function getCols() {
32 return $this->mParams
['cols'] ??
static::DEFAULT_COLS
;
35 public function getRows() {
36 return $this->mParams
['rows'] ??
static::DEFAULT_ROWS
;
39 public function getSpellCheck() {
40 $val = $this->mParams
['spellcheck'] ??
null;
41 if ( is_bool( $val ) ) {
42 // "spellcheck" attribute literally requires "true" or "false" to work.
43 return $val === true ?
'true' : 'false';
48 public function getInputHTML( $value ) {
53 'cols' => $this->getCols(),
54 'rows' => $this->getRows(),
55 'spellcheck' => $this->getSpellCheck(),
56 ] +
$this->getTooltipAndAccessKey();
58 if ( $this->mClass
!== '' ) {
59 array_push( $classes, $this->mClass
);
61 if ( $this->mUseEditFont
) {
62 // The following classes can be used here:
63 // * mw-editfont-monospace
64 // * mw-editfont-sans-serif
65 // * mw-editfont-serif
68 'mw-editfont-' . $this->mParent
->getUser()->getOption( 'editfont' )
70 $this->mParent
->getOutput()->addModuleStyles( 'mediawiki.editfont.styles' );
72 if ( $this->mPlaceholder
!== '' ) {
73 $attribs['placeholder'] = $this->mPlaceholder
;
75 if ( count( $classes ) ) {
76 $attribs['class'] = implode( ' ', $classes );
87 $attribs +
= $this->getAttributes( $allowedParams );
88 return Html
::textarea( $this->mName
, $value, $attribs );
91 function getInputOOUI( $value ) {
94 if ( isset( $this->mParams
['cols'] ) ) {
95 throw new Exception( "OOUIHTMLForm does not support the 'cols' parameter for textareas" );
98 $attribs = $this->getTooltipAndAccessKeyOOUI();
100 if ( $this->mClass
!== '' ) {
101 array_push( $classes, $this->mClass
);
103 if ( $this->mUseEditFont
) {
104 // The following classes can be used here:
105 // * mw-editfont-monospace
106 // * mw-editfont-sans-serif
107 // * mw-editfont-serif
110 'mw-editfont-' . $this->mParent
->getUser()->getOption( 'editfont' )
112 $this->mParent
->getOutput()->addModuleStyles( 'mediawiki.editfont.styles' );
114 if ( $this->mPlaceholder
!== '' ) {
115 $attribs['placeholder'] = $this->mPlaceholder
;
117 if ( count( $classes ) ) {
118 $attribs['classes'] = $classes;
129 $attribs +
= OOUI\Element
::configFromHtmlAttributes(
130 $this->getAttributes( $allowedParams )
133 return new OOUI\
MultilineTextInputWidget( [
135 'name' => $this->mName
,
137 'rows' => $this->getRows(),