MediaWiki master
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
41 public function normalizeSettings( array $settings ) {
42 $settings += [
43 self::PARAM_MIN => 0,
44 ];
45
46 // Cannot be multi-valued
47 $settings[ParamValidator::PARAM_ISMULTI] = false;
48
49 return parent::normalizeSettings( $settings );
50 }
51
53 public function checkSettings( string $name, $settings, array $options, array $ret ): array {
54 $ret = parent::checkSettings( $name, $settings, $options, $ret );
55
56 if ( !empty( $settings[ParamValidator::PARAM_ISMULTI] ) &&
57 !isset( $ret['issues'][ParamValidator::PARAM_ISMULTI] )
58 ) {
59 $ret['issues'][ParamValidator::PARAM_ISMULTI] =
60 'PARAM_ISMULTI cannot be used for limit-type parameters';
61 }
62
63 if ( ( $settings[self::PARAM_MIN] ?? 0 ) < 0 ) {
64 $ret['issues'][] = 'PARAM_MIN must be greater than or equal to 0';
65 }
66 if ( !isset( $settings[self::PARAM_MAX] ) ) {
67 $ret['issues'][] = 'PARAM_MAX must be set';
68 }
69
70 return $ret;
71 }
72
74 public function getHelpInfo( $name, array $settings, array $options ) {
75 $info = parent::getHelpInfo( $name, $settings, $options );
76
77 $info[ParamValidator::PARAM_TYPE] = MessageValue::new( 'paramvalidator-help-type-limit' )
78 ->params( 1 );
79
80 return $info;
81 }
82
83}
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:41
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:53
getHelpInfo( $name, array $settings, array $options)
Describe parameter settings in human-readable format.Keys in the returned array should generally corr...
Definition LimitDef.php:74
const PARAM_MAX2
(int|float) Maximum allowed value (high limits)
const PARAM_MAX
(int|float) Maximum allowed value (normal limits)