]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - includes/HistoryBlob.php
MediaWiki 1.11.0
[autoinstalls/mediawiki.git] / includes / HistoryBlob.php
index 3eb2b6f5335e9d83dcaa96fa6336d4468278c7e2..984ee2d4f808d6e429a4f9ea4d1acb68565fbe97 100644 (file)
@@ -1,82 +1,86 @@
 <?php
 /**
  *
- * @package MediaWiki
  */
 
 /**
  * Pure virtual parent
- * @package MediaWiki
+ * @todo document (needs a one-sentence top-level class description, that answers the question: "what is a HistoryBlob?") 
  */
-class HistoryBlob
+interface 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 ) {}
+       public function setMeta( $meta );
 
        /**
         * setMeta and getMeta currently aren't used for anything, I just thought
         * they might be useful in the future.
         * Gets the meta-value
         */
-       function getMeta() {}
+       public function getMeta();
 
        /**
         * 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
         */
-       function addItem() {}
+       public function addItem( $text );
 
-       /** 
+       /**
         * Get item by hash
         */
-       function getItem( $hash ) {}
-       
+       public 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() {}
+       public function setText( $text );
 
        /**
         * Get default text. This is called from Revision::getRevisionText()
         */
-       function getText() {}
+       function getText();
 }
 
 /**
  * The real object
- * @package MediaWiki
+ * @todo document (needs one-sentence top-level class description + function descriptions).
  */
-class ConcatenatedGzipHistoryBlob extends HistoryBlob
+class ConcatenatedGzipHistoryBlob implements HistoryBlob
 {
-       /* private */ var $mVersion = 0, $mCompressed = false, $mItems = array(), $mDefaultHash = '';
-       /* private */ var $mFast = 0, $mSize = 0;
+       public $mVersion = 0, $mCompressed = false, $mItems = array(), $mDefaultHash = '';
+       public $mFast = 0, $mSize = 0;
 
-       function ConcatenatedGzipHistoryBlob() {
+       /** Constructor */
+       public 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" );
                }
        }
 
+       #
+       # HistoryBlob implementation:
+       #
+
        /** @todo document */
-       function setMeta( $metaData ) {
+       public function setMeta( $metaData ) {
                $this->uncompress();
                $this->mItems['meta'] = $metaData;
        }
 
        /** @todo document */
-       function getMeta() {
+       public function getMeta() {
                $this->uncompress();
                return $this->mItems['meta'];
        }
 
        /** @todo document */
-       function addItem( $text ) {
+       public function addItem( $text ) {
                $this->uncompress();
                $hash = md5( $text );
                $this->mItems[$hash] = $text;
@@ -87,7 +91,7 @@ class ConcatenatedGzipHistoryBlob extends HistoryBlob
        }
 
        /** @todo document */
-       function getItem( $hash ) {
+       public function getItem( $hash ) {
                $this->uncompress();
                if ( array_key_exists( $hash, $this->mItems ) ) {
                        return $this->mItems[$hash];
@@ -97,13 +101,29 @@ class ConcatenatedGzipHistoryBlob extends HistoryBlob
        }
 
        /** @todo document */
-       function removeItem( $hash ) {
+       public function setText( $text ) {
+               $this->uncompress();
+               $stub = $this->addItem( $text );
+               $this->mDefaultHash = $stub->mHash;
+       }
+
+       /** @todo document */
+       public function getText() {
+               $this->uncompress();
+               return $this->getItem( $this->mDefaultHash );
+       }
+
+       # HistoryBlob implemented.
+
+
+       /** @todo document */
+       public function removeItem( $hash ) {
                $this->mSize -= strlen( $this->mItems[$hash] );
                unset( $this->mItems[$hash] );
        }
 
        /** @todo document */
-       function compress() {
+       public function compress() {
                if ( !$this->mCompressed  ) {
                        $this->mItems = gzdeflate( serialize( $this->mItems ) );
                        $this->mCompressed = true;
@@ -111,25 +131,13 @@ class ConcatenatedGzipHistoryBlob extends HistoryBlob
        }
 
        /** @todo document */
-       function uncompress() { 
+       public function uncompress() {
                if ( $this->mCompressed ) {
                        $this->mItems = unserialize( gzinflate( $this->mItems ) );
                        $this->mCompressed = false;
                }
        }
 
-       /** @todo document */
-       function getText() {
-               $this->uncompress();
-               return $this->getItem( $this->mDefaultHash );
-       }
-
-       /** @todo document */
-       function setText( $text ) {
-               $this->uncompress();
-               $stub = $this->addItem( $text );
-               $this->mDefaultHash = $stub->mHash;
-       }
 
        /** @todo document */
        function __sleep() {
@@ -145,7 +153,7 @@ class ConcatenatedGzipHistoryBlob extends HistoryBlob
        /**
         * Determines if this object is happy
         */
-       function isHappy( $maxFactor, $factorThreshold ) {
+       public function isHappy( $maxFactor, $factorThreshold ) {
                if ( count( $this->mItems ) == 0 ) {
                        return true;
                }
@@ -179,16 +187,16 @@ $wgBlobCache = array();
 
 
 /**
- * @package MediaWiki
+ * @todo document (needs one-sentence top-level class description + some function descriptions).
  */
 class HistoryBlobStub {
-       var $mOldId, $mHash,$mRef;
+       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
@@ -213,31 +221,31 @@ class HistoryBlobStub {
 
        /** @todo document */
        function getText() {
+               $fname = 'HistoryBlobStub::getText';
                global $wgBlobCache;
                if( isset( $wgBlobCache[$this->mOldId] ) ) {
                        $obj = $wgBlobCache[$this->mOldId];
                } else {
-                       $dbr =& wfGetDB( DB_SLAVE );
+                       $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);
+                               $url=$row->old_text;
+                               @list( /* $proto */ ,$path)=explode('://',$url,2);
+                               if ($path=="") {
+                                       wfProfileOut( $fname );
+                                       return false;
+                               }
+                               $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.
@@ -245,12 +253,12 @@ class HistoryBlobStub {
                        } 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();
@@ -273,8 +281,6 @@ class HistoryBlobStub {
  *
  * Serialized HistoryBlobCurStub objects will be inserted into the text table
  * on conversion if $wgFastSchemaUpgrades is set to true.
- *
- * @package MediaWiki
  */
 class HistoryBlobCurStub {
        var $mCurId;
@@ -283,7 +289,7 @@ class HistoryBlobCurStub {
        function HistoryBlobCurStub( $curid = 0 ) {
                $this->mCurId = $curid;
        }
-       
+
        /**
         * Sets the location (cur_id) of the main object to which this object
         * points
@@ -294,7 +300,7 @@ class HistoryBlobCurStub {
 
        /** @todo document */
        function getText() {
-               $dbr =& wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
                $row = $dbr->selectRow( 'cur', array( 'cur_text' ), array( 'cur_id' => $this->mCurId ) );
                if( !$row ) {
                        return false;
@@ -304,4 +310,4 @@ class HistoryBlobCurStub {
 }
 
 
-?>
+