Redirect a page, when it does not exist, but one of the parent pages is a redirection
We use the MoinMoin wiki to document and explain some words that are used quite often in daily work but rather in an abbreviated form. E.g. the word Ticket Master System is always referred to as TMS. When writing wiki pages, it's also much easier to write "TMS" instead of that long word every time. The solution is a redirection from the abbreviation to the long form (TMS -> TicketMasterSystem).
The TMS also has some sub-subjects that are written in subpages, e.g. TicketMasterSystem/Server. To access this page easily through TMS/Server, one would have to create a new page which is a redirection - redundant data in my opinion.
Solution 1
would be to redirect the other way, i.e. from TicketMasterSystem to TMS, and then always use the abbreviated form in all links.
Solution 2
Instead I hacked a bit into the Page.py and came up with a solution, which will redirect non-existing pages to existing ones, if one of the parent pages specifies the redirect-PI.
Since I'm not a regular Moin-developer, I don't know about the quality of that code. Anyway, here's the code for line 927 in Page.py, before starting to parse the PIs.
1 # Redirect from parent-pages
2 if not content_only and self.default_formatter and not request.form.has_key('action') and not request.form.has_key('redirect'):
3 below = os.path.basename(self.page_name)
4 above = os.path.dirname(self.page_name)
5 testpage = self
6 while above and not testpage.exists():
7 aparent = Page(request, above)
8 if aparent.exists():
9 aparent.parse_PI(request)
10 if aparent._pi.has_key('redirect'):
11 above = aparent._pi['redirect']
12 testpage = Page(request, '/'.join((above, below)))
13 continue
14 below = '/'.join((os.path.basename(above), below))
15 above = os.path.dirname(above)
16 if not self.exists() and testpage.exists():
17 request.http_redirect('%s/%s?action=show&redirect=%s' % (
18 request.getScriptname(),
19 wikiutil.quoteWikinameURL(testpage.page_name),
20 urllib.quote_plus(self.page_name.encode(config.charset), ''),))
21 return
It uses a function Page.parse_PI, which I added, too. I suggest that the whole parsing of the PIs should be separated from the processing in send_page. Up to now I only copied the redirect-if-clause from the parse-loop. Please tell me if you agree to that separation, I would then do that work and post a suggestion-diff.
- We have another branch where send_page has been refactored (and that mess is cleaned up there of course). And the stable branch should not get such heavy edits. So it would be nice if you could supply a patch that can be applied to 1.3 and which does not necessarily introduce such new functions.
That would be pretty much the snippet above. I just realized, however, that it would be smarter to start splitting from root upwards instead of from request-page downwards; so I will rewrite that part. But what is then the best way to fetch the redirect-PI from a Page instance that is not likely to be displayed? Of course I could parse the page's content there and then...
- Yeah, you would need to fetch the page contents.
Take that: contextdiff , it now scans from rootpage upwards. Works fine for my single test-case, please do further testing!
Here are some test cases to make the behavior more clear:
One level
Link: LN/SubPage
Behavior: visit LongName/SubPage
Multiple levels
Link: LN/SubPage/SubSubPage
Behavior: visit LongName/SubPage/SubSubPage
Middle
Link: ParentPage/LN/SubPage
Behavior: visit ParentPage/LongName/SubPage
At the end
Link: ParentPage/LN
Behavior: visit ParentPage/LongName
Multiple aliases
Aliases: LN -> LongName, AO -> AnotherOne
Behavior: visit ParentPage/LongName/SomePage/AnotherOne/LastOne
Seems that we need to expand aliases when building paths. This can be done while formatting links - no redirect needed, or when dispatching requests, by a redirect. If we have all aliases in the wiki cached, they can be expanded when needed.
Other solutions:
Better links syntax like [TicketMasterSystem TSM] [TicketMasterSystem/Server TSM Server]
Meta data based aliases? define aliases to any page in the page meta data: #alias TSM, or aliases page that define alias for other pages.
- Might clash with existing page names
Auto expand list for common terms - you type @TSM@ (or similar syntax) and moin will expand it when you save. To use this, define the vars on a dict page, e.g WikiDict using definition list, then they will be expanded when you save the page. See HelpOnPageCreation.
Make it simpler by using only one name, no aliases. If no one is using the long name use only the short name and put the long name on page, so someone looking for Ticket Master System will find that text on TMS.
-- NirSoffer 2005-05-23 19:59:46
I disagree. The first solution with the []-Syntax is what we do at the moment. It completely disagrees with the easiness of wiki, as you might feel yourself when writing texts like
The [:TicketMasterSystem/Team:TMS/Team] is responsible for maintaining the [TicketMasterSystem TMS] and adinistrating the [:TicketMasterSystem/Server:TMS/Server] where the [:TicketMasterSystem/Database:TMS/Database] is running
Mind that it's not the only abbreviation and nobody ever really mentions most of the long forms. It took me some months to learn what TMS means. Also, I'm trying to convince people to use the wiki, that have never done so before. Forcing them to write these long forms will discourage them very fast.
I don't really understand the second solution. You mean that on the TMS page, which is in fact a redirection, there should be a list of aliases for all subpages? Wherever you write that meta-data, it will be outdated as soon as someone creates a new subpage.
- Have one page that define all aliases in the wiki, like you use .profile or bashrc etc - no more redirect pages. The wiki can cache the page contents like it does with group pages, and use the data when you add an alias to a page.
I didn't know about these WikiDicts. An AT-sign would be OK, while the longer getVal-form again seems a bit to complicated for a thing that can be automated easily.
Anyway, maybe I should rename all pages to use the abbreviated form for the content and the long form for the redirect, since page titles like TicketMasterSystem/CharacterUserInterface or their sub-pages are wider than my browser window. On the other hand TMS/CUI does not look any better...
- I just realized a big flaw: The link to one of these pages is still a non-existent - link, thus gray or with a red questionmark.
-- FabianKreutz (2005-05-24 07:59:23)