Attachment 'BlikiSummary.py'
Download 1 """
2 Abridged RecentChanges-like summary of a blog-wiki (bliki) page
3
4 Copyright (C) 2007 Boris Smus <boris@z3.ca>
5 Licence: GPL [see http://www.gnu.org/copyleft/gpl.html]
6 """
7
8 from MoinMoin.logfile import editlog
9 from MoinMoin import wikiutil
10 from MoinMoin.Page import Page
11
12 import time
13
14 Dependencies = ["time"]
15
16 DAY_IN_SECS = 86400
17 NUMBER_OF_CHANGES = 10
18 NUMBER_OF_DAYS = 20
19
20 def execute(macro, args):
21 request = macro.request
22 _ = request.getText
23 log = editlog.EditLog(request)
24
25 now = long(time.time())
26
27 pages = []
28 for page in log.reverse():
29 if not request.user.may.read(page.pagename):
30 # ignore pages that aren't readable
31 continue
32
33 # last edited time property
34 edit_time = wikiutil.version2timestamp(page.ed_time_usecs)
35 # the day modification of
36 page.edit_diff = time_diff(now, edit_time)
37
38 if page.edit_diff[0] > NUMBER_OF_DAYS:
39 # all further pages are older
40 break
41
42 if Page(request, page.pagename).exists() and \
43 page.pagename not in [p.pagename for p in pages]:
44 # if this page was edited today, it exists and we haven't yet
45 # seen it
46 pages.append(page)
47 if len(pages) > NUMBER_OF_CHANGES:
48 break
49 prev_pagename = page.pagename
50 #return `[page.pagename for page in pages]`
51
52 html = []
53 html.append(macro.formatter.number_list(1))
54 for page in pages:
55 html.append(macro.formatter.listitem(1))
56 html.append(macro.formatter.pagelink(1, page.pagename, generated=1))
57 html.append(macro.formatter.text(page.pagename))
58 html.append(macro.formatter.pagelink(0))
59
60 diff = page.edit_diff
61 html.append(macro.formatter.text(" changed "))
62 if diff[0] != 0:
63 # more than a day ago
64 html.append(macro.formatter.text(" %d day%s " %
65 (diff[0], (diff[0] > 1 and 's' or ''))))
66 if diff[1] != 0:
67 html.append(macro.formatter.text(" %d hour%s " %
68 (diff[1], (diff[1] > 1 and 's' or ''))))
69 else:
70 html.append(macro.formatter.text(" %d minute%s" %
71 (diff[2], (diff[2] > 1 and 's' or ''))))
72 html.append(macro.formatter.text(" ago."))
73
74
75 html.append(macro.formatter.listitem(0))
76 html.append(macro.formatter.number_list(0))
77
78 return "".join(html)
79
80 def time_diff(t1, t2):
81 t = t1 - t2
82 t,s = divmod(t,60)
83 t,m = divmod(t,60)
84 d,h = divmod(t,24)
85 return (d,h,m,s)
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.