MediaWiki  master
MediaWiki\User\UserNameUtils Class Reference

UserNameUtils service. More...

Collaboration diagram for MediaWiki\User\UserNameUtils:

Public Member Functions

 __construct (ServiceOptions $options, Language $contentLang, LoggerInterface $logger, TitleParser $titleParser, ITextFormatter $textFormatter, HookContainer $hookContainer)
 
 getCanonical (string $name, string $validate=self::RIGOR_VALID)
 Given unvalidated user input, return a canonical username, or false if the username is invalid. More...
 
 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. More...
 
 isIP (string $name)
 Does the string match an anonymous IP address? More...
 
 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. More...
 
 isValid (string $name)
 Is the input a valid username? More...
 
 isValidIPRange (string $range)
 Wrapper for IPUtils::isValidRange. More...
 

Public Attributes

const CONSTRUCTOR_OPTIONS
 
const RIGOR_CREATABLE = 'creatable'
 
const RIGOR_NONE = 'none'
 
const RIGOR_USABLE = 'usable'
 
const RIGOR_VALID = 'valid'
 

Private Attributes

Language $contentLang
 
HookRunner $hookRunner
 
LoggerInterface $logger
 
ServiceOptions $options
 
string[] false $reservedUsernames = false
 Cache for isUsable() More...
 
ITextFormatter $textFormatter
 
TitleParser $titleParser
 

Detailed Description

UserNameUtils service.

Since
1.35

Definition at line 42 of file UserNameUtils.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 101 of file UserNameUtils.php.

References MediaWiki\User\UserNameUtils\$contentLang, MediaWiki\User\UserNameUtils\$logger, MediaWiki\User\UserNameUtils\$options, MediaWiki\User\UserNameUtils\$textFormatter, MediaWiki\User\UserNameUtils\$titleParser, and 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
bool|string

Definition at line 259 of file UserNameUtils.php.

References $title, MediaWiki\User\UserNameUtils\isCreatable(), MediaWiki\User\UserNameUtils\isUsable(), MediaWiki\User\UserNameUtils\isValid(), NS_USER, MediaWiki\User\UserNameUtils\RIGOR_CREATABLE, MediaWiki\User\UserNameUtils\RIGOR_USABLE, and MediaWiki\User\UserNameUtils\RIGOR_VALID.

◆ 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 blacklisting may be added here rather than in isValidUserName() to avoid disrupting existing accounts.

Parameters
string$nameString to match
Returns
bool

Definition at line 220 of file UserNameUtils.php.

References MediaWiki\User\UserNameUtils\isUsable().

Referenced by MediaWiki\User\UserNameUtils\getCanonical().

◆ 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.

Unlike User::isIP, this does //not// match IPv6 ranges (T239527)

Parameters
string$nameName to check
Returns
bool

Definition at line 338 of file UserNameUtils.php.

Referenced by MediaWiki\User\UserNameUtils\isValid().

◆ 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 182 of file UserNameUtils.php.

References MediaWiki\User\UserNameUtils\$reservedUsernames, MediaWiki\User\UserNameUtils\isValid(), and Wikimedia\Message\MessageValue\new().

Referenced by MediaWiki\User\UserNameUtils\getCanonical(), and MediaWiki\User\UserNameUtils\isCreatable().

◆ 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, 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 129 of file UserNameUtils.php.

References $title, and MediaWiki\User\UserNameUtils\isIP().

Referenced by MediaWiki\User\UserNameUtils\getCanonical(), and MediaWiki\User\UserNameUtils\isUsable().

◆ isValidIPRange()

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

Wrapper for IPUtils::isValidRange.

Parameters
string$rangeRange to check
Returns
bool

Definition at line 350 of file UserNameUtils.php.

Member Data Documentation

◆ $contentLang

Language MediaWiki\User\UserNameUtils::$contentLang
private

Definition at line 66 of file UserNameUtils.php.

Referenced by MediaWiki\User\UserNameUtils\__construct().

◆ $hookRunner

HookRunner MediaWiki\User\UserNameUtils::$hookRunner
private

Definition at line 91 of file UserNameUtils.php.

◆ $logger

LoggerInterface MediaWiki\User\UserNameUtils::$logger
private

Definition at line 71 of file UserNameUtils.php.

Referenced by MediaWiki\User\UserNameUtils\__construct().

◆ $options

ServiceOptions MediaWiki\User\UserNameUtils::$options
private

Definition at line 61 of file UserNameUtils.php.

Referenced by MediaWiki\User\UserNameUtils\__construct().

◆ $reservedUsernames

string [] false MediaWiki\User\UserNameUtils::$reservedUsernames = false
private

Cache for isUsable()

Definition at line 86 of file UserNameUtils.php.

Referenced by MediaWiki\User\UserNameUtils\isUsable().

◆ $textFormatter

ITextFormatter MediaWiki\User\UserNameUtils::$textFormatter
private

Definition at line 81 of file UserNameUtils.php.

Referenced by MediaWiki\User\UserNameUtils\__construct().

◆ $titleParser

TitleParser MediaWiki\User\UserNameUtils::$titleParser
private

Definition at line 76 of file UserNameUtils.php.

Referenced by MediaWiki\User\UserNameUtils\__construct().

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\User\UserNameUtils::CONSTRUCTOR_OPTIONS
Initial value:
= [
'MaxNameChars',
'ReservedUsernames',
'InvalidUsernameCharacters'
]

Definition at line 47 of file UserNameUtils.php.

◆ RIGOR_CREATABLE

const MediaWiki\User\UserNameUtils::RIGOR_CREATABLE = 'creatable'

Definition at line 53 of file UserNameUtils.php.

Referenced by MediaWiki\User\UserNameUtils\getCanonical().

◆ RIGOR_NONE

const MediaWiki\User\UserNameUtils::RIGOR_NONE = 'none'

◆ RIGOR_USABLE

const MediaWiki\User\UserNameUtils::RIGOR_USABLE = 'usable'

Definition at line 54 of file UserNameUtils.php.

Referenced by MediaWiki\User\UserNameUtils\getCanonical().

◆ RIGOR_VALID

const MediaWiki\User\UserNameUtils::RIGOR_VALID = 'valid'

Definition at line 55 of file UserNameUtils.php.

Referenced by MediaWiki\User\UserNameUtils\getCanonical().


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