6
6
http://feedvalidator.org/
8
@copyright: 2006-2007 MoinMoin:ThomasWaldmann
8
9
@license: GNU GPL, see COPYING for details.
10
import StringIO, re, os, time
11
import StringIO, re, time
11
12
from MoinMoin import wikixml, config, wikiutil
12
13
from MoinMoin.logfile import editlog
13
from MoinMoin.util import timefuncs, MoinMoinNoFooter
14
from MoinMoin.util import timefuncs
14
15
from MoinMoin.Page import Page
15
16
from MoinMoin.wikixml.util import RssGenerator
18
def full_url(request, page, querystr=None, anchor=None):
19
url = page.url(request, anchor=anchor, querystr=querystr)
20
url = wikiutil.escape(url)
21
return request.getQualifiedURL(url)
17
23
def execute(pagename, request):
18
24
""" Send recent changes as an RSS document
21
#XXX send error message
27
httpheaders = ["Content-Type: text/plain; charset=%s" % config.charset]
28
request.emit_http_headers(httpheaders)
29
request.write("rss_rc action is not supported because of missing pyxml module.")
44
52
ddiffs = int(request.form.get('ddiffs', [0])[0])
47
# calculating diffs is expensive, so limit this:
48
if diffs and max_items > 5:
52
57
log = editlog.EditLog(request)
57
62
for line in log.reverse():
58
63
if not request.user.may.read(line.pagename):
60
if ((line.action[:4] != 'SAVE') or
65
if (not line.action.startswith('SAVE') or
61
66
((line.pagename in pages) and unique)): continue
62
67
#if log.dayChanged() and log.daycount > _MAX_DAYS: break
63
68
line.editor = line.getInterwikiEditorData(request)
81
86
if request.if_modified_since == timestamp:
82
87
if request.if_none_match:
83
88
if request.if_none_match == etag:
84
request.http_headers(["Status: 304 Not modified"])
85
request.setResponseCode(304)
89
request.emit_http_headers(["Status: 304 Not modified"])
87
request.http_headers(["Status: 304 Not modified"])
88
request.setResponseCode(304)
91
request.emit_http_headers(["Status: 304 Not modified"])
89
92
elif request.if_none_match == etag:
90
93
if request.if_modified_since:
91
94
if request.if_modified_since == timestamp:
92
request.http_headers(["Status: 304 Not modified"])
93
request.setResponseCode(304)
95
request.emit_http_headers(["Status: 304 Not modified"])
95
request.http_headers(["Status: 304 Not modified"])
96
request.setResponseCode(304)
97
request.emit_http_headers(["Status: 304 Not modified"])
98
99
# generate an Expires header, using whatever setting the admin
99
100
# defined for suggested cache lifetime of the RecentChanges RSS doc
105
106
"Etag: %s" % etag, ]
107
108
# send the generated XML document
108
request.http_headers(httpheaders)
109
request.emit_http_headers(httpheaders)
110
interwiki = request.getBaseURL()
111
if interwiki[-1] != "/":
112
interwiki = interwiki + "/"
111
baseurl = request.getBaseURL()
112
if not baseurl.endswith('/'):
114
115
logo = re.search(r'src="([^"]*)"', cfg.logo_string)
141
142
(handler.xmlns['rdf'], 'about'): request.getBaseURL(),
143
144
handler.simpleNode('title', cfg.sitename)
144
handler.simpleNode('link', interwiki + wikiutil.quoteWikinameURL(pagename))
145
page = Page(request, pagename)
146
handler.simpleNode('link', full_url(request, page))
145
147
handler.simpleNode('description', 'RecentChanges at %s' % cfg.sitename)
147
149
handler.simpleNode('image', None, {
153
155
handler.startNode('items')
154
156
handler.startNode(('rdf', 'Seq'))
155
157
for item in logdata:
156
link = "%s%s#%04d%02d%02d%02d%02d%02d" % ((interwiki,
157
wikiutil.quoteWikinameURL(item.pagename),) + item.time[:6])
158
handler.simpleNode(('rdf', 'li'), None, attr={
159
(handler.xmlns['rdf'], 'resource'): link,
158
anchor = "%04d%02d%02d%02d%02d%02d" % item.time[:6]
159
page = Page(request, item.pagename)
160
link = full_url(request, page, anchor=anchor)
161
handler.simpleNode(('rdf', 'li'), None, attr={(handler.xmlns['rdf'], 'resource'): link, })
161
162
handler.endNode(('rdf', 'Seq'))
162
163
handler.endNode('items')
163
164
handler.endNode('channel')
168
169
(handler.xmlns['rdf'], 'about'): logo,
170
171
handler.simpleNode('title', cfg.sitename)
171
handler.simpleNode('link', interwiki)
172
handler.simpleNode('link', baseurl)
172
173
handler.simpleNode('url', logo)
173
174
handler.endNode('image')
176
177
for item in logdata:
177
178
page = Page(request, item.pagename)
178
link = interwiki + wikiutil.quoteWikinameURL(item.pagename)
179
rdflink = "%s#%04d%02d%02d%02d%02d%02d" % ((link,) + item.time[:6])
180
handler.startNode('item', attr={
181
(handler.xmlns['rdf'], 'about'): rdflink,
179
anchor = "%04d%02d%02d%02d%02d%02d" % item.time[:6]
180
rdflink = full_url(request, page, anchor=anchor)
181
handler.startNode('item', attr={(handler.xmlns['rdf'], 'about'): rdflink, })
184
183
# general attributes
185
184
handler.simpleNode('title', item.pagename)
187
handler.simpleNode('link', link+"?action=diff")
186
handler.simpleNode('link', full_url(request, page, querystr={'action': 'diff'}))
189
handler.simpleNode('link', link)
188
handler.simpleNode('link', full_url(request, page))
191
190
handler.simpleNode(('dc', 'date'), timefuncs.W3CDate(item.time))
201
200
for idx in range(rl):
202
201
rev = revisions[idx]
203
202
if rev <= item.rev:
205
204
lines = wikiutil.pagediff(request, item.pagename, revisions[idx+1], item.pagename, 0, ignorews=1)
206
205
if len(lines) > 20:
207
206
lines = lines[:20] + ['...\n']
218
217
edattr[(handler.xmlns['wiki'], 'host')] = item.hostname
219
218
if item.editor[0] == 'interwiki':
220
219
edname = "%s:%s" % item.editor[1]
221
##edattr[(None, 'link')] = interwiki + wikiutil.quoteWikiname(edname)
220
##edattr[(None, 'link')] = baseurl + wikiutil.quoteWikiname(edname)
223
222
edname = item.editor[1]
224
223
##edattr[(None, 'link')] = link + "?action=info"
235
234
# wiki extensions
236
235
handler.simpleNode(('wiki', 'version'), "%i" % (item.ed_time_usecs))
237
236
handler.simpleNode(('wiki', 'status'), ('deleted', 'updated')[page.exists()])
238
handler.simpleNode(('wiki', 'diff'), link + "?action=diff")
239
handler.simpleNode(('wiki', 'history'), link + "?action=info")
240
# handler.simpleNode(('wiki', 'importance'), ) # ( major | minor )
241
# handler.simpleNode(('wiki', 'version'), ) # ( #PCDATA )
237
handler.simpleNode(('wiki', 'diff'), full_url(request, page, querystr={'action': 'diff'}))
238
handler.simpleNode(('wiki', 'history'), full_url(request, page, querystr={'action': 'info'}))
239
# handler.simpleNode(('wiki', 'importance'), ) # ( major | minor )
240
# handler.simpleNode(('wiki', 'version'), ) # ( #PCDATA )
243
242
handler.endNode('item')