Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / htmlform / fields / HTMLFloatField.php
blobe036fed00ea59998e89fcd00d22e8cbfe36b3d54
1 <?php
3 namespace MediaWiki\HTMLForm\Field;
5 /**
6 * A field that will contain a numeric value
8 * @stable to extend
9 */
10 class HTMLFloatField extends HTMLTextField {
11 public function getSize() {
12 return $this->mParams['size'] ?? 20;
15 public function validate( $value, $alldata ) {
16 $p = parent::validate( $value, $alldata );
18 if ( $p !== true ) {
19 return $p;
22 $value = trim( $value ?? '' );
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' );
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'];
35 if ( $min > $value ) {
36 return $this->msg( 'htmlform-int-toolow', $min );
40 if ( isset( $this->mParams['max'] ) ) {
41 $max = $this->mParams['max'];
43 if ( $max < $value ) {
44 return $this->msg( 'htmlform-int-toohigh', $max );
48 return true;
51 /**
52 * @inheritDoc
53 * @stable to override
55 protected function getInputWidget( $params ) {
56 return new \OOUI\NumberInputWidget( $params );
60 /** @deprecated class alias since 1.42 */
61 class_alias( HTMLFloatField::class, 'HTMLFloatField' );