MediaWiki  REL1_23
HTMLTextField.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class HTMLTextField extends HTMLFormField {
00004     function getSize() {
00005         return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 45;
00006     }
00007 
00008     function getInputHTML( $value ) {
00009         $attribs = array(
00010                 'id' => $this->mID,
00011                 'name' => $this->mName,
00012                 'size' => $this->getSize(),
00013                 'value' => $value,
00014             ) + $this->getTooltipAndAccessKey();
00015 
00016         if ( $this->mClass !== '' ) {
00017             $attribs['class'] = $this->mClass;
00018         }
00019 
00020         # @todo Enforce pattern, step, required, readonly on the server side as
00021         # well
00022         $allowedParams = array(
00023             'min',
00024             'max',
00025             'pattern',
00026             'title',
00027             'step',
00028             'placeholder',
00029             'list',
00030             'maxlength',
00031             'tabindex',
00032             'disabled',
00033             'required',
00034             'autofocus',
00035             'multiple',
00036             'readonly'
00037         );
00038 
00039         $attribs += $this->getAttributes( $allowedParams );
00040 
00041         # Implement tiny differences between some field variants
00042         # here, rather than creating a new class for each one which
00043         # is essentially just a clone of this one.
00044         if ( isset( $this->mParams['type'] ) ) {
00045             switch ( $this->mParams['type'] ) {
00046                 case 'int':
00047                     $attribs['type'] = 'number';
00048                     break;
00049                 case 'float':
00050                     $attribs['type'] = 'number';
00051                     $attribs['step'] = 'any';
00052                     break;
00053                 # Pass through
00054                 case 'email':
00055                 case 'password':
00056                 case 'file':
00057                 case 'url':
00058                     $attribs['type'] = $this->mParams['type'];
00059                     break;
00060             }
00061         }
00062 
00063         return Html::element( 'input', $attribs );
00064     }
00065 }