13 # setMeta and getMeta currently aren't used for anything, I just thought they might be useful in the future
14 # The meta value is a single string
15 function setMeta( $meta ) {}
20 # Adds an item of text, returns a stub object which points to the item
21 # You must call setLocation() on the stub object before storing it to the database
25 function getItem( $hash ) {}
27 # Set the "default text"
28 # This concept is an odd property of the current DB schema, whereby each text item has a revision
29 # associated with it. The default text is the text of the associated revision. There may, however,
30 # be other revisions in the same object
33 # Get default text. This is called from Revision::getRevisionText()
41 class ConcatenatedGzipHistoryBlob
extends HistoryBlob
43 /* private */ var $mVersion = 0, $mCompressed = false, $mItems = array(), $mDefaultHash = '';
44 /* private */ var $mFast = 0, $mSize = 0;
46 function ConcatenatedGzipHistoryBlob() {
47 if ( !function_exists( 'gzdeflate' ) ) {
48 die( "Need zlib support to read or write this kind of history object (ConcatenatedGzipHistoryBlob)\n" );
52 function setMeta( $metaData ) {
54 $this->mItems
['meta'] = $metaData;
59 return $this->mItems
['meta'];
62 function addItem( $text ) {
65 $this->mItems
[$hash] = $text;
66 $this->mSize +
= strlen( $text );
68 $stub = new HistoryBlobStub( $hash );
72 function getItem( $hash ) {
74 if ( array_key_exists( $hash, $this->mItems
) ) {
75 return $this->mItems
[$hash];
81 function removeItem( $hash ) {
82 $this->mSize
-= strlen( $this->mItems
[$hash] );
83 unset( $this->mItems
[$hash] );
87 if ( !$this->mCompressed
) {
88 $this->mItems
= gzdeflate( serialize( $this->mItems
) );
89 $this->mCompressed
= true;
93 function uncompress() {
94 if ( $this->mCompressed
) {
95 $this->mItems
= unserialize( gzinflate( $this->mItems
) );
96 $this->mCompressed
= false;
102 return $this->getItem( $this->mDefaultHash
);
105 function setText( $text ) {
107 $stub = $this->addItem( $text );
108 $this->mDefaultHash
= $stub->mHash
;
113 return array( 'mVersion', 'mCompressed', 'mItems', 'mDefaultHash' );
116 function __wakeup() {
120 # Determines if this object is happy
121 function isHappy( $maxFactor, $factorThreshold ) {
122 if ( count( $this->mItems
) == 0 ) {
125 if ( !$this->mFast
) {
127 $record = serialize( $this->mItems
);
128 $size = strlen( $record );
129 $avgUncompressed = $size / count( $this->mItems
);
130 $compressed = strlen( gzdeflate( $record ) );
132 if ( $compressed < $factorThreshold * 1024 ) {
135 return $avgUncompressed * $maxFactor < $compressed;
138 return count( $this->mItems
) <= 10;
143 class HistoryBlobStub
147 function HistoryBlobStub( $hash = '', $oldid = 0 ) {
148 $this->mHash
= $hash;
151 # Sets the location (old_id) of the main object to which this object points
152 function setLocation( $id ) {
157 $dbr =& wfGetDB( DB_SLAVE
);
158 $row = $dbr->selectRow( 'text', array( 'old_flags', 'old_text' ), array( 'old_id' => $this->mOldId
) );
159 if ( !$row ||
$row->old_flags
!= 'object' ) {
162 $obj = unserialize( $row->old_text
);
163 if ( !is_object( $obj ) ) {
164 $obj = unserialize( $obj );
166 return $obj->getItem( $this->mHash
);