Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
HTMLSelectLimitField | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
validate | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | namespace MediaWiki\HTMLForm\Field; |
4 | |
5 | /** |
6 | * A limit dropdown, which accepts any valid number |
7 | * |
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 |
14 | * |
15 | * @param string $value |
16 | * @param array $alldata |
17 | * @return bool |
18 | */ |
19 | public function validate( $value, $alldata ) { |
20 | if ( $value == '' ) { |
21 | return true; |
22 | } |
23 | |
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'] ); |
35 | } |
36 | |
37 | return true; |
38 | } |
39 | } |
40 | |
41 | /** @deprecated class alias since 1.42 */ |
42 | class_alias( HTMLSelectLimitField::class, 'HTMLSelectLimitField' ); |