39'usemodwiki-ipallowed' =>
false,
45'excludenamed' =>
false,
50 parent::__construct( $params );
55// If the value is null, reset it to an empty string which is what is expected by the parent. 58// If the value is empty, there are no additional checks that can be performed. 60return parent::validate( $value, $alldata );
63// check if the input is a valid username 66// check if the user exists, if requested 67if ( $this->mParams[
'exists'] && !(
68 $user->isRegistered() &&
69// Treat hidden users as unregistered if current user can't view them (T309894) 70 !( $user->isHidden() && !( $this->mParent && $this->mParent->getUser()->isAllowed(
'hideuser' ) ) )
75// check if the user account type matches the account type filter 76 $excludeNamed = $this->mParams[
'excludenamed'] ??
null;
77 $excludeTemp = $this->mParams[
'excludetemp'] ??
null;
78if ( ( $excludeTemp && $user->isTemp() ) || ( $excludeNamed && $user->isNamed() ) ) {
82// not a valid username 84// check if the input is a valid external user 85if ( $this->mParams[
'external'] && ExternalUserNames::isExternal( $value ) ) {
88// check if the input is a valid IP address, optionally also checking for usemod wiki IPs 89if ( $this->mParams[
'ipallowed'] ) {
90 $b = IPUtils::RE_IP_BYTE;
91if ( IPUtils::isValid( $value ) ) {
93 } elseif ( $this->mParams[
'usemodwiki-ipallowed'] && preg_match(
"/^$b\.$b\.$b\.xxx$/", $value ) ) {
97// check if the input is a valid IP range 98if ( $this->mParams[
'iprange'] ) {
100if ( $rangeError ===
true ) {
102 } elseif ( $rangeError !==
false ) {
111return parent::validate( $value, $alldata );
119 $cidrIPRanges = $this->mParams[
'iprangelimits'];
121if ( !IPUtils::isValidRange( $value ) ) {
125 [ $ip, $range ] = explode(
'/', $value, 2 );
128 ( IPUtils::isIPv4( $ip ) && $cidrIPRanges[
'IPv4'] == 32 ) ||
129 ( IPUtils::isIPv6( $ip ) && $cidrIPRanges[
'IPv6'] == 128 )
131// Range block effectively disabled 132return $this->
msg(
'ip_range_toolow' );
136 ( IPUtils::isIPv4( $ip ) && $range > 32 ) ||
137 ( IPUtils::isIPv6( $ip ) && $range > 128 )
140return $this->
msg(
'ip_range_invalid' );
143if ( IPUtils::isIPv4( $ip ) && $range < $cidrIPRanges[
'IPv4'] ) {
144return $this->
msg(
'ip_range_exceeded', $cidrIPRanges[
'IPv4'] );
147if ( IPUtils::isIPv6( $ip ) && $range < $cidrIPRanges[
'IPv6'] ) {
148return $this->
msg(
'ip_range_exceeded', $cidrIPRanges[
'IPv6'] );
156if ( isset( $this->mParams[
'excludenamed'] ) ) {
157 $params[
'excludenamed'] = $this->mParams[
'excludenamed'];
160if ( isset( $this->mParams[
'excludetemp'] ) ) {
161 $params[
'excludetemp'] = $this->mParams[
'excludetemp'];
174return [
'mediawiki.widgets.UserInputWidget' ];
179// add the required module and css class for user suggestions in non-OOUI mode 180 $this->mParent->getOutput()->addModules(
'mediawiki.userSuggest' );
181 $this->mClass .=
' mw-autocomplete-user';
184return parent::getInputHTML( $value );
189class_alias( HTMLUserTextField::class,
'HTMLUserTextField' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfArrayPlus2d(array $baseArray, array $newValues)
Merges two (possibly) 2 dimensional arrays into the target array ($baseArray).
Implements a text input field for user names.
validate( $value, $alldata)
Override this function to add specific validation checks on the field input.Don't forget to call pare...
shouldInfuseOOUI()
Whether the field should be automatically infused.Note that all OOUI HTMLForm fields are infusable (y...
getOOUIModules()
Get the list of extra ResourceLoader modules which must be loaded client-side before it's possible to...
getInputWidget( $params)
to overrideWidget
msg( $key,... $params)
Get a translated interface message.
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
The Message class deals with fetching and processing of interface message into a variety of formats.
Class to parse and build external user names.