1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - SharedUpdates Action 4 5 @copyright: 2012 by Paul Boddie <paul@boddie.org.uk> 6 @license: GNU GPL (v2 or later), see COPYING.txt for details. 7 """ 8 9 from MoinMoin.action import ActionBase 10 from MoinMoin import wikiutil 11 from MoinShare import * 12 13 Dependencies = ['pages'] 14 15 # Action class and supporting functions. 16 17 class SharedUpdates(ActionBase, ActionSupport): 18 19 "A summary dialogue requesting various parameters." 20 21 def get_form_html(self, buttons_html): 22 _ = self._ 23 request = self.request 24 form = self.get_form() 25 page = self.page 26 27 pagename = form.get("pagename", [page.page_name])[0] 28 29 d = { 30 "buttons_html" : buttons_html, 31 "pagename_label" : escape(_("Page name for updates")), 32 "pagename" : escattr(pagename), 33 } 34 35 return ''' 36 <table> 37 <tr> 38 <td class="label"><label>%(pagename_label)s</label></td> 39 <td class="content"> 40 <input name="pagename" type="text" size="40" value="%(pagename)s" /> 41 </td> 42 </tr> 43 <tr> 44 <td></td> 45 <td class="buttons"> 46 %(buttons_html)s 47 </td> 48 </tr> 49 </table> 50 ''' % d 51 52 def do_action(self): 53 54 "Write the syndication resource." 55 56 write_resource(self.request) 57 return 1, None 58 59 def render_success(self, msg, msgtype=None): 60 61 """ 62 Render neither 'msg' nor 'msgtype' since a resource has already been 63 produced. 64 NOTE: msgtype is optional because MoinMoin 1.5.x does not support it. 65 """ 66 67 pass 68 69 def write_resource(request): 70 71 """ 72 For the given 'request', write an Atom summary of updates found on the 73 specified page. 74 See: http://tools.ietf.org/html/rfc4287 75 """ 76 77 form = get_form(request) 78 79 pagename = form.get("pagename", [request.page.page_name])[0] 80 81 page = Page(request, pagename) 82 metadata = getMetadata(page) 83 84 # Output summary data... 85 86 writeHeaders(request, "application/atom+xml", metadata) 87 updated = getUpdatedTime(metadata) 88 89 # Atom output... 90 91 # Using the page name and the page URL in the title, link and 92 # subtitle. 93 94 path_info = getPathInfo(request) 95 link = "%s%s" % (request.getBaseURL(), path_info) 96 97 d = { 98 "title" : escape(path_info[1:]), 99 "link" : escape(link), 100 "href" : escattr(link), 101 "updated" : escape(updated), 102 } 103 104 request.write('''\ 105 <?xml version="1.0" encoding="utf-8"?>\r 106 <feed xmlns="http://www.w3.org/2005/Atom">\r 107 <title type="text">%(title)s</title>\r 108 <subtitle type="text">Shared updates published on %(link)s</subtitle>\r 109 <link rel="self" href="%(href)s"/>\r 110 <updated>%(updated)s</updated>\r 111 ''' % d) 112 113 # Get the fragment regions for the page. 114 115 for n, (format, attributes, body) in enumerate(getFragments(page.get_raw_body())): 116 117 # Produce a fragment identifier. 118 # NOTE: Choose a more robust identifier where none is explicitly given. 119 120 fragment = attributes.get("fragment", str(n)) 121 summary = attributes.get("summary", "Update #%d" % n) 122 123 # Get the URL that yields only the fragment. 124 125 fragment_link = "%s?action=SharedUpdate&fragment=%s" % (link, fragment) 126 127 # Get the preferred content types available for the fragment. 128 129 preferred = getPreferredOutputTypes(request, getOutputTypes(request, format)) 130 131 download_links = [] 132 133 for mimetype in preferred: 134 specific_link = "%s&type=%s&doit=1" % (fragment_link, mimetype) 135 136 download_links.append('<link rel="alternate" type="%s" href="%s"/>' % ( 137 escattr(mimetype), escattr(specific_link))) 138 139 # NOTE: Could potentially get a summary for the fragment. 140 # NOTE: The published and updated details would need to be deduced from 141 # NOTE: the page history. 142 143 d = { 144 "title" : escape(summary), 145 "fragment_link" : escape(fragment_link), 146 "download_links" : "\r\n".join(download_links), 147 } 148 149 request.write('''\ 150 <entry>\r 151 <title>%(title)s</title>\r 152 <id>%(fragment_link)s</id>\r 153 %(download_links)s\r 154 </entry>\r 155 ''' % d) 156 157 request.write('</feed>\r\n') 158 159 # Action function. 160 161 def execute(pagename, request): 162 SharedUpdates(pagename, request).render() 163 164 # vim: tabstop=4 expandtab shiftwidth=4