# HG changeset patch # User Paul Boddie # Date 1238626793 -7200 # Node ID bc1a37ac27c07fe4c1e019395ea08f31c3c8977b # Parent c59f92f89613b4b838869454acfa53b1726f1297 Added support for MoinMoin 1.5.x and 1.6.x in page format detection, edit details retrieval, title splitting, action method signatures, HTTP response generation, and link generation. Added a note about the bundled pages. diff -r c59f92f89613 -r bc1a37ac27c0 EventAggregatorSupport.py --- a/EventAggregatorSupport.py Tue Mar 31 00:43:20 2009 +0200 +++ b/EventAggregatorSupport.py Thu Apr 02 00:59:53 2009 +0200 @@ -92,7 +92,11 @@ # From MoinMoin.xmlrpc... - edit_info = page.edit_info() + if hasattr(page, "edit_info"): + edit_info = page.edit_info() + else: + edit_info = page.last_edit(page.request) # MoinMoin 1.5.x and 1.6.x + mtime = wikiutil.version2timestamp(long(edit_info['timestamp'])) # must be long for py 2.2.x return tuple(time.gmtime(mtime)) @@ -128,14 +132,23 @@ return "".join([s for s in verbatim_regexp.split(text) if s is not None]) +def getFormat(page): + + "Get the format used on 'page'." + + if isMoin15(): + return "wiki" # page.pi_format + else: + return page.pi["format"] + def getEventDetails(page): "Return a dictionary of event details from the given 'page'." event_details = {} - if page.pi["format"] == "wiki": - for match in definition_list_regexp.finditer(page.body): + if getFormat(page) == "wiki": + for match in definition_list_regexp.finditer(page.get_raw_body()): # Permit case-insensitive list terms. @@ -587,7 +600,12 @@ "Return a nicely formatted title/name for the given 'page'." - return page.split_title(force=1).replace("_", " ").replace("/", u" » ") + if isMoin15(): + title = page.split_title(page.request, force=1) + else: + title = page.split_title(force=1) + + return title.replace("_", " ").replace("/", u" » ") def getMonthLabel(month): @@ -601,4 +619,21 @@ return weekday_labels[weekday] +def linkToPage(request, page, text, query_string=None): + + """ + Using 'request', return a link to 'page' with the given link 'text' and + optional 'query_string'. + """ + + text = wikiutil.escape(text) + + 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) + # vim: tabstop=4 expandtab shiftwidth=4 diff -r c59f92f89613 -r bc1a37ac27c0 README.txt --- a/README.txt Tue Mar 31 00:43:20 2009 +0200 +++ b/README.txt Thu Apr 02 00:59:53 2009 +0200 @@ -60,6 +60,13 @@ On non-UNIX platforms, it is necessary to manually copy the contents of the actions directory in this distribution into the actions directory of your Wiki. +Useful Pages +------------ + +The pages directory contains a selection of useful pages using a syntax +appropriate for use with MoinMoin 1.6 or later. These pages can be created +through the Wiki and their contents copied in from each of the files. + Using the Macro --------------- diff -r c59f92f89613 -r bc1a37ac27c0 actions/EventAggregatorSummary.py --- a/actions/EventAggregatorSummary.py Tue Mar 31 00:43:20 2009 +0200 +++ b/actions/EventAggregatorSummary.py Thu Apr 02 00:59:53 2009 +0200 @@ -13,6 +13,7 @@ from MoinMoin.action import ActionBase from MoinMoin import config from MoinMoin.Page import Page +import MoinMoin.util # for MoinMoin 1.5.x import EventAggregatorSupport Dependencies = ['pages'] @@ -111,11 +112,12 @@ write_resource(self.request) return 1, None - def render_success(self, msg, msgtype): + def render_success(self, msg, msgtype=None): """ Render neither 'msg' nor 'msgtype' since a resource has already been produced. + NOTE: msgtype is optional because MoinMoin 1.5.x does not support it. """ pass @@ -157,7 +159,12 @@ # Output iCalendar data... - request.emit_http_headers(["Content-Type: text/calendar; charset=%s" % config.charset]) + if EventAggregatorSupport.isMoin15(): + send_headers = request.http_headers + else: + send_headers = request.emit_http_headers + + send_headers(["Content-Type: text/calendar; charset=%s" % config.charset]) request.write("BEGIN:VCALENDAR\r\n") request.write("PRODID:-//MoinMoin//EventAggregatorSummary\r\n") @@ -205,6 +212,9 @@ request.write("END:VCALENDAR\r\n") + if EventAggregatorSupport.isMoin15(): + raise MoinMoin.util.MoinMoinNoFooter + # Action function. def execute(pagename, request): diff -r c59f92f89613 -r bc1a37ac27c0 macros/EventAggregator.py --- a/macros/EventAggregator.py Tue Mar 31 00:43:20 2009 +0200 +++ b/macros/EventAggregator.py Thu Apr 02 00:59:53 2009 +0200 @@ -12,6 +12,8 @@ import EventAggregatorSupport import calendar +linkToPage = EventAggregatorSupport.linkToPage + try: set except NameError: @@ -163,10 +165,10 @@ output.append(fmt.div(on=1, css_class="event-controls")) output.append(fmt.span(on=1, css_class="event-download-calendar")) - output.append(page.link_to_raw(request, wikiutil.escape(_("Download this calendar in iCalendar format")), download_link)) + output.append(linkToPage(request, page, _("Download this calendar in iCalendar format"), download_link)) output.append(fmt.span(on=0)) output.append(fmt.span(on=1, css_class="event-download-all")) - output.append(page.link_to_raw(request, wikiutil.escape(_("Download all events in iCalendar format")), download_all_link)) + output.append(linkToPage(request, page, _("Download all events in iCalendar format"), download_all_link)) output.append(fmt.span(on=0)) output.append(fmt.div(on=0)) @@ -210,9 +212,9 @@ ) output.append(fmt.span(on=1, css_class="previous-month")) - output.append(page.link_to_raw(request, wikiutil.escape("<<"), previous_set_link)) + output.append(linkToPage(request, page, "<<", previous_set_link)) output.append(fmt.text(" ")) - output.append(page.link_to_raw(request, wikiutil.escape("<"), previous_month_link)) + output.append(linkToPage(request, page, "<", previous_month_link)) output.append(fmt.span(on=0)) # Links to the next set of months and to a calendar shifted @@ -228,9 +230,9 @@ ) output.append(fmt.span(on=1, css_class="next-month")) - output.append(page.link_to_raw(request, wikiutil.escape(">"), next_month_link)) + output.append(linkToPage(request, page, ">", next_month_link)) output.append(fmt.text(" ")) - output.append(page.link_to_raw(request, wikiutil.escape(">>"), next_set_link)) + output.append(linkToPage(request, page, ">>", next_set_link)) output.append(fmt.span(on=0)) # A link leading to this month being at the top of the calendar. @@ -242,7 +244,7 @@ getMonthQueryString(calendar_name, "start", (year, month)), getMonthQueryString(calendar_name, "end", end_month) ) - output.append(page.link_to_raw(request, wikiutil.escape(full_month_label), month_link)) + output.append(linkToPage(request, page, full_month_label, month_link)) else: output.append(fmt.span(on=1)) @@ -411,7 +413,7 @@ if not hide_text: output.append(fmt.div(on=1, css_class=(" ".join(css_classes)), style=style)) - output.append(event_page.link_to_raw(request, wikiutil.escape(event_summary))) + output.append(linkToPage(request, event_page, event_summary)) else: output.append(fmt.div(on=1, css_class=(" ".join(css_classes)), style=hidden_style)) output.append(fmt.text(event_summary)) @@ -467,7 +469,7 @@ # Link to the page using the summary. output.append(fmt.paragraph(on=1)) - output.append(event_page.link_to_raw(request, wikiutil.escape(event_summary))) + output.append(linkToPage(request, event_page, event_summary)) output.append(fmt.paragraph(on=0)) # Start and end dates.