MediaWiki REL1_39
LimitDef.php
Go to the documentation of this file.
1<?php
2
4
7
18class LimitDef extends IntegerDef {
19
27 public function validate( $name, $value, array $settings, array $options ) {
28 if ( $value === 'max' ) {
29 if ( $options['parse-limit'] ?? true ) {
30 $value = $this->callbacks->useHighLimits( $options )
31 ? $settings[self::PARAM_MAX2] ?? $settings[self::PARAM_MAX] ?? PHP_INT_MAX
32 : $settings[self::PARAM_MAX] ?? PHP_INT_MAX;
33 }
34 return $value;
35 }
36
37 return parent::validate( $name, $value, $settings, $options );
38 }
39
40 public function normalizeSettings( array $settings ) {
41 $settings += [
42 self::PARAM_MIN => 0,
43 ];
44
45 // Cannot be multi-valued
46 $settings[ParamValidator::PARAM_ISMULTI] = false;
47
48 return parent::normalizeSettings( $settings );
49 }
50
51 public function checkSettings( string $name, $settings, array $options, array $ret ): array {
52 $ret = parent::checkSettings( $name, $settings, $options, $ret );
53
54 if ( !empty( $settings[ParamValidator::PARAM_ISMULTI] ) &&
55 !isset( $ret['issues'][ParamValidator::PARAM_ISMULTI] )
56 ) {
57 $ret['issues'][ParamValidator::PARAM_ISMULTI] =
58 'PARAM_ISMULTI cannot be used for limit-type parameters';
59 }
60
61 if ( ( $settings[self::PARAM_MIN] ?? 0 ) < 0 ) {
62 $ret['issues'][] = 'PARAM_MIN must be greater than or equal to 0';
63 }
64 if ( !isset( $settings[self::PARAM_MAX] ) ) {
65 $ret['issues'][] = 'PARAM_MAX must be set';
66 }
67
68 return $ret;
69 }
70
71 public function getHelpInfo( $name, array $settings, array $options ) {
72 $info = parent::getHelpInfo( $name, $settings, $options );
73
74 $info[ParamValidator::PARAM_TYPE] = MessageValue::new( 'paramvalidator-help-type-limit' )
75 ->params( 1 );
76
77 return $info;
78 }
79
80}
Value object representing a message for i18n.
Service for formatting and validating API parameters.
const PARAM_ISMULTI
(bool) Indicate that the parameter is multi-valued.
const PARAM_TYPE
(string|array) Type of the parameter.
Type definition for integer types.
Type definition for "limit" types.
Definition LimitDef.php:18
validate( $name, $value, array $settings, array $options)
Validate the value.When ParamValidator is processing a multi-valued parameter, this will be called on...
Definition LimitDef.php:27
normalizeSettings(array $settings)
Normalize a settings array.to override arrayto override
Definition LimitDef.php:40
checkSettings(string $name, $settings, array $options, array $ret)
Validate a parameter settings array.This is intended for validation of parameter settings during unit...
Definition LimitDef.php:51
getHelpInfo( $name, array $settings, array $options)
Describe parameter settings in human-readable format.Keys in the returned array should generally corr...
Definition LimitDef.php:71
const PARAM_MAX2
(int|float) Maximum allowed value (high limits)
const PARAM_MAX
(int|float) Maximum allowed value (normal limits)