[PATCH 1 of 2] Fix baseurl configuration, detection, and use in templates

Wesley J. Landaker wjl at icecavern.net
Fri Jul 13 13:13:44 CDT 2007


# HG changeset patch
# User Wesley J. Landaker <wjl at icecavern.net>
# Date 1184348977 21600
# Node ID dce126cc02f5543074b3cf2753f122ac53305003
# Parent  28b23b9073a8652f95b87975f6648912dfec5f71
Fix baseurl configuration, detection, and use in templates.

This patch fixes the current ad-hoc HTTPS detection for the current
{urlbase} template variable, and unifies it with the currently existing
[web]/baseurl configuration parameter.

We already have an existing, documented [web] setting called baseurl,
that is exactly what the heuristically created urlbase template setting
is trying to recreate. We should use this when it's set; when it's not
set, we use the same educated guessing as before.

Also, rename the {urlbase} template variable to {baseurl}, because this
matches the [web]/baseurl setting that currently exists for exactly
this kind of thing.

For backwards compatibility, {urlbase} still works, but it might be
better to just remove it, since the only place it is used in mercurial
is the RSS templates, and these have been updated in this patch as well.
The main concern would be external users with their own templates, so
I tried to err on the safe side, although it's also annoying to introduce
a backwards compatibility feature for something that was undocumented and
might cause future confusion if left there.

diff -r 28b23b9073a8 -r dce126cc02f5 mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py	Fri Jul 13 08:28:57 2007 -0700
+++ b/mercurial/hgweb/hgweb_mod.py	Fri Jul 13 11:49:37 2007 -0600
@@ -787,17 +787,20 @@ class hgweb(object):
             style = req.form['style'][0]
         mapfile = style_map(self.templatepath, style)
 
-        proto = req.env.get('wsgi.url_scheme')
-        if proto == 'https':
-            proto = 'https'
-            default_port = "443"
-        else:
-            proto = 'http'
-            default_port = "80"
-
-        port = req.env["SERVER_PORT"]
-        port = port != default_port and (":" + port) or ""
-        urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port)
+        # use [web]/baseurl if set, otherwise use heuristic
+        baseurl = self.config("web", "baseurl")
+        if not baseurl:
+            proto = req.env.get('wsgi.url_scheme')
+            if proto == 'https':
+                proto = 'https'
+                default_port = "443"
+            else:
+                proto = 'http'
+                default_port = "80"
+            port = req.env["SERVER_PORT"]
+            port = port != default_port and (":" + port) or ""
+            baseurl = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port)
+            
         staticurl = self.config("web", "staticurl") or req.url + 'static/'
         if not staticurl.endswith('/'):
             staticurl += '/'
@@ -810,7 +813,8 @@ class hgweb(object):
         self.t = templater.templater(mapfile, templater.common_filters,
                                      defaults={"url": req.url,
                                                "staticurl": staticurl,
-                                               "urlbase": urlbase,
+                                               "baseurl": baseurl,
+                                               "urlbase": baseurl, # backwards compatibility only
                                                "repo": self.reponame,
                                                "header": header,
                                                "footer": footer,
diff -r 28b23b9073a8 -r dce126cc02f5 templates/rss/changelogentry.tmpl
--- a/templates/rss/changelogentry.tmpl	Fri Jul 13 08:28:57 2007 -0700
+++ b/templates/rss/changelogentry.tmpl	Fri Jul 13 11:49:37 2007 -0600
@@ -1,6 +1,6 @@
 <item>
     <title>#desc|strip|firstline|strip|escape#</title>
-    <link>{urlbase}{url}rev/{node|short}</link>
+    <link>{baseurl}{url}rev/{node|short}</link>
     <description><![CDATA[#desc|strip|escape|addbreaks#]]></description>
     <author>#author|obfuscate#</author>
     <pubDate>#date|rfc822date#</pubDate>
diff -r 28b23b9073a8 -r dce126cc02f5 templates/rss/filelogentry.tmpl
--- a/templates/rss/filelogentry.tmpl	Fri Jul 13 08:28:57 2007 -0700
+++ b/templates/rss/filelogentry.tmpl	Fri Jul 13 11:49:37 2007 -0600
@@ -1,6 +1,6 @@
 <item>
     <title>#desc|strip|firstline|strip|escape#</title>
-    <link>{urlbase}{url}log{#node|short#}/{file|urlescape}</link>
+    <link>{baseurl}{url}log{#node|short#}/{file|urlescape}</link>
     <description><![CDATA[#desc|strip|escape|addbreaks#]]></description>
     <author>#author|obfuscate#</author>
     <pubDate>#date|rfc822date#</pubDate>
diff -r 28b23b9073a8 -r dce126cc02f5 templates/rss/header.tmpl
--- a/templates/rss/header.tmpl	Fri Jul 13 08:28:57 2007 -0700
+++ b/templates/rss/header.tmpl	Fri Jul 13 11:49:37 2007 -0600
@@ -3,5 +3,5 @@ Content-type: text/xml; charset={encodin
 <?xml version="1.0" encoding="{encoding}"?>
 <rss version="2.0">
   <channel>
-    <link>{urlbase}{url}</link>
+    <link>{baseurl}{url}</link>
     <language>en-us</language>
diff -r 28b23b9073a8 -r dce126cc02f5 templates/rss/tagentry.tmpl
--- a/templates/rss/tagentry.tmpl	Fri Jul 13 08:28:57 2007 -0700
+++ b/templates/rss/tagentry.tmpl	Fri Jul 13 11:49:37 2007 -0600
@@ -1,6 +1,6 @@
 <item>
     <title>#tag|escape#</title>
-    <link>{urlbase}{url}rev/{node|short}</link>
+    <link>{baseurl}{url}rev/{node|short}</link>
     <description><![CDATA[#tag|strip|escape|addbreaks#]]></description>
     <pubDate>#date|rfc822date#</pubDate>
 </item>


More information about the Mercurial-devel mailing list