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

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.