Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / htmlform / fields / HTMLSelectLimitField.php
blobc7e7e17bc1c0a0e02aee1379db7e9c53742fed05
1 <?php
3 namespace MediaWiki\HTMLForm\Field;
5 /**
6 * A limit dropdown, which accepts any valid number
8 * @stable to extend
9 */
10 class HTMLSelectLimitField extends HTMLSelectField {
11 /**
12 * Basically don't do any validation. If it's a number that's fine. Also,
13 * add it to the list if it's not there already
15 * @param string $value
16 * @param array $alldata
17 * @return bool
19 public function validate( $value, $alldata ) {
20 if ( $value == '' ) {
21 return true;
24 // Let folks pick an explicit limit not from our list, as long as it's a real number.
25 if ( !in_array( $value, $this->mParams['options'] )
26 && $value == intval( $value )
27 && $value > 0
28 ) {
29 // This adds the explicitly requested limit value to the drop-down,
30 // then makes sure it's sorted correctly so when we output the list
31 // later, the custom option doesn't just show up last.
32 $this->mParams['options'][$this->mParent->getLanguage()->formatNum( $value )] =
33 intval( $value );
34 asort( $this->mParams['options'] );
37 return true;
41 /** @deprecated class alias since 1.42 */
42 class_alias( HTMLSelectLimitField::class, 'HTMLSelectLimitField' );