52 public const SERIAL_VERSION_ID =
'2013-01-23';
230 $this->forward = $shouldForward;
244 if (
$path ===
null ) {
248 $domain = parse_url(
$path, PHP_URL_HOST );
250 if ( $domain ===
false ) {
264 $path = $this->getLinkPath();
266 if (
$path ===
null ) {
270 $protocol = parse_url(
$path, PHP_URL_SCHEME );
273 if ( $protocol ===
false ) {
274 throw new UnexpectedValueException(
"failed to parse URL '$path'" );
278 if ( $protocol ===
null ) {
295 $type = $this->getLinkPathType();
297 if ( $type ===
null ) {
298 throw new RuntimeException(
"This Site does not support link paths." );
301 $this->setPath( $type, $fullUrl );
312 $type = $this->getLinkPathType();
313 return $type ===
null ? null : $this->getPath( $type );
329 return self::PATH_LINK;
347 $url = $this->getLinkPath();
349 if ( $url ===
null ) {
353 if ( $pageName !==
false ) {
354 $url = str_replace(
'$1', rawurlencode( $pageName ), $url );
377 public function normalizePageName( $pageName, $followRedirect = MediaWikiPageNameNormalizer::FOLLOW_REDIRECT ) {
389 return $this->extraData;
400 $this->extraData = $extraData;
411 return $this->extraConfig;
422 $this->extraConfig = $extraConfig;
434 return $this->languageCode;
445 if ( $languageCode !==
null
446 && !MediaWikiServices::getInstance()
447 ->getLanguageNameUtils()
448 ->isValidCode( $languageCode )
450 throw new InvalidArgumentException(
"$languageCode is not a valid language code." );
452 $this->languageCode = $languageCode;
463 return $this->internalId;
475 $this->internalId = $internalId;
487 if ( $this->localIds ===
false ) {
488 $this->localIds = [];
491 if ( !array_key_exists( $type, $this->localIds ) ) {
492 $this->localIds[$type] = [];
495 if ( !in_array( $identifier, $this->localIds[$type] ) ) {
496 $this->localIds[$type][] = $identifier;
508 $this->addLocalId( self::ID_INTERWIKI, $identifier );
519 $this->addLocalId( self::ID_EQUIVALENT, $identifier );
530 return array_key_exists( self::ID_INTERWIKI, $this->localIds )
531 ? $this->localIds[self::ID_INTERWIKI]
544 return array_key_exists( self::ID_EQUIVALENT, $this->localIds )
545 ? $this->localIds[self::ID_EQUIVALENT] :
557 return $this->localIds;
569 public function setPath( $pathType,
string $fullUrl ) {
570 if ( !array_key_exists(
'paths', $this->extraData ) ) {
571 $this->extraData[
'paths'] = [];
574 $this->extraData[
'paths'][$pathType] = $fullUrl;
587 $paths = $this->getAllPaths();
588 return $paths[$pathType] ??
null;
600 return $this->extraData[
'paths'] ?? [];
611 if ( array_key_exists(
'paths', $this->extraData ) ) {
612 unset( $this->extraData[
'paths'][$pathType] );
624 $siteTypes = MediaWikiServices::getInstance()->getMainConfig()->get(
625 MainConfigNames::SiteTypes );
627 if ( array_key_exists( $siteType, $siteTypes ) ) {
628 return new $siteTypes[$siteType]();
643 'globalid' => $this->globalId,
644 'type' => $this->type,
645 'group' => $this->group,
647 'language' => $this->languageCode,
648 'localids' => $this->localIds,
649 'config' => $this->extraConfig,
650 'data' => $this->extraData,
651 'forward' => $this->forward,
652 'internalid' => $this->internalId,
664 $this->__construct( $fields[
'type'] );
666 $this->setGlobalId( $fields[
'globalid'] );
667 $this->setGroup( $fields[
'group'] );
668 $this->setSource( $fields[
'source'] );
669 $this->setLanguageCode( $fields[
'language'] );
670 $this->localIds = $fields[
'localids'];
671 $this->setExtraConfig( $fields[
'config'] );
672 $this->setExtraData( $fields[
'data'] );
673 $this->setForward( $fields[
'forward'] );
674 $this->setInternalId( $fields[
'internalid'] );
A class containing constants representing the names of configuration variables.
Service for normalizing a page name via a MediaWiki action API.
Represents a single site.
normalizePageName( $pageName, $followRedirect=MediaWikiPageNameNormalizer::FOLLOW_REDIRECT)
Attempt to normalize the page name in some fashion.
shouldForward()
Gets if site.tld/path/key:pageTitle should forward users to the page on the actual site,...
getExtraData()
Returns the type specific fields.
addInterwikiId( $identifier)
Adds an interwiki id to the site.
getPath( $pathType)
Returns the path of the provided type or null if there is no such path.
string[][] false $localIds
Holds the local ids for this site.
getSource()
Returns the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
static newForType( $siteType)
getProtocol()
Returns the protocol of the site.
getType()
Returns the type of the site (ie mediawiki).
removePath( $pathType)
Removes the path of the provided type if it's set.
addLocalId( $type, $identifier)
Adds a local identifier.
setLanguageCode( $languageCode)
Sets language code of the sites primary language.
getGlobalId()
Returns the global site identifier (ie enwiktionary).
setSource(string $source)
Sets the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
getLinkPathType()
Returns the main path type, that is the type of the path that should generally be used to construct l...
getExtraConfig()
Returns the type specific config.
setGlobalId(?string $globalId)
Sets the global site identifier (ie enwiktionary).
addNavigationId( $identifier)
Adds a navigation id to the site.
getPageUrl( $pageName=false)
Get the full URL for the given page on the site.
string null $languageCode
getAllPaths()
Returns the paths as associative array.
getLocalIds()
Returns all local ids.
getGroup()
Gets the group of the site (ie wikipedia).
setInternalId( $internalId=null)
Sets the internal identifier for the site.
getLanguageCode()
Returns language code of the sites primary language.
getInternalId()
Returns the set internal identifier for the site.
setExtraConfig(array $extraConfig)
Sets the type specific config.
__construct( $type=self::TYPE_UNKNOWN)
getNavigationIds()
Returns the equivalent link identifiers that can be used to make the site show up in interfaces such ...
setForward(bool $shouldForward)
Sets if site.tld/path/key:pageTitle should forward users to the page on the actual site,...
setPath( $pathType, string $fullUrl)
Set the path used to construct links with.
getDomain()
Returns the domain of the site, ie en.wikipedia.org Or null if it's not known.
getLinkPath()
Returns the path used to construct links with or false if there is no such path.
setLinkPath( $fullUrl)
Set the path used to construct links with.
setGroup(string $group)
Sets the group of the site (ie wikipedia).
getInterwikiIds()
Returns the interwiki link identifiers that can be used for this site.
setExtraData(array $extraData)
Sets the type specific fields.