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