MediaWiki REL1_39
HTMLFloatField.php
Go to the documentation of this file.
1<?php
2
9 public function getSize() {
10 return $this->mParams['size'] ?? 20;
11 }
12
13 public function validate( $value, $alldata ) {
14 $p = parent::validate( $value, $alldata );
15
16 if ( $p !== true ) {
17 return $p;
18 }
19
20 $value = trim( $value ?? '' );
21 if ( $value === '' ) {
22 return true;
23 }
24
25 # https://www.w3.org/TR/html5/infrastructure.html#floating-point-numbers
26 # with the addition that a leading '+' sign is ok.
27 if ( !preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) {
28 return $this->msg( 'htmlform-float-invalid' );
29 }
30
31 # The "int" part of these message names is rather confusing.
32 # They make equal sense for all numbers.
33 if ( isset( $this->mParams['min'] ) ) {
34 $min = $this->mParams['min'];
35
36 if ( $min > $value ) {
37 return $this->msg( 'htmlform-int-toolow', $min );
38 }
39 }
40
41 if ( isset( $this->mParams['max'] ) ) {
42 $max = $this->mParams['max'];
43
44 if ( $max < $value ) {
45 return $this->msg( 'htmlform-int-toohigh', $max );
46 }
47 }
48
49 return true;
50 }
51
56 protected function getInputWidget( $params ) {
57 return new OOUI\NumberInputWidget( $params );
58 }
59}
A field that will contain a numeric value.
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.
getInputWidget( $params)
to overrideWidget
msg( $key,... $params)
Get a translated interface message.
<input> field.