2004-06-15 15:05:56 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-06-15 15:05:56 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Pure virtual parent
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-06-15 15:05:56 +00:00
|
|
|
class HistoryBlob
|
|
|
|
|
{
|
2004-10-30 14:39:40 +00:00
|
|
|
# setMeta and getMeta currently aren't used for anything, I just thought they might be useful in the future
|
|
|
|
|
# The meta value is a single string
|
|
|
|
|
function setMeta( $meta ) {}
|
|
|
|
|
|
|
|
|
|
# Gets the meta-value
|
2004-06-15 15:05:56 +00:00
|
|
|
function getMeta() {}
|
2004-10-30 14:39:40 +00:00
|
|
|
|
|
|
|
|
# Adds an item of text, returns a stub object which points to the item
|
|
|
|
|
# You must call setLocation() on the stub object before storing it to the database
|
2004-06-15 15:05:56 +00:00
|
|
|
function addItem() {}
|
2004-10-30 14:39:40 +00:00
|
|
|
|
|
|
|
|
# Get item by hash
|
|
|
|
|
function getItem( $hash ) {}
|
|
|
|
|
|
|
|
|
|
# Set the "default text"
|
|
|
|
|
# This concept is an odd property of the current DB schema, whereby each text item has a revision
|
|
|
|
|
# associated with it. The default text is the text of the associated revision. There may, however,
|
|
|
|
|
# be other revisions in the same object
|
|
|
|
|
function setText() {}
|
|
|
|
|
|
|
|
|
|
# Get default text. This is called from Article::getRevisionText()
|
|
|
|
|
function getText() {}
|
2004-06-15 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* The real object
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2004-10-30 14:39:40 +00:00
|
|
|
class ConcatenatedGzipHistoryBlob extends HistoryBlob
|
2004-06-15 15:05:56 +00:00
|
|
|
{
|
2004-10-30 14:39:40 +00:00
|
|
|
/* private */ var $mVersion = 0, $mCompressed = false, $mItems = array(), $mDefaultHash = '';
|
|
|
|
|
/* private */ var $mFast = 0, $mSize = 0;
|
2004-06-15 15:05:56 +00:00
|
|
|
|
2004-10-30 14:39:40 +00:00
|
|
|
function ConcatenatedGzipHistoryBlob() {
|
2004-06-15 15:05:56 +00:00
|
|
|
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();
|
2004-10-30 14:39:40 +00:00
|
|
|
$hash = md5( $text );
|
|
|
|
|
$this->mItems[$hash] = $text;
|
|
|
|
|
$this->mSize += strlen( $text );
|
|
|
|
|
|
|
|
|
|
$stub = new HistoryBlobStub( $hash );
|
|
|
|
|
return $stub;
|
2004-06-15 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getItem( $hash ) {
|
2004-10-30 14:39:40 +00:00
|
|
|
$this->uncompress();
|
|
|
|
|
if ( array_key_exists( $hash, $this->mItems ) ) {
|
|
|
|
|
return $this->mItems[$hash];
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2004-06-15 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
2004-10-30 14:39:40 +00:00
|
|
|
function removeItem( $hash ) {
|
|
|
|
|
$this->mSize -= strlen( $this->mItems[$hash] );
|
|
|
|
|
unset( $this->mItems[$hash] );
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-15 15:05:56 +00:00
|
|
|
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 ) );
|
2004-10-30 14:39:40 +00:00
|
|
|
$this->mCompressed = false;
|
2004-06-15 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-30 14:39:40 +00:00
|
|
|
function getText() {
|
|
|
|
|
$this->uncompress();
|
|
|
|
|
return $this->getItem( $this->mDefaultHash );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setText( $text ) {
|
|
|
|
|
$this->uncompress();
|
|
|
|
|
$stub = $this->addItem( $text );
|
|
|
|
|
$this->mDefaultHash = $stub->mHash;
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-15 15:05:56 +00:00
|
|
|
function __sleep() {
|
2004-10-30 14:39:40 +00:00
|
|
|
$this->compress();
|
|
|
|
|
return array( 'mVersion', 'mCompressed', 'mItems', 'mDefaultHash' );
|
2004-06-15 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function __wakeup() {
|
2004-10-30 14:39:40 +00:00
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class HistoryBlobStub
|
|
|
|
|
{
|
|
|
|
|
var $mOldId, $mHash;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getText() {
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE );
|
|
|
|
|
$row = $dbr->selectRow( 'old', 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 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getHash() {
|
|
|
|
|
return $this->mHash;
|
2004-06-15 15:05:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
?>
|