Attachment 'Hits-1.3.1-2.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - Hits Macro
4
5 PURPOSE:
6 This macro is used to show the cummulative hits of the wikipage where the Macro is called from.
7 Optional you could count how much a page was altered on this or all pages.
8
9 CALLING SEQUENCE:
10 [[Hits([text],[bgcolor=bgcolor],[all=(0,1)],[filter=(VIEWPAGE,SAVEPAGE)],[divid=(logo,searchform)],[noframe=(0,1)])]]
11
12 OPTIONAL INPUTS:
13 text: the text which is used as description of counter number
14
15 KEYWORD PARAMETERS:
16 bgcolor: if set to the rgb color triple this color is used. Default color is #FFFFFF
17 all: if set to 1 then cummulative hits over all wiki pages is returned. Default is 0
18 filter: if set to SAVEPAGE then the saved pages are counted. Default is VIEWPAGE.
19 divid: if set this divid is used. Default is logo. You could use each defined in screen.css.
20 I have tried logo and searchform.
21 noframe: if set to 1 only text is written without a table border. Default is 0.
22
23 EXAMPLE:
24 [[Hits]]
25
26 [[Hits(counts)]]
27
28 [[Hits(counts,divid=searchform)]]
29
30 [[Hits(counts,bgcolor=#CCCCCC)]]
31
32 [[Hits(counts,all=1)]]
33
34 [[Hits(X pages altered,all=1,filter=SAVEPAGE)]]
35
36 PROCEDURE:
37
38 It must be in "MoinMoin/macro"
39
40 Please remove the version number from the file name!
41
42 MODIFICATION HISTORY:
43 @copyright: 2004 by Reimar Bauer (R.Bauer@fz-juelich.de)
44 @license: GNU GPL, see COPYING for details.
45 2004-12-29 RB bug fixed eventlog is in logfile
46
47
48 """
49
50
51 from MoinMoin import wikiutil
52 from MoinMoin.logfile import eventlog
53 import os,string
54
55
56 def execute(macro, text):
57 kw ={} # create a dictionary for the formatter.image call
58 if text:
59 args=text.split(',')
60 else:
61 args=[]
62
63 number_args=len(args)
64 count=0
65 kw["bgcolor"]="#FFFFFF"
66 kw["all"]=0
67 kw["filter"]="VIEWPAGE"
68 kw["divid"]="logo"
69 kw["noframe"]=0
70
71 for a in args :
72 if (a.find('=') > -1):
73 count=count+1
74 key=a.split('=')
75
76 kw[str(key[0])]=wikiutil.escape(string.join(key[1],''), quote=1)
77
78 number_args=number_args-count
79
80 if (number_args == 1):
81 descr=' '+string.strip(args[0])
82 else:
83 descr=''
84
85
86 pagename=macro.formatter.page.page_name
87 filename ="./data/event-log"
88
89 file = open(filename, 'r')
90 events = file.readlines()
91 file.close()
92
93
94
95 count=0
96 for event in events:
97
98 try:
99 time, eventtype, kvpairs = string.split(string.rstrip(event), '\t')
100 except ValueError:
101 # badly formatted line in file, skip it
102 continue
103 if kw["filter"] and eventtype not in kw["filter"]: continue
104 if (kw["all"] == 0) :
105 if (event.find(pagename+'&') > -1):
106 count=count+1
107 else:
108 count=count+1
109
110 if( kw["noframe"] == 0) :
111 result='<div id="'+kw["divid"]+'"><table><tr><td bgcolor="'+kw["bgcolor"]+'">'+str(count)+descr+' </td></tr></table></div>'
112 else:
113 result='<div id="'+kw["divid"]+'">'+str(count)+descr+'</div>'
114
115 return result
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.