Attachment 'Hits-1.5.3-5.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 2005-07-15 BenjaminVrolijk exchange of filename for event-log by getPagePath
47 2006-05-01 1.5.3-4 RB bug fixed for quoting pagenames and some parts refactored
48 2006-05-02 1.5.3-5 RB bug fixed quoting changed to url_quote_plus because of the '+' sign used for a blank
49 in a Wiki Name instead of the '_' in the log file
50
51
52 """
53
54
55 from MoinMoin import wikiutil
56 from MoinMoin.logfile import eventlog
57 import os
58
59 def execute(macro,args):
60 request = macro.request
61 _ = request.getText
62 formatter = macro.formatter
63
64 kw = {} # create a dictionary for the formatter.image call
65 kw["bgcolor"] = "#FFFFFF"
66 kw["all"] = 0
67 kw["filter"] = "VIEWPAGE"
68 kw["divid"] = "logo"
69 kw["noframe"] = 0
70
71 if args:
72 args = args.split(',')
73 args = [arg.strip() for arg in args]
74 else:
75 args = []
76
77 argc = len(args)
78 kw_count = 0
79 for arg in args :
80 if '=' in arg:
81 kw_count += 1
82 key, value = arg.split('=', 1)
83 kw[str(key)] = wikiutil.escape(value,quote=1)
84
85 argc -= kw_count
86
87 if argc == 1:
88 descr = args[0]
89 else:
90 descr = ''
91
92 #pagename = wikiutil.quoteWikinameURL(formatter.page.page_name)
93 pagename = wikiutil.url_quote_plus(formatter.page.page_name)
94 filename = request.rootpage.getPagePath('event-log',isfile=1)
95
96 file = open(filename, 'r')
97 events = file.readlines()
98 file.close()
99
100 count = 0
101 for event in events:
102 try:
103 line = event.rstrip()
104 time, eventtype, kvpairs = line.split('\t')
105 except ValueError:
106 # badly formatted line in file, skip it
107 continue
108 if kw["filter"] and eventtype not in kw["filter"]: continue
109 if kw["all"] == 0:
110 if event.find(pagename+'&') > -1:
111 count += 1
112 else:
113 count += 1
114
115 if kw["noframe"] == 0 :
116 return '<div id="%(divid)s"><table><tr><td bgcolor="%(bgcolor)s">%(count)s %(descr)s </td></tr></table></div>' % {
117 "divid": kw["divid"],
118 "bgcolor": kw["bgcolor"],
119 "count": str(count),
120 "descr": descr }
121 else:
122 return '<div id="%(divid)s">%(count)s %(descr)s</div>' % {
123 "divid": kw["divid"],
124 "count": str(count),
125 "descr": descr }
126
127
128
129
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.