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.

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...

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

Multiple levels

Middle

At the end

Multiple aliases

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:

-- 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.

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...

-- FabianKreutz (2005-05-24 07:59:23)


CategoryFeatureRequest CategoryMoinMoinPatch

MoinMoin: FeatureRequests/RedirectFromParent (last edited 2007-10-29 19:10:32 by localhost)