Attachment 'PageHits.py'

Download

   1 #format Python
   2 
   3 """
   4     MoinMoin - PageHits Macro
   5 
   6     Copyright (c) 2002 by Thomas Waldmann <ThomasWaldmann@gmx.de>
   7     All rights reserved, see COPYING for details.
   8 
   9     Revision history:
  10     0.xx first version without a number
  11     0.2  do not display non-existing pages
  12 """
  13 
  14 # Imports
  15 import string
  16 from MoinMoin import config, wikiutil
  17 from MoinMoin.Page import Page
  18 #from MoinMoin.i18n import _
  19 
  20 
  21 def execute(macro, args):
  22     data = macro.request.getEventLogger().read(['VIEWPAGE'])
  23     pagehits={}
  24     for event in data:
  25         page = event[2]['pagename']
  26         try:
  27             pagehits[page]=pagehits[page]+1
  28         except:
  29             pagehits[page]=1
  30 
  31     # get hits and sort them
  32     hits = []
  33     for pagehit in pagehits.items():
  34         if Page(pagehit[0]).exists():
  35             hits.append((pagehit[1],pagehit[0]))
  36     hits.sort()
  37     hits.reverse()
  38 
  39     # format list
  40     result = macro.formatter.number_list(1)
  41     for hit, page in hits:
  42         result = (result + macro.formatter.listitem(1) +
  43             macro.formatter.code(1) + 
  44             string.replace("%6d" % hit, " ", "&nbsp;") + " " +
  45             macro.formatter.code(0) + 
  46             macro.formatter.pagelink(page) + 
  47             macro.formatter.listitem(0)
  48         )
  49     result = result + macro.formatter.number_list(0)
  50 
  51     return result
  52 
  53 #
  54 
  55 ## enhancement: only count hits newer than N days (would this be possible using macro args)
  56 ## save as ... url ?

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] (2003-12-07 18:15:54, 1.3 KB) [[attachment:MacroMarket-PageHits.py]]
  • [get | view] (2008-01-29 20:55:04, 1.5 KB) [[attachment:PageHits.py]]
  • [get | view] (2008-01-29 20:55:10, 1.3 KB) [[attachment:PageHits1.2.1.py]]
 All files | Selected Files: delete move to page copy to page

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