Make revision content decompression publicly available
authorMatthias Mullie <git@mullie.eu>
Wed, 7 Aug 2013 16:14:18 +0000 (18:14 +0200)
committerMatthias Mullie <git@mullie.eu>
Wed, 7 Aug 2013 18:53:34 +0000 (20:53 +0200)
compressRevisionText() is already publicly available, but the decompression was
not. For others using compressRevisionText(), the only way to decompress was to
duplicate the gzinflate code.

Change-Id: I61cd87acb52a482ba88f7c9d3826ecee66c89911

includes/Revision.php

index b3b971b..ddcaf17 100644 (file)
@@ -1205,35 +1205,7 @@ class Revision implements IDBAccessObject {
 
                // If the text was fetched without an error, convert it
                if ( $text !== false ) {
-                       if ( in_array( 'gzip', $flags ) ) {
-                               # Deal with optional compression of archived pages.
-                               # This can be done periodically via maintenance/compressOld.php, and
-                               # as pages are saved if $wgCompressRevisions is set.
-                               $text = gzinflate( $text );
-                       }
-
-                       if ( in_array( 'object', $flags ) ) {
-                               # Generic compressed storage
-                               $obj = unserialize( $text );
-                               if ( !is_object( $obj ) ) {
-                                       // Invalid object
-                                       wfProfileOut( __METHOD__ );
-                                       return false;
-                               }
-                               $text = $obj->getText();
-                       }
-
-                       global $wgLegacyEncoding;
-                       if ( $text !== false && $wgLegacyEncoding
-                               && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) )
-                       {
-                               # Old revisions kept around in a legacy encoding?
-                               # Upconvert on demand.
-                               # ("utf8" checked for compatibility with some broken
-                               #  conversion scripts 2008-12-30)
-                               global $wgContLang;
-                               $text = $wgContLang->iconv( $wgLegacyEncoding, 'UTF-8', $text );
-                       }
+                       $text = self::decompressRevisionText( $text, $flags );
                }
                wfProfileOut( __METHOD__ );
                return $text;
@@ -1268,6 +1240,46 @@ class Revision implements IDBAccessObject {
                return implode( ',', $flags );
        }
 
+       /**
+        * Re-converts revision text according to it's flags.
+        *
+        * @param $text Mixed: reference to a text
+        * @param $flags array: compression flags
+        * @return String|bool decompressed text, or false on failure
+        */
+       public static function decompressRevisionText( $text, $flags ) {
+               if ( in_array( 'gzip', $flags ) ) {
+                       # Deal with optional compression of archived pages.
+                       # This can be done periodically via maintenance/compressOld.php, and
+                       # as pages are saved if $wgCompressRevisions is set.
+                       $text = gzinflate( $text );
+               }
+
+               if ( in_array( 'object', $flags ) ) {
+                       # Generic compressed storage
+                       $obj = unserialize( $text );
+                       if ( !is_object( $obj ) ) {
+                               // Invalid object
+                               return false;
+                       }
+                       $text = $obj->getText();
+               }
+
+               global $wgLegacyEncoding;
+               if ( $text !== false && $wgLegacyEncoding
+                       && !in_array( 'utf-8', $flags ) && !in_array( 'utf8', $flags ) )
+               {
+                       # Old revisions kept around in a legacy encoding?
+                       # Upconvert on demand.
+                       # ("utf8" checked for compatibility with some broken
+                       #  conversion scripts 2008-12-30)
+                       global $wgContLang;
+                       $text = $wgContLang->iconv( $wgLegacyEncoding, 'UTF-8', $text );
+               }
+
+               return $text;
+       }
+
        /**
         * Insert a new revision into the database, returning the new revision ID
         * number on success and dies horribly on failure.