00001
00002 """
00003 MoinMoin - Navigation Macro
00004
00005 @copyright: 2003 by Jürgen Hermann <jh@web.de>
00006 @license: GNU GPL, see COPYING for details.
00007 """
00008
00009 import re, string
00010 from MoinMoin import config
00011
00012 from MoinMoin.Page import Page
00013
00014 Dependencies = ["namespace"]
00015
00016 def _getPages(request, pagename):
00017 """ Return a (filtered) list of pages names.
00018 """
00019 page = Page(request, pagename)
00020
00021 links = page.getPageLinks(request)
00022 return links
00023
00024 class Navigation:
00025 """ Dispatcher class implementing the navigation schemes.
00026 """
00027
00028
00029 PROJECTION = 'action=print&media=projection'
00030
00031 def __init__(self, macro, args):
00032 """ Prepare common values used during processing.
00033 """
00034 self.macro = macro
00035 self.args = args.split(',')
00036 self._ = self.macro.request.getText
00037
00038 self.pagename = self.macro.formatter.page.page_name
00039 self.print_mode = self.macro.request.form.has_key('action') \
00040 and self.macro.request.form['action'][0] == 'print'
00041 self.media = self.macro.request.form.get('media', [None])[0]
00042 self.querystr = self.print_mode and self.PROJECTION or ''
00043
00044 def dispatch(self):
00045 """ Return None if in plain print mode (no navigational
00046 elements in printouts), else the proper HTML code.
00047 """
00048
00049 return self.do_siblings(self.args[0])
00050
00051
00052 def do_siblings(self, parentPage, root=None):
00053 """ Navigate from a subpage to its siblings.
00054 """
00055 _ = self._
00056
00057
00058 result = []
00059 children = _getPages(self.macro.request, parentPage)
00060 for child in children:
00061
00062
00063 if child.startswith("Category"): continue
00064 shortname = child
00065 if child.startswith(parentPage):
00066 shortname = child[len(parentPage):]
00067
00068 parts = string.split(child, "/")
00069 shortname = parts[-1]
00070
00071 if not shortname: continue
00072
00073 if child == self.pagename:
00074
00075 result.append(self.macro.formatter.text(shortname))
00076 else:
00077
00078 result.append(Page(self.macro.request, child).link_to(self.macro.request, text=shortname))
00079
00080
00081 return ' | '.join(result)
00082
00083
00084
00085
00086 def execute(macro, args):
00087
00088 navi = Navigation(macro, args or '').dispatch()
00089
00090 if navi:
00091
00092 return navi
00093
00094
00095 return ''
00096