Merge "Import: Handle uploads with sha1 starting with 0 properly"
[mediawiki.git] / includes / htmlform / HTMLTextField.php
blob157116d829e76059fbf0ab43f81e6ea27cba17f6
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 = array(
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();
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 = array(
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'] = array( $this->mClass );
94 # @todo Enforce pattern, step, required, readonly on the server side as
95 # well
96 $allowedParams = array(
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, array(
111 'maxlength' => 'maxLength',
112 'readonly' => 'readOnly',
113 'tabindex' => 'tabIndex',
114 ) );
116 $type = $this->getType( $attribs );
118 return $this->getInputWidget( array(
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 );