[dokuwiki] patch for pageutils.php

  • From: "Oliver Schulze L." <oliver@xxxxxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Mon, 24 Jul 2006 11:31:03 -0400

Hi,
I'm have done a litle cosmetic changes to inc/pageutils.php

The patch just make the function http_conditionalRequest() more redeable.

About my darcs experiences:
I try to run darcs on CentOS 4.3 but could not build it or download
a .rpm for that OS.
I also tryied installing darcs in WinXP SP2. In WinXP it worked, but
the "darcs send" does not find any changes in my local copy.

I followed the instructions from http://wiki.splitbrain.org/wiki:darcs, and run:
darcs get --partial http://dev.splitbrain.org/darcs/dokuwiki
cd dokuwiki
edit inc/pageutils.php
darcs send -o mypatch.patch
and I get:
plink: unknown option "-O"
Creating patch to "http://dev.splitbrain.org/darcs/dokuwiki";...
No recorded local changes to send!


So, I created the patch like this in CentOS 4.3:
 diff -u pageutils.php.ori pageutils.php > pageutils.php.patch

HTH
Oliver

--
Oliver Schulze L.
<oliver@xxxxxxxxxxxxx>

--- pageutils.php.ori   2006-07-24 11:14:47.000000000 -0400
+++ pageutils.php       2006-07-24 11:01:56.000000000 -0400
@@ -398,37 +398,48 @@
 /**
  * Checks and sets HTTP headers for conditional HTTP requests
  *
- * @author Simon Willison <swillison@xxxxxxxxx>
- * @link   http://simon.incutio.com/archive/2003/04/23/conditionalGet
+ * @author   Simon Willison <swillison@xxxxxxxxx>
+ * @link     http://simon.incutio.com/archive/2003/04/23/conditionalGet
+ * @param    timestamp $timestamp lastmodified time of the cache file
+ * @returns  void or void with previously header() commands executed
  */
 function http_conditionalRequest($timestamp){
-    // A PHP implementation of conditional get, see
-    //   http://fishbowl.pastiche.org/archives/001132.html
-    $last_modified = substr(date('r', $timestamp), 0, -5).'GMT';
-    $etag = '"'.md5($last_modified).'"';
-    // Send the headers
-    header("Last-Modified: $last_modified");
-    header("ETag: $etag");
-    // See if the client has provided the required headers
-    $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ?
-        stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) :
-        false;
-    $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ?
-        stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) :
-        false;
-    if (!$if_modified_since && !$if_none_match) {
-        return;
-    }
-    // At least one of the headers is there - check them
-    if ($if_none_match && $if_none_match != $etag) {
-        return; // etag is there but doesn't match
-    }
-    if ($if_modified_since && $if_modified_since != $last_modified) {
-        return; // if-modified-since is there but doesn't match
-    }
-    // Nothing has changed since their last request - serve a 304 and exit
-    header('HTTP/1.0 304 Not Modified');
-    exit;
+  // A PHP implementation of conditional get, see
+  //   http://fishbowl.pastiche.org/archives/001132.html
+  $last_modified = substr(date('r', $timestamp), 0, -5).'GMT';
+  $etag = '"'.md5($last_modified).'"';
+  // Send the headers
+  header("Last-Modified: $last_modified");
+  header("ETag: $etag");
+  // See if the client has provided the required headers
+  if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
+    $if_modified_since = stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']);
+  }else{
+    $if_modified_since = false;
+  }
+
+  if (isset($_SERVER['HTTP_IF_NONE_MATCH'])){
+    $if_none_match = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']);
+  }else{
+    $if_none_match = false;
+  }
+
+  if (!$if_modified_since && !$if_none_match){
+    return;
+  }
+
+  // At least one of the headers is there - check them
+  if ($if_none_match && $if_none_match != $etag) {
+    return; // etag is there but doesn't match
+  }
+
+  if ($if_modified_since && $if_modified_since != $last_modified) {
+    return; // if-modified-since is there but doesn't match
+  }
+
+  // Nothing has changed since their last request - serve a 304 and exit
+  header('HTTP/1.0 304 Not Modified');
+  exit;
 }
 
 //Setup VIM: ex: et ts=2 enc=utf-8 :

Other related posts: