9use InvalidArgumentException;
13use UnexpectedValueException;
42 public const SERIAL_VERSION_ID =
'2013-01-23';
220 $this->forward = $shouldForward;
234 if (
$path ===
null ) {
238 $domain = parse_url(
$path, PHP_URL_HOST );
240 if ( $domain ===
false ) {
254 $path = $this->getLinkPath();
256 if (
$path ===
null ) {
260 $protocol = parse_url(
$path, PHP_URL_SCHEME );
263 if ( $protocol ===
false ) {
264 throw new UnexpectedValueException(
"failed to parse URL '$path'" );
268 return $protocol ??
'';
280 $type = $this->getLinkPathType();
282 if ( $type ===
null ) {
283 throw new RuntimeException(
"This Site does not support link paths." );
286 $this->setPath( $type, $fullUrl );
297 $type = $this->getLinkPathType();
298 return $type ===
null ? null : $this->getPath( $type );
314 return self::PATH_LINK;
332 $url = $this->getLinkPath();
334 if (
$url ===
null ) {
338 if ( $pageName !==
false ) {
339 $url = str_replace(
'$1', rawurlencode( $pageName ),
$url );
374 return $this->extraData;
385 $this->extraData = $extraData;
396 return $this->extraConfig;
407 $this->extraConfig = $extraConfig;
419 return $this->languageCode;
430 if ( $languageCode !==
null &&
432 throw new InvalidArgumentException(
"$languageCode is not a valid language code." );
434 $this->languageCode = $languageCode;
445 return $this->internalId;
457 $this->internalId = $internalId;
469 if ( $this->localIds ===
false ) {
470 $this->localIds = [];
473 $this->localIds[$type] ??= [];
475 if ( !in_array( $identifier, $this->localIds[$type] ) ) {
476 $this->localIds[$type][] = $identifier;
488 $this->addLocalId( self::ID_INTERWIKI, $identifier );
499 $this->addLocalId( self::ID_EQUIVALENT, $identifier );
510 return $this->localIds[self::ID_INTERWIKI] ?? [];
522 return $this->localIds[self::ID_EQUIVALENT] ?? [];
533 return $this->localIds;
545 public function setPath( $pathType,
string $fullUrl ) {
546 $this->extraData[
'paths'][$pathType] = $fullUrl;
559 $paths = $this->getAllPaths();
560 return $paths[$pathType] ??
null;
572 return $this->extraData[
'paths'] ?? [];
583 if ( array_key_exists(
'paths', $this->extraData ) ) {
584 unset( $this->extraData[
'paths'][$pathType] );
601 if ( array_key_exists( $siteType, $siteTypes ) ) {
602 return new $siteTypes[$siteType]();
617 'globalid' => $this->globalId,
618 'type' => $this->type,
619 'group' => $this->group,
621 'language' => $this->languageCode,
622 'localids' => $this->localIds,
623 'config' => $this->extraConfig,
624 'data' => $this->extraData,
625 'forward' => $this->forward,
626 'internalid' => $this->internalId,
638 $this->__construct( $fields[
'type'] );
640 $this->setGlobalId( $fields[
'globalid'] );
641 $this->setGroup( $fields[
'group'] );
642 $this->setSource( $fields[
'source'] );
643 $this->setLanguageCode( $fields[
'language'] );
644 $this->localIds = $fields[
'localids'];
645 $this->setExtraConfig( $fields[
'config'] );
646 $this->setExtraData( $fields[
'data'] );
647 $this->setForward( $fields[
'forward'] );
648 $this->setInternalId( $fields[
'internalid'] );
653class_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()