* 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
- * Returns the key for getItem()
+ *
+ * @return String: the key for getItem()
*/
- public function addItem( $text );
+ function addItem( $text );
/**
* Get item by key, or false if the key is not present
+ *
+ * @return String or false
*/
- public function getItem( $key );
+ function getItem( $key );
/**
* Set the "default text"
*
* Default text is not required for two-part external storage URLs.
*/
- public function setText( $text );
+ function setText( $text );
/**
* Get default text. This is called from Revision::getRevisionText()
+ *
+ * @return String
*/
function getText();
}
public $mMaxCount = 100;
/** Constructor */
- public function ConcatenatedGzipHistoryBlob() {
+ public function __construct() {
if ( !function_exists( 'gzdeflate' ) ) {
throw new MWException( "Need zlib support to read or write this kind of history object (ConcatenatedGzipHistoryBlob)\n" );
}
}
-/**
- * One-step cache variable to hold base blobs; operations that
- * pull multiple revisions may often pull multiple times from
- * the same blob. By keeping the last-used one open, we avoid
- * redundant unserialization and decompression overhead.
- */
-global $wgBlobCache;
-$wgBlobCache = array();
/**
* Pointer object for an item within a CGZ blob stored in the text table.
*/
class HistoryBlobStub {
+ /**
+ * One-step cache variable to hold base blobs; operations that
+ * pull multiple revisions may often pull multiple times from
+ * the same blob. By keeping the last-used one open, we avoid
+ * redundant unserialization and decompression overhead.
+ */
+ protected static $blobCache = array();
+
var $mOldId, $mHash, $mRef;
/**
- * @param string $hash The content hash of the text
- * @param integer $oldid The old_id for the CGZ object
+ * @param $hash Strng: the content hash of the text
+ * @param $oldid Integer: the old_id for the CGZ object
*/
- function HistoryBlobStub( $hash = '', $oldid = 0 ) {
+ function __construct( $hash = '', $oldid = 0 ) {
$this->mHash = $hash;
}
function getText() {
$fname = 'HistoryBlobStub::getText';
- global $wgBlobCache;
- if( isset( $wgBlobCache[$this->mOldId] ) ) {
- $obj = $wgBlobCache[$this->mOldId];
+
+ if( isset( self::$blobCache[$this->mOldId] ) ) {
+ $obj = self::$blobCache[$this->mOldId];
} else {
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow( 'text', array( 'old_flags', 'old_text' ), array( 'old_id' => $this->mOldId ) );
// Save this item for reference; if pulling many
// items in a row we'll likely use it again.
$obj->uncompress();
- $wgBlobCache = array( $this->mOldId => $obj );
+ self::$blobCache = array( $this->mOldId => $obj );
}
return $obj->getItem( $this->mHash );
}
var $mCurId;
/**
- * @param integer $curid The cur_id pointed to
+ * @param $curid Integer: the cur_id pointed to
*/
- function HistoryBlobCurStub( $curid = 0 ) {
+ function __construct( $curid = 0 ) {
$this->mCurId = $curid;
}
}
function compress() {
- if ( !function_exists( 'xdiff_string_bdiff' ) ){
+ if ( !function_exists( 'xdiff_string_rabdiff' ) ){
throw new MWException( "Need xdiff 1.5+ support to write DiffHistoryBlob\n" );
}
if ( isset( $this->mDiffs ) ) {
# Need to do a null concatenation with warnings off, due to bugs in the current version of xdiff
# "String is not zero-terminated"
wfSuppressWarnings();
- $diff = xdiff_string_bdiff( $t1, $t2 ) . '';
+ $diff = xdiff_string_rabdiff( $t1, $t2 ) . '';
wfRestoreWarnings();
return $diff;
}
}
}
if ( $header['csize'] != strlen( $base ) ) {
- wfDebug( __METHOD__. ": incorrect base length {$header['csize']} -> {strlen($base)}\n" );
+ wfDebug( __METHOD__. ": incorrect base length\n" );
return false;
}
if ( isset( $info['default'] ) ) {
$this->mDefaultKey = $info['default'];
}
- $map = explode( ',', $info['map'] );
- $cur = 0;
- $this->mDiffMap = array();
- foreach ( $map as $i ) {
- $cur += $i;
- $this->mDiffMap[] = $cur;
- }
$this->mDiffs = $info['diffs'];
+ if ( isset( $info['base'] ) ) {
+ // Old format
+ $this->mDiffMap = range( 0, count( $this->mDiffs ) - 1 );
+ array_unshift( $this->mDiffs,
+ pack( 'VVCV', 0, 0, self::XDL_BDOP_INSB, strlen( $info['base'] ) ) .
+ $info['base'] );
+ } else {
+ // New format
+ $map = explode( ',', $info['map'] );
+ $cur = 0;
+ $this->mDiffMap = array();
+ foreach ( $map as $i ) {
+ $cur += $i;
+ $this->mDiffMap[] = $cur;
+ }
+ }
$this->uncompress();
}