From 524be65dda410b9a3ced3fa06e672b4fd2cda5e4 Mon Sep 17 00:00:00 2001
From: Ben Coburn <btcoburn@silicodon.net>
Date: Tue, 16 May 2006 10:41:32 +0200
Subject: [PATCH] gzip content-encoding option

  - Enables gzip compression of output xhtml for browsers that support it.
    For example the wiki:syntax page takes up 46.80KB raw, but only 9.88KB gzip encoded.
  - Setting is configurable through the config plugin.

darcs-hash:20060516084132-05dcb-d8d1c7911a951b00e166c5a94f46a2cf1cfa5846.gz
---
 conf/dokuwiki.php                               | 1 +
 inc/template.php                                | 7 ++++++-
 lib/plugins/config/lang/en/lang.php             | 5 +++--
 lib/plugins/config/settings/config.metadata.php | 3 ++-
 4 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/conf/dokuwiki.php b/conf/dokuwiki.php
index d1fc851fd..f95eb56fe 100644
--- a/conf/dokuwiki.php
+++ b/conf/dokuwiki.php
@@ -76,6 +76,7 @@ $conf['purgeonadd']  = 1;                //purge cache when a new file is added
 $conf['locktime']    = 15*60;            //maximum age for lockfiles (defaults to 15 minutes)
 $conf['notify']      = '';               //send change info to this email (leave blank for nobody)
 $conf['mailfrom']    = '';               //use this email when sending mails
+$conf['gzip_output'] = 1;                //use gzip content encodeing for the output xhtml (if allowed by browser)
 $conf['gdlib']       = 2;                //the GDlib version (0, 1 or 2) 2 tries to autodetect
 $conf['im_convert']  = '';               //path to ImageMagicks convert (will be used instead of GD)
 $conf['jpg_quality'] = '70';             //quality of compression when scaling jpg images (0-100)
diff --git a/inc/template.php b/inc/template.php
index 17d6294bc..1af735382 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -11,13 +11,18 @@
 
 /**
  * Returns the path to the given template, uses
- * default one if the custom version doesn't exist
+ * default one if the custom version doesn't exist.
+ * Also enables gzip compression if configured.
  *
  * @author Andreas Gohr <andi@splitbrain.org>
  */
 function template($tpl){
   global $conf;
 
+  if ($conf['gzip_output'] && extension_loaded('zlib') && preg_match('/gzip|deflate/', $_SERVER['HTTP_ACCEPT_ENCODING'])) {
+    ob_start('ob_gzhandler');
+  }
+
   if(@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl))
     return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl;
 
diff --git a/lib/plugins/config/lang/en/lang.php b/lib/plugins/config/lang/en/lang.php
index b41402072..5e2599419 100644
--- a/lib/plugins/config/lang/en/lang.php
+++ b/lib/plugins/config/lang/en/lang.php
@@ -93,18 +93,19 @@ $lang['usedraft']    = 'Automatically save a draft while editing';
 $lang['sepchar']     = 'Page name word separator';
 $lang['canonical']   = 'Use fully canonical URLs';
 $lang['autoplural']  = 'Check for plural forms in links';
-$lang['usegzip']     = 'Use gzip (for attic)';
+$lang['usegzip']     = 'Use gzip for attic files';
 $lang['cachetime']   = 'Maximum age for cache (sec)';
 $lang['purgeonadd']  = 'Purge cache when new pages are added';
 $lang['locktime']    = 'Maximum age for lock files (sec)';
 $lang['notify']      = 'Send change notifications to this email address';
 $lang['mailfrom']    = 'Email address to use for automatic mails';
+$lang['gzip_output'] = 'Use gzip Content-Encoding for xhtml';
 $lang['gdlib']       = 'GD Lib version';
 $lang['im_convert']  = 'Path to ImageMagick\'s convert tool';
 $lang['jpg_quality'] = 'JPG compression quality (0-100)';
 $lang['spellchecker']= 'Enable spellchecker';
 $lang['subscribers'] = 'Enable page subscription support';
-$lang['compress']    = 'Compress CSS and javascript files';
+$lang['compress']    = 'Compact CSS and javascript output';
 $lang['hidepages']   = 'Hide matching pages (regular expressions)';
 $lang['send404']     = 'Send "HTTP 404/Page Not Found" for non existing pages';
 $lang['sitemap']     = 'Generate Google sitemap (days)';
diff --git a/lib/plugins/config/settings/config.metadata.php b/lib/plugins/config/settings/config.metadata.php
index d48d08d56..1514d731c 100644
--- a/lib/plugins/config/settings/config.metadata.php
+++ b/lib/plugins/config/settings/config.metadata.php
@@ -144,11 +144,12 @@ $meta['useslash']    = array('onoff');
 $meta['sepchar']     = array('sepchar');
 $meta['canonical']   = array('onoff');
 $meta['autoplural']  = array('onoff');
-$meta['usegzip']     = array('onoff');
 $meta['mailfrom']    = array('email');
 $meta['compress']    = array('onoff');
+$meta['gzip_output'] = array('onoff');
 $meta['hidepages']   = array('string');
 $meta['send404']     = array('onoff');
+$meta['usegzip']     = array('onoff');
 $meta['sitemap']     = array('numeric');
 $meta['rss_type']    = array('multichoice','_choices' => array('rss','rss1','rss2','atom'));
 $meta['rss_linkto']  = array('multichoice','_choices' => array('diff','page','rev','current'));
-- 
GitLab