From 7e6107b55554ae0e204ce4e13f230c0927701b4c Mon Sep 17 00:00:00 2001 From: Matthias Mullie Date: Wed, 7 Aug 2013 18:14:18 +0200 Subject: [PATCH] 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 --- includes/Revision.php | 70 +++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/includes/Revision.php b/includes/Revision.php index b3b971b17a..ddcaf1776f 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -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. -- 2.20.1