MediaWiki  REL1_24
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         $type = 'text';
00045         if ( isset( $this->mParams['type'] ) ) {
00046             switch ( $this->mParams['type'] ) {
00047                 case 'int':
00048                     $type = 'number';
00049                     break;
00050                 case 'float':
00051                     $type = 'number';
00052                     $attribs['step'] = 'any';
00053                     break;
00054                 # Pass through
00055                 case 'email':
00056                 case 'password':
00057                 case 'file':
00058                 case 'url':
00059                     $type = $this->mParams['type'];
00060                     break;
00061             }
00062         }
00063         return Html::input( $this->mName, $value, $type, $attribs );
00064     }
00065 }