1 """
2 MoinMoin - Hits Macro
3
4 This macro is used to show the cumulative hits of the wikipage where the Macro is called from.
5 Optionally you could count how much this page or all pages were changed or viewed.
6
7 <<Hits([all=(0,1)],[filter=(VIEWPAGE,SAVEPAGE)>>
8
9 all: if set to 1/True/yes then cumulative hits over all wiki pages is returned.
10 Default is 0/False/no.
11 filter: if set to SAVEPAGE then the saved pages are counted. Default is VIEWPAGE.
12
13 @copyright: 2004-2007 MoinMoin:ReimarBauer,
14 2005 BenjaminVrolijk
15 @license: GNU GPL, see COPYING for details.
16 """
17
18 Dependencies = ['time']
19
20 from MoinMoin import wikiutil
21 from MoinMoin.logfile import eventlog
22
23
24 def macro_Hits(macro, all=False, filter=(u'VIEWPAGE', u'SAVEPAGE')):
25 this_page = macro.formatter.page.page_name
26 event_log = eventlog.EventLog(macro.request)
27 event_log.set_filter([str(filter)])
28 count = 0
29 for event in event_log.reverse():
30 pagename = event[2].get('pagename')
31 if all or pagename == this_page:
32 count += 1
33
34 return u'%d' % count
35
36 def execute(macro, args):
37 try:
38 return wikiutil.invoke_extension_function(
39 macro.request, macro_Hits,
40 args, [macro])
41 except ValueError, err:
42 return macro.request.formatter.text(
43 "<<Example: %s>>" % err.args[0])
MoinMoin: MacroMarket/Hits-1.6.py (last edited 2008-01-19 22:32:51 by ReimarBauer)