MediaWiki  1.23.12
Site.php
Go to the documentation of this file.
1 <?php
2 
29 class Site implements Serializable {
30 
31  const TYPE_UNKNOWN = 'unknown';
32  const TYPE_MEDIAWIKI = 'mediawiki';
33 
34  const GROUP_NONE = 'none';
35 
36  const ID_INTERWIKI = 'interwiki';
37  const ID_EQUIVALENT = 'equivalent';
38 
39  const SOURCE_LOCAL = 'local';
40 
41  const PATH_LINK = 'link';
42 
50  const SERIAL_VERSION_ID = '2013-01-23';
51 
57  protected $globalId = null;
58 
64  protected $type = self::TYPE_UNKNOWN;
65 
71  protected $group = self::GROUP_NONE;
72 
78  protected $source = self::SOURCE_LOCAL;
79 
85  protected $languageCode = null;
86 
95  protected $localIds = array();
96 
102  protected $extraData = array();
103 
109  protected $extraConfig = array();
110 
116  protected $forward = false;
117 
123  protected $internalId = null;
124 
132  public function __construct( $type = self::TYPE_UNKNOWN ) {
133  $this->type = $type;
134  }
135 
143  public function getGlobalId() {
144  return $this->globalId;
145  }
146 
156  public function setGlobalId( $globalId ) {
157  if ( $globalId !== null && !is_string( $globalId ) ) {
158  throw new MWException( '$globalId needs to be string or null' );
159  }
160 
161  $this->globalId = $globalId;
162  }
163 
171  public function getType() {
172  return $this->type;
173  }
174 
182  public function getGroup() {
183  return $this->group;
184  }
185 
195  public function setGroup( $group ) {
196  if ( !is_string( $group ) ) {
197  throw new MWException( '$group needs to be a string' );
198  }
199 
200  $this->group = $group;
201  }
202 
210  public function getSource() {
211  return $this->source;
212  }
213 
223  public function setSource( $source ) {
224  if ( !is_string( $source ) ) {
225  throw new MWException( '$source needs to be a string' );
226  }
227 
228  $this->source = $source;
229  }
230 
239  public function shouldForward() {
240  return $this->forward;
241  }
242 
253  public function setForward( $shouldForward ) {
254  if ( !is_bool( $shouldForward ) ) {
255  throw new MWException( '$shouldForward needs to be a boolean' );
256  }
257 
258  $this->forward = $shouldForward;
259  }
260 
269  public function getDomain() {
270  $path = $this->getLinkPath();
271 
272  if ( $path === null ) {
273  return null;
274  }
275 
276  return parse_url( $path, PHP_URL_HOST );
277  }
278 
287  public function getProtocol() {
288  $path = $this->getLinkPath();
289 
290  if ( $path === null ) {
291  return '';
292  }
293 
294  $protocol = parse_url( $path, PHP_URL_SCHEME );
295 
296  // Malformed URL
297  if ( $protocol === false ) {
298  throw new MWException( "failed to parse URL '$path'" );
299  }
300 
301  // No schema
302  if ( $protocol === null ) {
303  // Used for protocol relative URLs
304  $protocol = '';
305  }
306 
307  return $protocol;
308  }
309 
320  public function setLinkPath( $fullUrl ) {
321  $type = $this->getLinkPathType();
322 
323  if ( $type === null ) {
324  throw new MWException( "This Site does not support link paths." );
325  }
326 
327  $this->setPath( $type, $fullUrl );
328  }
329 
337  public function getLinkPath() {
338  $type = $this->getLinkPathType();
339  return $type === null ? null: $this->getPath( $type );
340  }
341 
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() {
411  }
412 
420  public function setExtraData( array $extraData ) {
421  $this->extraData = $extraData;
422  }
423 
431  public function getExtraConfig() {
433  }
434 
442  public function setExtraConfig( array $extraConfig ) {
443  $this->extraConfig = $extraConfig;
444  }
445 
454  public function getLanguageCode() {
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 = array();
503  }
504 
505  if ( !array_key_exists( $type, $this->localIds ) ) {
506  $this->localIds[$type] = array();
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 ) ? $this->localIds[self::ID_INTERWIKI] : array();
545  }
546 
555  public function getNavigationIds() {
556  return array_key_exists( self::ID_EQUIVALENT, $this->localIds ) ? $this->localIds[self::ID_EQUIVALENT] : array();
557  }
558 
566  public function getLocalIds() {
567  return $this->localIds;
568  }
569 
581  public function setPath( $pathType, $fullUrl ) {
582  if ( !is_string( $fullUrl ) ) {
583  throw new MWException( '$fullUrl needs to be a string' );
584  }
585 
586  if ( !array_key_exists( 'paths', $this->extraData ) ) {
587  $this->extraData['paths'] = array();
588  }
589 
590  $this->extraData['paths'][$pathType] = $fullUrl;
591  }
592 
602  public function getPath( $pathType ) {
603  $paths = $this->getAllPaths();
604  return array_key_exists( $pathType, $paths ) ? $paths[$pathType] : null;
605  }
606 
615  public function getAllPaths() {
616  return array_key_exists( 'paths', $this->extraData ) ? $this->extraData['paths'] : array();
617  }
618 
626  public function removePath( $pathType ) {
627  if ( array_key_exists( 'paths', $this->extraData ) ) {
628  unset( $this->extraData['paths'][$pathType] );
629  }
630  }
631 
639  public static function newForType( $siteType ) {
640  global $wgSiteTypes;
641 
642  if ( array_key_exists( $siteType, $wgSiteTypes ) ) {
643  return new $wgSiteTypes[$siteType]();
644  }
645 
646  return new Site();
647  }
648 
656  public function serialize() {
657  $fields = array(
658  'globalid' => $this->globalId,
659  'type' => $this->type,
660  'group' => $this->group,
661  'source' => $this->source,
662  'language' => $this->languageCode,
663  'localids' => $this->localIds,
664  'config' => $this->extraConfig,
665  'data' => $this->extraData,
666  'forward' => $this->forward,
667  'internalid' => $this->internalId,
668 
669  );
670 
671  return serialize( $fields );
672  }
673 
681  public function unserialize( $serialized ) {
682  $fields = unserialize( $serialized );
683 
684  $this->__construct( $fields['type'] );
685 
686  $this->setGlobalId( $fields['globalid'] );
687  $this->setGroup( $fields['group'] );
688  $this->setSource( $fields['source'] );
689  $this->setLanguageCode( $fields['language'] );
690  $this->localIds = $fields['localids'];
691  $this->setExtraConfig( $fields['config'] );
692  $this->setExtraData( $fields['data'] );
693  $this->setForward( $fields['forward'] );
694  $this->setInternalId( $fields['internalid'] );
695  }
696 
697 }
698 
702 class SiteObject extends Site {}
Site\ID_EQUIVALENT
const ID_EQUIVALENT
Definition: Site.php:37
Site\getInterwikiIds
getInterwikiIds()
Returns the interwiki link identifiers that can be used for this site.
Definition: Site.php:533
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Site\$extraConfig
array $extraConfig
Definition: Site.php:101
Site\getType
getType()
Returns the type of the site (ie mediawiki).
Definition: Site.php:161
Site\getDomain
getDomain()
Returns the domain of the site, ie en.wikipedia.org Or false if it's not known.
Definition: Site.php:259
Site\$languageCode
string null $languageCode
Definition: Site.php:80
Site\setSource
setSource( $source)
Sets the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
Definition: Site.php:213
Site\getPageUrl
getPageUrl( $pageName=false)
Returns the full URL for the given page on the site.
Definition: Site.php:362
Site\getInternalId
getInternalId()
Returns the set internal identifier for the site.
Definition: Site.php:466
Site\setLinkPath
setLinkPath( $fullUrl)
Sets the path used to construct links with.
Definition: Site.php:310
$serialized
foreach( $res as $row) $serialized
Definition: testCompression.php:77
Site\setGroup
setGroup( $group)
Sets the type of the site (ie wikipedia).
Definition: Site.php:185
Site\setInternalId
setInternalId( $internalId=null)
Sets the internal identifier for the site.
Definition: Site.php:478
Site\getPath
getPath( $pathType)
Returns the path of the provided type or false if there is no such path.
Definition: Site.php:592
Site\getLanguageCode
getLanguageCode()
Returns language code of the sites primary language.
Definition: Site.php:444
Site\ID_INTERWIKI
const ID_INTERWIKI
Definition: Site.php:36
Site\newForType
static newForType( $siteType)
Definition: Site.php:629
Site\$type
string $type
Definition: Site.php:62
Site\$internalId
int null $internalId
Definition: Site.php:113
Site\__construct
__construct( $type=self::TYPE_UNKNOWN)
Constructor.
Definition: Site.php:122
Site\serialize
serialize()
Definition: Site.php:646
MWException
MediaWiki exception.
Definition: MWException.php:26
Site\$globalId
string null $globalId
Definition: Site.php:56
Site\TYPE_UNKNOWN
const TYPE_UNKNOWN
Definition: Site.php:31
SiteObject
Definition: Site.php:692
Site\getGlobalId
getGlobalId()
Returns the global site identifier (ie enwiktionary).
Definition: Site.php:133
Site\getSource
getSource()
Returns the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
Definition: Site.php:200
Site\setForward
setForward( $shouldForward)
Sets if site.tld/path/key:pageTitle should forward users to the page on the actual site,...
Definition: Site.php:243
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
Site\setLanguageCode
setLanguageCode( $languageCode)
Sets language code of the sites primary language.
Definition: Site.php:455
Site\getGroup
getGroup()
Gets the type of the site (ie wikipedia).
Definition: Site.php:172
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
Site\addInterwikiId
addInterwikiId( $identifier)
Adds an interwiki id to the site.
Definition: Site.php:511
Site\addLocalId
addLocalId( $type, $identifier)
Adds a local identifier.
Definition: Site.php:490
Site\SERIAL_VERSION_ID
const SERIAL_VERSION_ID
Definition: Site.php:50
Site\unserialize
unserialize( $serialized)
Definition: Site.php:671
Site
Definition: Site.php:29
Site\getLinkPathType
getLinkPathType()
Returns the main path type, that is the type of the path that should generally be used to construct l...
Definition: Site.php:343
Site\$localIds
array[] $localIds
Holds the local ids for this site.
Definition: Site.php:89
Site\setExtraData
setExtraData(array $extraData)
Sets the type specific fields.
Definition: Site.php:410
Site\addNavigationId
addNavigationId( $identifier)
Adds a navigation id to the site.
Definition: Site.php:522
Site\$group
string $group
Definition: Site.php:68
Site\setPath
setPath( $pathType, $fullUrl)
Sets the path used to construct links with.
Definition: Site.php:571
Site\$extraData
array $extraData
Definition: Site.php:95
Site\getNavigationIds
getNavigationIds()
Returns the equivalent link identifiers that can be used to make the site show up in interfaces such ...
Definition: Site.php:545
Site\getExtraConfig
getExtraConfig()
Returns the type specific config.
Definition: Site.php:421
Site\getAllPaths
getAllPaths()
Returns the paths as associative array.
Definition: Site.php:605
Site\removePath
removePath( $pathType)
Removes the path of the provided type if it's set.
Definition: Site.php:616
Site\$forward
bool $forward
Definition: Site.php:107
type
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:22
Site\setExtraConfig
setExtraConfig(array $extraConfig)
Sets the type specific config.
Definition: Site.php:432
Site\setGlobalId
setGlobalId( $globalId)
Sets the global site identifier (ie enwiktionary).
Definition: Site.php:146
$path
$path
Definition: NoLocalSettings.php:35
Site\normalizePageName
normalizePageName( $pageName)
Returns $pageName without changes.
Definition: Site.php:388
Site\shouldForward
shouldForward()
Gets if site.tld/path/key:pageTitle should forward users to the page on the actual site,...
Definition: Site.php:229
source
return true to allow those checks to and false if checking is done use this to change the tables headers temp or archived zone change it to an object instance and return false override the list derivative used the name of the old file when set the default code will be skipped add a value to it if you want to add a cookie that have to vary cache options can modify source
Definition: hooks.txt:1227
Site\GROUP_NONE
const GROUP_NONE
Definition: Site.php:34
Site\SOURCE_LOCAL
const SOURCE_LOCAL
Definition: Site.php:39
Site\PATH_LINK
const PATH_LINK
Definition: Site.php:41
Site\getProtocol
getProtocol()
Returns the protocol of the site.
Definition: Site.php:277
Site\TYPE_MEDIAWIKI
const TYPE_MEDIAWIKI
Definition: Site.php:32
Site\$source
string $source
Definition: Site.php:74
Site\getExtraData
getExtraData()
Returns the type specific fields.
Definition: Site.php:399
Site\getLinkPath
getLinkPath()
Returns the path used to construct links with or false if there is no such path.
Definition: Site.php:327
Site\getLocalIds
getLocalIds()
Returns all local ids.
Definition: Site.php:556