14 * setMeta and getMeta currently aren't used for anything, I just thought
15 * they might be useful in the future.
16 * @param $meta String: a single string.
18 function setMeta( $meta ) {}
21 * setMeta and getMeta currently aren't used for anything, I just thought
22 * they might be useful in the future.
28 * Adds an item of text, returns a stub object which points to the item.
29 * You must call setLocation() on the stub object before storing it to the
37 function getItem( $hash ) {}
39 # Set the "default text"
40 # This concept is an odd property of the current DB schema, whereby each text item has a revision
41 # associated with it. The default text is the text of the associated revision. There may, however,
42 # be other revisions in the same object
46 * Get default text. This is called from Revision::getRevisionText()
55 class ConcatenatedGzipHistoryBlob
extends HistoryBlob
{
64 function ConcatenatedGzipHistoryBlob() {
65 if ( !function_exists( 'gzdeflate' ) ) {
66 wfDie( "Need zlib support to read or write this kind of history object (ConcatenatedGzipHistoryBlob)\n" );
71 function setMeta( $metaData ) {
73 $this->mItems
['meta'] = $metaData;
79 return $this->mItems
['meta'];
83 function addItem( $text ) {
86 $this->mItems
[$hash] = $text;
87 $this->mSize +
= strlen( $text );
89 $stub = new HistoryBlobStub( $hash );
94 function getItem( $hash ) {
96 if ( array_key_exists( $hash, $this->mItems
) ) {
97 return $this->mItems
[$hash];
103 /** @todo document */
104 function removeItem( $hash ) {
105 $this->mSize
-= strlen( $this->mItems
[$hash] );
106 unset( $this->mItems
[$hash] );
109 /** @todo document */
110 function compress() {
111 if ( !$this->mCompressed
) {
112 $this->mItems
= gzdeflate( serialize( $this->mItems
) );
113 $this->mCompressed
= true;
117 /** @todo document */
118 function uncompress() {
119 if ( $this->mCompressed
) {
120 $this->mItems
= unserialize( gzinflate( $this->mItems
) );
121 $this->mCompressed
= false;
125 /** @todo document */
128 return $this->getItem( $this->mDefaultHash
);
131 /** @todo document */
132 function setText( $text ) {
134 $stub = $this->addItem( $text );
135 $this->mDefaultHash
= $stub->mHash
;
138 /** @todo document */
141 return array( 'mVersion', 'mCompressed', 'mItems', 'mDefaultHash' );
144 /** @todo document */
145 function __wakeup() {
150 * Determines if this object is happy
152 function isHappy( $maxFactor, $factorThreshold ) {
153 if ( count( $this->mItems
) == 0 ) {
156 if ( !$this->mFast
) {
158 $record = serialize( $this->mItems
);
159 $size = strlen( $record );
160 $avgUncompressed = $size / count( $this->mItems
);
161 $compressed = strlen( gzdeflate( $record ) );
163 if ( $compressed < $factorThreshold * 1024 ) {
166 return $avgUncompressed * $maxFactor < $compressed;
169 return count( $this->mItems
) <= 10;
176 * One-step cache variable to hold base blobs; operations that
177 * pull multiple revisions may often pull multiple times from
178 * the same blob. By keeping the last-used one open, we avoid
179 * redundant unserialization and decompression overhead.
182 $wgBlobCache = array();
188 class HistoryBlobStub
{
194 /** @todo document */
195 function HistoryBlobStub( $hash = '', $oldid = 0 ) {
196 $this->mHash
= $hash;
200 * Sets the location (old_id) of the main object to which this object
203 function setLocation( $id ) {
208 * Sets the location (old_id) of the referring object
210 function setReferrer( $id ) {
215 * Gets the location of the referring object
217 function getReferrer() {
221 /** @todo document */
223 $fname = 'HistoryBlob::getText';
225 if( isset( $wgBlobCache[$this->mOldId
] ) ) {
226 $obj = $wgBlobCache[$this->mOldId
];
228 $dbr =& wfGetDB( DB_SLAVE
);
229 $row = $dbr->selectRow( 'text', array( 'old_flags', 'old_text' ), array( 'old_id' => $this->mOldId
) );
233 $flags = explode( ',', $row->old_flags
);
234 if( in_array( 'external', $flags ) ) {
236 @list
($proto,$path)=explode('://',$url,2);
238 wfProfileOut( $fname );
241 require_once('ExternalStore.php');
242 $row->old_text
=ExternalStore
::fetchFromUrl($url);
245 if( !in_array( 'object', $flags ) ) {
249 if( in_array( 'gzip', $flags ) ) {
250 // This shouldn't happen, but a bug in the compress script
251 // may at times gzip-compress a HistoryBlob object row.
252 $obj = unserialize( gzinflate( $row->old_text
) );
254 $obj = unserialize( $row->old_text
);
257 if( !is_object( $obj ) ) {
258 // Correct for old double-serialization bug.
259 $obj = unserialize( $obj );
262 // Save this item for reference; if pulling many
263 // items in a row we'll likely use it again.
265 $wgBlobCache = array( $this->mOldId
=> $obj );
267 return $obj->getItem( $this->mHash
);
270 /** @todo document */
278 * To speed up conversion from 1.4 to 1.5 schema, text rows can refer to the
279 * leftover cur table as the backend. This avoids expensively copying hundreds
280 * of megabytes of data during the conversion downtime.
282 * Serialized HistoryBlobCurStub objects will be inserted into the text table
283 * on conversion if $wgFastSchemaUpgrades is set to true.
287 class HistoryBlobCurStub
{
291 /** @todo document */
292 function HistoryBlobCurStub( $curid = 0 ) {
293 $this->mCurId
= $curid;
297 * Sets the location (cur_id) of the main object to which this object
300 function setLocation( $id ) {
304 /** @todo document */
306 $dbr =& wfGetDB( DB_SLAVE
);
307 $row = $dbr->selectRow( 'cur', array( 'cur_text' ), array( 'cur_id' => $this->mCurId
) );
311 return $row->cur_text
;