37 private string $usernamePrefix;
38 private bool $assignKnownUsers;
43 private $triedCreations = [];
49 public function __construct( $usernamePrefix, $assignKnownUsers ) {
50 $this->usernamePrefix = rtrim( (
string)$usernamePrefix,
':>' );
51 $this->assignKnownUsers = (bool)$assignKnownUsers;
62 $pos = strpos( $userName,
'>' );
64 if ( $pos !==
false ) {
65 $iw = explode(
':', substr( $userName, 0, $pos ) );
66 $firstIw = array_shift( $iw );
67 $interwikiLookup = $services->getInterwikiLookup();
68 if ( $interwikiLookup->isValidInterwiki( $firstIw ) ) {
69 $title = $services->getNamespaceInfo()->getCanonicalName(
NS_USER ) .
70 ':' . substr( $userName, $pos + 1 );
72 $title = implode(
':', $iw ) .
':' . $title;
74 return Title::makeTitle(
NS_MAIN, $title,
'', $firstIw );
80 $services->getUserNameUtils()->isIP( $userName )
81 || $services->getUserNameUtils()->isValidIPRange( $userName )
82 || $services->getUserNameUtils()->isValid( $userName )
108 $userNameUtils = $services->getUserNameUtils();
109 if ( $userNameUtils->getCanonical( $name, UserRigorOptions::RIGOR_USABLE ) ===
false ) {
113 if ( $this->assignKnownUsers ) {
114 $userIdentityLookup = $services->getUserIdentityLookup();
115 $userIdentity = $userIdentityLookup->getUserIdentityByName( $name );
116 if ( $userIdentity && $userIdentity->isRegistered() ) {
121 if ( !isset( $this->triedCreations[$name] ) ) {
122 $this->triedCreations[$name] =
true;
123 if ( !(
new HookRunner( $services->getHookContainer() ) )->onImportHandleUnknownUser( $name ) ) {
124 $userIdentity = $userIdentityLookup->getUserIdentityByName( $name, IDBAccessObject::READ_LATEST );
125 if ( $userIdentity && $userIdentity->isRegistered() ) {
142 return substr( $this->usernamePrefix .
'>' . $name, 0, 255 );
152 return str_contains( $username,
'>' );
162 if ( !self::isExternal( $username ) ) {
166 return substr( $username, strpos( $username,
'>' ) + 1 );
172class_alias( ExternalUserNames::class,
'ExternalUserNames' );
Parent class for all special pages.
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,...
Interface for database access objects.