Merge "qunit: Make use of 'config' and 'messages' shortcuts in module setup"
[lhc/web/wiklou.git] / includes / site / SiteList.php
index b0d1f95..dfe4ec5 100644 (file)
  * @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,10 +41,20 @@ 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
         *
@@ -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,12 +209,49 @@ 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.
@@ -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
  */
-class SiteArray extends SiteList {}
+class SiteArray extends SiteList {
+}