aboutsummaryrefslogtreecommitdiffstats
path: root/includes/HistoryBlob.php
blob: 0c44b34415118aa383297fd9f79334024a22d545 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/**
 *
 * @package MediaWiki
 */

/**
 * Pure virtual parent
 * @package MediaWiki
 */
class HistoryBlob
{
	function setMeta() {}
	function getMeta() {}
	function addItem() {}
	function getItem() {}
}

/**
 * The real object
 * @package MediaWiki
 */
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();
	}
}
?>