83 public function validate( $name, $value, array $settings, array $options ) {
86 if ( !$user || !in_array(
$type, $settings[self::PARAM_ALLOWED_USER_TYPES],
true ) ) {
87 $this->
failure(
'baduser', $name, $value, $settings, $options );
90 return empty( $settings[self::PARAM_RETURN_OBJECT] ) ? $user->getName() : $user;
94 if ( isset( $settings[self::PARAM_ALLOWED_USER_TYPES] ) ) {
96 [
'name',
'ip',
'cidr',
'interwiki',
'id' ],
97 $settings[self::PARAM_ALLOWED_USER_TYPES]
100 if ( empty( $settings[self::PARAM_ALLOWED_USER_TYPES] ) ) {
104 return parent::normalizeSettings( $settings );
107 public function checkSettings(
string $name, $settings, array $options, array $ret ): array {
108 $ret = parent::
checkSettings( $name, $settings, $options, $ret );
110 $ret[
'allowedKeys'] = array_merge( $ret[
'allowedKeys'], [
111 self::PARAM_ALLOWED_USER_TYPES, self::PARAM_RETURN_OBJECT,
114 if ( !is_bool( $settings[self::PARAM_RETURN_OBJECT] ??
false ) ) {
116 . gettype( $settings[self::PARAM_RETURN_OBJECT] );
120 if ( isset( $settings[self::PARAM_ALLOWED_USER_TYPES] ) ) {
121 if ( !is_array( $settings[self::PARAM_ALLOWED_USER_TYPES] ) ) {
123 .
'got ' . gettype( $settings[self::PARAM_ALLOWED_USER_TYPES] );
124 } elseif ( $settings[self::PARAM_ALLOWED_USER_TYPES] === [] ) {
128 $settings[self::PARAM_ALLOWED_USER_TYPES],
129 [
'name',
'ip',
'cidr',
'interwiki',
'id' ]
133 'PARAM_ALLOWED_USER_TYPES contains invalid values: ' . implode(
', ', $bad );
136 $hasId = in_array(
'id', $settings[self::PARAM_ALLOWED_USER_TYPES],
true );
140 if ( !empty( $settings[ParamValidator::PARAM_ISMULTI] ) &&
141 ( $hasId || !empty( $settings[self::PARAM_RETURN_OBJECT] ) ) &&
143 ( $settings[ParamValidator::PARAM_ISMULTI_LIMIT1] ?? 100 ) > 10 ||
144 ( $settings[ParamValidator::PARAM_ISMULTI_LIMIT2] ?? 100 ) > 10
147 $ret[
'issues'][] =
'Multi-valued user-type parameters with PARAM_RETURN_OBJECT or allowing IDs '
148 .
'should set low values (<= 10) for PARAM_ISMULTI_LIMIT1 and PARAM_ISMULTI_LIMIT2.'
149 .
' (Note that "<= 10" is arbitrary. If something hits this, we can investigate a real limit '
150 .
'once we have a real use case to look at.)';
164 if ( preg_match(
'/^#(\d+)$/D', $value, $m ) ) {
165 return [
'id', $this->userFactory->newFromId( $m[1] ) ];
171 $name = $this->userNameUtils->getCanonical( $value, UserNameUtils::RIGOR_NONE );
178 $user = is_string( $name ) ?
new UserIdentityValue( 0, $value, UserIdentityValue::LOCAL ) : null;
179 return [
'interwiki', $user ];
183 $user = $this->userFactory->newFromName( $value, UserFactory::RIGOR_VALID );
185 return [
'name', $user ];
190 if ( strpos( $value,
'#' ) !==
false ) {
194 $t = $this->titleFactory->newFromText( $value );
195 if ( !
$t ||
$t->getNamespace() !==
NS_USER ||
$t->isExternal() ) {
196 $t = $this->titleFactory->newFromText(
"User:$value" );
198 if ( !
$t ||
$t->getNamespace() !==
NS_USER ||
$t->isExternal() ) {
202 $value =
$t->getText();
205 $b = IPUtils::RE_IP_BYTE;
206 if ( IPUtils::isValid( $value ) ||
211 preg_match(
"/^$b\.$b\.$b\.xxx$/D", $value )
213 $name = IPUtils::sanitizeIP( $value );
219 $name = $this->userNameUtils->getCanonical( $name, UserNameUtils::RIGOR_NONE );
220 return [
'ip', UserIdentityValue::newAnonymous( $name ) ];
224 if ( IPUtils::isValidRange( $value ) ) {
225 $name = IPUtils::sanitizeIP( $value );
227 $name = $this->userNameUtils->getCanonical( $name, UserNameUtils::RIGOR_NONE );
228 return [
'cidr', UserIdentityValue::newAnonymous( $name ) ];
235 public function getParamInfo( $name, array $settings, array $options ) {
236 $info = parent::getParamInfo( $name, $settings, $options );
238 $info[
'subtypes'] = $settings[self::PARAM_ALLOWED_USER_TYPES];
243 public function getHelpInfo( $name, array $settings, array $options ) {
244 $info = parent::getParamInfo( $name, $settings, $options );
246 $isMulti = !empty( $settings[ParamValidator::PARAM_ISMULTI] );
249 foreach ( $settings[self::PARAM_ALLOWED_USER_TYPES] as $st ) {
253 $subtypes[] = MessageValue::new(
"paramvalidator-help-type-user-subtype-$st" );
255 $info[ParamValidator::PARAM_TYPE] = MessageValue::new(
'paramvalidator-help-type-user' )
256 ->params( $isMulti ? 2 : 1 )
257 ->textListParams( $subtypes )
258 ->numParams( count( $subtypes ) );
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Class to parse and build external user names.
static isExternal( $username)
Tells whether the username is external or not.