uncompress(); $this->mItems['meta'] = $metaData; } /** @todo document */ function getMeta() { $this->uncompress(); return $this->mItems['meta']; } /** @todo document */ function addItem( $text ) { $this->uncompress(); $hash = md5( $text ); $this->mItems[$hash] = $text; $this->mSize += strlen( $text ); $stub = new HistoryBlobStub( $hash ); return $stub; } /** @todo document */ function getItem( $hash ) { $this->uncompress(); if ( array_key_exists( $hash, $this->mItems ) ) { return $this->mItems[$hash]; } else { return false; } } /** @todo document */ function removeItem( $hash ) { $this->mSize -= strlen( $this->mItems[$hash] ); unset( $this->mItems[$hash] ); } /** @todo document */ function compress() { if ( !$this->mCompressed ) { $this->mItems = gzdeflate( serialize( $this->mItems ) ); $this->mCompressed = true; } } /** @todo document */ function uncompress() { if ( $this->mCompressed ) { $this->mItems = unserialize( gzinflate( $this->mItems ) ); $this->mCompressed = false; } } /** @todo document */ function getText() { $this->uncompress(); return $this->getItem( $this->mDefaultHash ); } /** @todo document */ function setText( $text ) { $this->uncompress(); $stub = $this->addItem( $text ); $this->mDefaultHash = $stub->mHash; } /** @todo document */ function __sleep() { $this->compress(); return array( 'mVersion', 'mCompressed', 'mItems', 'mDefaultHash' ); } /** @todo document */ function __wakeup() { $this->uncompress(); } /** * Determines if this object is happy */ function isHappy( $maxFactor, $factorThreshold ) { if ( count( $this->mItems ) == 0 ) { return true; } if ( !$this->mFast ) { $this->uncompress(); $record = serialize( $this->mItems ); $size = strlen( $record ); $avgUncompressed = $size / count( $this->mItems ); $compressed = strlen( gzdeflate( $record ) ); if ( $compressed < $factorThreshold * 1024 ) { return true; } else { return $avgUncompressed * $maxFactor < $compressed; } } else { return count( $this->mItems ) <= 10; } } } /** * @package MediaWiki */ class HistoryBlobStub { var $mOldId, $mHash; /** @todo document */ function HistoryBlobStub( $hash = '', $oldid = 0 ) { $this->mHash = $hash; } /** * Sets the location (old_id) of the main object to which this object * points */ function setLocation( $id ) { $this->mOldId = $id; } /** @todo document */ function getText() { $dbr =& wfGetDB( DB_SLAVE ); $row = $dbr->selectRow( 'text', array( 'old_flags', 'old_text' ), array( 'old_id' => $this->mOldId ) ); if ( !$row || $row->old_flags != 'object' ) { return false; } $obj = unserialize( $row->old_text ); if ( !is_object( $obj ) ) { $obj = unserialize( $obj ); } return $obj->getItem( $this->mHash ); } /** @todo document */ function getHash() { return $this->mHash; } } ?>