MediaWiki REL1_40
SiteList.php
Go to the documentation of this file.
1<?php
36 protected $byInternalId = [];
37
45 protected $byGlobalId = [];
46
55 protected $byNavigationId = [];
56
64 public function getObjectType() {
65 return Site::class;
66 }
67
78 protected function preSetElement( $index, $site ) {
79 if ( $this->hasSite( $site->getGlobalId() ) ) {
80 $this->removeSite( $site->getGlobalId() );
81 }
82
83 $this->byGlobalId[$site->getGlobalId()] = $index;
84 $this->byInternalId[$site->getInternalId()] = $index;
85
86 $ids = $site->getNavigationIds();
87 foreach ( $ids as $navId ) {
88 $this->byNavigationId[$navId] = $index;
89 }
90
91 return true;
92 }
93
101 public function offsetUnset( $index ): void {
102 if ( $this->offsetExists( $index ) ) {
106 $site = $this->offsetGet( $index );
107
108 unset( $this->byGlobalId[$site->getGlobalId()] );
109 unset( $this->byInternalId[$site->getInternalId()] );
110
111 $ids = $site->getNavigationIds();
112 foreach ( $ids as $navId ) {
113 unset( $this->byNavigationId[$navId] );
114 }
115 }
116
117 parent::offsetUnset( $index );
118 }
119
128 public function getGlobalIdentifiers() {
129 return array_keys( $this->byGlobalId );
130 }
131
139 public function hasSite( $globalSiteId ) {
140 return array_key_exists( $globalSiteId, $this->byGlobalId );
141 }
142
153 public function getSite( $globalSiteId ) {
154 return $this->offsetGet( $this->byGlobalId[$globalSiteId] );
155 }
156
165 public function removeSite( $globalSiteId ) {
166 $this->offsetUnset( $this->byGlobalId[$globalSiteId] );
167 }
168
176 public function isEmpty() {
177 return $this->byGlobalId === [];
178 }
179
187 public function hasInternalId( $id ) {
188 return array_key_exists( $id, $this->byInternalId );
189 }
190
201 public function getSiteByInternalId( $id ) {
202 return $this->offsetGet( $this->byInternalId[$id] );
203 }
204
213 public function removeSiteByInternalId( $id ) {
214 $this->offsetUnset( $this->byInternalId[$id] );
215 }
216
224 public function hasNavigationId( $id ) {
225 return array_key_exists( $id, $this->byNavigationId );
226 }
227
238 public function getSiteByNavigationId( $id ) {
239 return $this->offsetGet( $this->byNavigationId[$id] );
240 }
241
250 public function removeSiteByNavigationId( $id ) {
251 $this->offsetUnset( $this->byNavigationId[$id] );
252 }
253
262 public function setSite( Site $site ) {
263 $this[] = $site;
264 }
265
275 public function getGroup( $groupName ) {
276 $group = new self();
277
281 foreach ( $this as $site ) {
282 if ( $site->getGroup() === $groupName ) {
283 $group[] = $site;
284 }
285 }
286
287 return $group;
288 }
289
298 private const SERIAL_VERSION_ID = '2014-03-17';
299
309 public static function getSerialVersionId() {
310 return self::SERIAL_VERSION_ID . '+Site:' . Site::SERIAL_VERSION_ID;
311 }
312
320 protected function getSerializationData() {
321 // NOTE: When changing the structure, either implement unserialize() to handle the
322 // old structure too, or update SERIAL_VERSION_ID to kill any caches.
323 return array_merge(
324 parent::getSerializationData(),
325 [
326 'internalIds' => $this->byInternalId,
327 'globalIds' => $this->byGlobalId,
328 'navigationIds' => $this->byNavigationId
329 ]
330 );
331 }
332
340 public function __unserialize( $serializationData ): void {
341 parent::__unserialize( $serializationData );
342
343 $this->byInternalId = $serializationData['internalIds'];
344 $this->byGlobalId = $serializationData['globalIds'];
345 $this->byNavigationId = $serializationData['navigationIds'];
346 }
347}
__unserialize( $data)
if(!defined('MW_SETUP_CALLBACK'))
The persistent session ID (if any) loaded at startup.
Definition WebStart.php:88
Extends ArrayObject and does two things:
Collection of Site objects.
Definition SiteList.php:28
removeSite( $globalSiteId)
Removes the site with the specified global site identifier.
Definition SiteList.php:165
isEmpty()
Returns if the list contains no sites.
Definition SiteList.php:176
removeSiteByInternalId( $id)
Removes the site with the specified site id.
Definition SiteList.php:213
hasInternalId( $id)
Returns if the list contains the site with the provided site id.
Definition SiteList.php:187
hasNavigationId( $id)
Returns if the list contains the site with the provided navigational site id.
Definition SiteList.php:224
getObjectType()
Definition SiteList.php:64
getGlobalIdentifiers()
Returns all the global site identifiers.
Definition SiteList.php:128
setSite(Site $site)
Sets a site in the list.
Definition SiteList.php:262
array $byInternalId
Internal site identifiers pointing to their sites offset value.
Definition SiteList.php:36
array $byGlobalId
Global site identifiers pointing to their sites offset value.
Definition SiteList.php:45
getSiteByNavigationId( $id)
Returns the Site with the provided navigational site id.
Definition SiteList.php:238
getGroup( $groupName)
Returns the sites that are in the provided group.
Definition SiteList.php:275
removeSiteByNavigationId( $id)
Removes the site with the specified navigational site id.
Definition SiteList.php:250
__unserialize( $serializationData)
Definition SiteList.php:340
static getSerialVersionId()
Returns the version ID that identifies the serialization structure used by getSerializationData() and...
Definition SiteList.php:309
offsetUnset( $index)
Definition SiteList.php:101
array $byNavigationId
Navigational site identifiers alias inter-language prefixes pointing to their sites offset value.
Definition SiteList.php:55
hasSite( $globalSiteId)
Returns if the list contains the site with the provided global site identifier.
Definition SiteList.php:139
getSite( $globalSiteId)
Returns the Site with the provided global site identifier.
Definition SiteList.php:153
getSiteByInternalId( $id)
Returns the Site with the provided site id.
Definition SiteList.php:201
getSerializationData()
Definition SiteList.php:320
preSetElement( $index, $site)
Definition SiteList.php:78
Represents a single site.
Definition Site.php:32