MediaWiki REL1_33
SiteList.php
Go to the documentation of this file.
1<?php
2
37 protected $byInternalId = [];
38
46 protected $byGlobalId = [];
47
56 protected $byNavigationId = [];
57
65 public function getObjectType() {
66 return Site::class;
67 }
68
79 protected function preSetElement( $index, $site ) {
80 if ( $this->hasSite( $site->getGlobalId() ) ) {
81 $this->removeSite( $site->getGlobalId() );
82 }
83
84 $this->byGlobalId[$site->getGlobalId()] = $index;
85 $this->byInternalId[$site->getInternalId()] = $index;
86
87 $ids = $site->getNavigationIds();
88 foreach ( $ids as $navId ) {
89 $this->byNavigationId[$navId] = $index;
90 }
91
92 return true;
93 }
94
102 public function offsetUnset( $index ) {
103 if ( $this->offsetExists( $index ) ) {
107 $site = $this->offsetGet( $index );
108
109 unset( $this->byGlobalId[$site->getGlobalId()] );
110 unset( $this->byInternalId[$site->getInternalId()] );
111
112 $ids = $site->getNavigationIds();
113 foreach ( $ids as $navId ) {
114 unset( $this->byNavigationId[$navId] );
115 }
116 }
117
118 parent::offsetUnset( $index );
119 }
120
129 public function getGlobalIdentifiers() {
130 return array_keys( $this->byGlobalId );
131 }
132
140 public function hasSite( $globalSiteId ) {
141 return array_key_exists( $globalSiteId, $this->byGlobalId );
142 }
143
154 public function getSite( $globalSiteId ) {
155 return $this->offsetGet( $this->byGlobalId[$globalSiteId] );
156 }
157
166 public function removeSite( $globalSiteId ) {
167 $this->offsetUnset( $this->byGlobalId[$globalSiteId] );
168 }
169
177 public function isEmpty() {
178 return $this->byGlobalId === [];
179 }
180
188 public function hasInternalId( $id ) {
189 return array_key_exists( $id, $this->byInternalId );
190 }
191
202 public function getSiteByInternalId( $id ) {
203 return $this->offsetGet( $this->byInternalId[$id] );
204 }
205
214 public function removeSiteByInternalId( $id ) {
215 $this->offsetUnset( $this->byInternalId[$id] );
216 }
217
225 public function hasNavigationId( $id ) {
226 return array_key_exists( $id, $this->byNavigationId );
227 }
228
239 public function getSiteByNavigationId( $id ) {
240 return $this->offsetGet( $this->byNavigationId[$id] );
241 }
242
251 public function removeSiteByNavigationId( $id ) {
252 $this->offsetUnset( $this->byNavigationId[$id] );
253 }
254
263 public function setSite( Site $site ) {
264 $this[] = $site;
265 }
266
276 public function getGroup( $groupName ) {
277 $group = new self();
278
282 foreach ( $this as $site ) {
283 if ( $site->getGroup() === $groupName ) {
284 $group[] = $site;
285 }
286 }
287
288 return $group;
289 }
290
299 const SERIAL_VERSION_ID = '2014-03-17';
300
310 public static function getSerialVersionId() {
311 return self::SERIAL_VERSION_ID . '+Site:' . Site::SERIAL_VERSION_ID;
312 }
313
321 protected function getSerializationData() {
322 // NOTE: When changing the structure, either implement unserialize() to handle the
323 // old structure too, or update SERIAL_VERSION_ID to kill any caches.
324 return array_merge(
325 parent::getSerializationData(),
326 [
327 'internalIds' => $this->byInternalId,
328 'globalIds' => $this->byGlobalId,
329 'navigationIds' => $this->byNavigationId
330 ]
331 );
332 }
333
343 public function unserialize( $serialization ) {
344 $serializationData = parent::unserialize( $serialization );
345
346 $this->byInternalId = $serializationData['internalIds'];
347 $this->byGlobalId = $serializationData['globalIds'];
348 $this->byNavigationId = $serializationData['navigationIds'];
349
350 return $serializationData;
351 }
352}
removeSite( $globalSiteId)
Removes the site with the specified global site identifier.
Definition SiteList.php:166
isEmpty()
Returns if the list contains no sites.
Definition SiteList.php:177
removeSiteByInternalId( $id)
Removes the site with the specified site id.
Definition SiteList.php:214
hasInternalId( $id)
Returns if the list contains the site with the provided site id.
Definition SiteList.php:188
hasNavigationId( $id)
Returns if the list contains the site with the provided navigational site id.
Definition SiteList.php:225
getObjectType()
Definition SiteList.php:65
getGlobalIdentifiers()
Returns all the global site identifiers.
Definition SiteList.php:129
setSite(Site $site)
Sets a site in the list.
Definition SiteList.php:263
array $byInternalId
Internal site identifiers pointing to their sites offset value.
Definition SiteList.php:37
array $byGlobalId
Global site identifiers pointing to their sites offset value.
Definition SiteList.php:46
getSiteByNavigationId( $id)
Returns the Site with the provided navigational site id.
Definition SiteList.php:239
getGroup( $groupName)
Returns the sites that are in the provided group.
Definition SiteList.php:276
removeSiteByNavigationId( $id)
Removes the site with the specified navigational site id.
Definition SiteList.php:251
static getSerialVersionId()
Returns the version ID that identifies the serialization structure used by getSerializationData() and...
Definition SiteList.php:310
offsetUnset( $index)
Definition SiteList.php:102
array $byNavigationId
Navigational site identifiers alias inter-language prefixes pointing to their sites offset value.
Definition SiteList.php:56
hasSite( $globalSiteId)
Returns if the list contains the site with the provided global site identifier.
Definition SiteList.php:140
getSite( $globalSiteId)
Returns the Site with the provided global site identifier.
Definition SiteList.php:154
getSiteByInternalId( $id)
Returns the Site with the provided site id.
Definition SiteList.php:202
unserialize( $serialization)
Definition SiteList.php:343
getSerializationData()
Definition SiteList.php:321
preSetElement( $index, $site)
Definition SiteList.php:79
Definition Site.php:29
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))