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