MediaWiki master
MediaWiki\User\UserNameUtils Class Reference

UserNameUtils service. More...

Inherits MediaWiki\User\UserRigorOptions.

Collaboration diagram for MediaWiki\User\UserNameUtils:

Public Member Functions

 __construct (ServiceOptions $options, Language $contentLang, LoggerInterface $logger, TitleParser $titleParser, ITextFormatter $textFormatter, HookContainer $hookContainer, TempUserConfig $tempUserConfig)
 
 getCanonical (string $name, string $validate=self::RIGOR_VALID)
 Given unvalidated user input, return a canonical username, or false if the username is invalid.
 
 getTempPlaceholder ()
 Get a placeholder name for a temporary user before serial acquisition.
 
 isCreatable (string $name)
 Usernames which fail to pass this function will be blocked from new account registrations, but may be used internally either by batch processes or by user accounts which have already been created.
 
 isIP (string $name)
 Does the string match an anonymous IP address?
 
 isLikeIPv4DashRange (string $range)
 Validates IPv4 and IPv4-like ranges in the form of 1.2.3.4-5.6.7.8, (which we'd like to avoid as a username/title pattern).
 
 isTemp (string $name)
 Does the username indicate a temporary user?
 
 isTempReserved (string $name)
 Is the username uncreatable due to it being reserved by the temp username system? Note that unlike isTemp(), this does not imply that a user having this name is an actual temp account.
 
 isUsable (string $name)
 Usernames which fail to pass this function will be blocked from user login and new account registrations, but may be used internally by batch processes.
 
 isValid (string $name)
 Is the input a valid username?
 
 isValidIPRange (string $range)
 Wrapper for IPUtils::isValidRange.
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 

Detailed Description

UserNameUtils service.

Since
1.35

Definition at line 44 of file UserNameUtils.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\User\UserNameUtils::__construct ( ServiceOptions $options,
Language $contentLang,
LoggerInterface $logger,
TitleParser $titleParser,
ITextFormatter $textFormatter,
HookContainer $hookContainer,
TempUserConfig $tempUserConfig )
Parameters
ServiceOptions$options
Language$contentLang
LoggerInterface$logger
TitleParser$titleParser
ITextFormatter$textFormatterthe text formatter for the current content language
HookContainer$hookContainer
TempUserConfig$tempUserConfig

Definition at line 86 of file UserNameUtils.php.

References MediaWiki\Config\ServiceOptions\assertRequiredOptions().

Member Function Documentation

◆ getCanonical()

MediaWiki\User\UserNameUtils::getCanonical ( string $name,
string $validate = self::RIGOR_VALID )

Given unvalidated user input, return a canonical username, or false if the username is invalid.

Parameters
string$nameUser input
string$validateType of validation to use Use of public constants RIGOR_* is preferred
  • RIGOR_NONE No validation
  • RIGOR_VALID Valid for batch processes
  • RIGOR_USABLE Valid for batch processes and login
  • RIGOR_CREATABLE Valid for batch processes, login and account creation
Exceptions
InvalidArgumentException
Returns
string|false

Definition at line 263 of file UserNameUtils.php.

References NS_USER.

◆ getTempPlaceholder()

MediaWiki\User\UserNameUtils::getTempPlaceholder ( )

Get a placeholder name for a temporary user before serial acquisition.

Since
1.39
Returns
string

Definition at line 401 of file UserNameUtils.php.

◆ isCreatable()

MediaWiki\User\UserNameUtils::isCreatable ( string $name)

Usernames which fail to pass this function will be blocked from new account registrations, but may be used internally either by batch processes or by user accounts which have already been created.

Additional preventions may be added here rather than in isValid() to avoid disrupting existing accounts.

Parameters
string$nameString to match
Returns
bool

Definition at line 217 of file UserNameUtils.php.

◆ isIP()

MediaWiki\User\UserNameUtils::isIP ( string $name)

Does the string match an anonymous IP address?

This function exists for username validation, in order to reject usernames which are similar in form to IP addresses. Strings such as 300.300.300.300 will return true because it looks like an IP address, despite not being strictly valid.

We match "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.xxx" as an anonymous IP address because the usemod software would "cloak" anonymous IP addresses like this, if we allowed accounts like this to be created new users could get the old edits of these anonymous users.

This does //not// match IPv6 ranges (T239527)

Parameters
string$nameName to check
Returns
bool

Definition at line 339 of file UserNameUtils.php.

Referenced by MediaWiki\Pager\ImageListPager\__construct().

◆ isLikeIPv4DashRange()

MediaWiki\User\UserNameUtils::isLikeIPv4DashRange ( string $range)

Validates IPv4 and IPv4-like ranges in the form of 1.2.3.4-5.6.7.8, (which we'd like to avoid as a username/title pattern).

Since
1.42
Parameters
string$rangeIPv4 dash range to check
Returns
bool

Definition at line 363 of file UserNameUtils.php.

◆ isTemp()

MediaWiki\User\UserNameUtils::isTemp ( string $name)

Does the username indicate a temporary user?

Since
1.39
Parameters
string$name
Returns
bool

Definition at line 377 of file UserNameUtils.php.

◆ isTempReserved()

MediaWiki\User\UserNameUtils::isTempReserved ( string $name)

Is the username uncreatable due to it being reserved by the temp username system? Note that unlike isTemp(), this does not imply that a user having this name is an actual temp account.

This should only be used to deny account creation.

Since
1.41
Parameters
string$name
Returns
bool

Definition at line 391 of file UserNameUtils.php.

◆ isUsable()

MediaWiki\User\UserNameUtils::isUsable ( string $name)

Usernames which fail to pass this function will be blocked from user login and new account registrations, but may be used internally by batch processes.

If an account already exists in this form, login will be blocked by a failure to pass this function.

Parameters
string$nameName to match
Returns
bool

Definition at line 171 of file UserNameUtils.php.

◆ isValid()

MediaWiki\User\UserNameUtils::isValid ( string $name)

Is the input a valid username?

Checks if the input is a valid username, we don't want an empty string, an IP address, any type of IP range, anything that contains slashes (would mess up subpages), is longer than the maximum allowed username size or doesn't begin with a capital letter.

Parameters
string$nameName to match
Returns
bool

Definition at line 116 of file UserNameUtils.php.

◆ isValidIPRange()

MediaWiki\User\UserNameUtils::isValidIPRange ( string $range)

Wrapper for IPUtils::isValidRange.

Parameters
string$rangeRange to check
Returns
bool

Definition at line 351 of file UserNameUtils.php.

Member Data Documentation

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\User\UserNameUtils::CONSTRUCTOR_OPTIONS
Initial value:
= [
]
const MaxNameChars
Name constant for the MaxNameChars setting, for use with Config::get()
const ReservedUsernames
Name constant for the ReservedUsernames setting, for use with Config::get()
const InvalidUsernameCharacters
Name constant for the InvalidUsernameCharacters setting, for use with Config::get()
Access: internal
For use by ServiceWiring

Definition at line 49 of file UserNameUtils.php.


The documentation for this class was generated from the following file: