~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/action/rss_rc.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
    http://feedvalidator.org/
7
7
 
 
8
    @copyright: 2006-2007 MoinMoin:ThomasWaldmann
8
9
    @license: GNU GPL, see COPYING for details.
9
10
"""
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
16
17
 
 
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)
 
22
 
17
23
def execute(pagename, request):
18
24
    """ Send recent changes as an RSS document
19
25
    """
20
26
    if not wikixml.ok:
21
 
        #XXX send error message
22
 
        pass
 
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.")
 
30
        return
23
31
 
24
32
    cfg = request.cfg
25
33
 
44
52
        ddiffs = int(request.form.get('ddiffs', [0])[0])
45
53
    except ValueError:
46
54
        ddiffs = 0
47
 
    # calculating diffs is expensive, so limit this:
48
 
    if diffs and max_items > 5:
49
 
        max_items = 5
50
55
 
51
56
    # get data
52
57
    log = editlog.EditLog(request)
57
62
    for line in log.reverse():
58
63
        if not request.user.may.read(line.pagename):
59
64
            continue
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"])
86
90
        else:
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"])
94
96
        else:
95
 
            request.http_headers(["Status: 304 Not modified"])
96
 
            request.setResponseCode(304)
 
97
            request.emit_http_headers(["Status: 304 Not modified"])
97
98
    else:
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, ]
106
107
 
107
108
        # send the generated XML document
108
 
        request.http_headers(httpheaders)
 
109
        request.emit_http_headers(httpheaders)
109
110
 
110
 
        interwiki = request.getBaseURL()
111
 
        if interwiki[-1] != "/":
112
 
            interwiki = interwiki + "/"
 
111
        baseurl = request.getBaseURL()
 
112
        if not baseurl.endswith('/'):
 
113
            baseurl += '/'
113
114
 
114
115
        logo = re.search(r'src="([^"]*)"', cfg.logo_string)
115
116
        if logo:
141
142
            (handler.xmlns['rdf'], 'about'): request.getBaseURL(),
142
143
            })
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)
146
148
        if logo:
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,
160
 
            })
 
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,
169
170
                })
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')
174
175
 
175
176
        # emit items
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,
182
 
            })
 
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, })
183
182
 
184
183
            # general attributes
185
184
            handler.simpleNode('title', item.pagename)
186
185
            if ddiffs:
187
 
                handler.simpleNode('link', link+"?action=diff")
 
186
                handler.simpleNode('link', full_url(request, page, querystr={'action': 'diff'}))
188
187
            else:
189
 
                handler.simpleNode('link', link)
 
188
                handler.simpleNode('link', full_url(request, page))
190
189
 
191
190
            handler.simpleNode(('dc', 'date'), timefuncs.W3CDate(item.time))
192
191
 
201
200
                for idx in range(rl):
202
201
                    rev = revisions[idx]
203
202
                    if rev <= item.rev:
204
 
                        if idx+1 < rl:
 
203
                        if idx + 1 < rl:
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)
222
221
            else: # 'ip'
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 )
242
241
 
243
242
            handler.endNode('item')
244
243
 
247
246
 
248
247
        request.write(out.getvalue())
249
248
 
250
 
    raise MoinMoinNoFooter
251