MediaWiki  master
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 
22  # https://www.w3.org/TR/html5/infrastructure.html#floating-point-numbers
23  # with the addition that a leading '+' sign is ok.
24  if ( !preg_match( '/^((\+|\-)?\d+(\.\d+)?(E(\+|\-)?\d+)?)?$/i', $value ) ) {
25  return $this->msg( 'htmlform-float-invalid' );
26  }
27 
28  # The "int" part of these message names is rather confusing.
29  # They make equal sense for all numbers.
30  if ( isset( $this->mParams['min'] ) ) {
31  $min = $this->mParams['min'];
32 
33  if ( $min > $value ) {
34  return $this->msg( 'htmlform-int-toolow', $min );
35  }
36  }
37 
38  if ( isset( $this->mParams['max'] ) ) {
39  $max = $this->mParams['max'];
40 
41  if ( $max < $value ) {
42  return $this->msg( 'htmlform-int-toohigh', $max );
43  }
44  }
45 
46  return true;
47  }
48 
53  protected function getInputWidget( $params ) {
54  return new OOUI\NumberInputWidget( $params );
55  }
56 }
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)
Stability: stableto overrideWidget
msg( $key,... $params)
Get a translated interface message.
<input> field.