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