Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
HTMLFloatField | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
90 | |
0.00% |
0 / 1 |
getSize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
validate | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
56 | |||
getInputWidget | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\HTMLForm\Field; |
4 | |
5 | /** |
6 | * A field that will contain a numeric value |
7 | * |
8 | * @stable to extend |
9 | */ |
10 | class HTMLFloatField extends HTMLTextField { |
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 | |
51 | /** |
52 | * @inheritDoc |
53 | * @stable to override |
54 | */ |
55 | protected function getInputWidget( $params ) { |
56 | return new \OOUI\NumberInputWidget( $params ); |
57 | } |
58 | } |
59 | |
60 | /** @deprecated class alias since 1.42 */ |
61 | class_alias( HTMLFloatField::class, 'HTMLFloatField' ); |