# HG changeset patch # User Paul Boddie # Date 1339889499 -7200 # Node ID 3ca98b7e975bcf4554ef29665480d80085281300 # Parent fbc23cb12279288a1ab741e766d7590f4a34b2d9 Added an action to publish fragment information for pages. diff -r fbc23cb12279 -r 3ca98b7e975b actions/SharedUpdates.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/actions/SharedUpdates.py Sun Jun 17 01:31:39 2012 +0200 @@ -0,0 +1,186 @@ +# -*- coding: iso-8859-1 -*- +""" + MoinMoin - SharedUpdates Action + + @copyright: 2012 by Paul Boddie + @license: GNU GPL (v2 or later), see COPYING.txt for details. +""" + +from MoinMoin.action import ActionBase +from MoinMoin import config +from MoinMoin import wikiutil +from MoinShare import * +from DateSupport import getCurrentTime + +Dependencies = ['pages'] + +# Action class and supporting functions. + +class SharedUpdates(ActionBase, ActionSupport): + + "A summary dialogue requesting various parameters." + + def get_form_html(self, buttons_html): + _ = self._ + request = self.request + form = self.get_form() + page = self.page + + pagename = form.get("pagename", [page.page_name])[0] + + d = { + "buttons_html" : buttons_html, + "pagename_label" : escape(_("Page name for updates")), + "pagename" : escattr(pagename), + } + + return ''' + + + + + + + + + +
+ +
+ %(buttons_html)s +
+''' % d + + def do_action(self): + + "Write the syndication resource." + + _ = self._ + form = self.get_form() + + # If no page name exists in the request, an error message is returned. + + pagename = form.get("pagename", []) + + if not pagename: + return 0, _("No page name for updates specified.") + + write_resource(self.request) + return 1, None + + 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 + +def write_resource(request): + + """ + For the given 'request', write an Atom summary of updates found on the + specified page. + See: http://tools.ietf.org/html/rfc4287 + """ + + form = get_form(request) + + pagename = form.get("pagename")[0] + + # Output summary data... + + send_headers = get_send_headers(request) + + # Define headers. + + headers = ["Content-Type: application/atom+xml; charset=%s" % config.charset] + + # Define the last modified time. + # NOTE: We could get edits since a certain time and only process those. + + page = Page(request, pagename) + metadata = getMetadata(page) + + if metadata.has_key("last-modified"): + latest_timestamp = metadata["last-modified"] + headers.append("Last-Modified: %s" % latest_timestamp.as_HTTP_datetime_string()) + updated = latest_timestamp.as_ISO8601_datetime_string() + else: + updated = getCurrentTime().as_ISO8601_datetime_string() + + send_headers(headers) + + # Atom output... + + # Using the page name and the page URL in the title, link and + # subtitle. + + path_info = getPathInfo(request) + link = "%s%s" % (request.getBaseURL(), path_info) + + d = { + "title" : escape(path_info[1:]), + "link" : escape(link), + "href" : escattr(link), + "updated" : escape(updated), + } + + request.write('''\ +\r + \r + %(title)s\r + Shared updates published on %(link)s\r + \r + %(updated)s\r +''' % d) + + # Get the fragment regions for the page. + + for n, (format, attributes, body) in enumerate(getFragments(page.get_raw_body())): + + # Produce a fragment identifier. + # NOTE: Choose a more robust identifier where none is explicitly given. + + fragment = attributes.get("fragment", str(n)) + summary = attributes.get("summary", "Update #%d" % n) + + # Get the URL that yields only the fragment. + + fragment_link = "%s?action=ShowUpdate&fragment=%s" % (link, fragment) + + request.write('\r\n') + request.write('%s\r\n' % escape(summary)) + request.write('%s\r\n' % escape(fragment_link)) + + # Get the types available for the fragment. + # This uses an extended parser API method if available. + + parser = getParserClass(request, format) + if hasattr(parser, "getOutputTypes"): + mimetypes = parser.getOutputTypes() + else: + mimetypes = ["text/html"] + + for mimetype in mimetypes: + specific_link = "%s&mimetype=%s" % (fragment_link, mimetype) + + request.write('\r\n' % ( + escattr(mimetype), escattr(specific_link))) + + # NOTE: Could potentially get a summary for the fragment. + # NOTE: The published and updated details would need to be deduced from + # NOTE: the page history. + + request.write('\r\n') + + request.write('\r\n') + +# Action function. + +def execute(pagename, request): + SharedUpdates(pagename, request).render() + +# vim: tabstop=4 expandtab shiftwidth=4