Matthias Mullie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/78079


Change subject: Make revision content decompression publicly available
......................................................................

Make revision content decompression publicly available

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
---
M includes/Revision.php
1 file changed, 42 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/79/78079/1

diff --git a/includes/Revision.php b/includes/Revision.php
index b3b971b..0105ded 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -1205,35 +1205,7 @@
 
                // 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;
@@ -1269,6 +1241,47 @@
        }
 
        /**
+        * Re-converts revision text according to it's flags.
+        *
+        * @param $text Mixed: reference to a text
+        * @param $flags array: compression flags
+        * @return String
+        */
+       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
+                               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 );
+               }
+
+               return $text;
+       }
+
+       /**
         * Insert a new revision into the database, returning the new revision 
ID
         * number on success and dies horribly on failure.
         *

-- 
To view, visit https://gerrit.wikimedia.org/r/78079
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I61cd87acb52a482ba88f7c9d3826ecee66c89911
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to