MediaWiki
1.40.4
HTMLTextAreaField.php
Go to the documentation of this file.
1
<?php
2
3
/*
4
* @stable to extend
5
*/
6
7
use
MediaWiki\Html\Html
;
8
use
MediaWiki\MediaWikiServices
;
9
10
class
HTMLTextAreaField
extends
HTMLFormField
{
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
array_push( $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
array_push(
82
$classes,
83
'mw-editfont-'
. $userOptionsLookup->getOption(
84
$this->mParent->getUser(),
85
'editfont'
86
)
87
);
88
$this->mParent->getOutput()->addModuleStyles(
'mediawiki.editfont.styles'
);
89
}
90
if
( $this->mPlaceholder !==
''
) {
91
$attribs[
'placeholder'
] =
$this->mPlaceholder
;
92
}
93
if
( $classes ) {
94
$attribs[
'class'
] = $classes;
95
}
96
97
$allowedParams = [
98
'tabindex'
,
99
'disabled'
,
100
'readonly'
,
101
'required'
,
102
'autofocus'
103
];
104
105
$attribs += $this->
getAttributes
( $allowedParams );
106
return
Html::textarea( $this->mName, $value, $attribs );
107
}
108
113
public
function
getInputOOUI
( $value ) {
114
$classes = [];
115
116
if
( isset( $this->mParams[
'cols'
] ) ) {
117
throw
new
Exception(
"OOUIHTMLForm does not support the 'cols' parameter for textareas"
);
118
}
119
120
$attribs = $this->
getTooltipAndAccessKeyOOUI
();
121
122
if
( $this->mClass !==
''
) {
123
array_push( $classes, $this->mClass );
124
}
125
if
( $this->mUseEditFont ) {
126
$userOptionsLookup = MediaWikiServices::getInstance()
127
->getUserOptionsLookup();
128
// The following classes can be used here:
129
// * mw-editfont-monospace
130
// * mw-editfont-sans-serif
131
// * mw-editfont-serif
132
array_push(
133
$classes,
134
'mw-editfont-'
. $userOptionsLookup->getOption(
135
$this->mParent->getUser(),
136
'editfont'
137
)
138
);
139
$this->mParent->getOutput()->addModuleStyles(
'mediawiki.editfont.styles'
);
140
}
141
if
( $this->mPlaceholder !==
''
) {
142
$attribs[
'placeholder'
] =
$this->mPlaceholder
;
143
}
144
if
( count( $classes ) ) {
145
$attribs[
'classes'
] = $classes;
146
}
147
148
$allowedParams = [
149
'tabindex'
,
150
'disabled'
,
151
'readonly'
,
152
'required'
,
153
'autofocus'
,
154
];
155
156
$attribs += OOUI\Element::configFromHtmlAttributes(
157
$this->
getAttributes
( $allowedParams )
158
);
159
160
return
new
OOUI\MultilineTextInputWidget( [
161
'id'
=> $this->mID,
162
'name'
=> $this->mName,
163
'value'
=> $value,
164
'rows'
=> $this->
getRows
(),
165
] + $attribs );
166
}
167
}
HTMLFormField
The parent class to generate form fields.
Definition
HTMLFormField.php:12
HTMLFormField\$mID
$mID
Definition
HTMLFormField.php:21
HTMLFormField\getMessage
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
Definition
HTMLFormField.php:1312
HTMLFormField\getTooltipAndAccessKeyOOUI
getTooltipAndAccessKeyOOUI()
Returns the attributes required for the tooltip and accesskey, for OOUI widgets' config.
Definition
HTMLFormField.php:1133
HTMLFormField\getAttributes
getAttributes(array $list)
Returns the given attributes from the parameters.
Definition
HTMLFormField.php:1151
HTMLFormField\getTooltipAndAccessKey
getTooltipAndAccessKey()
Returns the attributes required for the tooltip and accesskey, for Html::element() etc.
Definition
HTMLFormField.php:1120
HTMLTextAreaField
Definition
HTMLTextAreaField.php:10
HTMLTextAreaField\getInputHTML
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
Definition
HTMLTextAreaField.php:61
HTMLTextAreaField\__construct
__construct( $params)
Definition
HTMLTextAreaField.php:26
HTMLTextAreaField\$mUseEditFont
$mUseEditFont
Definition
HTMLTextAreaField.php:15
HTMLTextAreaField\DEFAULT_ROWS
const DEFAULT_ROWS
Definition
HTMLTextAreaField.php:12
HTMLTextAreaField\getCols
getCols()
Definition
HTMLTextAreaField.php:40
HTMLTextAreaField\getRows
getRows()
Definition
HTMLTextAreaField.php:44
HTMLTextAreaField\DEFAULT_COLS
const DEFAULT_COLS
Definition
HTMLTextAreaField.php:11
HTMLTextAreaField\getInputOOUI
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
Definition
HTMLTextAreaField.php:113
HTMLTextAreaField\getSpellCheck
getSpellCheck()
Definition
HTMLTextAreaField.php:48
HTMLTextAreaField\$mPlaceholder
$mPlaceholder
Definition
HTMLTextAreaField.php:14
MediaWiki\Html\Html
This class is a collection of static functions that serve two purposes:
Definition
Html.php:55
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
Definition
MediaWikiServices.php:223
includes
htmlform
fields
HTMLTextAreaField.php
Generated on Thu Jun 27 2024 15:50:53 for MediaWiki by
1.10.0