*** Page.py 2005-05-23 14:28:32.000000000 +0300 --- Page.py.new 2005-05-23 14:28:32.000000000 +0300 *************** *** 891,896 **** --- 891,931 ---- return subscriber_list + # I hacked this in to make the redirect-on-parent easier. + # The PI-parsing is already remodelled in the devel-branch, so + # this is a temporary hack. TODO + def get_redirect(self): + body = self.get_raw_body() + redirect = None + + # check processing instructions + while body and body[0] == '#': + # extract first line + try: + line, body = body.split('\n', 1) + except ValueError: + line = body + body = '' + + # end parsing on empty (invalid) PI + if line == "#": + body = line + '\n' + body + break + + # skip comments (lines with two hash marks) + if line[1] == '#': continue + + # parse the PI + verb, args = (line[1:]+' ').split(' ', 1) + verb = verb.lower() + args = args.strip() + + if verb == "redirect": + redirect = args + break + + return redirect + def send_page(self, request, msg=None, **keywords): """ *************** *** 925,930 **** --- 960,990 ---- if keywords.get('count_hit', 0): eventlog.EventLog(request).add(request, 'VIEWPAGE', {'pagename': self.page_name}) + # Redirect from parent-pages + if not content_only and \ + self.default_formatter and \ + not request.form.has_key('action') and \ + not request.form.has_key('redirect'): + aparent = request.rootpage + below = self.page_name + testpage = self + while not testpage.exists() and below.count('/'): + above, below = below.split('/', 1) + aparent = Page(request, \ + '/'.join((aparent.page_name, above)).strip('/')) + if aparent.exists(): + redirect = aparent.get_redirect() + if redirect: + aparent = Page(request, redirect) + testpage = Page(request, '/'.join((redirect, below))) + continue + if not self.exists() and testpage.exists(): + request.http_redirect('%s/%s?action=show&redirect=%s' % ( + request.getScriptname(), + wikiutil.quoteWikinameURL(testpage.page_name), + urllib.quote_plus(self.page_name.encode(config.charset), ''),)) + return + # load the text body = self.get_raw_body()