1.1 --- a/actions/SharedUpdates.py Mon May 06 17:16:54 2013 +0200
1.2 +++ b/actions/SharedUpdates.py Mon May 06 19:44:51 2013 +0200
1.3 @@ -2,13 +2,23 @@
1.4 """
1.5 MoinMoin - SharedUpdates Action
1.6
1.7 - @copyright: 2012 by Paul Boddie <paul@boddie.org.uk>
1.8 + @copyright: 2012, 2013 by Paul Boddie <paul@boddie.org.uk>
1.9 @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.10 """
1.11
1.12 from MoinMoin.action import ActionBase
1.13 +from MoinMoin.Page import Page
1.14 from MoinMoin import wikiutil
1.15 -from MoinShare import *
1.16 +from MoinShare import getPreferredOutputTypes, getOutputTypes, getUpdatedTime
1.17 +from MoinSupport import escattr, formatText, get_form, getFragments, \
1.18 + getMetadata, getParserClass, getPathInfo, writeHeaders, ActionSupport
1.19 +
1.20 +try:
1.21 + from cStringIO import StringIO
1.22 +except ImportError:
1.23 + from StringIO import StringIO
1.24 +
1.25 +escape = wikiutil.escape
1.26
1.27 Dependencies = ['pages']
1.28
1.29 @@ -101,6 +111,8 @@
1.30 "updated" : escape(updated),
1.31 }
1.32
1.33 + # Start the output.
1.34 +
1.35 request.write('''\
1.36 <?xml version="1.0" encoding="utf-8"?>\r
1.37 <feed xmlns="http://www.w3.org/2005/Atom">\r
1.38 @@ -136,7 +148,26 @@
1.39 download_links.append('<link rel="alternate" type="%s" href="%s"/>' % (
1.40 escattr(mimetype), escattr(specific_link)))
1.41
1.42 + # Try and obtain some suitable content for the entry.
1.43 # NOTE: Could potentially get a summary for the fragment.
1.44 +
1.45 + content = None
1.46 +
1.47 + if "text/html" in preferred:
1.48 + parser_cls = getParserClass(request, format)
1.49 + parser = parser_cls(body, request)
1.50 +
1.51 + if format == "html":
1.52 + content = body
1.53 + elif hasattr(parser, "formatForOutputType"):
1.54 + s = StringIO()
1.55 + parser.formatForOutputType("text/html", write=s.write)
1.56 + content = s.getvalue()
1.57 + else:
1.58 + fmt = request.html_formatter
1.59 + fmt.setPage(page)
1.60 + content = formatText(body, request, fmt, parser_cls)
1.61 +
1.62 # NOTE: The published and updated details would need to be deduced from
1.63 # NOTE: the page history.
1.64
1.65 @@ -144,16 +175,22 @@
1.66 "title" : escape(summary),
1.67 "fragment_link" : escape(fragment_link),
1.68 "download_links" : "\r\n".join(download_links),
1.69 + "content" : content and ('<content type="html">%s</content>' % escape(content)) or "",
1.70 }
1.71
1.72 + # Write the entry output.
1.73 +
1.74 request.write('''\
1.75 <entry>\r
1.76 <title>%(title)s</title>\r
1.77 <id>%(fragment_link)s</id>\r
1.78 %(download_links)s\r
1.79 +%(content)s\r
1.80 </entry>\r
1.81 ''' % d)
1.82
1.83 + # End the feed output.
1.84 +
1.85 request.write('</feed>\r\n')
1.86
1.87 # Action function.