23use InvalidArgumentException;
27use UnexpectedValueException;
56 public const SERIAL_VERSION_ID =
'2013-01-23';
234 $this->forward = $shouldForward;
248 if (
$path ===
null ) {
252 $domain = parse_url(
$path, PHP_URL_HOST );
254 if ( $domain ===
false ) {
268 $path = $this->getLinkPath();
270 if (
$path ===
null ) {
274 $protocol = parse_url(
$path, PHP_URL_SCHEME );
277 if ( $protocol ===
false ) {
278 throw new UnexpectedValueException(
"failed to parse URL '$path'" );
282 if ( $protocol ===
null ) {
299 $type = $this->getLinkPathType();
301 if ( $type ===
null ) {
302 throw new RuntimeException(
"This Site does not support link paths." );
305 $this->setPath( $type, $fullUrl );
316 $type = $this->getLinkPathType();
317 return $type ===
null ? null : $this->getPath( $type );
333 return self::PATH_LINK;
351 $url = $this->getLinkPath();
353 if ( $url ===
null ) {
357 if ( $pageName !==
false ) {
358 $url = str_replace(
'$1', rawurlencode( $pageName ), $url );
393 return $this->extraData;
404 $this->extraData = $extraData;
415 return $this->extraConfig;
426 $this->extraConfig = $extraConfig;
438 return $this->languageCode;
449 if ( $languageCode !==
null &&
451 throw new InvalidArgumentException(
"$languageCode is not a valid language code." );
453 $this->languageCode = $languageCode;
464 return $this->internalId;
476 $this->internalId = $internalId;
488 if ( $this->localIds ===
false ) {
489 $this->localIds = [];
492 if ( !array_key_exists( $type, $this->localIds ) ) {
493 $this->localIds[$type] = [];
496 if ( !in_array( $identifier, $this->localIds[$type] ) ) {
497 $this->localIds[$type][] = $identifier;
509 $this->addLocalId( self::ID_INTERWIKI, $identifier );
520 $this->addLocalId( self::ID_EQUIVALENT, $identifier );
531 return array_key_exists( self::ID_INTERWIKI, $this->localIds )
532 ? $this->localIds[self::ID_INTERWIKI]
545 return array_key_exists( self::ID_EQUIVALENT, $this->localIds )
546 ? $this->localIds[self::ID_EQUIVALENT] :
558 return $this->localIds;
570 public function setPath( $pathType,
string $fullUrl ) {
571 $this->extraData[
'paths'][$pathType] = $fullUrl;
584 $paths = $this->getAllPaths();
585 return $paths[$pathType] ??
null;
597 return $this->extraData[
'paths'] ?? [];
608 if ( array_key_exists(
'paths', $this->extraData ) ) {
609 unset( $this->extraData[
'paths'][$pathType] );
625 if ( array_key_exists( $siteType, $siteTypes ) ) {
626 return new $siteTypes[$siteType]();
641 'globalid' => $this->globalId,
642 'type' => $this->type,
643 'group' => $this->group,
645 'language' => $this->languageCode,
646 'localids' => $this->localIds,
647 'config' => $this->extraConfig,
648 'data' => $this->extraData,
649 'forward' => $this->forward,
650 'internalid' => $this->internalId,
662 $this->__construct( $fields[
'type'] );
664 $this->setGlobalId( $fields[
'globalid'] );
665 $this->setGroup( $fields[
'group'] );
666 $this->setSource( $fields[
'source'] );
667 $this->setLanguageCode( $fields[
'language'] );
668 $this->localIds = $fields[
'localids'];
669 $this->setExtraConfig( $fields[
'config'] );
670 $this->setExtraData( $fields[
'data'] );
671 $this->setForward( $fields[
'forward'] );
672 $this->setInternalId( $fields[
'internalid'] );
677class_alias( Site::class,
'Site' );
A class containing constants representing the names of configuration variables.
const SiteTypes
Name constant for the SiteTypes setting, for use with Config::get()