MediaWiki  REL1_24
HTMLFloatField.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class HTMLFloatField extends HTMLTextField {
00007     function getSize() {
00008         return isset( $this->mParams['size'] ) ? $this->mParams['size'] : 20;
00009     }
00010 
00011     function validate( $value, $alldata ) {
00012         $p = parent::validate( $value, $alldata );
00013 
00014         if ( $p !== true ) {
00015             return $p;
00016         }
00017 
00018         $value = trim( $value );
00019 
00020         # http://dev.w3.org/html5/spec/common-microsyntaxes.html#real-numbers
00021         # with the addition that a leading '+' sign is ok.
00022         if ( !preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) {
00023             return $this->msg( 'htmlform-float-invalid' )->parseAsBlock();
00024         }
00025 
00026         # The "int" part of these message names is rather confusing.
00027         # They make equal sense for all numbers.
00028         if ( isset( $this->mParams['min'] ) ) {
00029             $min = $this->mParams['min'];
00030 
00031             if ( $min > $value ) {
00032                 return $this->msg( 'htmlform-int-toolow', $min )->parseAsBlock();
00033             }
00034         }
00035 
00036         if ( isset( $this->mParams['max'] ) ) {
00037             $max = $this->mParams['max'];
00038 
00039             if ( $max < $value ) {
00040                 return $this->msg( 'htmlform-int-toohigh', $max )->parseAsBlock();
00041             }
00042         }
00043 
00044         return true;
00045     }
00046 }