11use UnexpectedValueException;
40 public const SERIAL_VERSION_ID =
'2013-01-23';
222 $this->forward = $shouldForward;
236 if (
$path ===
null ) {
240 $domain = parse_url(
$path, PHP_URL_HOST );
242 if ( $domain ===
false ) {
256 $path = $this->getLinkPath();
258 if (
$path ===
null ) {
262 $protocol = parse_url(
$path, PHP_URL_SCHEME );
265 if ( $protocol ===
false ) {
266 throw new UnexpectedValueException(
"failed to parse URL '$path'" );
270 return $protocol ??
'';
282 $type = $this->getLinkPathType();
284 if ( $type ===
null ) {
285 throw new RuntimeException(
"This Site does not support link paths." );
288 $this->setPath( $type, $fullUrl );
299 return $this->getPath( $this->getLinkPathType() );
315 return self::PATH_LINK;
333 $url = $this->getLinkPath();
335 if (
$url ===
null ) {
339 if ( $pageName !==
false ) {
340 $url = str_replace(
'$1', rawurlencode( $pageName ),
$url );
375 return $this->extraData;
386 $this->extraData = $extraData;
398 return $this->extraConfig;
410 $this->extraConfig = $extraConfig;
422 return $this->languageCode;
433 $this->languageCode = $languageCode;
445 return $this->internalId;
458 $this->internalId = $internalId;
470 if ( $this->localIds ===
false ) {
471 $this->localIds = [];
474 $this->localIds[$type] ??= [];
476 if ( !in_array( $identifier, $this->localIds[$type] ) ) {
477 $this->localIds[$type][] = $identifier;
489 $this->addLocalId( self::ID_INTERWIKI, $identifier );
500 $this->addLocalId( self::ID_EQUIVALENT, $identifier );
511 return $this->localIds[self::ID_INTERWIKI] ?? [];
523 return $this->localIds[self::ID_EQUIVALENT] ?? [];
534 return $this->localIds;
546 public function setPath( $pathType,
string $fullUrl ) {
547 $this->extraData[
'paths'][$pathType] = $fullUrl;
560 $paths = $this->getAllPaths();
561 return $paths[$pathType] ??
null;
573 return $this->extraData[
'paths'] ?? [];
584 if ( array_key_exists(
'paths', $this->extraData ) ) {
585 unset( $this->extraData[
'paths'][$pathType] );
610 'globalid' => $this->globalId,
611 'type' => $this->type,
612 'group' => $this->group,
614 'language' => $this->languageCode,
615 'localids' => $this->localIds,
616 'config' => $this->extraConfig,
617 'data' => $this->extraData,
618 'forward' => $this->forward,
619 'internalid' => $this->internalId,
631 $this->__construct( $fields[
'type'] );
633 $this->setGlobalId( $fields[
'globalid'] );
634 $this->setGroup( $fields[
'group'] );
635 $this->setSource( $fields[
'source'] );
636 $this->setLanguageCode( $fields[
'language'] );
637 $this->localIds = $fields[
'localids'];
638 $this->setExtraConfig( $fields[
'config'] );
639 $this->setExtraData( $fields[
'data'] );
640 $this->setForward( $fields[
'forward'] );
641 $this->setInternalId( $fields[
'internalid'] );
646class_alias( Site::class,
'Site' );