annotate MoinMoin/action/sisterpages.py @ 3572:870cc4c47705

AttachFile: fix saving of drawing files
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 10 May 2008 17:28:44 +0200
parents a739558ca3dc
children 85884c67228d
rev   line source
1787
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 MoinMoin - "sisterpages" action
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5 This action generates a list of page urls and page names, so that other wikis
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 can implement SisterWiki functionality easily.
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7 See: http://usemod.com/cgi-bin/mb.pl?SisterSitesImplementationGuide
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
8
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1788
diff changeset
9 @copyright: 2007 MoinMoin:ThomasWaldmann
1787
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 @license: GNU GPL, see COPYING for details.
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 """
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 import time
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15 from MoinMoin import wikiutil
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 from MoinMoin.Page import Page
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17 from MoinMoin.util import timefuncs
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 from MoinMoin.logfile import editlog
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20 def execute(pagename, request):
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 log = editlog.EditLog(request)
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22 try:
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23 lastmod = wikiutil.version2timestamp(log.date())
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24 except:
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 lastmod = 0
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
27 timestamp = timefuncs.formathttpdate(lastmod)
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
28 etag = "%d" % lastmod
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
29
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30 # for 304, we look at if-modified-since and if-none-match headers,
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31 # one of them must match and the other is either not there or must match.
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32 if request.if_modified_since == timestamp:
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33 if request.if_none_match:
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34 if request.if_none_match == etag:
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35 request.emit_http_headers(["Status: 304 Not modified"])
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 else:
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37 request.emit_http_headers(["Status: 304 Not modified"])
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38 elif request.if_none_match == etag:
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39 if request.if_modified_since:
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40 if request.if_modified_since == timestamp:
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41 request.emit_http_headers(["Status: 304 Not modified"])
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42 else:
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 request.emit_http_headers(["Status: 304 Not modified"])
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44 else:
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45 # generate an Expires header, using 1d cache lifetime of sisterpages list
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
46 expires = timefuncs.formathttpdate(time.time() + 24*3600)
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
47
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
48 httpheaders = ["Content-Type: text/plain; charset=UTF-8",
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49 "Expires: %s" % expires,
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
50 "Last-Modified: %s" % timestamp,
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 "Etag: %s" % etag, ]
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53 # send the generated XML document
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54 request.emit_http_headers(httpheaders)
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
55
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
56 baseurl = request.getBaseURL()
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57 if not baseurl.endswith('/'):
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
58 baseurl += '/'
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
59
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
60 # Get list of user readable pages
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61 pages = request.rootpage.getPageList()
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
62 pages.sort()
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
63 for pn in pages:
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
64 p = Page(request, pn)
3234
a739558ca3dc Page.url() default changed to relative=False
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
65 entry = u"%s %s\r\n" % (request.getQualifiedURL(p.url(request)), p.page_name)
1787
f4a941fe32f8 added SisterSites/SisterPages support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66 request.write(entry.encode('utf-8'))