Attachment 'moin-cache-friendly.diff'
Download 1 * looking for arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-730 to compare with
2 * comparing to arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-730
3 M MoinMoin/action/rss_rc.py
4 M MoinMoin/server/standalone.py
5 M MoinMoin/Page.py
6 M MoinMoin/multiconfig.py
7 M MoinMoin/i18n/__init__.py
8 M MoinMoin/request.py
9 M MoinMoin/util/datetime.py
10 M MoinMoin/wikiaction.py
11
12 * modified files
13
14 --- orig/MoinMoin/Page.py
15 +++ mod/MoinMoin/Page.py
16 @@ -13,6 +13,7 @@
17 from MoinMoin import config, caching, user, util, wikiutil
18 from MoinMoin.logfile import eventlog
19 from MoinMoin.util import filesys, web
20 +from MoinMoin.util.datetime import formathttpdate
21
22
23 # There are many places accessing ACLs even without actually sending
24 @@ -1068,8 +1069,20 @@
25 page_exists = self.exists()
26 if not content_only:
27 # send the document leader
28 +
29 + # use "nocache" headers if we're using a method that
30 + # is not simply "display", or if a user is logged in
31 + # (which triggers personalisation features)
32 +
33 if page_exists:
34 - request.http_headers()
35 + if (request.bust_cache or request.user.valid):
36 + request.http_headers(request.nocache)
37 + else:
38 + # use the correct last-modified value from the on-disk file
39 + # to ensure cacheability where supported
40 + request.http_headers(["Last-Modified: " +
41 + formathttpdate(os.path.getmtime(self._text_filename()))]);
42 +
43 else:
44 request.http_headers(['Status: 404 NOTFOUND'])
45 request.setResponseCode(404)
46
47
48 --- orig/MoinMoin/action/rss_rc.py
49 +++ mod/MoinMoin/action/rss_rc.py
50 @@ -7,9 +7,10 @@
51
52 @license: GNU GPL, see COPYING for details.
53 """
54 -import StringIO, re, os
55 +import StringIO, re, os, time
56 from MoinMoin import wikixml, config, wikiutil, util
57 from MoinMoin.logfile import editlog
58 +from MoinMoin.util.datetime import formathttpdate
59 from MoinMoin.Page import Page
60 from MoinMoin.wikixml.util import RssGenerator
61
62 @@ -59,6 +60,7 @@
63 logdata = []
64 counter = 0
65 pages = {}
66 + lastmod = 0
67 for line in log.reverse():
68 if not request.user.may.read(line.pagename):
69 continue
70 @@ -69,6 +71,10 @@
71 line.time = util.datetime.tmtuple(wikiutil.version2timestamp(line.ed_time_usecs)) # UTC
72 logdata.append(line)
73 pages[line.pagename] = None
74 +
75 + if not lastmod:
76 + lastmod = wikiutil.version2timestamp(line.ed_time_usecs)
77 +
78 counter += 1
79 if counter >= max_items:
80 break
81 @@ -197,8 +203,20 @@
82 # end SAX stream
83 handler.endDocument()
84
85 + # generate an Expires header, using whatever setting the admin
86 + # defined for suggested cache lifetime of the RecentChanges RSS doc
87 + expires = formathttpdate(time.time() + cfg.rss_cache)
88 +
89 + httpheaders = ["Content-Type: text/xml; charset=%s" % config.charset,
90 + "Expires: "+expires]
91 +
92 + # use a correct Last-Modified header, set to whatever the mod date
93 + # on the most recent page was; if there were no mods, don't send one
94 + if lastmod:
95 + httpheaders.append("Last-Modified: "+formathttpdate(lastmod))
96 +
97 # send the generated XML document
98 - request.http_headers(["Content-Type: text/xml; charset=%s" % config.charset] + request.nocache)
99 + request.http_headers(httpheaders)
100 request.write(out.getvalue())
101 request.finish()
102 request.no_closing_html_code = 1
103
104
105 --- orig/MoinMoin/i18n/__init__.py
106 +++ mod/MoinMoin/i18n/__init__.py
107 @@ -204,6 +204,8 @@
108 available = wikiLanguages()
109 for lang in browserLanguages(request):
110 if available.has_key(lang):
111 + if request.http_accept_language:
112 + request.setHttpHeader('Vary: Accept-Language')
113 return lang
114
115 # Or return the wiki default language...
116
117
118 --- orig/MoinMoin/multiconfig.py
119 +++ mod/MoinMoin/multiconfig.py
120 @@ -240,6 +240,7 @@
121 'up': ("%(q_page_parent_page)s", _("Up"), "up"),
122 }
123 refresh = None # (minimum_delay, type), e.g.: (2, 'internal')
124 + rss_cache = 60 # suggested caching time for RecentChanges RSS, in seconds
125 shared_intermap = None # can be string or list of strings (filenames)
126 show_hosts = 1
127 show_section_numbers = 1
128
129
130 --- orig/MoinMoin/request.py
131 +++ mod/MoinMoin/request.py
132 @@ -71,6 +71,7 @@
133
134 self.sent_headers = 0
135 self.user_headers = []
136 + self.bust_cache = 0
137 self.page = None
138
139 # Fix dircaching problems on Windows 9x
140
141
142 --- orig/MoinMoin/server/standalone.py
143 +++ mod/MoinMoin/server/standalone.py
144 @@ -35,12 +35,12 @@
145 # Imports
146 import os, signal, sys, time, urllib, socket, errno
147 import BaseHTTPServer, SimpleHTTPServer, SocketServer
148 -from email.Utils import formatdate
149
150 # MoinMoin imports
151 from MoinMoin import version
152 from MoinMoin.server import Config, switchUID
153 from MoinMoin.request import RequestStandAlone
154 +from MoinMoin.util.datetime import formathttpdate
155
156 # Set threads flag, so other code can use proper locking
157 from MoinMoin import config
158 @@ -204,7 +204,7 @@
159 if self.expires:
160 now = time.time()
161 expires = now + self.expires
162 - self.send_header('Expires', formatdate(expires))
163 + self.send_header('Expires', formathttpdate(expires))
164 SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
165
166
167
168
169 --- orig/MoinMoin/util/datetime.py
170 +++ mod/MoinMoin/util/datetime.py
171 @@ -8,7 +8,8 @@
172
173 # we guarantee that time is always imported!
174 import time
175 -
176 +import re
177 +from email.Utils import formatdate
178
179 def tmtuple(tmsecs=None):
180 """ Return a time tuple.
181 @@ -20,3 +21,12 @@
182 tmsecs = 0 # 0 initially, so reset it to 0.
183 return time.gmtime(tmsecs or time.time())
184
185 +def formathttpdate(tmsecs=None):
186 + """ Return a HTTP date/time stamp as defined in
187 + http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3 .
188 + """
189 + stamp = formatdate(tmsecs, False)
190 + # replace non-standard "-0000" at end with http-mandated "GMT"
191 + stamp = re.match('^(.*) [\-\+]0000$', stamp).group(1) + " GMT"
192 + return stamp
193 +
194
195
196 --- orig/MoinMoin/wikiaction.py
197 +++ mod/MoinMoin/wikiaction.py
198 @@ -30,6 +30,7 @@
199 #############################################################################
200
201 def do_diff(pagename, request):
202 + request.bust_cache = 1
203 """ Handle "action=diff"
204 checking for either a "rev=formerrevision" parameter
205 or rev1 and rev2 parameters
206 @@ -194,6 +195,7 @@
207
208
209 def do_info(pagename, request):
210 + request.bust_cache = 1
211 if not request.user.may.read(pagename):
212 Page(request, pagename).send_page(request)
213 return
214 @@ -426,6 +428,7 @@
215
216
217 def do_recall(pagename, request):
218 + request.bust_cache = 1
219 # We must check if the current page has different ACLs.
220 if not request.user.may.read(pagename):
221 Page(request, pagename).send_page(request)
222 @@ -464,6 +467,7 @@
223
224
225 def do_refresh(pagename, request):
226 + request.bust_cache = 1
227 """ Handle refresh action """
228 # Without arguments, refresh action will refresh the page text_html
229 # cache.
230 @@ -480,10 +484,12 @@
231
232
233 def do_print(pagename, request):
234 + request.bust_cache = 1
235 do_show(pagename, request)
236
237
238 def do_content(pagename, request):
239 + request.bust_cache = 1
240 request.http_headers()
241 page = Page(request, pagename)
242 request.write('<!-- Transclusion of %s -->' % request.getQualifiedURL(page.url(request)))
243 @@ -492,6 +498,7 @@
244
245
246 def do_edit(pagename, request):
247 + request.bust_cache = 1
248 if not request.user.may.write(pagename):
249 _ = request.getText
250 Page(request, pagename).send_page(request,
251 @@ -502,6 +509,7 @@
252
253
254 def do_revert(pagename, request):
255 + request.bust_cache = 1
256 from MoinMoin.PageEditor import PageEditor
257 _ = request.getText
258
259 @@ -525,6 +533,7 @@
260 return None
261
262 def do_savepage(pagename, request):
263 + request.bust_cache = 1
264 from MoinMoin.PageEditor import PageEditor
265
266 _ = request.getText
267 @@ -639,6 +648,7 @@
268
269
270 def do_subscribe(pagename, request):
271 + request.bust_cache = 1
272 """ Add the current wiki page to the subscribed_page property in
273 current user profile.
274 """
275 @@ -683,11 +693,13 @@
276
277
278 def do_userform(pagename, request):
279 + request.bust_cache = 1
280 from MoinMoin import userform
281 savemsg = userform.savedata(request)
282 Page(request, pagename).send_page(request, msg=savemsg)
283
284 def do_bookmark(pagename, request):
285 + request.bust_cache = 1
286 if request.form.has_key('time'):
287 if request.form['time'][0] == 'del':
288 tm = None
289 @@ -707,6 +719,7 @@
290
291
292 def do_formtest(pagename, request):
293 + request.bust_cache = 1
294 # test a user defined form
295 from MoinMoin import wikiform
296 wikiform.do_formtest(pagename, request)
297 @@ -735,6 +748,7 @@
298 #############################################################################
299
300 def do_raw(pagename, request):
301 + request.bust_cache = 1
302 if not request.user.may.read(pagename):
303 Page(request, pagename).send_page(request)
304 return
305 @@ -761,6 +775,7 @@
306
307
308 def do_format(pagename, request):
309 + request.bust_cache = 1
310 # get the MIME type
311 if request.form.has_key('mimetype'):
312 mimetype = request.form['mimetype'][0]
313 @@ -785,6 +800,7 @@
314
315
316 def do_chart(pagename, request):
317 + request.bust_cache = 1
318 if request.user.may.read(pagename) and request.cfg.chart_options:
319 chart_type = request.form['type'][0]
320 func = pysupport.importName("MoinMoin.stats." + chart_type, "draw")
321 @@ -793,6 +809,7 @@
322
323
324 def do_dumpform(pagename, request):
325 + request.bust_cache = 1
326 data = util.dumpFormData(request.form)
327
328 request.http_headers()
329 @@ -801,6 +818,7 @@
330
331
332 def do_export(pagename, request):
333 + request.bust_cache = 1
334 import shutil, StringIO
335 from MoinMoin.wikixml import wikiexport
336
337 @@ -840,6 +858,7 @@
338
339
340 def do_test(pagename, request):
341 + request.bust_cache = 1
342 from MoinMoin.wikitest import runTest
343 request.http_headers(["Content-type: text/plain;charset=%s" % config.charset])
344 request.write('MoinMoin Diagnosis\n======================\n\n')
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.