54 public function validate( $name, $value, array $settings, array $options ) {
57 if ( !$user || !in_array(
$type, $settings[self::PARAM_ALLOWED_USER_TYPES],
true ) ) {
58 $this->
failure(
'baduser', $name, $value, $settings, $options );
60 return empty( $settings[self::PARAM_RETURN_OBJECT] ) ? $user->getName() : $user;
64 if ( isset( $settings[self::PARAM_ALLOWED_USER_TYPES] ) ) {
66 [
'name',
'ip',
'cidr',
'interwiki',
'id' ],
67 $settings[self::PARAM_ALLOWED_USER_TYPES]
70 if ( empty( $settings[self::PARAM_ALLOWED_USER_TYPES] ) ) {
74 return parent::normalizeSettings( $settings );
77 public function checkSettings(
string $name, $settings, array $options, array $ret ) : array {
78 $ret = parent::
checkSettings( $name, $settings, $options, $ret );
80 $ret[
'allowedKeys'] = array_merge( $ret[
'allowedKeys'], [
81 self::PARAM_ALLOWED_USER_TYPES, self::PARAM_RETURN_OBJECT,
84 if ( !is_bool( $settings[self::PARAM_RETURN_OBJECT] ??
false ) ) {
86 . gettype( $settings[self::PARAM_RETURN_OBJECT] );
90 if ( isset( $settings[self::PARAM_ALLOWED_USER_TYPES] ) ) {
91 if ( !is_array( $settings[self::PARAM_ALLOWED_USER_TYPES] ) ) {
93 .
'got ' . gettype( $settings[self::PARAM_ALLOWED_USER_TYPES] );
94 } elseif ( $settings[self::PARAM_ALLOWED_USER_TYPES] === [] ) {
98 $settings[self::PARAM_ALLOWED_USER_TYPES],
99 [
'name',
'ip',
'cidr',
'interwiki',
'id' ]
103 'PARAM_ALLOWED_USER_TYPES contains invalid values: ' . implode(
', ', $bad );
106 $hasId = in_array(
'id', $settings[self::PARAM_ALLOWED_USER_TYPES],
true );
110 if ( !empty( $settings[ParamValidator::PARAM_ISMULTI] ) &&
111 ( $hasId || !empty( $settings[self::PARAM_RETURN_OBJECT] ) ) &&
113 ( $settings[ParamValidator::PARAM_ISMULTI_LIMIT1] ?? 100 ) > 10 ||
114 ( $settings[ParamValidator::PARAM_ISMULTI_LIMIT2] ?? 100 ) > 10
117 $ret[
'issues'][] =
'Multi-valued user-type parameters with PARAM_RETURN_OBJECT or allowing IDs '
118 .
'should set low values (<= 10) for PARAM_ISMULTI_LIMIT1 and PARAM_ISMULTI_LIMIT2.'
119 .
' (Note that "<= 10" is arbitrary. If something hits this, we can investigate a real limit '
120 .
'once we have a real use case to look at.)';
134 if ( preg_match(
'/^#(\d+)$/D', $value, $m ) ) {
150 return [
'name', $user ];
155 if ( strpos( $value,
'#' ) !==
false ) {
158 $t = Title::newFromText( $value );
159 if ( !
$t ||
$t->getNamespace() !==
NS_USER ||
$t->isExternal() ) {
160 $t = Title::newFromText(
"User:$value" );
162 if ( !
$t ||
$t->getNamespace() !==
NS_USER ||
$t->isExternal() ) {
166 $value =
$t->getText();
169 $b = IPUtils::RE_IP_BYTE;
170 if ( IPUtils::isValid( $value ) ||
175 preg_match(
"/^$b\.$b\.$b\.xxx$/D", $value )
181 if ( IPUtils::isValidRange( $value ) ) {
189 public function getParamInfo( $name, array $settings, array $options ) {
190 $info = parent::getParamInfo( $name, $settings, $options );
192 $info[
'subtypes'] = $settings[self::PARAM_ALLOWED_USER_TYPES];
197 public function getHelpInfo( $name, array $settings, array $options ) {
198 $info = parent::getParamInfo( $name, $settings, $options );
200 $isMulti = !empty( $settings[ParamValidator::PARAM_ISMULTI] );
203 foreach ( $settings[self::PARAM_ALLOWED_USER_TYPES] as $st ) {
207 $subtypes[] = MessageValue::new(
"paramvalidator-help-type-user-subtype-$st" );
209 $info[ParamValidator::PARAM_TYPE] = MessageValue::new(
'paramvalidator-help-type-user' )
210 ->params( $isMulti ? 2 : 1 )
211 ->textListParams( $subtypes )
212 ->numParams( count( $subtypes ) );
Class to parse and build external user names.
static isExternal( $username)
Tells whether the username is external or not.
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.
static newFromId( $id)
Static factory method for creation from a given user ID.
static newFromAnyId( $userId, $userName, $actorId, $dbDomain=false)
Static factory method for creation from an ID, name, and/or actor ID.