mercurial/hgweb.py
changeset 599 765182a4c843
parent 598 f8d44a2e6928
child 600 11c379e23ad6
--- a/mercurial/hgweb.py	Sun Jul 03 12:29:37 2005 -0800
+++ b/mercurial/hgweb.py	Sun Jul 03 13:32:59 2005 -0800
@@ -108,6 +108,12 @@
             tmpl = self.cache[t] = file(self.map[t]).read()
         return template(tmpl, self.filters, **map)
 
+def rfc822date(x):
+    month= [None,"Jan", "Feb", "Mar", "Apr", "May", "Jun",
+                 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
+    yyyy,mon,dd,hh,mm,ss,wd,x,y = time.gmtime(x)
+    return "%d %s %d %d:%d:%d"%(dd, month[mon], yyyy, hh, mm, ss)
+
 class hgweb:
     maxchanges = 10
     maxfiles = 10
@@ -127,7 +133,8 @@
             "obfuscate": obfuscate,
             "short": (lambda x: x[:12]),
             "firstline": (lambda x: x.splitlines(1)[0]),
-            "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--")
+            "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"),
+            "rfc822date": rfc822date,
             }
 
     def refresh(self):
@@ -217,7 +224,12 @@
             yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn)
 
     def header(self):
-        yield self.t("header", repo = self.reponame)
+        port = os.environ["SERVER_PORT"]
+        port = port != "80" and (":" + port) or ""
+        self.url = "http://%s%s%s" % \
+                   (os.environ["SERVER_NAME"], port, os.environ["REQUEST_URI"])
+
+        yield self.t("header", repo = self.reponame, url = self.url)
 
     def footer(self):
         yield self.t("footer", repo = self.reponame)
@@ -729,6 +741,9 @@
             env = {}
             env['GATEWAY_INTERFACE'] = 'CGI/1.1'
             env['REQUEST_METHOD'] = self.command
+            env['SERVER_NAME'] = self.server.server_name
+            env['SERVER_PORT'] = str(self.server.server_port)
+            env['REQUEST_URI'] = "/"
             if query:
                 env['QUERY_STRING'] = query
             host = self.address_string()