33 class Site implements Serializable {
53 public const SERIAL_VERSION_ID =
'2013-01-23';
159 throw new MWException(
'$globalId needs to be string or null' );
197 if ( !is_string(
$group ) ) {
198 throw new MWException(
'$group needs to be a string' );
226 throw new MWException(
'$source needs to be a string' );
255 if ( !is_bool( $shouldForward ) ) {
256 throw new MWException(
'$shouldForward needs to be a boolean' );
259 $this->forward = $shouldForward;
273 if (
$path ===
null ) {
277 return parse_url(
$path, PHP_URL_HOST );
291 if (
$path ===
null ) {
295 $protocol = parse_url(
$path, PHP_URL_SCHEME );
298 if ( $protocol ===
false ) {
299 throw new MWException(
"failed to parse URL '$path'" );
303 if ( $protocol ===
null ) {
324 if (
$type ===
null ) {
325 throw new MWException(
"This Site does not support link paths." );
377 if ( $url ===
null ) {
381 if ( $pageName !==
false ) {
382 $url = str_replace(
'$1', rawurlencode( $pageName ), $url );
405 public function normalizePageName( $pageName, $followRedirect = MediaWikiPageNameNormalizer::FOLLOW_REDIRECT ) {
474 && !MediaWikiServices::getInstance()
475 ->getLanguageNameUtils()
478 throw new InvalidArgumentException(
"$languageCode is not a valid language code." );
515 if ( $this->localIds ===
false ) {
516 $this->localIds = [];
519 if ( !array_key_exists(
$type, $this->localIds ) ) {
520 $this->localIds[
$type] = [];
523 if ( !in_array( $identifier, $this->localIds[
$type] ) ) {
524 $this->localIds[
$type][] = $identifier;
536 $this->
addLocalId( self::ID_INTERWIKI, $identifier );
547 $this->
addLocalId( self::ID_EQUIVALENT, $identifier );
558 return array_key_exists( self::ID_INTERWIKI, $this->localIds )
572 return array_key_exists( self::ID_EQUIVALENT, $this->localIds )
599 public function setPath( $pathType, $fullUrl ) {
600 if ( !is_string( $fullUrl ) ) {
601 throw new MWException(
'$fullUrl needs to be a string' );
604 if ( !array_key_exists(
'paths', $this->extraData ) ) {
605 $this->extraData[
'paths'] = [];
608 $this->extraData[
'paths'][$pathType] = $fullUrl;
622 return $paths[$pathType] ??
null;
634 return $this->extraData[
'paths'] ?? [];
645 if ( array_key_exists(
'paths', $this->extraData ) ) {
646 unset( $this->extraData[
'paths'][$pathType] );
658 $siteTypes = MediaWikiServices::getInstance()->getMainConfig()->get(
659 MainConfigNames::SiteTypes );
661 if ( array_key_exists( $siteType, $siteTypes ) ) {
662 return new $siteTypes[$siteType]();
723 $this->
setGroup( $fields[
'group'] );
726 $this->localIds = $fields[
'localids'];
A class containing constants representing the names of configuration variables.
Service for normalizing a page name using a MediaWiki api.
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,...
setPath( $pathType, $fullUrl)
Sets the path used to construct links with.
getExtraData()
Returns the type specific fields.
setGroup( $group)
Sets the group of the site (ie wikipedia).
addInterwikiId( $identifier)
Adds an interwiki id to the site.
getPath( $pathType)
Returns the path of the provided type or false if there is no such path.
setForward( $shouldForward)
Sets if site.tld/path/key:pageTitle should forward users to the page on the actual site,...
setSource( $source)
Sets the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
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).
setGlobalId( $globalId)
Sets the global site identifier (ie enwiktionary).
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.
addNavigationId( $identifier)
Adds a navigation id to the site.
getPageUrl( $pageName=false)
Returns 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.
unserialize( $serialized)
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 ...
getDomain()
Returns the domain of the site, ie en.wikipedia.org Or false if it's not known.
getLinkPath()
Returns the path used to construct links with or false if there is no such path.
setLinkPath( $fullUrl)
Sets the path used to construct links with.
getInterwikiIds()
Returns the interwiki link identifiers that can be used for this site.
setExtraData(array $extraData)
Sets the type specific fields.
foreach( $res as $row) $serialized