MediaWiki 1.41.2
HTMLTextAreaField.php
Go to the documentation of this file.
1<?php
2
3/*
4 * @stable to extend
5 */
6
9
11 protected const DEFAULT_COLS = 80;
12 protected const DEFAULT_ROWS = 25;
13
14 protected $mPlaceholder = '';
15 protected $mUseEditFont = false;
16
26 public function __construct( $params ) {
27 parent::__construct( $params );
28
29 if ( isset( $params['placeholder-message'] ) ) {
30 $this->mPlaceholder = $this->getMessage( $params['placeholder-message'] )->text();
31 } elseif ( isset( $params['placeholder'] ) ) {
32 $this->mPlaceholder = $params['placeholder'];
33 }
34
35 if ( isset( $params['useeditfont'] ) ) {
36 $this->mUseEditFont = $params['useeditfont'];
37 }
38 }
39
40 public function getCols() {
41 return $this->mParams['cols'] ?? static::DEFAULT_COLS;
42 }
43
44 public function getRows() {
45 return $this->mParams['rows'] ?? static::DEFAULT_ROWS;
46 }
47
48 public function getSpellCheck() {
49 $val = $this->mParams['spellcheck'] ?? null;
50 if ( is_bool( $val ) ) {
51 // "spellcheck" attribute literally requires "true" or "false" to work.
52 return $val ? 'true' : 'false';
53 }
54 return null;
55 }
56
61 public function getInputHTML( $value ) {
62 $classes = [];
63
64 $attribs = [
65 'id' => $this->mID,
66 'cols' => $this->getCols(),
67 'rows' => $this->getRows(),
68 'spellcheck' => $this->getSpellCheck(),
69 ] + $this->getTooltipAndAccessKey();
70
71 if ( $this->mClass !== '' ) {
72 $classes[] = $this->mClass;
73 }
74 if ( $this->mUseEditFont ) {
75 $userOptionsLookup = MediaWikiServices::getInstance()
76 ->getUserOptionsLookup();
77 // The following classes can be used here:
78 // * mw-editfont-monospace
79 // * mw-editfont-sans-serif
80 // * mw-editfont-serif
81 $classes[] =
82 'mw-editfont-' .
83 $userOptionsLookup->getOption( $this->mParent->getUser(), 'editfont' );
84 $this->mParent->getOutput()->addModuleStyles( 'mediawiki.editfont.styles' );
85 }
86 if ( $this->mPlaceholder !== '' ) {
87 $attribs['placeholder'] = $this->mPlaceholder;
88 }
89 if ( $classes ) {
90 $attribs['class'] = $classes;
91 }
92
93 $allowedParams = [
94 'maxlength',
95 'minlength',
96 'tabindex',
97 'disabled',
98 'readonly',
99 'required',
100 'autofocus'
101 ];
102
103 $attribs += $this->getAttributes( $allowedParams );
104 return Html::textarea( $this->mName, $value, $attribs );
105 }
106
111 public function getInputOOUI( $value ) {
112 $classes = [];
113
114 if ( isset( $this->mParams['cols'] ) ) {
115 throw new Exception( "OOUIHTMLForm does not support the 'cols' parameter for textareas" );
116 }
117
118 $attribs = $this->getTooltipAndAccessKeyOOUI();
119
120 if ( $this->mClass !== '' ) {
121 $classes[] = $this->mClass;
122 }
123 if ( $this->mUseEditFont ) {
124 $userOptionsLookup = MediaWikiServices::getInstance()
125 ->getUserOptionsLookup();
126 // The following classes can be used here:
127 // * mw-editfont-monospace
128 // * mw-editfont-sans-serif
129 // * mw-editfont-serif
130 $classes[] =
131 'mw-editfont-' .
132 $userOptionsLookup->getOption( $this->mParent->getUser(), 'editfont' );
133 $this->mParent->getOutput()->addModuleStyles( 'mediawiki.editfont.styles' );
134 }
135 if ( $this->mPlaceholder !== '' ) {
136 $attribs['placeholder'] = $this->mPlaceholder;
137 }
138 if ( count( $classes ) ) {
139 $attribs['classes'] = $classes;
140 }
141
142 $allowedParams = [
143 'maxlength',
144 'minlength',
145 'tabindex',
146 'disabled',
147 'readonly',
148 'required',
149 'autofocus',
150 ];
151
152 $attribs += OOUI\Element::configFromHtmlAttributes(
153 $this->getAttributes( $allowedParams )
154 );
155
156 return new OOUI\MultilineTextInputWidget( [
157 'id' => $this->mID,
158 'name' => $this->mName,
159 'value' => $value,
160 'rows' => $this->getRows(),
161 ] + $attribs );
162 }
163}
The parent class to generate form fields.
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
getTooltipAndAccessKeyOOUI()
Returns the attributes required for the tooltip and accesskey, for OOUI widgets' config.
getAttributes(array $list)
Returns the given attributes from the parameters.
getTooltipAndAccessKey()
Returns the attributes required for the tooltip and accesskey, for Html::element() etc.
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
This class is a collection of static functions that serve two purposes:
Definition Html.php:57
Service locator for MediaWiki core services.