usernamePrefix = rtrim( (string)$usernamePrefix, ':>' ); $this->assignKnownUsers = (bool)$assignKnownUsers; } /** * Get a target Title to link a username. * * @param string $userName Username to link * * @return null|Title */ public static function getUserLinkTitle( $userName ) { $pos = strpos( $userName, '>' ); if ( $pos !== false ) { $iw = explode( ':', substr( $userName, 0, $pos ) ); $firstIw = array_shift( $iw ); $interwikiLookup = MediaWikiServices::getInstance()->getInterwikiLookup(); if ( $interwikiLookup->isValidInterwiki( $firstIw ) ) { $title = MWNamespace::getCanonicalName( NS_USER ) . ':' . substr( $userName, $pos + 1 ); if ( $iw ) { $title = implode( ':', $iw ) . ':' . $title; } return Title::makeTitle( NS_MAIN, $title, '', $firstIw ); } return null; } else { return SpecialPage::getTitleFor( 'Contributions', $userName ); } } /** * Add an interwiki prefix to the username, if appropriate * * @param string $name Name being imported * @return string Name, possibly with the prefix prepended. */ public function applyPrefix( $name ) { if ( !User::isUsableName( $name ) ) { return $name; } if ( $this->assignKnownUsers ) { if ( User::idFromName( $name ) ) { return $name; } // See if any extension wants to create it. if ( !isset( $this->triedCreations[$name] ) ) { $this->triedCreations[$name] = true; if ( !Hooks::run( 'ImportHandleUnknownUser', [ $name ] ) && User::idFromName( $name, User::READ_LATEST ) ) { return $name; } } } return $this->addPrefix( $name ); } /** * Add an interwiki prefix to the username regardless of circumstances * * @param string $name Name being imported * @return string Name */ public function addPrefix( $name ) { return substr( $this->usernamePrefix . '>' . $name, 0, 255 ); } /** * Tells whether the username is external or not * * @param string $username Username to check * @return bool true if it's external, false otherwise. */ public static function isExternal( $username ) { return strpos( $username, '>' ) !== false; } /** * Get local part of the user name * * @param string $username Username to get * @return string */ public static function getLocal( $username ) { if ( !self::isExternal( $username ) ) { return $username; } return substr( $username, strpos( $username, '>' ) + 1 ); } }