Description

The url_mappings setting is described as

That is bogus. First of all, fully qualified URLs to local pages are not used in moin, thus that is superfluous.

url_mapping might break redirects

Redirects should use absolute URI (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30). But our redirect code is:

    def http_redirect(self, url):
        """ Redirect to a fully qualified, or server-rooted URL
        
        @param url: relative or absolute url, ascii using url encoding.
        """
        url = self.getQualifiedURL(url)
        self.http_headers(["Status: 302", "Location: %s" % url])

    def getQualifiedURL(self, uri=''):
        """ Return an absolute URL starting with schema and host.

        Already qualified urls are returned unchanged.

        @param uri: server rootted uri e.g /scriptname/pagename. It
            must start with a slash. Must be ascii and url encoded.
        """
        import urlparse
        scheme = urlparse.urlparse(uri)[0]
        if scheme:
            return uri

        schema = ('http', 'https')[self.is_ssl]
        result = "%s://%s%s" % (schema, self.http_host, uri)

        # This might break qualified urls in redirects!
        # e.g. mapping 'http://netloc' -> '/'
        return wikiutil.mapURL(self, result)

So if one map 'http://netloc' to '/' as explained in the top of this page, his redirects will use relative URI.

Map urls used in email notification

This second patch makes the wiki honour the url_mappings variable in the case generated in-wiki links which are used in emails.

--- orig/MoinMoin/request.py
+++ mod/MoinMoin/request.py
@@ -706,7 +706,8 @@
         if uri:
             result = result + uri
 
-        return result
+        # return mapped result
+        return wikiutil.mapURL(self, result)
 
 
     def getUserAgent(self):

[If these patches do not apply please check an older version of this page, I generated them by hand.]

Along with these patches, CHANGES should be updated to say that the above url_mappings from the docs are bogus and should be removed, and that people wanting to use the newly documented trick

url_mappings = {
  'http://': '/cgi-bin/derefer.cgi?url=http://'
}

should change that to

url_mappings = {
  'http://own-wiki/': 'http://own-wiki/',
  'http://': 'http://own-wiki/cgi-bin/derefer.cgi?url=http://'
}

because otherwise the dereferer will also be applied to links to the own wiki (that can occur in emails).

Fixing Twisted redirect

--- orig/MoinMoin/request.py
+++ mod/MoinMoin/request.py
@@ -1394,8 +1394,7 @@
     def http_redirect(self, url):
         """ Redirect to a fully qualified, or server-rooted URL """
         if url.count("://") == 0:
-            # no https method??
-            url = "http://%s:%s%s" % (self.server_name, self.server_port, url)
+            url = self.getQualifiedURL(url)

         if isinstance(url, unicode):
             url = url.encode('ascii')

This patch is (kind of) applied in patch-899

Workaround

Apply above patch ;)

Discussion

Another solution, since this url_mapping never worked, and probably nobody needs it, we can simply remove config option. url_mapping was broken (caused a backtrace if you set it) in 1.3 - and we got a bug report about that only few weeks ago, from someone who tried to misuse it (could use standard config instead). We should check if it was also broken in 1.1 and 1.2. -- NirSoffer 2005-02-22 20:33:11

In any case we should clean up the bogus hint IMHO. Then we should test if the above patch catches all broken code paths that may be relevant to this option. -- AlexanderSchremmer 2005-02-22 21:31:45

I check 1.2.4, url_mappings is not broken there, as it is in 1.3.0-1.3.3. You can set a value and it seems to work for interwiki and external links. -- NirSoffer 2005-02-22 21:49:17

I've been running the (pretty much) latest MoinMoin with above patch for a while on my server and noticed no adverse effects. Redirecting seems to work, URL-mappings work (even in the emails that are sent out) and all is well. Can we apply this patch and get rid of another bug? -- JohannesBerg 2005-03-02 18:23:11

I have updated the documentation on HelpMiscellaneous accordingly, parts of the change should be done regardless of the application of above patch (removing the remapping to relative URLs argument), others apply only if the patch is applied. -- JohannesBerg 2005-03-02 18:47:48

I now split the patch into two patches of which the first needs to go into MoinMoin to make #REDIRECT directives work correctly in presence of https URLs etc. by redirecting to absolute paths but not fully qualified URLs. The second one is open for discussion, but it makes url_mappings work correctly for links that are emailed out. -- JohannesBerg 2005-03-02 18:55:08

url_mapping might be broken in some places, but with current code (patch-897), you don't need any url mapping to run behind a proxy (if it set X-Forwarded-Host), and both mail notifications, redirects, urls, and rss_c action work fine. See HelpOnConfiguration/IntegratingWithApache.

You can also manipulate urls with requests properties argument to the constructor:

request = RequestBlah(properties={'http_host':'blah.org'})

Plan


CategoryMoinMoinBug

MoinMoin: MoinMoinBugs/URLMappingsBogosities (last edited 2007-11-17 00:37:05 by ThomasWaldmann)