summaryrefslogtreecommitdiff
path: root/includes/site/SiteList.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/site/SiteList.php')
-rw-r--r--includes/site/SiteList.php88
1 files changed, 73 insertions, 15 deletions
diff --git a/includes/site/SiteList.php b/includes/site/SiteList.php
index b0d1f95b..2d9f22dd 100644
--- a/includes/site/SiteList.php
+++ b/includes/site/SiteList.php
@@ -27,13 +27,12 @@
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class SiteList extends GenericArrayObject {
-
/**
* Internal site identifiers pointing to their sites offset value.
*
* @since 1.21
*
- * @var array of integer
+ * @var array Array of integer
*/
protected $byInternalId = array();
@@ -42,11 +41,21 @@ class SiteList extends GenericArrayObject {
*
* @since 1.21
*
- * @var array of string
+ * @var array Array of string
*/
protected $byGlobalId = array();
/**
+ * Navigational site identifiers alias inter-language prefixes
+ * pointing to their sites offset value.
+ *
+ * @since 1.23
+ *
+ * @var array Array of string
+ */
+ protected $byNavigationId = array();
+
+ /**
* @see GenericArrayObject::getObjectType
*
* @since 1.21
@@ -65,7 +74,7 @@ class SiteList extends GenericArrayObject {
* @param int|string $index
* @param Site $site
*
- * @return boolean
+ * @return bool
*/
protected function preSetElement( $index, $site ) {
if ( $this->hasSite( $site->getGlobalId() ) ) {
@@ -75,6 +84,11 @@ class SiteList extends GenericArrayObject {
$this->byGlobalId[$site->getGlobalId()] = $index;
$this->byInternalId[$site->getInternalId()] = $index;
+ $ids = $site->getNavigationIds();
+ foreach ( $ids as $navId ) {
+ $this->byNavigationId[$navId] = $index;
+ }
+
return true;
}
@@ -94,6 +108,11 @@ class SiteList extends GenericArrayObject {
unset( $this->byGlobalId[$site->getGlobalId()] );
unset( $this->byInternalId[$site->getInternalId()] );
+
+ $ids = $site->getNavigationIds();
+ foreach ( $ids as $navId ) {
+ unset( $this->byNavigationId[$navId] );
+ }
}
parent::offsetUnset( $index );
@@ -116,7 +135,7 @@ class SiteList extends GenericArrayObject {
*
* @param string $globalSiteId
*
- * @return boolean
+ * @return bool
*/
public function hasSite( $globalSiteId ) {
return array_key_exists( $globalSiteId, $this->byGlobalId );
@@ -153,7 +172,7 @@ class SiteList extends GenericArrayObject {
*
* @since 1.21
*
- * @return boolean
+ * @return bool
*/
public function isEmpty() {
return $this->byGlobalId === array();
@@ -162,9 +181,9 @@ class SiteList extends GenericArrayObject {
/**
* Returns if the list contains the site with the provided site id.
*
- * @param integer $id
+ * @param int $id
*
- * @return boolean
+ * @return bool
*/
public function hasInternalId( $id ) {
return array_key_exists( $id, $this->byInternalId );
@@ -176,7 +195,7 @@ class SiteList extends GenericArrayObject {
*
* @since 1.21
*
- * @param integer $id
+ * @param int $id
*
* @return Site
*/
@@ -190,13 +209,50 @@ class SiteList extends GenericArrayObject {
*
* @since 1.21
*
- * @param integer $id
+ * @param int $id
*/
public function removeSiteByInternalId( $id ) {
$this->offsetUnset( $this->byInternalId[$id] );
}
/**
+ * Returns if the list contains the site with the provided navigational site id.
+ *
+ * @param string $id
+ *
+ * @return bool
+ */
+ public function hasNavigationId( $id ) {
+ return array_key_exists( $id, $this->byNavigationId );
+ }
+
+ /**
+ * Returns the Site with the provided navigational site id.
+ * The site needs to exist, so if not sure, call has first.
+ *
+ * @since 1.23
+ *
+ * @param string $id
+ *
+ * @return Site
+ */
+ public function getSiteByNavigationId( $id ) {
+ return $this->offsetGet( $this->byNavigationId[$id] );
+ }
+
+ /**
+ * Removes the site with the specified navigational site id.
+ * The site needs to exist, so if not sure, call has first.
+ *
+ * @since 1.23
+ *
+ * @param string $id
+ */
+ public function removeSiteByNavigationId( $id ) {
+ $this->offsetUnset( $this->byNavigationId[$id] );
+ }
+
+ /**
* Sets a site in the list. If the site was not there,
* it will be added. If it was, it will be updated.
*
@@ -221,7 +277,7 @@ class SiteList extends GenericArrayObject {
$group = new self();
/**
- * @var \Site $site
+ * @var Site $site
*/
foreach ( $this as $site ) {
if ( $site->getGroup() === $groupName ) {
@@ -240,7 +296,7 @@ class SiteList extends GenericArrayObject {
* @var string A string uniquely identifying the version of the serialization structure,
* not including any sub-structures.
*/
- const SERIAL_VERSION_ID = '2013-02-07';
+ const SERIAL_VERSION_ID = '2014-03-17';
/**
* Returns the version ID that identifies the serialization structure used by
@@ -270,6 +326,7 @@ class SiteList extends GenericArrayObject {
array(
'internalIds' => $this->byInternalId,
'globalIds' => $this->byGlobalId,
+ 'navigationIds' => $this->byNavigationId
)
);
}
@@ -288,13 +345,14 @@ class SiteList extends GenericArrayObject {
$this->byInternalId = $serializationData['internalIds'];
$this->byGlobalId = $serializationData['globalIds'];
+ $this->byNavigationId = $serializationData['navigationIds'];
return $serializationData;
}
-
}
/**
- * @deprecated
+ * @deprecated since 1.21
*/
-class SiteArray extends SiteList {}
+class SiteArray extends SiteList {
+}