Don't check namespace in SpecialWantedtemplates
[lhc/web/wiklou.git] / includes / htmlform / HTMLTextField.php
1 <?php
2
3 class HTMLTextField extends HTMLFormField {
4 function getSize() {
5 return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45;
6 }
7
8 function getInputHTML( $value ) {
9 $attribs = array(
10 'id' => $this->mID,
11 'name' => $this->mName,
12 'size' => $this->getSize(),
13 'value' => $value,
14 'dir' => $this->mDir,
15 ) + $this->getTooltipAndAccessKey();
16
17 if ( $this->mClass !== '' ) {
18 $attribs['class'] = $this->mClass;
19 }
20
21 # @todo Enforce pattern, step, required, readonly on the server side as
22 # well
23 $allowedParams = array(
24 'type',
25 'min',
26 'max',
27 'pattern',
28 'title',
29 'step',
30 'placeholder',
31 'list',
32 'maxlength',
33 'tabindex',
34 'disabled',
35 'required',
36 'autofocus',
37 'multiple',
38 'readonly'
39 );
40
41 $attribs += $this->getAttributes( $allowedParams );
42
43 # Extract 'type'
44 $type = $this->getType( $attribs );
45 return Html::input( $this->mName, $value, $type, $attribs );
46 }
47
48 protected function getType( &$attribs ) {
49 $type = isset( $attribs['type'] ) ? $attribs['type'] : 'text';
50 unset( $attribs['type'] );
51
52 # Implement tiny differences between some field variants
53 # here, rather than creating a new class for each one which
54 # is essentially just a clone of this one.
55 if ( isset( $this->mParams['type'] ) ) {
56 switch ( $this->mParams['type'] ) {
57 case 'int':
58 $type = 'number';
59 break;
60 case 'float':
61 $type = 'number';
62 $attribs['step'] = 'any';
63 break;
64 # Pass through
65 case 'email':
66 case 'password':
67 case 'file':
68 case 'url':
69 $type = $this->mParams['type'];
70 break;
71 }
72 }
73
74 return $type;
75 }
76
77 function getInputOOUI( $value ) {
78 $attribs = $this->getTooltipAndAccessKey();
79
80 if ( $this->mClass !== '' ) {
81 $attribs['classes'] = array( $this->mClass );
82 }
83
84 # @todo Enforce pattern, step, required, readonly on the server side as
85 # well
86 $allowedParams = array(
87 'autofocus',
88 'autosize',
89 'disabled',
90 'flags',
91 'indicator',
92 'maxlength',
93 'placeholder',
94 'readonly',
95 'required',
96 'tabindex',
97 'type',
98 );
99
100 $attribs += $this->getAttributes( $allowedParams, array(
101 'maxlength' => 'maxLength',
102 'readonly' => 'readOnly',
103 'tabindex' => 'tabIndex',
104 ) );
105
106 $type = $this->getType( $attribs );
107
108 return new OOUI\TextInputWidget( array(
109 'id' => $this->mID,
110 'name' => $this->mName,
111 'value' => $value,
112 'type' => $type,
113 ) + $attribs );
114 }
115 }