Only letter salad in the browser
Symptoms
After installation, when accessing the Wikka main URL (or any page for that matter) only results in garbage characters ("letter salad") in the browser window (looks like viewing a binary file).Cause
In fact, what you're seeing is a binary file, a gzipped file more precisely. This happens when the server (or PHP) is set to serve files gzip-encoded, and Wikka (with its default setting to allow gzip encoding) detects that it is available - the result is that Wikka does its own gzip-encoding, and then the server does it again, while the browser of course decodes it only once.Applies to
Any Wikka version.Solution
There are actually two possible solutions; which one is best depends on the context Wikka is used in:- If Wikka is the only (or main) application running on a server, you could turn off the server-configured gzip encoding; how, depends on how it's configured, of course.
- If gzip encoding needs to remain active at the server / PHP level, you can configure Wikka not to do its own gzip encoding; two simple changes are needed:
A new configuration value and a small change in the code can be used to tell Wikka not do do gzip encoding even if it's available and the browser accepts it. (Note: this solution parallells that on BlankPageWorkaround.)
First, open /wikka.config.php (after allowing write access on it!) and find the line
"wikiping_server" => "",
(or possibly there's a value after the =>) and add the following line right after it:
"allow_gzip" => "0",
to indicate you don't want Wikka do so its own gzip encoding. (Make the file read-only again after editing it).
Then open /wikka.php and find this code at the end:
$content = ob_get_contents();
if (strstr ($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') )
{
// Tell the browser the content is compressed with gzip
header ("Content-Encoding: gzip");
$page_output = gzencode($content);
$page_length = strlen($page_output);
} else {
$page_output = $content;
$page_length = strlen($page_output);
}
// header("Cache-Control: pre-check=0");
header("Cache-Control: no-cache");
// header("Pragma: ");
// header("Expires: ");
$etag = md5($content);
header('ETag: '.$etag);
header('Content-Length: '.$page_length);
ob_end_clean();
echo $page_output;
and change it as follows:
if (strstr ($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') )
{
// Tell the browser the content is compressed with gzip
header ("Content-Encoding: gzip");
$page_output = gzencode($content);
$page_length = strlen($page_output);
} else {
$page_output = $content;
$page_length = strlen($page_output);
}
// header("Cache-Control: pre-check=0");
header("Cache-Control: no-cache");
// header("Pragma: ");
// header("Expires: ");
$etag = md5($content);
header('ETag: '.$etag);
header('Content-Length: '.$page_length);
ob_end_clean();
echo $page_output;
$content = ob_get_contents();
// if server/PHP already does gzip encoding we prevent Wikka doing it as well by setting 'allow_gzip' to '0' in the configuration
if (strstr ($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') && $wakka->config['allow_gzip'] == '1')
{
// Tell the browser the content is compressed with gzip
header ("Content-Encoding: gzip");
$page_output = gzencode($content);
header('Content-Length: '.strlen($page_output));
} else {
$page_output = $content;
// if server does gzip encoding we don't want content-length calculation to prevent a wrong byte count to be sent to the browser
if ($wakka->config['allow_gzip'] == '1')
{
header('Content-Length: '.strlen($page_output));
}
}
// header("Cache-Control: pre-check=0");
header("Cache-Control: no-cache");
// header("Pragma: ");
// header("Expires: ");
$etag = md5($content);
header('ETag: '.$etag);
//header('Content-Length: '.$page_length); # moved
ob_end_clean();
echo $page_output;
// if server/PHP already does gzip encoding we prevent Wikka doing it as well by setting 'allow_gzip' to '0' in the configuration
if (strstr ($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') && $wakka->config['allow_gzip'] == '1')
{
// Tell the browser the content is compressed with gzip
header ("Content-Encoding: gzip");
$page_output = gzencode($content);
header('Content-Length: '.strlen($page_output));
} else {
$page_output = $content;
// if server does gzip encoding we don't want content-length calculation to prevent a wrong byte count to be sent to the browser
if ($wakka->config['allow_gzip'] == '1')
{
header('Content-Length: '.strlen($page_output));
}
}
// header("Cache-Control: pre-check=0");
header("Cache-Control: no-cache");
// header("Pragma: ");
// header("Expires: ");
$etag = md5($content);
header('ETag: '.$etag);
//header('Content-Length: '.$page_length); # moved
ob_end_clean();
echo $page_output;
If later the server-level gzip encoding is no longer done (or you move Wikka to a different server where this isn't configured), just change the config to set 'allow_gzip' to '1' and you'll get gzip encoding in Wikka enabled again, as well as content-length calculation. Using Gzip encoding costs a little extra in CPU but saves on bandwidth.
CategoryWorkaround