From 80dc53604bbcf8f39c0e9e7727928f5a0fde296a Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 4 Jan 2004 03:35:00 +0000 Subject: [PATCH] Add $wgCompressRevisions option to compress old revisions on page save. (Off by default.) Also change default of $wgUseGzip to be on if zlib is available (this affects the file cache only). --- includes/Article.php | 23 ++++++++++++++++++++--- includes/DefaultSettings.php | 8 +++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 0c7ba47f06..5f8a57beff 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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 ); diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f1b66a25bf..0980a999fd 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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. -- 2.20.1