Attachment 'ViewTrackbacks.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - "ViewTrackbacks" action
4
5 @copyright: 2004 by Jos Yule <jos@theorganization.net>
6 @license: GNU GPL, see COPYING for details.
7 """
8
9 from MoinMoin import config, util, wikiutil
10 from MoinMoin.Page import Page
11 from xml.sax.handler import ContentHandler
12 from time import strftime, strptime
13 import xml.sax
14
15 class countHandler(ContentHandler):
16 def __init__(self):
17 self.pings = []
18 self.inItem = 0
19 self.currentElement = ''
20 self.currentPing = {}
21
22 def startElement(self, qname, attr):
23 self.currentElement = qname
24 if qname == 'item':
25 #print 'Start Item'
26 self.currentPing = {}
27 self.inItem = 1
28
29 def characters(self, s):
30 if self.inItem == 1:
31 self.currentPing[self.currentElement] = s
32
33 def endElement(self, qname):
34 if qname == 'item':
35 #print 'End Item'
36 self.pings.append(self.currentPing)
37 self.inItem = 0
38
39
40
41
42 def execute(pagename, request):
43 _ = request.getText
44 #get data directory
45 tbFile = config.data_dir + "/trackback/" + wikiutil.quoteFilename(pagename) + ".xml"
46 aMsg = ''
47
48
49 parser = xml.sax.make_parser()
50 handler = countHandler()
51 parser.setContentHandler(handler)
52 try:
53 parser.parse(tbFile)
54 for ping in handler.pings:
55
56 strTemplate = """<p><strong><a href="%s">%s</a></strong>
57 <blockquote>%s</blockquote>
58 on %s from %s"""
59
60 aMsg = strTemplate % (ping.get("link"), ping.get("title", "No title"), ping.get("description", ''), strftime("%c",strptime(ping.get("date"),"%Y-%m-%dT%H:%MZ")), ping.get("blogName", ping.get("link"))) + aMsg
61
62
63 except Exception, x:
64 pass
65
66 request.http_headers()
67 wikiutil.send_title(request, _('Trackbacks for page "%s".') % (pagename,) , pagename=pagename)
68
69 request.write('<div id="content">\n') # start content div
70 request.write(aMsg)
71 request.write('</div>\n') # end content div
72
73 wikiutil.send_footer(request, pagename)
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.