Back to index

moin  1.9.0~rc2
sisterpages.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - "sisterpages" action
00004 
00005     This action generates a list of page urls and page names, so that other wikis
00006     can implement SisterWiki functionality easily.
00007     See: http://usemod.com/cgi-bin/mb.pl?SisterSitesImplementationGuide
00008 
00009     @copyright: 2007 MoinMoin:ThomasWaldmann
00010     @license: GNU GPL, see COPYING for details.
00011 """
00012 
00013 import time
00014 
00015 from MoinMoin import wikiutil
00016 from MoinMoin.Page import Page
00017 from MoinMoin.util import timefuncs
00018 from MoinMoin.logfile import editlog
00019 
00020 def execute(pagename, request):
00021     log = editlog.EditLog(request)
00022     try:
00023         lastmod = wikiutil.version2timestamp(log.date())
00024     except:
00025         lastmod = 0
00026 
00027     timestamp = timefuncs.formathttpdate(lastmod)
00028     etag = "%d" % lastmod
00029 
00030     # for 304, we look at if-modified-since and if-none-match headers,
00031     # one of them must match and the other is either not there or must match.
00032     if request.if_modified_since == timestamp:
00033         if request.if_none_match:
00034             if request.if_none_match == etag:
00035                 request.status_code = 304
00036         else:
00037             request.status_code = 304
00038     elif request.if_none_match == etag:
00039         if request.if_modified_since:
00040             if request.if_modified_since == timestamp:
00041                 request.status_code = 304
00042         else:
00043             request.status_code = 304
00044     else:
00045         # generate an Expires header, using 1d cache lifetime of sisterpages list
00046         expires = time.time() + 24*3600
00047 
00048         request.mime_type = 'text/plain'
00049         request.expires = expires
00050         request.last_modified = timestamp
00051         request.headers.add("Etag", etag)
00052 
00053         # send the generated XML document
00054         # Get list of user readable pages
00055         pages = request.rootpage.getPageList()
00056         pages.sort()
00057         for pn in pages:
00058             p = Page(request, pn)
00059             entry = u"%s %s\r\n" % (request.getQualifiedURL(p.url(request)), p.page_name)
00060             request.write(entry.encode('utf-8'))