aboutsummaryrefslogtreecommitdiffstats
path: root/includes/HistoryBlob.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/HistoryBlob.php')
-rw-r--r--includes/HistoryBlob.php64
1 files changed, 64 insertions, 0 deletions
diff --git a/includes/HistoryBlob.php b/includes/HistoryBlob.php
new file mode 100644
index 000000000000..cf170b759531
--- /dev/null
+++ b/includes/HistoryBlob.php
@@ -0,0 +1,64 @@
+<?php
+
+# Pure virtual parent
+class HistoryBlob
+{
+ function setMeta() {}
+ function getMeta() {}
+ function addItem() {}
+ function getItem() {}
+}
+
+# The real object
+class ConcatenatedGzipHistoryBlob
+{
+ /* private */ var $mVersion = 0, $mCompressed = false, $mItems = array();
+
+ function HistoryBlob() {
+ if ( !function_exists( 'gzdeflate' ) ) {
+ die( "Need zlib support to read or write this kind of history object (ConcatenatedGzipHistoryBlob)\n" );
+ }
+ }
+
+ function setMeta( $metaData ) {
+ $this->uncompress();
+ $this->mItems['meta'] = $metaData;
+ }
+
+ function getMeta() {
+ $this->uncompress();
+ return $this->mItems['meta'];
+ }
+
+ function addItem( $text ) {
+ $this->uncompress();
+ $this->mItems[md5($text)] = $text;
+ }
+
+ function getItem( $hash ) {
+ $this->compress();
+ return $this->mItems[$hash];
+ }
+
+ function compress() {
+ if ( !$this->mCompressed ) {
+ $this->mItems = gzdeflate( serialize( $this->mItems ) );
+ $this->mCompressed = true;
+ }
+ }
+
+ function uncompress() {
+ if ( $this->mCompressed ) {
+ $this->mItems = unserialize( gzinflate( $this->mItems ) );
+ }
+ }
+
+ function __sleep() {
+ compress();
+ }
+
+ function __wakeup() {
+ uncompress();
+ }
+}
+?>