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