Skip to content
Snippets Groups Projects
Commit e44528c0 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

Merge pull request #1412 from splitbrain/nozlib

Fix behavior when zlib is not available
parents f829245b a8d25969
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,9 @@ php:
- "5.4"
- "5.3"
- "hhvm"
env:
- DISABLE_FUNCTIONS=
- DISABLE_FUNCTIONS="gzopen"
matrix:
allow_failures:
- php: "hhvm"
......@@ -16,4 +19,5 @@ notifications:
- "chat.freenode.net#dokuwiki"
on_success: change
on_failure: change
before_script: echo "disable_functions=$DISABLE_FUNCTIONS" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
script: cd _test && phpunit --verbose --stderr
......@@ -6,7 +6,7 @@ class io_readfile_test extends DokuWikiTest {
* dependency for tests needing zlib extension to pass
*/
public function test_ext_zlib() {
if (!extension_loaded('zlib')) {
if (!DOKU_HAS_GZIP) {
$this->markTestSkipped('skipping all zlib tests. Need zlib extension');
}
}
......@@ -15,7 +15,7 @@ class io_readfile_test extends DokuWikiTest {
* dependency for tests needing zlib extension to pass
*/
public function test_ext_bz2() {
if (!extension_loaded('bz2')) {
if (!DOKU_HAS_BZIP) {
$this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension');
}
}
......
......@@ -8,7 +8,7 @@ class io_replaceinfile_test extends DokuWikiTest {
* dependency for tests needing zlib extension to pass
*/
public function test_ext_zlib() {
if (!extension_loaded('zlib')) {
if (!DOKU_HAS_GZIP) {
$this->markTestSkipped('skipping all zlib tests. Need zlib extension');
}
}
......@@ -17,7 +17,7 @@ class io_replaceinfile_test extends DokuWikiTest {
* dependency for tests needing zlib extension to pass
*/
public function test_ext_bz2() {
if (!extension_loaded('bz2')) {
if (!DOKU_HAS_BZIP) {
$this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension');
}
}
......
......@@ -6,7 +6,7 @@ class io_savefile_test extends DokuWikiTest {
* dependency for tests needing zlib extension to pass
*/
public function test_ext_zlib() {
if (!extension_loaded('zlib')) {
if (!DOKU_HAS_GZIP) {
$this->markTestSkipped('skipping all zlib tests. Need zlib extension');
}
}
......@@ -15,7 +15,7 @@ class io_savefile_test extends DokuWikiTest {
* dependency for tests needing zlib extension to pass
*/
public function test_ext_bz2() {
if (!extension_loaded('bz2')) {
if (!DOKU_HAS_BZIP) {
$this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension');
}
}
......
......@@ -197,6 +197,8 @@ function http_rangeRequest($fh,$size,$mime){
* @return bool
*/
function http_gzip_valid($uncompressed_file) {
if(!DOKU_HAS_GZIP) return false;
$gzip = $uncompressed_file.'.gz';
if (filemtime($gzip) < filemtime($uncompressed_file)) { // filemtime returns false (0) if file doesn't exist
return copy($uncompressed_file, 'compress.zlib://'.$gzip);
......@@ -252,10 +254,10 @@ function http_cached_finish($file, $content) {
// save cache file
io_saveFile($file, $content);
if(function_exists('gzopen')) io_saveFile("$file.gz",$content);
if(DOKU_HAS_GZIP) io_saveFile("$file.gz",$content);
// finally send output
if ($conf['gzip_output'] && function_exists('gzencode')) {
if ($conf['gzip_output'] && DOKU_HAS_GZIP) {
header('Vary: Accept-Encoding');
header('Content-Encoding: gzip');
print gzencode($content,9,FORCE_GZIP);
......
......@@ -195,10 +195,12 @@ require_once(DOKU_INC.'vendor/autoload.php');
require_once(DOKU_INC.'inc/load.php');
// disable gzip if not available
if($conf['compression'] == 'bz2' && !function_exists('bzopen')){
define('DOKU_HAS_BZIP', function_exists('bzopen'));
define('DOKU_HAS_GZIP', function_exists('gzopen'));
if($conf['compression'] == 'bz2' && !DOKU_HAS_BZIP) {
$conf['compression'] = 'gz';
}
if($conf['compression'] == 'gz' && !function_exists('gzopen')){
if($conf['compression'] == 'gz' && !DOKU_HAS_GZIP) {
$conf['compression'] = 0;
}
......
......@@ -107,9 +107,11 @@ function io_readFile($file,$clean=true){
$ret = '';
if(file_exists($file)){
if(substr($file,-3) == '.gz'){
if(!DOKU_HAS_GZIP) return false;
$ret = gzfile($file);
if(is_array($ret)) $ret = join('', $ret);
}else if(substr($file,-4) == '.bz2'){
if(!DOKU_HAS_BZIP) return false;
$ret = bzfile($file);
}else{
$ret = file_get_contents($file);
......@@ -222,11 +224,13 @@ function _io_saveFile($file, $content, $append) {
$fileexists = file_exists($file);
if(substr($file,-3) == '.gz'){
if(!DOKU_HAS_GZIP) return false;
$fh = @gzopen($file,$mode.'9');
if(!$fh) return false;
gzwrite($fh, $content);
gzclose($fh);
}else if(substr($file,-4) == '.bz2'){
if(!DOKU_HAS_BZIP) return false;
if($append) {
$bzcontent = bzfile($file);
if($bzcontent === false) return false;
......@@ -313,8 +317,10 @@ function io_replaceInFile($file, $oldline, $newline, $regex=false, $maxlines=0)
// load into array
if(substr($file,-3) == '.gz'){
if(!DOKU_HAS_GZIP) return false;
$lines = gzfile($file);
}else if(substr($file,-4) == '.bz2'){
if(!DOKU_HAS_BZIP) return false;
$lines = bzfile($file, true);
}else{
$lines = file($file);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment