Attachment 'MacroMarket-PageHits.py'

Download

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

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.