Merge "Restore ability for getAttributes to set HTMLTextField type"
[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 ) + $this->getTooltipAndAccessKey();
15
16 if ( $this->mClass !== '' ) {
17 $attribs['class'] = $this->mClass;
18 }
19
20 # @todo Enforce pattern, step, required, readonly on the server side as
21 # well
22 $allowedParams = array(
23 'type',
24 'min',
25 'max',
26 'pattern',
27 'title',
28 'step',
29 'placeholder',
30 'list',
31 'maxlength',
32 'tabindex',
33 'disabled',
34 'required',
35 'autofocus',
36 'multiple',
37 'readonly'
38 );
39
40 $attribs += $this->getAttributes( $allowedParams );
41
42 # Extract 'type'
43 $type = isset( $attribs['type'] ) ? $attribs['type'] : 'text';
44 unset( $attribs['type'] );
45
46 # Implement tiny differences between some field variants
47 # here, rather than creating a new class for each one which
48 # is essentially just a clone of this one.
49 if ( isset( $this->mParams['type'] ) ) {
50 switch ( $this->mParams['type'] ) {
51 case 'int':
52 $type = 'number';
53 break;
54 case 'float':
55 $type = 'number';
56 $attribs['step'] = 'any';
57 break;
58 # Pass through
59 case 'email':
60 case 'password':
61 case 'file':
62 case 'url':
63 $type = $this->mParams['type'];
64 break;
65 }
66 }
67
68 return Html::input( $this->mName, $value, $type, $attribs );
69 }
70 }