Add $wgCompressRevisions option to compress old revisions on page save.
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 4 Jan 2004 03:35:00 +0000 (03:35 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 4 Jan 2004 03:35:00 +0000 (03:35 +0000)
(Off by default.) Also change default of $wgUseGzip to be on if zlib
is available (this affects the file cache only).

includes/Article.php
includes/DefaultSettings.php

index 0c7ba47..5f8a57b 100644 (file)
@@ -38,7 +38,8 @@ class Article {
 
        /* static */ function getRevisionText( $row, $prefix = "old_" ) {
                # Deal with optional compression of archived pages.
-               # This can be done periodically via maintenance/compressOld.php
+               # This can be done periodically via maintenance/compressOld.php, and
+               # as pages are saved if $wgCompressRevisions is set.
                $text = $prefix . "text";
                $flags = $prefix . "flags";
                if( isset( $row->$flags ) && (false !== strpos( $row->$flags, "gzip" ) ) ) {
@@ -50,6 +51,19 @@ class Article {
                return false;
        }
        
+       /* static */ function compressRevisionText( &$text ) {
+               global $wgCompressRevisions;
+               if( !$wgCompressRevisions ) {
+                       return "";
+               }
+               if( !function_exists( "gzdeflate" ) ) {
+                       wfDebug( "Article::compressRevisionText() -- no zlib support, not compressing\n" );
+                       return "";
+               }
+               $text = gzdeflate( $text );
+               return "gzip";
+       }
+       
        # Note that getContent/loadContent may follow redirects if
        # not told otherwise, and so may cause a change to mTitle.
 
@@ -479,9 +493,12 @@ class Article {
                                return false;
                        }
 
+                       # This overwrites $oldtext if revision compression is on
+                       $flags = Article::compressRevisionText( $oldtext );
+                       
                        $sql = "INSERT INTO old (old_namespace,old_title,old_text," .
                          "old_comment,old_user,old_user_text,old_timestamp," .
-                         "old_minor_edit,inverse_timestamp) VALUES (" .
+                         "old_minor_edit,inverse_timestamp,old_flags) VALUES (" .
                          $this->mTitle->getNamespace() . ", '" .
                          wfStrencode( $this->mTitle->getDBkey() ) . "', '" .
                          wfStrencode( $oldtext ) . "', '" .
@@ -489,7 +506,7 @@ class Article {
                          $this->getUser() . ", '" .
                          wfStrencode( $this->getUserText() ) . "', '" .
                          $this->getTimestamp() . "', " . $me1 . ", '" .
-                         wfInvertTimestamp( $this->getTimestamp() ) . "')";
+                         wfInvertTimestamp( $this->getTimestamp() ) . "','$flags')";
                        $res = wfQuery( $sql, DB_WRITE, $fname );
                        $oldid = wfInsertID( $res );
 
index f1b66a2..0980a99 100644 (file)
@@ -150,7 +150,13 @@ $wgDisableAnonTalk = false;
 # We can serve pages compressed in order to save bandwidth,
 # but this will increase CPU usage.
 # Requires zlib support enabled in PHP.
-$wgUseGzip = false;
+$wgUseGzip = function_exists( "gzencode" );
+
+# We can also compress text in the old revisions table. If this is set on,
+# old revisions will be compressed on page save if zlib support is available.
+# Any compressed revisions will be decompressed on load regardless of this
+# setting *but will not be readable at all* if zlib support is not available.
+$wgCompressRevisions = false;
 
 # This is the list of preferred extensions for uploading files. Uploading
 # files with extensions not in this list will trigger a warning.