# HG changeset patch # User Paul Boddie # Date 1238540220 -7200 # Node ID fc1b55a3a89609a8cf2f32ec8fb8224cc93d61ff # Parent 780fb266c7c0f9c5908211b3d6dbcd19cfb2224a Restored MoinMoin 1.5.x support. Changed the presentation of subpage entries. diff -r 780fb266c7c0 -r fc1b55a3a896 README.txt --- a/README.txt Sat Mar 07 19:44:04 2009 +0100 +++ b/README.txt Wed Apr 01 00:57:00 2009 +0200 @@ -87,6 +87,13 @@ Copyright and licence information can be found in the docs directory - see docs/COPYING.txt and docs/LICENCE.txt for more information. +New in CategoryMenu 0.3 (Changes since CategoryMenu 0.2) +-------------------------------------------------------- + + * Restored MoinMoin 1.5.x compatibility. + * Changed the presentation of subpages in the menu, using » instead of an + em-dash. + New in CategoryMenu 0.2 (Changes since CategoryMenu 0.1) -------------------------------------------------------- diff -r 780fb266c7c0 -r fc1b55a3a896 macros/CategoryMenu.py --- a/macros/CategoryMenu.py Sat Mar 07 19:44:04 2009 +0100 +++ b/macros/CategoryMenu.py Wed Apr 01 00:57:00 2009 +0200 @@ -12,7 +12,7 @@ from MoinMoin import wikiutil, search, version import re -__version__ = "0.2" +__version__ = "0.3" Dependencies = ['pages'] @@ -90,11 +90,35 @@ pages.append(page) return pages -def getPrettyPageName(page): +def getPrettyPageName(request, page): + + """ + Using 'request', return a nicely formatted title/name for the given 'page'. + """ + + if isMoin15(): + title = page.split_title(request, force=1) + else: + title = page.split_title(force=1) + + return title.replace("_", " ").replace("/", u" » ") + +def linkToPage(request, page, text, query_string=None): - "Return a nicely formatted title/name for the given 'page'." + """ + Using 'request', return a link to 'page' with the given link 'text' and + optional 'query_string'. + """ + + text = wikiutil.escape(text) - return page.split_title(force=1).replace("_", " ").replace("/", u" » ") + if isMoin15(): + url = wikiutil.quoteWikinameURL(page.page_name) + if query_string is not None: + url = "%s?%s" % (url, query_string) + return wikiutil.link_tag(request, url, text, getattr(page, "formatter", None)) + else: + return page.link_to_raw(request, text, query_string) def execute(macro, args): @@ -169,8 +193,9 @@ real_page_in_category = Page(request, pagename) # Get a pretty version of the page name. + # NOTE: MoinMoin 1.5: request supplied. - pretty_pagename = getPrettyPageName(real_page_in_category) + pretty_pagename = getPrettyPageName(request, real_page_in_category) if page.page_name == pagename: output.append(fmt.listitem(on=1, attr={"class" : "selected"})) @@ -179,7 +204,7 @@ # Abbreviate long hierarchical names. - parts = pagename.split("/") + parts = pretty_pagename.split(u" » ") common = 0 for last, current in map(None, last_parts, parts): if last == current: @@ -187,16 +212,16 @@ else: break - # Use an em-dash to indicate subpages. + # Use the arrows to indicate subpages. - prefix = u"\u2014" * common - suffix = "/".join(parts[common:]) + prefix = u" » " * common + suffix = u" » ".join(parts[common:]) output.append(fmt.text(prefix)) # Link to the page using the pretty name. - output.append(real_page_in_category.link_to_raw(request, wikiutil.escape(pretty_pagename))) + output.append(linkToPage(request, real_page_in_category, suffix)) output.append(fmt.listitem(on=0)) last_parts = parts