Merge "$.suggestions: make it possible to re-show suggestions"
[lhc/web/wiklou.git] / includes / site / Site.php
index b11f2b2..525c375 100644 (file)
@@ -26,7 +26,7 @@
  * @license GNU GPL v2+
  * @author Jeroen De Dauw < jeroendedauw@gmail.com >
  */
-class Site {
+class Site implements Serializable {
 
        const TYPE_UNKNOWN = 'unknown';
        const TYPE_MEDIAWIKI = 'mediawiki';
@@ -40,6 +40,16 @@ class Site {
 
        const PATH_LINK = 'link';
 
+
+       /**
+        * A version ID that identifies the serialization structure used by getSerializationData()
+        * and unserialize(). This is useful for constructing cache keys in cases where the cache relies
+        * on serialization for storing the SiteList.
+        *
+        * @var string A string uniquely identifying the version of the serialization structure.
+        */
+       const SERIAL_VERSION_ID = '2013-01-23';
+
        /**
         * @since 1.21
         *
@@ -368,7 +378,7 @@ class Site {
                }
 
                if ( $pageName !== false ) {
-                       $url = str_replace( '$1', rawurlencode( $pageName ), $url ) ;
+                       $url = str_replace( '$1', rawurlencode( $pageName ), $url );
                }
 
                return $url;
@@ -620,8 +630,6 @@ class Site {
                }
        }
 
-       // TODO: config
-
        /**
         * @since 1.21
         *
@@ -639,9 +647,57 @@ class Site {
                return new Site();
        }
 
+       /**
+        * @see Serializable::serialize
+        *
+        * @since 1.21
+        *
+        * @return string
+        */
+       public function serialize() {
+               $fields = array(
+                       'globalid' => $this->globalId,
+                       'type' => $this->type,
+                       'group' => $this->group,
+                       'source' => $this->source,
+                       'language' => $this->languageCode,
+                       'localids' => $this->localIds,
+                       'config' => $this->extraConfig,
+                       'data' => $this->extraData,
+                       'forward' => $this->forward,
+                       'internalid' => $this->internalId,
+
+               );
+
+               return serialize( $fields );
+       }
+
+       /**
+        * @see Serializable::unserialize
+        *
+        * @since 1.21
+        *
+        * @param string $serialized
+        */
+       public function unserialize( $serialized ) {
+               $fields = unserialize( $serialized );
+
+               $this->__construct( $fields['type'] );
+
+               $this->setGlobalId( $fields['globalid'] );
+               $this->setGroup( $fields['group'] );
+               $this->setSource( $fields['source'] );
+               $this->setLanguageCode( $fields['language'] );
+               $this->localIds = $fields['localids'];
+               $this->setExtraConfig( $fields['config'] );
+               $this->setExtraData( $fields['data'] );
+               $this->setForward( $fields['forward'] );
+               $this->setInternalId( $fields['internalid'] );
+       }
+
 }
 
 /**
  * @deprecated
  */
-class SiteObject extends Site {}
\ No newline at end of file
+class SiteObject extends Site {}