Forum

Dokuwiki broken CSS fix (with patch)

Chris Wadge
15 October 2012, 13:44
Having problems with Dokuwiki breaking CSS on page reloads? So did I. It's not a problem with Hiawatha; the same thing happens on nginx and Cherokee. I'm a sysadmin, not a PHP developer, but poking around in the code, it appears that the offending entries look like:
header('HTTP/1.0 $CODE $MESSAGE');
...But I believe the more correct syntax would be:
header("Status: $CODE");
I've created a small patch against Dokuwiki "Adora Belle" which makes the necessary changes:
diff -Naur dokuwiki-2012-10-13//inc/actions.php dokuwiki-2012-10-13-patched//inc/actions.php
--- dokuwiki-2012-10-13//inc/actions.php 2012-10-13 04:25:31.000000000 -0700
+++ dokuwiki-2012-10-13-patched//inc/actions.php 2012-10-15 04:06:04.484340013 -0700
@@ -156,7 +156,7 @@
$evt->advise_after();
// Make sure plugs can handle 'denied'
if($conf['send404'] && $ACT == 'denied') {
- header('HTTP/1.0 403 Forbidden');
+ header('Status: 403');
}
unset($evt);

@@ -642,7 +642,7 @@
global $conf;

if ($conf['sitemap'] < 1 || !is_numeric($conf['sitemap'])) {
- header("HTTP/1.0 404 Not Found");
+ header("Status: 404");
print "Sitemap generation is disabled.";
exit;
}
@@ -674,7 +674,7 @@
exit;
}

- header("HTTP/1.0 500 Internal Server Error");
+ header("Status: 500");
print "Could not read the sitemap file - bad permissions?";
exit;
}
diff -Naur dokuwiki-2012-10-13//inc/auth.php dokuwiki-2012-10-13-patched//inc/auth.php
--- dokuwiki-2012-10-13//inc/auth.php 2012-10-13 04:25:31.000000000 -0700
+++ dokuwiki-2012-10-13-patched//inc/auth.php 2012-10-15 04:03:15.659663197 -0700
@@ -266,7 +266,7 @@
function auth_validateToken($token) {
if(!$token || $token != $_SESSION[DOKU_COOKIE]['auth']['token']) {
// bad token
- header("HTTP/1.0 401 Unauthorized");
+ header("Status: 401");
print 'Invalid auth token - maybe the session timed out';
unset($_SESSION[DOKU_COOKIE]['auth']['token']); // no second chance
exit;
diff -Naur dokuwiki-2012-10-13//inc/httputils.php dokuwiki-2012-10-13-patched//inc/httputils.php
--- dokuwiki-2012-10-13//inc/httputils.php 2012-10-13 04:25:31.000000000 -0700
+++ dokuwiki-2012-10-13-patched//inc/httputils.php 2012-10-15 04:04:40.953973107 -0700
@@ -53,7 +53,7 @@
}

// Nothing has changed since their last request - serve a 304 and exit
- header('HTTP/1.0 304 Not Modified');
+ header('Status: 304');

// don't produce output, even if compression is on
@ob_end_clean();
@@ -122,7 +122,7 @@
$end = (int)$p[1];
if (!$end) $end = $size - 1;
if ($start > $end || $start > $size || $end > $size){
- header('HTTP/1.1 416 Requested Range Not Satisfiable');
+ header('Status: 416');
print 'Bad Range Request!';
exit;
}
@@ -137,7 +137,7 @@
if(!$isrange){
header("Content-Type: $mime",true);
}else{
- header('HTTP/1.1 206 Partial Content');
+ header('Status: 206');
if($parts == 1){
header("Content-Type: $mime",true);
}else{
diff -Naur dokuwiki-2012-10-13//inc/parser/code.php dokuwiki-2012-10-13-patched//inc/parser/code.php
--- dokuwiki-2012-10-13//inc/parser/code.php 2012-10-13 04:25:31.000000000 -0700
+++ dokuwiki-2012-10-13-patched//inc/parser/code.php 2012-10-15 04:02:23.047323240 -0700
@@ -43,7 +43,7 @@
* This should never be reached, if it is send a 404
*/
function document_end() {
- header("HTTP/1.0 404 Not Found");
+ header("Status: 404");
echo '404 - Not found';
exit;
}
diff -Naur dokuwiki-2012-10-13//lib/exe/detail.php dokuwiki-2012-10-13-patched//lib/exe/detail.php
--- dokuwiki-2012-10-13//lib/exe/detail.php 2012-10-13 04:25:31.000000000 -0700
+++ dokuwiki-2012-10-13-patched//lib/exe/detail.php 2012-10-15 04:08:53.124028044 -0700
@@ -31,7 +31,7 @@
$SRC = mediaFN($IMG);
if(!@file_exists($SRC)){
//doesn't exist!
- header("HTTP/1.0 404 File not Found");
+ header("Status: 404");
$ERROR = 'File not found';
}
}else{
diff -Naur dokuwiki-2012-10-13//lib/exe/fetch.php dokuwiki-2012-10-13-patched//lib/exe/fetch.php
--- dokuwiki-2012-10-13//lib/exe/fetch.php 2012-10-13 04:25:31.000000000 -0700
+++ dokuwiki-2012-10-13-patched//lib/exe/fetch.php 2012-10-15 04:08:06.007511643 -0700
@@ -57,7 +57,7 @@
}
// send any non 200 status
if($data['status'] != 200){
- header('HTTP/1.0 ' . $data['status'] . ' ' . $data['statusmessage']);
+ header('Status: ' . $data['status'] . ' ' . $data['statusmessage']);
}
// die on errors
if($data['status'] > 203){
@@ -135,7 +135,7 @@
if($fp){
http_rangeRequest($fp,filesize($file),$mime);
}else{
- header("HTTP/1.0 500 Internal Server Error");
+ header("Status: 500");
print "Could not read $file - bad permissions?";
}
}
diff -Naur dokuwiki-2012-10-13//lib/exe/mediamanager.php dokuwiki-2012-10-13-patched//lib/exe/mediamanager.php
--- dokuwiki-2012-10-13//lib/exe/mediamanager.php 2012-10-13 04:25:31.000000000 -0700
+++ dokuwiki-2012-10-13-patched//lib/exe/mediamanager.php 2012-10-15 04:07:01.161554166 -0700
@@ -36,7 +36,7 @@

// do not display the manager if user does not have read access
if($AUTH < AUTH_READ && !$fullscreen) {
- header('HTTP/1.0 403 Forbidden');
+ header('Status: 403');
die($lang['accessdenied']);
}

@@ -48,7 +48,7 @@
$_FILES['upload'] =& $_FILES['Filedata'];
$JUMPTO = media_upload($NS,$AUTH);
if($JUMPTO == false){
- header("HTTP/1.0 400 Bad Request");
+ header("Status: 400");
echo 'Upload failed';
}
echo 'ok';
diff -Naur dokuwiki-2012-10-13//lib/exe/xmlrpc.php dokuwiki-2012-10-13-patched//lib/exe/xmlrpc.php
--- dokuwiki-2012-10-13//lib/exe/xmlrpc.php 2012-10-13 04:25:31.000000000 -0700
+++ dokuwiki-2012-10-13-patched//lib/exe/xmlrpc.php 2012-10-15 04:08:34.538613196 -0700
@@ -29,10 +29,10 @@
return $result;
} catch (RemoteAccessDeniedException $e) {
if (!isset($_SERVER['REMOTE_USER'])) {
- header('HTTP/1.1 401 Unauthorized');
+ header('Status: 401');
return new IXR_Error(-32603, "server error. not authorized to call method $methodname");
} else {
- header('HTTP/1.1 403 Forbidden');
+ header('Status: 403');
return new IXR_Error(-32604, "server error. forbidden to call the method $methodname");
}
} catch (RemoteException $e) {

...and also appended it to a bug report here: https://bugs.dokuwiki.org/index.php?do=details&action=details.addvote&task_id=1698 If the above patch works for you, please vote for the bug so somebody over there might notice, meaning we won't have to patch by hand with each new Dokuwiki release.

Thanks!
-Chris
Hugo Leisink
15 October 2012, 14:53
Thanks for your post. This issue was reported some time ago, but your patch makes it easier to solve. Thanks for sharing!
Chris Wadge
15 October 2012, 16:31
D'oh! If I'd noticed that topic earlier, I wouldn't have had to troubleshoot so deeply to find the root cause. Still, thanks for the feedback. Hopefully they accept my patch, or something close to it.

-C
Hugo Leisink
15 October 2012, 18:52
Well, if you had used the search page like suggested at the support page, you would have found it. It's the first when searching for 'dokuwiki'.
Chris Wadge
16 October 2012, 04:23
Hmm, seems unduly harsh. My bad for using Google instead of your search page, I guess. Still, came to the same conclusions eventually.
Ginghong Wong
26 October 2012, 09:10
https://duckduckgo.com/?q=dokuwiki+site:hiawatha-webserver.org which is not the same as some other search engines in https://duckduckgo.com/privacy.html
This topic has been closed.