MediaWiki REL1_40
PresenceBooleanDef.php
Go to the documentation of this file.
1<?php
2
4
8
22
23 public function getValue( $name, array $settings, array $options ) {
24 return $this->callbacks->hasParam( $name, $options ) ? true : null;
25 }
26
27 public function validate( $name, $value, array $settings, array $options ) {
28 return (bool)$value;
29 }
30
31 public function normalizeSettings( array $settings ) {
32 // Cannot be multi-valued
33 $settings[ParamValidator::PARAM_ISMULTI] = false;
34
35 // Default the default to false so ParamValidator::getValue() returns false (T244440)
36 $settings += [ ParamValidator::PARAM_DEFAULT => false ];
37
38 return parent::normalizeSettings( $settings );
39 }
40
41 public function checkSettings( string $name, $settings, array $options, array $ret ): array {
42 $ret = parent::checkSettings( $name, $settings, $options, $ret );
43
44 if ( !empty( $settings[ParamValidator::PARAM_ISMULTI] ) &&
45 !isset( $ret['issues'][ParamValidator::PARAM_ISMULTI] )
46 ) {
47 $ret['issues'][ParamValidator::PARAM_ISMULTI] =
48 'PARAM_ISMULTI cannot be used for presence-boolean-type parameters';
49 }
50
51 if ( ( $settings[ParamValidator::PARAM_DEFAULT] ?? false ) !== false &&
52 !isset( $ret['issues'][ParamValidator::PARAM_DEFAULT] )
53 ) {
54 $ret['issues'][ParamValidator::PARAM_DEFAULT] =
55 'Default for presence-boolean-type parameters must be false or null';
56 }
57
58 return $ret;
59 }
60
61 public function getParamInfo( $name, array $settings, array $options ) {
62 $info = parent::getParamInfo( $name, $settings, $options );
63
64 // No need to report the default of "false"
65 $info['default'] = null;
66
67 return $info;
68 }
69
70 public function getHelpInfo( $name, array $settings, array $options ) {
71 $info = parent::getHelpInfo( $name, $settings, $options );
72
73 $info[ParamValidator::PARAM_TYPE] = MessageValue::new(
74 'paramvalidator-help-type-presenceboolean'
75 )->params( 1 );
76
77 // No need to report the default of "false"
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_DEFAULT
(mixed) Default value of the parameter.
const PARAM_TYPE
(string|array) Type of the parameter.
Type definition for checkbox-like boolean types.
getParamInfo( $name, array $settings, array $options)
Describe parameter settings in a machine-readable format.
normalizeSettings(array $settings)
Normalize a settings array.
getValue( $name, array $settings, array $options)
Get the value from the request.
getHelpInfo( $name, array $settings, array $options)
Describe parameter settings in human-readable format.
validate( $name, $value, array $settings, array $options)
Validate the value.
checkSettings(string $name, $settings, array $options, array $ret)
Validate a parameter settings array.
Base definition for ParamValidator types.
Definition TypeDef.php:19
return true
Definition router.php:92