36 private $usernamePrefix;
41 private $assignKnownUsers;
46 private $triedCreations = [];
52 public function __construct( $usernamePrefix, $assignKnownUsers ) {
53 $this->usernamePrefix = rtrim( (
string)$usernamePrefix,
':>' );
54 $this->assignKnownUsers = (bool)$assignKnownUsers;
65 $pos = strpos( $userName,
'>' );
66 $services = MediaWikiServices::getInstance();
67 if ( $pos !==
false ) {
68 $iw = explode(
':', substr( $userName, 0, $pos ) );
69 $firstIw = array_shift( $iw );
70 $interwikiLookup = $services->getInterwikiLookup();
71 if ( $interwikiLookup->isValidInterwiki( $firstIw ) ) {
72 $title = $services->getNamespaceInfo()->getCanonicalName(
NS_USER ) .
73 ':' . substr( $userName, $pos + 1 );
83 $services->getUserNameUtils()->isIP( $userName )
84 || $services->getUserNameUtils()->isValidIPRange( $userName )
85 || $services->getUserNameUtils()->isValid( $userName )
110 $userNameUtils = MediaWikiServices::getInstance()->getUserNameUtils();
111 if ( $userNameUtils->getCanonical( $name, UserRigorOptions::RIGOR_USABLE ) ===
false ) {
115 if ( $this->assignKnownUsers ) {
116 $userIdentityLookup = MediaWikiServices::getInstance()->getUserIdentityLookup();
117 $userIdentity = $userIdentityLookup->getUserIdentityByName( $name );
118 if ( $userIdentity && $userIdentity->isRegistered() ) {
123 if ( !isset( $this->triedCreations[$name] ) ) {
124 $this->triedCreations[$name] =
true;
125 if ( !
Hooks::runner()->onImportHandleUnknownUser( $name ) ) {
126 $userIdentity = $userIdentityLookup->getUserIdentityByName( $name, IDBAccessObject::READ_LATEST );
127 if ( $userIdentity && $userIdentity->isRegistered() ) {
144 return substr( $this->usernamePrefix .
'>' . $name, 0, 255 );
154 return str_contains( $username,
'>' );
164 if ( !self::isExternal( $username ) ) {
168 return substr( $username, strpos( $username,
'>' ) + 1 );
Class to parse and build external user names.
static getUserLinkTitle( $userName)
Get a target Title to link a username.
addPrefix( $name)
Add an interwiki prefix to the username regardless of circumstances.
__construct( $usernamePrefix, $assignKnownUsers)
static isExternal( $username)
Tells whether the username is external or not.
static getLocal( $username)
Get local part of the user name.
applyPrefix( $name)
Add an interwiki prefix to the username, if appropriate.
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...