Description
The url_mappings setting is described as
A typical example is url_mappings = {'http://my.server.net/': '/'}, which removes the scheme from local URLs, and thus makes links to your own server work for both http and https.
That is bogus. First of all, fully qualified URLs to local pages are not used in moin, thus that is superfluous.
If you fail to train your user base to NOT use links pasted from the location bar, they ARE used in a wiki.
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):
This fix-url-mapping-in-100-places is wrong and will break easily in the future. We should have one place which implement url mapping, and all the code should use same mapped urls.
[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
I don't know why you want to deprecate every feature I need or refuse to see why a feature I want is useful, but I definitely need this because I'm doing some proxying. Also, HelpMiscellaneous has an interesting use-case for url_mappings which replaces the patches in RedirectingExternalLinks. But I already said that above. -- JohannesBerg 2005-02-22 20:42:28
I'm sorry but I don't see any use for this, and the fact it was broken shows that nobody else used it on 1.3 (it worked on 1.2). The only use that the docs show is redirecting external links, which I consider a bad idea, and can be implemented in other ways. If you there is a real need for url_mapping that can not be done by other means, please document this on HelpMiscellaneous. -- NirSoffer 2005-02-22 21:08:29
No. First, please show me how to do the external link redirection easily by other means (I can't see you proposing something on RedirectingExternalLinks, so how would I know?) then we can talk. Also, which I consider a bad idea doesn't really count. -- JohannesBerg 2005-02-22 21:42:57
I'm not going to waste my time on redirecting external links
I guess that says it all. Case closed, please apply above patch after I confirm that it works on my server (and not only my development machine). -- JohannesBerg 2005-02-22 21:53:27
- Nothing closed, we should consider removing this feature before fixing. About simpler solutions, search for "google rel=nofollow"...
- Not really. This is about 1.3. We cannot remove it there.
- Nothing closed, we should consider removing this feature before fixing. About simpler solutions, search for "google rel=nofollow"...
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
- Priority:
- Assigned to:
- Status: Committed second patch (about url_mappings) in patch-846.