* Added Revision::getSha1 function
authorAaron Schulz <aaron@users.mediawiki.org>
Fri, 12 Aug 2011 17:29:57 +0000 (17:29 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Fri, 12 Aug 2011 17:29:57 +0000 (17:29 +0000)
* Try to populate mSha1 when a Revision is made from an array (as rev_len does)

includes/Revision.php

index 89599bf..996f7ef 100644 (file)
@@ -405,9 +405,14 @@ class Revision {
 
                        $this->mTitle     = null; # Load on demand if needed
                        $this->mCurrent   = false;
-                       # If we still have no len_size, see it we have the text to figure it out
-                       if ( !$this->mSize )
-                               $this->mSize      = is_null( $this->mText ) ? null : strlen( $this->mText );
+                       # If we still have no length, see it we have the text to figure it out
+                       if ( !$this->mSize ) {
+                               $this->mSize = is_null( $this->mText ) ? null : strlen( $this->mText );
+                       }
+                       # Same for sha1
+                       if ( $this->mSha1 === null ) {
+                               $this->mSha1 = is_null( $this->mText ) ? null : self::base36Sha1( $this->mText );
+                       }
                } else {
                        throw new MWException( 'Revision constructor passed invalid row format.' );
                }
@@ -450,6 +455,15 @@ class Revision {
                return $this->mSize;
        }
 
+       /**
+        * Returns the base36 sha1 of the text in this revision, or null if unknown.
+        *
+        * @return String
+        */
+       public function getSha1() {
+               return $this->mSha1;
+       }
+
        /**
         * Returns the title of the page associated with this entry.
         *