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 return $protocol ??
'';
294 $type = $this->getLinkPathType();
296 if ( $type ===
null ) {
297 throw new RuntimeException(
"This Site does not support link paths." );
300 $this->setPath( $type, $fullUrl );
311 $type = $this->getLinkPathType();
312 return $type ===
null ? null : $this->getPath( $type );
328 return self::PATH_LINK;
346 $url = $this->getLinkPath();
348 if (
$url ===
null ) {
352 if ( $pageName !==
false ) {
353 $url = str_replace(
'$1', rawurlencode( $pageName ),
$url );
388 return $this->extraData;
399 $this->extraData = $extraData;
410 return $this->extraConfig;
421 $this->extraConfig = $extraConfig;
433 return $this->languageCode;
444 if ( $languageCode !==
null &&
446 throw new InvalidArgumentException(
"$languageCode is not a valid language code." );
448 $this->languageCode = $languageCode;
459 return $this->internalId;
471 $this->internalId = $internalId;
483 if ( $this->localIds ===
false ) {
484 $this->localIds = [];
487 $this->localIds[$type] ??= [];
489 if ( !in_array( $identifier, $this->localIds[$type] ) ) {
490 $this->localIds[$type][] = $identifier;
502 $this->addLocalId( self::ID_INTERWIKI, $identifier );
513 $this->addLocalId( self::ID_EQUIVALENT, $identifier );
524 return $this->localIds[self::ID_INTERWIKI] ?? [];
536 return $this->localIds[self::ID_EQUIVALENT] ?? [];
547 return $this->localIds;
559 public function setPath( $pathType,
string $fullUrl ) {
560 $this->extraData[
'paths'][$pathType] = $fullUrl;
573 $paths = $this->getAllPaths();
574 return $paths[$pathType] ??
null;
586 return $this->extraData[
'paths'] ?? [];
597 if ( array_key_exists(
'paths', $this->extraData ) ) {
598 unset( $this->extraData[
'paths'][$pathType] );
615 if ( array_key_exists( $siteType, $siteTypes ) ) {
616 return new $siteTypes[$siteType]();
631 'globalid' => $this->globalId,
632 'type' => $this->type,
633 'group' => $this->group,
635 'language' => $this->languageCode,
636 'localids' => $this->localIds,
637 'config' => $this->extraConfig,
638 'data' => $this->extraData,
639 'forward' => $this->forward,
640 'internalid' => $this->internalId,
652 $this->__construct( $fields[
'type'] );
654 $this->setGlobalId( $fields[
'globalid'] );
655 $this->setGroup( $fields[
'group'] );
656 $this->setSource( $fields[
'source'] );
657 $this->setLanguageCode( $fields[
'language'] );
658 $this->localIds = $fields[
'localids'];
659 $this->setExtraConfig( $fields[
'config'] );
660 $this->setExtraData( $fields[
'data'] );
661 $this->setForward( $fields[
'forward'] );
662 $this->setInternalId( $fields[
'internalid'] );
667class_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()