Movatterモバイル変換


[0]ホーム

URL:


MediaWiki master
HTMLTextField.php
Go to the documentation of this file.
1<?php
2
3namespaceMediaWiki\HTMLForm\Field;
4
5useMediaWiki\Html\Html;
6useMediaWiki\HTMLForm\HTMLFormField;
7use OOUI\Widget;
8
19classHTMLTextFieldextendsHTMLFormField {
21protected$mPlaceholder ='';
22
24protected$autocomplete;
25
37publicfunction__construct( $params ) {
38if ( isset( $params['autocomplete'] ) && is_bool( $params['autocomplete'] ) ) {
39 $params['autocomplete'] = $params['autocomplete'] ?'on' :'off';
40 }
41
42 parent::__construct( $params );
43
44if ( isset( $params['placeholder-message'] ) ) {
45 $this->mPlaceholder = $this->getMessage( $params['placeholder-message'] )->text();
46 } elseif ( isset( $params['placeholder'] ) ) {
47 $this->mPlaceholder = $params['placeholder'];
48 }
49 }
50
55publicfunctiongetSize() {
56return $this->mParams['size'] ?? 45;
57 }
58
62publicfunctiongetSpellCheck() {
63 $val = $this->mParams['spellcheck'] ??null;
64if ( is_bool( $val ) ) {
65// "spellcheck" attribute literally requires "true" or "false" to work.
66return $val ?'true' :'false';
67 }
68returnnull;
69 }
70
74publicfunctionisPersistent() {
75if ( isset( $this->mParams['persistent'] ) ) {
76return $this->mParams['persistent'];
77 }
78// don't put passwords into the HTML body, they could get cached or otherwise leaked
79return !( isset( $this->mParams['type'] ) && $this->mParams['type'] ==='password' );
80 }
81
86publicfunctiongetInputHTML( $value ) {
87if ( !$this->isPersistent() ) {
88 $value ='';
89 }
90
91 $attribs = [
92'id' =>$this->mID,
93'name' =>$this->mName,
94'size' => $this->getSize(),
95'value' => $value,
96'dir' =>$this->mDir,
97'spellcheck' => $this->getSpellCheck(),
98 ] + $this->getTooltipAndAccessKey() + $this->getDataAttribs();
99
100if ( $this->mClass !=='' ) {
101 $attribs['class'] =$this->mClass;
102 }
103if ( $this->mPlaceholder !=='' ) {
104 $attribs['placeholder'] =$this->mPlaceholder;
105 }
106
107 # @todo Enforce pattern, step, required, readonly on the server side as
108 # well
109 $allowedParams = [
110'type',
111'min',
112'max',
113'step',
114'title',
115'maxlength',
116'minlength',
117'tabindex',
118'disabled',
119'required',
120'autofocus',
121'readonly',
122'autocomplete',
123'inputmode',
124// Only used in HTML mode:
125'pattern',
126'list',
127 ];
128
129 $attribs += $this->getAttributes( $allowedParams );
130
131 # Extract 'type'
132 $type = $this->getType( $attribs );
133
134 $inputHtml = Html::input( $this->mName, $value, $type, $attribs );
135return $inputHtml;
136 }
137
142protectedfunctiongetType( &$attribs ) {
143 $type = $attribs['type'] ??'text';
144 unset( $attribs['type'] );
145
146 # Implement tiny differences between some field variants
147 # here, rather than creating a new class for each one which
148 # is essentially just a clone of this one.
149if ( isset( $this->mParams['type'] ) ) {
150switch ( $this->mParams['type'] ) {
151case'int':
152 $type ='number';
153 $attribs['step'] = 1;
154break;
155case'float':
156 $type ='number';
157 $attribs['step'] ='any';
158break;
159 # Pass through
160case'email':
161case'password':
162case'url':
163 $type = $this->mParams['type'];
164break;
165case'textwithbutton':
166 $type = $this->mParams['inputtype'] ??'text';
167break;
168 }
169 }
170
171return $type;
172 }
173
178publicfunctiongetInputOOUI( $value ) {
179if ( !$this->isPersistent() ) {
180 $value ='';
181 }
182
183 $attribs = $this->getTooltipAndAccessKeyOOUI();
184
185if ( $this->mClass !=='' ) {
186 $attribs['classes'] = [$this->mClass ];
187 }
188if ( $this->mPlaceholder !=='' ) {
189 $attribs['placeholder'] =$this->mPlaceholder;
190 }
191
192 # @todo Enforce pattern, step, required, readonly on the server side as
193 # well
194 $allowedParams = [
195'type',
196'min',
197'max',
198'step',
199'title',
200'maxlength',
201'minlength',
202'tabindex',
203'disabled',
204'required',
205'autofocus',
206'readonly',
207'autocomplete',
208'inputmode',
209// Only used in OOUI mode:
210'autosize',
211'flags',
212'indicator',
213 ];
214
215 $attribs += \OOUI\Element::configFromHtmlAttributes(
216 $this->getAttributes( $allowedParams )
217 );
218
219 $type = $this->getType( $attribs );
220if ( isset( $attribs['step'] ) && $attribs['step'] ==='any' ) {
221 $attribs['step'] =null;
222 }
223
224return $this->getInputWidget( [
225'id' => $this->mID,
226'name' => $this->mName,
227'value' => $value,
228'type' => $type,
229'dir' => $this->mDir,
230 ] + $attribs );
231 }
232
234publicfunctiongetInputCodex( $value, $hasErrors ) {
235if ( !$this->isPersistent() ) {
236 $value ='';
237 }
238
239 $attribs = [
240'id' =>$this->mID,
241'name' =>$this->mName,
242'size' => $this->getSize(),
243'value' => $value,
244'dir' =>$this->mDir,
245'spellcheck' => $this->getSpellCheck(),
246 ] + $this->getTooltipAndAccessKey() + $this->getDataAttribs();
247
248if ( $this->mPlaceholder !=='' ) {
249 $attribs['placeholder'] =$this->mPlaceholder;
250 }
251 $attribs['class'] = $this->mClass ? [$this->mClass ] : [];
252
253 $allowedParams = [
254'type',
255'min',
256'max',
257'step',
258'title',
259'maxlength',
260'minlength',
261'tabindex',
262'disabled',
263'required',
264'autofocus',
265'readonly',
266'autocomplete',
267'inputmode',
268'pattern',
269'list',
270 ];
271
272 $attribs += $this->getAttributes( $allowedParams );
273
274// Extract 'type'.
275 $type = $this->getType( $attribs );
276
277return static::buildCodexComponent( $value, $hasErrors, $type, $this->mName, $attribs );
278 }
279
290publicstaticfunctionbuildCodexComponent( $value, $hasErrors, $type, $name, $inputAttribs ) {
291// Set up classes for the outer <div>.
292 $wrapperClass = ['cdx-text-input' ];
293if ( $hasErrors ) {
294 $wrapperClass[] ='cdx-text-input--status-error';
295 }
296
297 $inputAttribs['class'][] ='cdx-text-input__input';
298 $inputHtml = Html::input( $name, $value, $type, $inputAttribs );
299
300return Html::rawElement('div', ['class' => $wrapperClass ], $inputHtml );
301 }
302
310protectedfunctiongetInputWidget( $params ) {
311return new \OOUI\TextInputWidget( $params );
312 }
313
320protectedfunctiongetDataAttribs() {
321return [];
322 }
323}
324
326class_alias( HTMLTextField::class,'HTMLTextField' );
MediaWiki\HTMLForm\Field\HTMLTextField
<input> field.
DefinitionHTMLTextField.php:19
MediaWiki\HTMLForm\Field\HTMLTextField\getType
getType(&$attribs)
DefinitionHTMLTextField.php:142
MediaWiki\HTMLForm\Field\HTMLTextField\getSpellCheck
getSpellCheck()
DefinitionHTMLTextField.php:62
MediaWiki\HTMLForm\Field\HTMLTextField\getInputHTML
getInputHTML( $value)
This function must be implemented to return the HTML to generate the input object itself....
DefinitionHTMLTextField.php:86
MediaWiki\HTMLForm\Field\HTMLTextField\getInputWidget
getInputWidget( $params)
DefinitionHTMLTextField.php:310
MediaWiki\HTMLForm\Field\HTMLTextField\getSize
getSize()
DefinitionHTMLTextField.php:55
MediaWiki\HTMLForm\Field\HTMLTextField\getInputCodex
getInputCodex( $value, $hasErrors)
Same as getInputHTML, but for Codex.This is called by CodexHTMLForm.If not overridden,...
DefinitionHTMLTextField.php:234
MediaWiki\HTMLForm\Field\HTMLTextField\$autocomplete
bool $autocomplete
HTML autocomplete attribute.
DefinitionHTMLTextField.php:24
MediaWiki\HTMLForm\Field\HTMLTextField\getDataAttribs
getDataAttribs()
Returns an array of data-* attributes to add to the field.
DefinitionHTMLTextField.php:320
MediaWiki\HTMLForm\Field\HTMLTextField\__construct
__construct( $params)
DefinitionHTMLTextField.php:37
MediaWiki\HTMLForm\Field\HTMLTextField\buildCodexComponent
static buildCodexComponent( $value, $hasErrors, $type, $name, $inputAttribs)
Build the markup of the Codex component.
DefinitionHTMLTextField.php:290
MediaWiki\HTMLForm\Field\HTMLTextField\$mPlaceholder
string $mPlaceholder
DefinitionHTMLTextField.php:21
MediaWiki\HTMLForm\Field\HTMLTextField\getInputOOUI
getInputOOUI( $value)
Same as getInputHTML, but returns an OOUI object.Defaults to false, which getOOUI will interpret as "...
DefinitionHTMLTextField.php:178
MediaWiki\HTMLForm\Field\HTMLTextField\isPersistent
isPersistent()
DefinitionHTMLTextField.php:74
MediaWiki\HTMLForm\HTMLFormField
The parent class to generate form fields.
DefinitionHTMLFormField.php:27
MediaWiki\HTMLForm\HTMLFormField\getTooltipAndAccessKey
getTooltipAndAccessKey()
Returns the attributes required for the tooltip and accesskey, for Html::element() etc.
DefinitionHTMLFormField.php:1241
MediaWiki\HTMLForm\HTMLFormField\getMessage
getMessage( $value)
Turns a *-message parameter (which could be a MessageSpecifier, or a message name,...
DefinitionHTMLFormField.php:1440
MediaWiki\HTMLForm\HTMLFormField\$mClass
string $mClass
DefinitionHTMLFormField.php:44
MediaWiki\HTMLForm\HTMLFormField\getTooltipAndAccessKeyOOUI
getTooltipAndAccessKeyOOUI()
Returns the attributes required for the tooltip and accesskey, for OOUI widgets' config.
DefinitionHTMLFormField.php:1254
MediaWiki\HTMLForm\HTMLFormField\$mID
string $mID
DefinitionHTMLFormField.php:42
MediaWiki\HTMLForm\HTMLFormField\getAttributes
getAttributes(array $list)
Returns the given attributes from the parameters.
DefinitionHTMLFormField.php:1272
MediaWiki\HTMLForm\HTMLFormField\$mName
string $mName
DefinitionHTMLFormField.php:36
MediaWiki\HTMLForm\HTMLFormField\$mDir
string $mDir
DefinitionHTMLFormField.php:38
MediaWiki\Html\Html
This class is a collection of static functions that serve two purposes:
DefinitionHtml.php:43
MediaWiki\HTMLForm\Field
DefinitionHTMLApiField.php:3

[8]ページ先頭

©2009-2025 Movatter.jp