12 * setMeta and getMeta currently aren't used for anything, I just thought
13 * they might be useful in the future.
14 * @param $meta String: a single string.
16 function setMeta( $meta ) {}
19 * setMeta and getMeta currently aren't used for anything, I just thought
20 * they might be useful in the future.
26 * Adds an item of text, returns a stub object which points to the item.
27 * You must call setLocation() on the stub object before storing it to the
35 function getItem( $hash ) {}
37 # Set the "default text"
38 # This concept is an odd property of the current DB schema, whereby each text item has a revision
39 # associated with it. The default text is the text of the associated revision. There may, however,
40 # be other revisions in the same object
44 * Get default text. This is called from Revision::getRevisionText()
52 class ConcatenatedGzipHistoryBlob
extends HistoryBlob
54 /* private */ var $mVersion = 0, $mCompressed = false, $mItems = array(), $mDefaultHash = '';
55 /* private */ var $mFast = 0, $mSize = 0;
57 function ConcatenatedGzipHistoryBlob() {
58 if ( !function_exists( 'gzdeflate' ) ) {
59 throw new MWException( "Need zlib support to read or write this kind of history object (ConcatenatedGzipHistoryBlob)\n" );
64 function setMeta( $metaData ) {
66 $this->mItems
['meta'] = $metaData;
72 return $this->mItems
['meta'];
76 function addItem( $text ) {
79 $this->mItems
[$hash] = $text;
80 $this->mSize +
= strlen( $text );
82 $stub = new HistoryBlobStub( $hash );
87 function getItem( $hash ) {
89 if ( array_key_exists( $hash, $this->mItems
) ) {
90 return $this->mItems
[$hash];
97 function removeItem( $hash ) {
98 $this->mSize
-= strlen( $this->mItems
[$hash] );
99 unset( $this->mItems
[$hash] );
102 /** @todo document */
103 function compress() {
104 if ( !$this->mCompressed
) {
105 $this->mItems
= gzdeflate( serialize( $this->mItems
) );
106 $this->mCompressed
= true;
110 /** @todo document */
111 function uncompress() {
112 if ( $this->mCompressed
) {
113 $this->mItems
= unserialize( gzinflate( $this->mItems
) );
114 $this->mCompressed
= false;
118 /** @todo document */
121 return $this->getItem( $this->mDefaultHash
);
124 /** @todo document */
125 function setText( $text ) {
127 $stub = $this->addItem( $text );
128 $this->mDefaultHash
= $stub->mHash
;
131 /** @todo document */
134 return array( 'mVersion', 'mCompressed', 'mItems', 'mDefaultHash' );
137 /** @todo document */
138 function __wakeup() {
143 * Determines if this object is happy
145 function isHappy( $maxFactor, $factorThreshold ) {
146 if ( count( $this->mItems
) == 0 ) {
149 if ( !$this->mFast
) {
151 $record = serialize( $this->mItems
);
152 $size = strlen( $record );
153 $avgUncompressed = $size / count( $this->mItems
);
154 $compressed = strlen( gzdeflate( $record ) );
156 if ( $compressed < $factorThreshold * 1024 ) {
159 return $avgUncompressed * $maxFactor < $compressed;
162 return count( $this->mItems
) <= 10;
169 * One-step cache variable to hold base blobs; operations that
170 * pull multiple revisions may often pull multiple times from
171 * the same blob. By keeping the last-used one open, we avoid
172 * redundant unserialization and decompression overhead.
175 $wgBlobCache = array();
180 class HistoryBlobStub
{
181 var $mOldId, $mHash, $mRef;
183 /** @todo document */
184 function HistoryBlobStub( $hash = '', $oldid = 0 ) {
185 $this->mHash
= $hash;
189 * Sets the location (old_id) of the main object to which this object
192 function setLocation( $id ) {
197 * Sets the location (old_id) of the referring object
199 function setReferrer( $id ) {
204 * Gets the location of the referring object
206 function getReferrer() {
210 /** @todo document */
212 $fname = 'HistoryBlobStub::getText';
214 if( isset( $wgBlobCache[$this->mOldId
] ) ) {
215 $obj = $wgBlobCache[$this->mOldId
];
217 $dbr = wfGetDB( DB_SLAVE
);
218 $row = $dbr->selectRow( 'text', array( 'old_flags', 'old_text' ), array( 'old_id' => $this->mOldId
) );
222 $flags = explode( ',', $row->old_flags
);
223 if( in_array( 'external', $flags ) ) {
225 @list
( /* $proto */ ,$path)=explode('://',$url,2);
227 wfProfileOut( $fname );
230 $row->old_text
=ExternalStore
::fetchFromUrl($url);
233 if( !in_array( 'object', $flags ) ) {
237 if( in_array( 'gzip', $flags ) ) {
238 // This shouldn't happen, but a bug in the compress script
239 // may at times gzip-compress a HistoryBlob object row.
240 $obj = unserialize( gzinflate( $row->old_text
) );
242 $obj = unserialize( $row->old_text
);
245 if( !is_object( $obj ) ) {
246 // Correct for old double-serialization bug.
247 $obj = unserialize( $obj );
250 // Save this item for reference; if pulling many
251 // items in a row we'll likely use it again.
253 $wgBlobCache = array( $this->mOldId
=> $obj );
255 return $obj->getItem( $this->mHash
);
258 /** @todo document */
266 * To speed up conversion from 1.4 to 1.5 schema, text rows can refer to the
267 * leftover cur table as the backend. This avoids expensively copying hundreds
268 * of megabytes of data during the conversion downtime.
270 * Serialized HistoryBlobCurStub objects will be inserted into the text table
271 * on conversion if $wgFastSchemaUpgrades is set to true.
274 class HistoryBlobCurStub
{
277 /** @todo document */
278 function HistoryBlobCurStub( $curid = 0 ) {
279 $this->mCurId
= $curid;
283 * Sets the location (cur_id) of the main object to which this object
286 function setLocation( $id ) {
290 /** @todo document */
292 $dbr = wfGetDB( DB_SLAVE
);
293 $row = $dbr->selectRow( 'cur', array( 'cur_text' ), array( 'cur_id' => $this->mCurId
) );
297 return $row->cur_text
;