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