Using a better method to get the English language file.
[lhc/web/wiklou.git] / includes / HistoryBlob.php
index 5b1f453..8f5d362 100644 (file)
@@ -13,7 +13,7 @@ class HistoryBlob
        /**
         * setMeta and getMeta currently aren't used for anything, I just thought
         * they might be useful in the future.
-        * @param string $meta a single string
+        * @param $meta String: a single string.
         */
        function setMeta( $meta ) {}
 
@@ -31,14 +31,14 @@ class HistoryBlob
         */
        function addItem() {}
 
-       /** 
+       /**
         * 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, 
+       # 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() {}
 
@@ -59,7 +59,7 @@ class ConcatenatedGzipHistoryBlob extends HistoryBlob
 
        function ConcatenatedGzipHistoryBlob() {
                if ( !function_exists( 'gzdeflate' ) ) {
-                       die( "Need zlib support to read or write this kind of history object (ConcatenatedGzipHistoryBlob)\n" );
+                       throw new MWException( "Need zlib support to read or write this kind of history object (ConcatenatedGzipHistoryBlob)\n" );
                }
        }
 
@@ -111,7 +111,7 @@ class ConcatenatedGzipHistoryBlob extends HistoryBlob
        }
 
        /** @todo document */
-       function uncompress() { 
+       function uncompress() {
                if ( $this->mCompressed ) {
                        $this->mItems = unserialize( gzinflate( $this->mItems ) );
                        $this->mCompressed = false;
@@ -167,17 +167,28 @@ class ConcatenatedGzipHistoryBlob extends HistoryBlob
        }
 }
 
+
+/**
+ * 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();
+
+
 /**
  * @package MediaWiki
  */
 class HistoryBlobStub {
-       var $mOldId, $mHash;
+       var $mOldId, $mHash, $mRef;
 
        /** @todo document */
        function HistoryBlobStub( $hash = '', $oldid = 0 ) {
                $this->mHash = $hash;
        }
-       
+
        /**
         * Sets the location (old_id) of the main object to which this object
         * points
@@ -186,29 +197,65 @@ class HistoryBlobStub {
                $this->mOldId = $id;
        }
 
+      /**
+       * Sets the location (old_id) of the referring object
+       */
+       function setReferrer( $id ) {
+               $this->mRef = $id;
+       }
+
+      /**
+       * Gets the location of the referring object
+       */
+       function getReferrer() {
+               return $this->mRef;
+       }
+
        /** @todo document */
        function getText() {
-               $dbr =& wfGetDB( DB_SLAVE );
-               $row = $dbr->selectRow( 'text', array( 'old_flags', 'old_text' ), array( 'old_id' => $this->mOldId ) );
-               if( !$row ) {
-                       return false;
-               }
-               $flags = explode( ',', $row->old_flags );
-               if( !in_array( 'object', $flags ) ) {
-                       return false;
-               }
-               
-               if( in_array( 'gzip', $flags ) ) {
-                       // This shouldn't happen, but a bug in the compress script
-                       // may at times gzip-compress a HistoryBlob object row.
-                       $obj = unserialize( gzinflate( $row->old_text ) );
+               $fname = 'HistoryBlob::getText';
+               global $wgBlobCache;
+               if( isset( $wgBlobCache[$this->mOldId] ) ) {
+                       $obj = $wgBlobCache[$this->mOldId];
                } else {
-                       $obj = unserialize( $row->old_text );
-               }
-               
-               if( !is_object( $obj ) ) {
-                       // Correct for old double-serialization bug.
-                       $obj = unserialize( $obj );
+                       $dbr =& wfGetDB( DB_SLAVE );
+                       $row = $dbr->selectRow( 'text', array( 'old_flags', 'old_text' ), array( 'old_id' => $this->mOldId ) );
+                       if( !$row ) {
+                               return false;
+                       }
+                       $flags = explode( ',', $row->old_flags );
+                       if( in_array( 'external', $flags ) ) {
+                               $url=$row->old_text;
+                               @list($proto,$path)=explode('://',$url,2);
+                               if ($path=="") {
+                                       wfProfileOut( $fname );
+                                       return false;
+                               }
+                               require_once('ExternalStore.php');
+                               $row->old_text=ExternalStore::fetchFromUrl($url);
+
+                       }
+                       if( !in_array( 'object', $flags ) ) {
+                               return false;
+                       }
+
+                       if( in_array( 'gzip', $flags ) ) {
+                               // This shouldn't happen, but a bug in the compress script
+                               // may at times gzip-compress a HistoryBlob object row.
+                               $obj = unserialize( gzinflate( $row->old_text ) );
+                       } else {
+                               $obj = unserialize( $row->old_text );
+                       }
+
+                       if( !is_object( $obj ) ) {
+                               // Correct for old double-serialization bug.
+                               $obj = unserialize( $obj );
+                       }
+
+                       // 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 );
                }
                return $obj->getItem( $this->mHash );
        }
@@ -237,7 +284,7 @@ class HistoryBlobCurStub {
        function HistoryBlobCurStub( $curid = 0 ) {
                $this->mCurId = $curid;
        }
-       
+
        /**
         * Sets the location (cur_id) of the main object to which this object
         * points
@@ -257,4 +304,5 @@ class HistoryBlobCurStub {
        }
 }
 
+
 ?>