32 $this->nsInfo = $nsInfo;
35 public function validate( $name, $value, array $settings, array $options ) {
36 if ( !is_int( $value ) && preg_match(
'/^[+-]?\d+$/D', $value ) ) {
41 return parent::validate( $name, $value, $settings, $options );
44 public function getEnumValues( $name, array $settings, array $options ) {
45 $namespaces = $this->nsInfo->getValidNamespaces();
47 if ( is_array( $extra ) && $extra !== [] ) {
48 $namespaces = array_merge( $namespaces, $extra );
56 if ( !empty( $settings[ParamValidator::PARAM_ISMULTI] ) ) {
57 $settings[ParamValidator::PARAM_ALL] =
true;
59 return parent::normalizeSettings( $settings );
62 public function checkSettings(
string $name, $settings, array $options, array $ret ): array {
63 $ret = parent::
checkSettings( $name, $settings, $options, $ret );
65 $ret[
'allowedKeys'] = array_merge( $ret[
'allowedKeys'], [
66 self::PARAM_EXTRA_NAMESPACES,
69 if ( !empty( $settings[ParamValidator::PARAM_ISMULTI] ) &&
70 ( $settings[ParamValidator::PARAM_ALL] ??
true ) !==
true &&
71 !isset( $ret[
'issues'][ParamValidator::PARAM_ALL] )
73 $ret[
'issues'][ParamValidator::PARAM_ALL] =
74 'PARAM_ALL cannot be false or a string for namespace-type parameters';
78 if ( !is_array( $ns ) ) {
79 $type = gettype( $ns );
80 } elseif ( $ns === [] ) {
83 $types = array_unique( array_map(
'gettype', $ns ) );
84 $type = implode(
'|', $types );
85 $type = count( $types ) > 1 ?
"($type)[]" :
"{$type}[]";
87 if ( $type !==
'integer[]' ) {
89 "PARAM_EXTRA_NAMESPACES must be an integer[], got $type";
95 public function getParamInfo( $name, array $settings, array $options ) {
96 $info = parent::getParamInfo( $name, $settings, $options );
98 $info[
'type'] =
'namespace';
99 $extra = $settings[self::PARAM_EXTRA_NAMESPACES] ?? [];
100 if ( is_array( $extra ) && $extra !== [] ) {
101 $info[
'extranamespaces'] = array_values( $extra );
102 if ( isset( $options[
'module'] ) ) {
104 ApiResult::setIndexedTagName( $info[
'extranamespaces'],
'ns' );