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