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.
  • [get | view] (2004-12-29 22:19:37, 3.0 KB) [[attachment:Hits-1.3.1-2.py]]
  • [get | view] (2005-08-04 13:28:13, 3.1 KB) [[attachment:Hits-1.3.4-3.py]]
  • [get | view] (2006-05-01 16:31:14, 3.6 KB) [[attachment:Hits-1.5.3-4.py]]
  • [get | view] (2006-05-02 20:40:48, 3.8 KB) [[attachment:Hits-1.5.3-5.py]]
  • [get | view] (2006-05-04 18:21:13, 4.3 KB) [[attachment:Hits-1.5.3-6.py]]
  • [get | view] (2006-05-05 04:35:45, 4.5 KB) [[attachment:Hits-1.5.3-7.py]]
  • [get | view] (2006-08-16 17:29:52, 3.6 KB) [[attachment:Hits-1.6.0-8.py]]
  • [get | view] (2006-08-16 17:37:53, 6.1 KB) [[attachment:Hits1.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.