1.1 --- a/MoinShare.py Tue May 14 00:53:38 2013 +0200
1.2 +++ b/MoinShare.py Tue May 14 01:37:22 2013 +0200
1.3 @@ -100,14 +100,39 @@
1.4
1.5 return getWikiDict(sources_page, request)
1.6
1.7 -def getUpdateFragmentsFromPage(page, request):
1.8 +# Entry/update classes.
1.9 +
1.10 +class Update:
1.11 +
1.12 + "A feed update entry."
1.13 +
1.14 + def __init__(self):
1.15 + self.title = None
1.16 + self.link = None
1.17 + self.content = None
1.18 + self.content_type = None
1.19 + self.updated = None
1.20 +
1.21 + # Page-related attributes.
1.22 +
1.23 + self.fragment = None
1.24 + self.preferred = None
1.25 +
1.26 + def __cmp__(self, other):
1.27 + if self.updated is None and other.updated is not None:
1.28 + return 1
1.29 + elif self.updated is not None and other.updated is None:
1.30 + return -1
1.31 + else:
1.32 + return cmp(self.updated, other.updated)
1.33 +
1.34 +# Update retrieval from pages.
1.35 +
1.36 +def getUpdatesFromPage(page, request):
1.37
1.38 """
1.39 - Get update fragments from the given 'page' using the 'request'. A list of
1.40 - update descriptions is returned, each being a tuple of the form...
1.41 -
1.42 - (fragment identifer, summary text, preferred mimetypes, textual content,
1.43 - updated datetime)
1.44 + Get updates from the given 'page' using the 'request'. A list of update
1.45 + objects is returned.
1.46 """
1.47
1.48 updates = []
1.49 @@ -126,34 +151,41 @@
1.50 # Produce a fragment identifier.
1.51 # NOTE: Choose a more robust identifier where none is explicitly given.
1.52
1.53 - fragment = attributes.get("fragment", str(n))
1.54 - summary = attributes.get("summary", "Update #%d" % n)
1.55 + update = Update()
1.56 +
1.57 + update.fragment = attributes.get("fragment", str(n))
1.58 + update.title = attributes.get("summary", "Update #%d" % n)
1.59
1.60 # Get the preferred content types available for the fragment.
1.61
1.62 - preferred = getPreferredOutputTypes(request, getOutputTypes(request, format))
1.63 + update.preferred = getPreferredOutputTypes(request, getOutputTypes(request, format))
1.64
1.65 # Try and obtain some suitable content for the entry.
1.66 # NOTE: Could potentially get a summary for the fragment.
1.67
1.68 - content = None
1.69 + update.content = None
1.70
1.71 - if "text/html" in preferred:
1.72 + if "text/html" in update.preferred:
1.73 parser_cls = getParserClass(request, format)
1.74 parser = parser_cls(body, request)
1.75
1.76 if format == "html":
1.77 - content = body
1.78 + update.content = body
1.79 elif hasattr(parser, "formatForOutputType"):
1.80 s = StringIO()
1.81 parser.formatForOutputType("text/html", write=s.write)
1.82 - content = s.getvalue()
1.83 + update.content = s.getvalue()
1.84 else:
1.85 fmt = request.html_formatter
1.86 fmt.setPage(page)
1.87 - content = formatText(body, request, fmt, parser_cls)
1.88 + update.content = formatText(body, request, fmt, parser_cls)
1.89 +
1.90 + update.content_type = "html"
1.91
1.92 - updates.append((fragment, summary, preferred, content, updated))
1.93 + update.link = page.url(request)
1.94 + update.updated = updated
1.95 +
1.96 + updates.append(update)
1.97
1.98 return updates
1.99
2.1 --- a/actions/SharedUpdates.py Tue May 14 00:53:38 2013 +0200
2.2 +++ b/actions/SharedUpdates.py Tue May 14 01:37:22 2013 +0200
2.3 @@ -9,7 +9,7 @@
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 getUpdatedTime, getUpdateFragmentsFromPage
2.8 +from MoinShare import getUpdatedTime, getUpdatesFromPage
2.9 from MoinSupport import escattr, get_form, getMetadata, getPathInfo, \
2.10 writeHeaders, ActionSupport
2.11
2.12 @@ -117,27 +117,26 @@
2.13 <updated>%(updated)s</updated>\r
2.14 ''' % d)
2.15
2.16 - for fragment, summary, preferred, content, updated in \
2.17 - getUpdateFragmentsFromPage(page, request):
2.18 + for update in getUpdatesFromPage(page, request):
2.19
2.20 # Get the URL that yields only the fragment.
2.21
2.22 - fragment_link = "%s?action=SharedUpdate&fragment=%s" % (link, fragment)
2.23 + fragment_link = "%s?action=SharedUpdate&fragment=%s" % (update.link, update.fragment)
2.24
2.25 download_links = []
2.26
2.27 - for mimetype in preferred:
2.28 + for mimetype in update.preferred:
2.29 specific_link = "%s&type=%s&doit=1" % (fragment_link, mimetype)
2.30
2.31 download_links.append('<link rel="alternate" type="%s" href="%s"/>' % (
2.32 escattr(mimetype), escattr(specific_link)))
2.33
2.34 d = {
2.35 - "title" : escape(summary),
2.36 + "title" : escape(update.title),
2.37 "fragment_link" : escape(fragment_link),
2.38 "download_links" : "\r\n".join(download_links),
2.39 - "content" : content and ('<content type="html">%s</content>' % escape(content)) or "",
2.40 - "updated" : escape(updated),
2.41 + "content" : update.content and ('<content type="html">%s</content>' % escape(update.content)) or "",
2.42 + "updated" : escape(update.updated),
2.43 }
2.44
2.45 # Write the entry output.
3.1 --- a/macros/SharedContent.py Tue May 14 00:53:38 2013 +0200
3.2 +++ b/macros/SharedContent.py Tue May 14 01:37:22 2013 +0200
3.3 @@ -10,6 +10,7 @@
3.4 from MoinMoin.Page import Page
3.5 from MoinRemoteSupport import *
3.6 from MoinSupport import parseMacroArguments
3.7 +from MoinShare import getUpdatesFromPage, Update
3.8 from email.utils import parsedate
3.9 import xml.dom.pulldom
3.10
3.11 @@ -55,27 +56,6 @@
3.12 class FeedContentTypeError(FeedError):
3.13 pass
3.14
3.15 -# Entry/update classes.
3.16 -
3.17 -class Update:
3.18 -
3.19 - "A feed update entry."
3.20 -
3.21 - def __init__(self):
3.22 - self.title = None
3.23 - self.link = None
3.24 - self.content = None
3.25 - self.content_type = None
3.26 - self.updated = None
3.27 -
3.28 - def __cmp__(self, other):
3.29 - if self.updated is None and other.updated is not None:
3.30 - return 1
3.31 - elif self.updated is not None and other.updated is None:
3.32 - return -1
3.33 - else:
3.34 - return cmp(self.updated, other.updated)
3.35 -
3.36 # Feed retrieval.
3.37
3.38 def getUpdates(request, feed_url, max_entries, show_content):
3.39 @@ -218,12 +198,15 @@
3.40 _ = request.getText
3.41
3.42 feed_urls = []
3.43 + pagenames = []
3.44 show_content = None
3.45 max_entries = None
3.46
3.47 for arg, value in parseMacroArguments(args):
3.48 if arg == "url":
3.49 feed_urls.append(value)
3.50 + elif arg == "page":
3.51 + pagenames.append(value)
3.52 elif arg == "show":
3.53 show_content = value.lower()
3.54 elif arg == "limit":
3.55 @@ -232,8 +215,8 @@
3.56 except ValueError:
3.57 return fmt.text(_("SharedContent: limit must be set to the maximum number of entries to be shown"))
3.58
3.59 - if not feed_urls:
3.60 - return fmt.text(_("SharedContent: a feed URL must be specified"))
3.61 + if not feed_urls and not pagenames:
3.62 + return fmt.text(_("SharedContent: at least one feed URL or page must be specified"))
3.63
3.64 show_content = show_content or False
3.65 max_entries = max_entries or MAX_ENTRIES
3.66 @@ -256,6 +239,23 @@
3.67 except FeedContentTypeError:
3.68 bad_content.append(feed_url)
3.69
3.70 + # Retrieve updates from pages.
3.71 +
3.72 + for pagename in pagenames:
3.73 + page = Page(request, pagename)
3.74 + updates += getUpdatesFromPage(page, request)
3.75 +
3.76 + # Build feed-equivalent information for the update source.
3.77 +
3.78 + feeds.append((
3.79 + page.url(request), (
3.80 + "internal", _("Updates from page %s") % pagename,
3.81 + page.url(request, {"action" : "SharedUpdates", "doit" : "1"})
3.82 + )
3.83 + ))
3.84 +
3.85 + # Prepare the output.
3.86 +
3.87 output = []
3.88 append = output.append
3.89