Merge "Remove ugly $wgTitle usage from edit.php maintenance script"
[lhc/web/wiklou.git] / includes / htmlform / HTMLFloatField.php
1 <?php
2 /**
3 * A field that will contain a numeric value
4 */
5 class HTMLFloatField extends HTMLTextField {
6 function getSize() {
7 return isset( $this->mParams[ 'size' ] ) ? $this->mParams[ 'size' ] : 20;
8 }
9
10 function validate( $value, $alldata ) {
11 $p = parent::validate( $value, $alldata );
12
13 if ( $p !== true ) {
14 return $p;
15 }
16
17 $value = trim( $value );
18
19 # http://dev.w3.org/html5/spec/common-microsyntaxes.html#real-numbers
20 # with the addition that a leading '+' sign is ok.
21 if ( ! preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) {
22 return $this->msg( 'htmlform-float-invalid' )->parseAsBlock();
23 }
24
25 # The "int" part of these message names is rather confusing.
26 # They make equal sense for all numbers.
27 if ( isset( $this->mParams[ 'min' ] ) ) {
28 $min = $this->mParams[ 'min' ];
29
30 if ( $min > $value ) {
31 return $this->msg( 'htmlform-int-toolow', $min )->parseAsBlock();
32 }
33 }
34
35 if ( isset( $this->mParams[ 'max' ] ) ) {
36 $max = $this->mParams[ 'max' ];
37
38 if ( $max < $value ) {
39 return $this->msg( 'htmlform-int-toohigh', $max )->parseAsBlock();
40 }
41 }
42
43 return true;
44 }
45 }