1.1 --- a/MoinShare.py Tue May 07 23:44:34 2013 +0200
1.2 +++ b/MoinShare.py Sat May 11 00:35:03 2013 +0200
1.3 @@ -12,6 +12,11 @@
1.4 from MoinMoin import wikiutil
1.5 import re
1.6
1.7 +try:
1.8 + from cStringIO import StringIO
1.9 +except ImportError:
1.10 + from StringIO import StringIO
1.11 +
1.12 escape = wikiutil.escape
1.13 _getFragments = getFragments
1.14
1.15 @@ -30,6 +35,9 @@
1.16 fragment_attribute = "moinshare"
1.17
1.18 def getFragments(s):
1.19 +
1.20 + "Return all fragments in 's' having the MoinShare fragment attribute."
1.21 +
1.22 fragments = []
1.23 for format, attributes, body in _getFragments(s):
1.24 if attributes.has_key(fragment_attribute):
1.25 @@ -81,4 +89,72 @@
1.26 else:
1.27 return getCurrentTime().as_ISO8601_datetime_string()
1.28
1.29 +def getUpdateSources(request, sources_page):
1.30 +
1.31 + """
1.32 + Using the 'request', return the update sources defined on the given
1.33 + 'sources_page'.
1.34 + """
1.35 +
1.36 + # Remote sources are accessed via dictionary page definitions.
1.37 +
1.38 + return getWikiDict(sources_page, request)
1.39 +
1.40 +def getUpdateFragmentsFromPage(page, request):
1.41 +
1.42 + """
1.43 + Get update fragments from the given 'page' using the 'request'. A list of
1.44 + update descriptions is returned, each being a tuple of the form...
1.45 +
1.46 + (fragment identifer, summary text, preferred mimetypes, textual content,
1.47 + updated datetime)
1.48 + """
1.49 +
1.50 + updates = []
1.51 +
1.52 + # NOTE: Use the updated datetime from the page for updates.
1.53 + # NOTE: The published and updated details would need to be deduced from
1.54 + # NOTE: the page history instead of being taken from the page as a whole.
1.55 +
1.56 + metadata = getMetadata(page)
1.57 + updated = getUpdatedTime(metadata)
1.58 +
1.59 + # Get the fragment regions for the page.
1.60 +
1.61 + for n, (format, attributes, body) in enumerate(getFragments(page.get_raw_body())):
1.62 +
1.63 + # Produce a fragment identifier.
1.64 + # NOTE: Choose a more robust identifier where none is explicitly given.
1.65 +
1.66 + fragment = attributes.get("fragment", str(n))
1.67 + summary = attributes.get("summary", "Update #%d" % n)
1.68 +
1.69 + # Get the preferred content types available for the fragment.
1.70 +
1.71 + preferred = getPreferredOutputTypes(request, getOutputTypes(request, format))
1.72 +
1.73 + # Try and obtain some suitable content for the entry.
1.74 + # NOTE: Could potentially get a summary for the fragment.
1.75 +
1.76 + content = None
1.77 +
1.78 + if "text/html" in preferred:
1.79 + parser_cls = getParserClass(request, format)
1.80 + parser = parser_cls(body, request)
1.81 +
1.82 + if format == "html":
1.83 + content = body
1.84 + elif hasattr(parser, "formatForOutputType"):
1.85 + s = StringIO()
1.86 + parser.formatForOutputType("text/html", write=s.write)
1.87 + content = s.getvalue()
1.88 + else:
1.89 + fmt = request.html_formatter
1.90 + fmt.setPage(page)
1.91 + content = formatText(body, request, fmt, parser_cls)
1.92 +
1.93 + updates.append((fragment, summary, preferred, content, updated))
1.94 +
1.95 + return updates
1.96 +
1.97 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/actions/SharedUpdates.py Tue May 07 23:44:34 2013 +0200
2.2 +++ b/actions/SharedUpdates.py Sat May 11 00:35:03 2013 +0200
2.3 @@ -9,14 +9,9 @@
2.4 from MoinMoin.action import ActionBase
2.5 from MoinMoin.Page import Page
2.6 from MoinMoin import wikiutil
2.7 -from MoinShare import getPreferredOutputTypes, getOutputTypes, getUpdatedTime
2.8 -from MoinSupport import escattr, formatText, get_form, getFragments, \
2.9 - getMetadata, getParserClass, getPathInfo, writeHeaders, ActionSupport
2.10 -
2.11 -try:
2.12 - from cStringIO import StringIO
2.13 -except ImportError:
2.14 - from StringIO import StringIO
2.15 +from MoinShare import getUpdatedTime, getUpdateFragmentsFromPage
2.16 +from MoinSupport import escattr, get_form, getMetadata, getPathInfo, \
2.17 + writeHeaders, ActionSupport
2.18
2.19 escape = wikiutil.escape
2.20
2.21 @@ -122,24 +117,13 @@
2.22 <updated>%(updated)s</updated>\r
2.23 ''' % d)
2.24
2.25 - # Get the fragment regions for the page.
2.26 -
2.27 - for n, (format, attributes, body) in enumerate(getFragments(page.get_raw_body())):
2.28 -
2.29 - # Produce a fragment identifier.
2.30 - # NOTE: Choose a more robust identifier where none is explicitly given.
2.31 -
2.32 - fragment = attributes.get("fragment", str(n))
2.33 - summary = attributes.get("summary", "Update #%d" % n)
2.34 + for fragment, summary, preferred, content, updated in \
2.35 + getUpdateFragmentsFromPage(page, request):
2.36
2.37 # Get the URL that yields only the fragment.
2.38
2.39 fragment_link = "%s?action=SharedUpdate&fragment=%s" % (link, fragment)
2.40
2.41 - # Get the preferred content types available for the fragment.
2.42 -
2.43 - preferred = getPreferredOutputTypes(request, getOutputTypes(request, format))
2.44 -
2.45 download_links = []
2.46
2.47 for mimetype in preferred:
2.48 @@ -148,29 +132,6 @@
2.49 download_links.append('<link rel="alternate" type="%s" href="%s"/>' % (
2.50 escattr(mimetype), escattr(specific_link)))
2.51
2.52 - # Try and obtain some suitable content for the entry.
2.53 - # NOTE: Could potentially get a summary for the fragment.
2.54 -
2.55 - content = None
2.56 -
2.57 - if "text/html" in preferred:
2.58 - parser_cls = getParserClass(request, format)
2.59 - parser = parser_cls(body, request)
2.60 -
2.61 - if format == "html":
2.62 - content = body
2.63 - elif hasattr(parser, "formatForOutputType"):
2.64 - s = StringIO()
2.65 - parser.formatForOutputType("text/html", write=s.write)
2.66 - content = s.getvalue()
2.67 - else:
2.68 - fmt = request.html_formatter
2.69 - fmt.setPage(page)
2.70 - content = formatText(body, request, fmt, parser_cls)
2.71 -
2.72 - # NOTE: The published and updated details would need to be deduced from
2.73 - # NOTE: the page history instead of being taken for the page as a whole.
2.74 -
2.75 d = {
2.76 "title" : escape(summary),
2.77 "fragment_link" : escape(fragment_link),