MediaWiki REL1_30
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
129 public function __construct( $type = self::TYPE_UNKNOWN ) {
130 $this->type = $type;
131 }
132
140 public function getGlobalId() {
141 return $this->globalId;
142 }
143
153 public function setGlobalId( $globalId ) {
154 if ( $globalId !== null && !is_string( $globalId ) ) {
155 throw new MWException( '$globalId needs to be string or null' );
156 }
157
158 $this->globalId = $globalId;
159 }
160
168 public function getType() {
169 return $this->type;
170 }
171
179 public function getGroup() {
180 return $this->group;
181 }
182
192 public function setGroup( $group ) {
193 if ( !is_string( $group ) ) {
194 throw new MWException( '$group needs to be a string' );
195 }
196
197 $this->group = $group;
198 }
199
207 public function getSource() {
208 return $this->source;
209 }
210
220 public function setSource( $source ) {
221 if ( !is_string( $source ) ) {
222 throw new MWException( '$source needs to be a string' );
223 }
224
225 $this->source = $source;
226 }
227
236 public function shouldForward() {
237 return $this->forward;
238 }
239
250 public function setForward( $shouldForward ) {
251 if ( !is_bool( $shouldForward ) ) {
252 throw new MWException( '$shouldForward needs to be a boolean' );
253 }
254
255 $this->forward = $shouldForward;
256 }
257
266 public function getDomain() {
267 $path = $this->getLinkPath();
268
269 if ( $path === null ) {
270 return null;
271 }
272
273 return parse_url( $path, PHP_URL_HOST );
274 }
275
284 public function getProtocol() {
285 $path = $this->getLinkPath();
286
287 if ( $path === null ) {
288 return '';
289 }
290
291 $protocol = parse_url( $path, PHP_URL_SCHEME );
292
293 // Malformed URL
294 if ( $protocol === false ) {
295 throw new MWException( "failed to parse URL '$path'" );
296 }
297
298 // No schema
299 if ( $protocol === null ) {
300 // Used for protocol relative URLs
301 $protocol = '';
302 }
303
304 return $protocol;
305 }
306
317 public function setLinkPath( $fullUrl ) {
318 $type = $this->getLinkPathType();
319
320 if ( $type === null ) {
321 throw new MWException( "This Site does not support link paths." );
322 }
323
324 $this->setPath( $type, $fullUrl );
325 }
326
334 public function getLinkPath() {
335 $type = $this->getLinkPathType();
336 return $type === null ? null : $this->getPath( $type );
337 }
338
351 public function getLinkPathType() {
352 return self::PATH_LINK;
353 }
354
370 public function getPageUrl( $pageName = false ) {
371 $url = $this->getLinkPath();
372
373 if ( $url === false ) {
374 return false;
375 }
376
377 if ( $pageName !== false ) {
378 $url = str_replace( '$1', rawurlencode( $pageName ), $url );
379 }
380
381 return $url;
382 }
383
396 public function normalizePageName( $pageName ) {
397 return $pageName;
398 }
399
407 public function getExtraData() {
408 return $this->extraData;
409 }
410
418 public function setExtraData( array $extraData ) {
419 $this->extraData = $extraData;
420 }
421
429 public function getExtraConfig() {
430 return $this->extraConfig;
431 }
432
440 public function setExtraConfig( array $extraConfig ) {
441 $this->extraConfig = $extraConfig;
442 }
443
452 public function getLanguageCode() {
453 return $this->languageCode;
454 }
455
463 public function setLanguageCode( $languageCode ) {
464 if ( !Language::isValidCode( $languageCode ) ) {
465 throw new InvalidArgumentException( "$languageCode is not a valid language code." );
466 }
467 $this->languageCode = $languageCode;
468 }
469
477 public function getInternalId() {
478 return $this->internalId;
479 }
480
489 public function setInternalId( $internalId = null ) {
490 $this->internalId = $internalId;
491 }
492
501 public function addLocalId( $type, $identifier ) {
502 if ( $this->localIds === false ) {
503 $this->localIds = [];
504 }
505
506 if ( !array_key_exists( $type, $this->localIds ) ) {
507 $this->localIds[$type] = [];
508 }
509
510 if ( !in_array( $identifier, $this->localIds[$type] ) ) {
511 $this->localIds[$type][] = $identifier;
512 }
513 }
514
522 public function addInterwikiId( $identifier ) {
523 $this->addLocalId( self::ID_INTERWIKI, $identifier );
524 }
525
533 public function addNavigationId( $identifier ) {
534 $this->addLocalId( self::ID_EQUIVALENT, $identifier );
535 }
536
544 public function getInterwikiIds() {
545 return array_key_exists( self::ID_INTERWIKI, $this->localIds )
546 ? $this->localIds[self::ID_INTERWIKI]
547 : [];
548 }
549
558 public function getNavigationIds() {
559 return array_key_exists( self::ID_EQUIVALENT, $this->localIds )
560 ? $this->localIds[self::ID_EQUIVALENT] :
561 [];
562 }
563
571 public function getLocalIds() {
572 return $this->localIds;
573 }
574
586 public function setPath( $pathType, $fullUrl ) {
587 if ( !is_string( $fullUrl ) ) {
588 throw new MWException( '$fullUrl needs to be a string' );
589 }
590
591 if ( !array_key_exists( 'paths', $this->extraData ) ) {
592 $this->extraData['paths'] = [];
593 }
594
595 $this->extraData['paths'][$pathType] = $fullUrl;
596 }
597
607 public function getPath( $pathType ) {
608 $paths = $this->getAllPaths();
609 return array_key_exists( $pathType, $paths ) ? $paths[$pathType] : null;
610 }
611
620 public function getAllPaths() {
621 return array_key_exists( 'paths', $this->extraData ) ? $this->extraData['paths'] : [];
622 }
623
631 public function removePath( $pathType ) {
632 if ( array_key_exists( 'paths', $this->extraData ) ) {
633 unset( $this->extraData['paths'][$pathType] );
634 }
635 }
636
644 public static function newForType( $siteType ) {
645 global $wgSiteTypes;
646
647 if ( array_key_exists( $siteType, $wgSiteTypes ) ) {
648 return new $wgSiteTypes[$siteType]();
649 }
650
651 return new Site();
652 }
653
661 public function serialize() {
662 $fields = [
663 'globalid' => $this->globalId,
664 'type' => $this->type,
665 'group' => $this->group,
666 'source' => $this->source,
667 'language' => $this->languageCode,
668 'localids' => $this->localIds,
669 'config' => $this->extraConfig,
670 'data' => $this->extraData,
671 'forward' => $this->forward,
672 'internalid' => $this->internalId,
673
674 ];
675
676 return serialize( $fields );
677 }
678
686 public function unserialize( $serialized ) {
687 $fields = unserialize( $serialized );
688
689 $this->__construct( $fields['type'] );
690
691 $this->setGlobalId( $fields['globalid'] );
692 $this->setGroup( $fields['group'] );
693 $this->setSource( $fields['source'] );
694 $this->setLanguageCode( $fields['language'] );
695 $this->localIds = $fields['localids'];
696 $this->setExtraConfig( $fields['config'] );
697 $this->setExtraData( $fields['data'] );
698 $this->setForward( $fields['forward'] );
699 $this->setInternalId( $fields['internalid'] );
700 }
701}
$wgSiteTypes
Register handlers for specific types of sites.
no text was provided for refs named< code > blankwithnoreference</code ></span ></li ></ol ></div > !end !test with< references/> in group !wikitext Wikipedia rocks< ref > Proceeds of vol XXI</ref > Wikipedia rocks< ref group=note > Proceeds of vol XXI</ref >< references/>< references group=note/> ! html< p > Wikipedia rocks< sup id="cite_ref-1" class="reference">< a href="#cite_note-1"> &Wikipedia rocks< sup id="cite_ref-2" class="reference">< a href="#cite_note-2"> &</p >< div class="mw-references-wrap">< ol class="references">< li id="cite_note-1">< span class="mw-cite-backlink">< a href="#cite_ref-1"> ↑</a ></span >< span class="reference-text"> Proceeds of vol XXI</span ></li ></ol ></div >< div class="mw-references-wrap">< ol class="references">< li id="cite_note-2">< span class="mw-cite-backlink">< a href="#cite_ref-2"> ↑</a ></span >< span class="reference-text"> Proceeds of vol XXI</span ></li ></ol ></div > !end !test with< references/> in group
MediaWiki exception.
Definition Site.php:29
normalizePageName( $pageName)
Returns $pageName without changes.
Definition Site.php:396
shouldForward()
Gets if site.tld/path/key:pageTitle should forward users to the page on the actual site,...
Definition Site.php:236
setPath( $pathType, $fullUrl)
Sets the path used to construct links with.
Definition Site.php:586
const TYPE_MEDIAWIKI
Definition Site.php:31
getExtraData()
Returns the type specific fields.
Definition Site.php:407
setGroup( $group)
Sets the group of the site (ie wikipedia).
Definition Site.php:192
addInterwikiId( $identifier)
Adds an interwiki id to the site.
Definition Site.php:522
getPath( $pathType)
Returns the path of the provided type or false if there is no such path.
Definition Site.php:607
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:250
setSource( $source)
Sets the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
Definition Site.php:220
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:207
static newForType( $siteType)
Definition Site.php:644
getProtocol()
Returns the protocol of the site.
Definition Site.php:284
getType()
Returns the type of the site (ie mediawiki).
Definition Site.php:168
int null $internalId
Definition Site.php:122
removePath( $pathType)
Removes the path of the provided type if it's set.
Definition Site.php:631
addLocalId( $type, $identifier)
Adds a local identifier.
Definition Site.php:501
setLanguageCode( $languageCode)
Sets language code of the sites primary language.
Definition Site.php:463
getGlobalId()
Returns the global site identifier (ie enwiktionary).
Definition Site.php:140
setGlobalId( $globalId)
Sets the global site identifier (ie enwiktionary).
Definition Site.php:153
getLinkPathType()
Returns the main path type, that is the type of the path that should generally be used to construct l...
Definition Site.php:351
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:429
addNavigationId( $identifier)
Adds a navigation id to the site.
Definition Site.php:533
getPageUrl( $pageName=false)
Returns the full URL for the given page on the site.
Definition Site.php:370
string null $languageCode
Definition Site.php:84
getAllPaths()
Returns the paths as associative array.
Definition Site.php:620
getLocalIds()
Returns all local ids.
Definition Site.php:571
unserialize( $serialized)
Definition Site.php:686
const ID_INTERWIKI
Definition Site.php:35
getGroup()
Gets the group of the site (ie wikipedia).
Definition Site.php:179
setInternalId( $internalId=null)
Sets the internal identifier for the site.
Definition Site.php:489
string $source
Definition Site.php:77
serialize()
Definition Site.php:661
getLanguageCode()
Returns language code of the sites primary language.
Definition Site.php:452
getInternalId()
Returns the set internal identifier for the site.
Definition Site.php:477
bool $forward
Definition Site.php:115
const SOURCE_LOCAL
Definition Site.php:38
setExtraConfig(array $extraConfig)
Sets the type specific config.
Definition Site.php:440
__construct( $type=self::TYPE_UNKNOWN)
Definition Site.php:129
getNavigationIds()
Returns the equivalent link identifiers that can be used to make the site show up in interfaces such ...
Definition Site.php:558
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:266
getLinkPath()
Returns the path used to construct links with or false if there is no such path.
Definition Site.php:334
setLinkPath( $fullUrl)
Sets the path used to construct links with.
Definition Site.php:317
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:544
setExtraData(array $extraData)
Sets the type specific fields.
Definition Site.php:418
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