Go to the documentation of this file.
29 class Site implements Serializable {
49 const SERIAL_VERSION_ID =
'2013-01-23';
155 throw new MWException(
'$globalId needs to be string or null' );
193 if ( !is_string(
$group ) ) {
194 throw new MWException(
'$group needs to be a string' );
222 throw new MWException(
'$source needs to be a string' );
251 if ( !is_bool( $shouldForward ) ) {
252 throw new MWException(
'$shouldForward needs to be a boolean' );
255 $this->forward = $shouldForward;
269 if (
$path ===
null ) {
273 return parse_url(
$path, PHP_URL_HOST );
287 if (
$path ===
null ) {
291 $protocol = parse_url(
$path, PHP_URL_SCHEME );
294 if ( $protocol ===
false ) {
295 throw new MWException(
"failed to parse URL '$path'" );
299 if ( $protocol ===
null ) {
320 if (
$type ===
null ) {
321 throw new MWException(
"This Site does not support link paths." );
373 if ( $url ===
null ) {
377 if ( $pageName !==
false ) {
378 $url = str_replace(
'$1', rawurlencode( $pageName ), $url );
467 throw new InvalidArgumentException(
"$languageCode is not a valid language code." );
504 if ( $this->localIds ===
false ) {
505 $this->localIds = [];
508 if ( !array_key_exists(
$type, $this->localIds ) ) {
509 $this->localIds[
$type] = [];
512 if ( !in_array( $identifier, $this->localIds[
$type] ) ) {
513 $this->localIds[
$type][] = $identifier;
525 $this->
addLocalId( self::ID_INTERWIKI, $identifier );
536 $this->
addLocalId( self::ID_EQUIVALENT, $identifier );
547 return array_key_exists( self::ID_INTERWIKI, $this->localIds )
561 return array_key_exists( self::ID_EQUIVALENT, $this->localIds )
588 public function setPath( $pathType, $fullUrl ) {
589 if ( !is_string( $fullUrl ) ) {
590 throw new MWException(
'$fullUrl needs to be a string' );
593 if ( !array_key_exists(
'paths', $this->extraData ) ) {
594 $this->extraData[
'paths'] = [];
597 $this->extraData[
'paths'][$pathType] = $fullUrl;
611 return array_key_exists( $pathType, $paths ) ? $paths[$pathType] :
null;
623 return array_key_exists(
'paths', $this->extraData ) ? $this->extraData[
'paths'] : [];
634 if ( array_key_exists(
'paths', $this->extraData ) ) {
635 unset( $this->extraData[
'paths'][$pathType] );
694 $this->
setGroup( $fields[
'group'] );
697 $this->localIds = $fields[
'localids'];
getInterwikiIds()
Returns the interwiki link identifiers that can be used for this site.
getType()
Returns the type of the site (ie mediawiki).
getDomain()
Returns the domain of the site, ie en.wikipedia.org Or false if it's not known.
string null $languageCode
setSource( $source)
Sets the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
getPageUrl( $pageName=false)
Returns the full URL for the given page on the site.
getInternalId()
Returns the set internal identifier for the site.
setLinkPath( $fullUrl)
Sets the path used to construct links with.
foreach( $res as $row) $serialized
setGroup( $group)
Sets the group of the site (ie wikipedia).
setInternalId( $internalId=null)
Sets the internal identifier for the site.
getPath( $pathType)
Returns the path of the provided type or false if there is no such path.
getLanguageCode()
Returns language code of the sites primary language.
static newForType( $siteType)
__construct( $type=self::TYPE_UNKNOWN)
getGlobalId()
Returns the global site identifier (ie enwiktionary).
getSource()
Returns the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
setForward( $shouldForward)
Sets if site.tld/path/key:pageTitle should forward users to the page on the actual site,...
setLanguageCode( $languageCode)
Sets language code of the sites primary language.
getGroup()
Gets the group of the site (ie wikipedia).
addInterwikiId( $identifier)
Adds an interwiki id to the site.
addLocalId( $type, $identifier)
Adds a local identifier.
unserialize( $serialized)
getLinkPathType()
Returns the main path type, that is the type of the path that should generally be used to construct l...
setExtraData(array $extraData)
Sets the type specific fields.
addNavigationId( $identifier)
Adds a navigation id to the site.
setPath( $pathType, $fullUrl)
Sets the path used to construct links with.
getNavigationIds()
Returns the equivalent link identifiers that can be used to make the site show up in interfaces such ...
getExtraConfig()
Returns the type specific config.
getAllPaths()
Returns the paths as associative array.
removePath( $pathType)
Removes the path of the provided type if it's set.
static isValidCode( $code)
Returns true if a language code string is of a valid form, whether or not it exists.
$wgSiteTypes
Register handlers for specific types of sites.
setExtraConfig(array $extraConfig)
Sets the type specific config.
array[] false $localIds
Holds the local ids for this site.
setGlobalId( $globalId)
Sets the global site identifier (ie enwiktionary).
normalizePageName( $pageName)
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,...
getProtocol()
Returns the protocol of the site.
getExtraData()
Returns the type specific fields.
getLinkPath()
Returns the path used to construct links with or false if there is no such path.
getLocalIds()
Returns all local ids.