Fix use of RawMessage in Status::getMessage()
[mediawiki.git] / includes / htmlform / HTMLTextField.php
blobfb7584b7d11227ece1916e6e64ab2f932801af8d
1 <?php
3 class HTMLTextField extends HTMLFormField {
4 function getSize() {
5 return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45;
8 function getSpellCheck() {
9 $val = isset( $this->mParams['spellcheck'] ) ? $this->mParams['spellcheck'] : null;
10 if ( is_bool( $val ) ) {
11 // "spellcheck" attribute literally requires "true" or "false" to work.
12 return $val === true ? 'true' : 'false';
14 return null;
17 function getInputHTML( $value ) {
18 $attribs = [
19 'id' => $this->mID,
20 'name' => $this->mName,
21 'size' => $this->getSize(),
22 'value' => $value,
23 'dir' => $this->mDir,
24 'spellcheck' => $this->getSpellCheck(),
25 ] + $this->getTooltipAndAccessKey() + $this->getDataAttribs();
27 if ( $this->mClass !== '' ) {
28 $attribs['class'] = $this->mClass;
31 # @todo Enforce pattern, step, required, readonly on the server side as
32 # well
33 $allowedParams = [
34 'type',
35 'min',
36 'max',
37 'pattern',
38 'title',
39 'step',
40 'placeholder',
41 'list',
42 'maxlength',
43 'tabindex',
44 'disabled',
45 'required',
46 'autofocus',
47 'multiple',
48 'readonly'
51 $attribs += $this->getAttributes( $allowedParams );
53 # Extract 'type'
54 $type = $this->getType( $attribs );
55 return Html::input( $this->mName, $value, $type, $attribs );
58 protected function getType( &$attribs ) {
59 $type = isset( $attribs['type'] ) ? $attribs['type'] : 'text';
60 unset( $attribs['type'] );
62 # Implement tiny differences between some field variants
63 # here, rather than creating a new class for each one which
64 # is essentially just a clone of this one.
65 if ( isset( $this->mParams['type'] ) ) {
66 switch ( $this->mParams['type'] ) {
67 case 'int':
68 $type = 'number';
69 break;
70 case 'float':
71 $type = 'number';
72 $attribs['step'] = 'any';
73 break;
74 # Pass through
75 case 'email':
76 case 'password':
77 case 'file':
78 case 'url':
79 $type = $this->mParams['type'];
80 break;
84 return $type;
87 function getInputOOUI( $value ) {
88 $attribs = $this->getTooltipAndAccessKey();
90 if ( $this->mClass !== '' ) {
91 $attribs['classes'] = [ $this->mClass ];
94 # @todo Enforce pattern, step, required, readonly on the server side as
95 # well
96 $allowedParams = [
97 'autofocus',
98 'autosize',
99 'disabled',
100 'flags',
101 'indicator',
102 'maxlength',
103 'placeholder',
104 'readonly',
105 'required',
106 'tabindex',
107 'type',
110 $attribs += $this->getAttributes( $allowedParams, [
111 'maxlength' => 'maxLength',
112 'readonly' => 'readOnly',
113 'tabindex' => 'tabIndex',
114 ] );
116 $type = $this->getType( $attribs );
118 return $this->getInputWidget( [
119 'id' => $this->mID,
120 'name' => $this->mName,
121 'value' => $value,
122 'type' => $type,
123 ] + $attribs );
126 protected function getInputWidget( $params ) {
127 return new OOUI\TextInputWidget( $params );
131 * Returns an array of data-* attributes to add to the field.
133 * @return array
135 protected function getDataAttribs() {
136 return [];