MediaWiki REL1_28
Site.php
Go to the documentation of this file.
1<?php
2
29class Site implements Serializable {
30 const TYPE_UNKNOWN = 'unknown';
31 const TYPE_MEDIAWIKI = 'mediawiki';
32
33 const GROUP_NONE = 'none';
34
35 const ID_INTERWIKI = 'interwiki';
36 const ID_EQUIVALENT = 'equivalent';
37
38 const SOURCE_LOCAL = 'local';
39
40 const PATH_LINK = 'link';
41
49 const SERIAL_VERSION_ID = '2013-01-23';
50
56 protected $globalId = null;
57
64
71
78
84 protected $languageCode = null;
85
94 protected $localIds = [];
95
101 protected $extraData = [];
102
108 protected $extraConfig = [];
109
115 protected $forward = false;
116
122 protected $internalId = null;
123
131 public function __construct( $type = self::TYPE_UNKNOWN ) {
132 $this->type = $type;
133 }
134
142 public function getGlobalId() {
143 return $this->globalId;
144 }
145
155 public function setGlobalId( $globalId ) {
156 if ( $globalId !== null && !is_string( $globalId ) ) {
157 throw new MWException( '$globalId needs to be string or null' );
158 }
159
160 $this->globalId = $globalId;
161 }
162
170 public function getType() {
171 return $this->type;
172 }
173
181 public function getGroup() {
182 return $this->group;
183 }
184
194 public function setGroup( $group ) {
195 if ( !is_string( $group ) ) {
196 throw new MWException( '$group needs to be a string' );
197 }
198
199 $this->group = $group;
200 }
201
209 public function getSource() {
210 return $this->source;
211 }
212
222 public function setSource( $source ) {
223 if ( !is_string( $source ) ) {
224 throw new MWException( '$source needs to be a string' );
225 }
226
227 $this->source = $source;
228 }
229
238 public function shouldForward() {
239 return $this->forward;
240 }
241
252 public function setForward( $shouldForward ) {
253 if ( !is_bool( $shouldForward ) ) {
254 throw new MWException( '$shouldForward needs to be a boolean' );
255 }
256
257 $this->forward = $shouldForward;
258 }
259
268 public function getDomain() {
269 $path = $this->getLinkPath();
270
271 if ( $path === null ) {
272 return null;
273 }
274
275 return parse_url( $path, PHP_URL_HOST );
276 }
277
286 public function getProtocol() {
287 $path = $this->getLinkPath();
288
289 if ( $path === null ) {
290 return '';
291 }
292
293 $protocol = parse_url( $path, PHP_URL_SCHEME );
294
295 // Malformed URL
296 if ( $protocol === false ) {
297 throw new MWException( "failed to parse URL '$path'" );
298 }
299
300 // No schema
301 if ( $protocol === null ) {
302 // Used for protocol relative URLs
303 $protocol = '';
304 }
305
306 return $protocol;
307 }
308
319 public function setLinkPath( $fullUrl ) {
320 $type = $this->getLinkPathType();
321
322 if ( $type === null ) {
323 throw new MWException( "This Site does not support link paths." );
324 }
325
326 $this->setPath( $type, $fullUrl );
327 }
328
336 public function getLinkPath() {
337 $type = $this->getLinkPathType();
338 return $type === null ? null: $this->getPath( $type );
339 }
340
353 public function getLinkPathType() {
354 return self::PATH_LINK;
355 }
356
372 public function getPageUrl( $pageName = false ) {
373 $url = $this->getLinkPath();
374
375 if ( $url === false ) {
376 return false;
377 }
378
379 if ( $pageName !== false ) {
380 $url = str_replace( '$1', rawurlencode( $pageName ), $url );
381 }
382
383 return $url;
384 }
385
398 public function normalizePageName( $pageName ) {
399 return $pageName;
400 }
401
409 public function getExtraData() {
410 return $this->extraData;
411 }
412
420 public function setExtraData( array $extraData ) {
421 $this->extraData = $extraData;
422 }
423
431 public function getExtraConfig() {
432 return $this->extraConfig;
433 }
434
442 public function setExtraConfig( array $extraConfig ) {
443 $this->extraConfig = $extraConfig;
444 }
445
454 public function getLanguageCode() {
455 return $this->languageCode;
456 }
457
465 public function setLanguageCode( $languageCode ) {
466 $this->languageCode = $languageCode;
467 }
468
476 public function getInternalId() {
477 return $this->internalId;
478 }
479
488 public function setInternalId( $internalId = null ) {
489 $this->internalId = $internalId;
490 }
491
500 public function addLocalId( $type, $identifier ) {
501 if ( $this->localIds === false ) {
502 $this->localIds = [];
503 }
504
505 if ( !array_key_exists( $type, $this->localIds ) ) {
506 $this->localIds[$type] = [];
507 }
508
509 if ( !in_array( $identifier, $this->localIds[$type] ) ) {
510 $this->localIds[$type][] = $identifier;
511 }
512 }
513
521 public function addInterwikiId( $identifier ) {
522 $this->addLocalId( self::ID_INTERWIKI, $identifier );
523 }
524
532 public function addNavigationId( $identifier ) {
533 $this->addLocalId( self::ID_EQUIVALENT, $identifier );
534 }
535
543 public function getInterwikiIds() {
544 return array_key_exists( self::ID_INTERWIKI, $this->localIds )
545 ? $this->localIds[self::ID_INTERWIKI]
546 : [];
547 }
548
557 public function getNavigationIds() {
558 return array_key_exists( self::ID_EQUIVALENT, $this->localIds )
559 ? $this->localIds[self::ID_EQUIVALENT] :
560 [];
561 }
562
570 public function getLocalIds() {
571 return $this->localIds;
572 }
573
585 public function setPath( $pathType, $fullUrl ) {
586 if ( !is_string( $fullUrl ) ) {
587 throw new MWException( '$fullUrl needs to be a string' );
588 }
589
590 if ( !array_key_exists( 'paths', $this->extraData ) ) {
591 $this->extraData['paths'] = [];
592 }
593
594 $this->extraData['paths'][$pathType] = $fullUrl;
595 }
596
606 public function getPath( $pathType ) {
607 $paths = $this->getAllPaths();
608 return array_key_exists( $pathType, $paths ) ? $paths[$pathType] : null;
609 }
610
619 public function getAllPaths() {
620 return array_key_exists( 'paths', $this->extraData ) ? $this->extraData['paths'] : [];
621 }
622
630 public function removePath( $pathType ) {
631 if ( array_key_exists( 'paths', $this->extraData ) ) {
632 unset( $this->extraData['paths'][$pathType] );
633 }
634 }
635
643 public static function newForType( $siteType ) {
645
646 if ( array_key_exists( $siteType, $wgSiteTypes ) ) {
647 return new $wgSiteTypes[$siteType]();
648 }
649
650 return new Site();
651 }
652
660 public function serialize() {
661 $fields = [
662 'globalid' => $this->globalId,
663 'type' => $this->type,
664 'group' => $this->group,
665 'source' => $this->source,
666 'language' => $this->languageCode,
667 'localids' => $this->localIds,
668 'config' => $this->extraConfig,
669 'data' => $this->extraData,
670 'forward' => $this->forward,
671 'internalid' => $this->internalId,
672
673 ];
674
675 return serialize( $fields );
676 }
677
685 public function unserialize( $serialized ) {
686 $fields = unserialize( $serialized );
687
688 $this->__construct( $fields['type'] );
689
690 $this->setGlobalId( $fields['globalid'] );
691 $this->setGroup( $fields['group'] );
692 $this->setSource( $fields['source'] );
693 $this->setLanguageCode( $fields['language'] );
694 $this->localIds = $fields['localids'];
695 $this->setExtraConfig( $fields['config'] );
696 $this->setExtraData( $fields['data'] );
697 $this->setForward( $fields['forward'] );
698 $this->setInternalId( $fields['internalid'] );
699 }
700}
$wgSiteTypes
Register handlers for specific types of sites.
MediaWiki exception.
Definition Site.php:29
normalizePageName( $pageName)
Returns $pageName without changes.
Definition Site.php:398
shouldForward()
Gets if site.tld/path/key:pageTitle should forward users to the page on the actual site,...
Definition Site.php:238
setPath( $pathType, $fullUrl)
Sets the path used to construct links with.
Definition Site.php:585
const TYPE_MEDIAWIKI
Definition Site.php:31
getExtraData()
Returns the type specific fields.
Definition Site.php:409
setGroup( $group)
Sets the group of the site (ie wikipedia).
Definition Site.php:194
addInterwikiId( $identifier)
Adds an interwiki id to the site.
Definition Site.php:521
getPath( $pathType)
Returns the path of the provided type or false if there is no such path.
Definition Site.php:606
const GROUP_NONE
Definition Site.php:33
setForward( $shouldForward)
Sets if site.tld/path/key:pageTitle should forward users to the page on the actual site,...
Definition Site.php:252
setSource( $source)
Sets the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
Definition Site.php:222
string $type
Definition Site.php:63
array $extraConfig
Definition Site.php:108
array $extraData
Definition Site.php:101
getSource()
Returns the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
Definition Site.php:209
static newForType( $siteType)
Definition Site.php:643
getProtocol()
Returns the protocol of the site.
Definition Site.php:286
getType()
Returns the type of the site (ie mediawiki).
Definition Site.php:170
int null $internalId
Definition Site.php:122
removePath( $pathType)
Removes the path of the provided type if it's set.
Definition Site.php:630
addLocalId( $type, $identifier)
Adds a local identifier.
Definition Site.php:500
setLanguageCode( $languageCode)
Sets language code of the sites primary language.
Definition Site.php:465
getGlobalId()
Returns the global site identifier (ie enwiktionary).
Definition Site.php:142
setGlobalId( $globalId)
Sets the global site identifier (ie enwiktionary).
Definition Site.php:155
getLinkPathType()
Returns the main path type, that is the type of the path that should generally be used to construct l...
Definition Site.php:353
const PATH_LINK
Definition Site.php:40
const TYPE_UNKNOWN
Definition Site.php:30
const ID_EQUIVALENT
Definition Site.php:36
getExtraConfig()
Returns the type specific config.
Definition Site.php:431
addNavigationId( $identifier)
Adds a navigation id to the site.
Definition Site.php:532
getPageUrl( $pageName=false)
Returns the full URL for the given page on the site.
Definition Site.php:372
string null $languageCode
Definition Site.php:84
getAllPaths()
Returns the paths as associative array.
Definition Site.php:619
getLocalIds()
Returns all local ids.
Definition Site.php:570
unserialize( $serialized)
Definition Site.php:685
const ID_INTERWIKI
Definition Site.php:35
getGroup()
Gets the group of the site (ie wikipedia).
Definition Site.php:181
setInternalId( $internalId=null)
Sets the internal identifier for the site.
Definition Site.php:488
string $source
Definition Site.php:77
serialize()
Definition Site.php:660
getLanguageCode()
Returns language code of the sites primary language.
Definition Site.php:454
getInternalId()
Returns the set internal identifier for the site.
Definition Site.php:476
bool $forward
Definition Site.php:115
const SOURCE_LOCAL
Definition Site.php:38
setExtraConfig(array $extraConfig)
Sets the type specific config.
Definition Site.php:442
__construct( $type=self::TYPE_UNKNOWN)
Constructor.
Definition Site.php:131
getNavigationIds()
Returns the equivalent link identifiers that can be used to make the site show up in interfaces such ...
Definition Site.php:557
string null $globalId
Definition Site.php:56
string $group
Definition Site.php:70
getDomain()
Returns the domain of the site, ie en.wikipedia.org Or false if it's not known.
Definition Site.php:268
getLinkPath()
Returns the path used to construct links with or false if there is no such path.
Definition Site.php:336
setLinkPath( $fullUrl)
Sets the path used to construct links with.
Definition Site.php:319
array[] $localIds
Holds the local ids for this site.
Definition Site.php:94
getInterwikiIds()
Returns the interwiki link identifiers that can be used for this site.
Definition Site.php:543
setExtraData(array $extraData)
Sets the type specific fields.
Definition Site.php:420
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
the array() calling protocol came about after MediaWiki 1.4rc1.
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify prev or next refreshes the diff cache allow viewing deleted revs difference engine object to be used for diff source
Definition hooks.txt:1609
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN type
Definition postgres.txt:36
foreach( $res as $row) $serialized