[Moin-devel] [Patch] Generating relative links

Carl Worth cworth at cworth.org
Mon Nov 22 13:11:04 EST 2004


I've got a (perhaps uncommon[*]) wish for moin to generate relative
links. For example, I'd like /path/to/moin/SomePage to have
href="OtherPage" rather than href="/path/to/moin/OtherPage".

I've put together an initial attempt at this. The patch is available
from:

http://cworth.org/~cworth/patches/moin_relative_cworth_20041122.patch

The patch is against version 1.2.4 (as found in recent
Debian/unstable). Let me know if I should regenerate it against a newer
version.

This patch adds a new configuration option "relative_links" which
defaults to False.

I was hoping to be able to write the patch such that it would be easy to
guarantee that the behavior was unchanged if the new option stayed at
it's default setting. However, the code often has:

	"%s/%s" % (request.getScriptname(), pagename)

which has an explicit '/' in it. In order to get relative links, I had
to change all instances of this construct into:

	"%s%s" % (request.getRelativeScriptname(), pagename)

where the new getRelativeScriptname is quite simply:

    def getRelativeScriptname(self):
        if config.relative_links:
            return ''
        else:
            return self.getScriptname() + '/'

I've tested the patch by bringing up a test wiki and clicking on pretty
much everything. It seems to work, but I haven't test inter-wiki things
at all, so they are likely broken.

If anyone could take a look at this patch and provide feedback, that
would be great.

-Carl

[*] Here's the motivation for this patch. I'm trying to serve a website
that consists of mixed wiki and non-wiki content, but I'm trying to
completely hid this implementation detail from the user.

For example, I might have:

	/var/www/static/index.html
and:	/var/wiki/data/text/FrontPage

And I want to be able to use URLs of the form:

	http://foo.org/static
	http://foo.org/FrontPage

where the wiki vs. non-wiki nature is hidden from the URL.

The approach I'm using right now is to point the web server document
root at my static pages, and then configure htpp://foo.org/wiki to point
at the wiki stuff.

Then, I hide the "/wiki" prefix with Apache's rewrite module to achieve
a conditional proxy pass for existing wiki pages:

	RewriteEngine on
        RewriteCond /var/wiki/data/text$1 -f
        RewriteRule (.*) http://foo.org/wiki$1 [proxy,last]

That does work for typing in a URL directly, such as:

	http://foo.org/FrontPage

But as soon as I click on a link I get what I don't want:

	http://foo.org/wiki/RecentChanges

With the patch, I get the desired URL:

	http://foo.org/RecentChanges








More information about the Moin-devel mailing list