Attachment 'BlikiSummary-v2.py'

Download

   1  # -*- coding: iso-8859-1 -*-
   2 
   3 """
   4  Macro: BlikiSummary
   5  Abridged RecentChanges-like summary of a blog-wiki (bliki) page
   6 
   7  Version:
   8  2.0 / 04.12.2008 (for MoinMoin 1.8) 
   9     Using the arg parser, output using now rawHTML formatter, created a div 
  10     "BlikiSummary" around the output... (MarcelHäfner)
  11 
  12  Syntax:
  13  <<BlikiSummary(numberOfChanges=10,numberOfDays=7)>>
  14  <<BlikiSummary(10,7)>>
  15  <<BlikiSummary>>
  16 
  17  Copyright (C) 2007 Boris Smus <boris@z3.ca>
  18  Licence: GPL [see http://www.gnu.org/copyleft/gpl.html]
  19 """
  20 
  21 from MoinMoin.logfile import editlog
  22 from MoinMoin import wikiutil
  23 from MoinMoin.Page import Page
  24 import time
  25 
  26 def macro_BlikiSummary(macro, numberOfChanges=12, numberOfDays=14 ):
  27     request = macro.request
  28     _ = request.getText
  29     log = editlog.EditLog(request)
  30     now = long(time.time())
  31 
  32     pages = []
  33     for page in log.reverse():
  34         if not request.user.may.read(page.pagename):
  35             # ignore pages that aren't readable
  36             continue
  37         
  38         # last edited time property
  39         edit_time = wikiutil.version2timestamp(page.ed_time_usecs)
  40 
  41         # the day modification of 
  42         page.edit_diff = time_diff(now, edit_time)
  43         if page.edit_diff[0] > numberOfDays:
  44             # all further pages are older
  45             break
  46         if Page(request, page.pagename).exists() and \
  47             page.pagename not in [p.pagename for p in pages]:
  48             # if this page was edited today, it exists and we haven't yet
  49             # seen it
  50             pages.append(page)
  51             if len(pages) >= numberOfChanges:
  52                 break
  53             prev_pagename = page.pagename
  54 
  55     #return `[page.pagename for page in pages]`
  56     html = []
  57     html.append('<div class="BlikiSummary">')
  58     html.append(macro.formatter.number_list(1))
  59     for page in pages:
  60         html.append(macro.formatter.listitem(1))
  61         html.append(macro.formatter.pagelink(1, page.pagename, generated=1))
  62         html.append(macro.formatter.text(page.pagename))
  63         html.append(macro.formatter.pagelink(0))
  64         diff = page.edit_diff
  65         html.append(macro.formatter.text(_(" changed ")))
  66         if diff[0] != 0:
  67             # more than a day ago
  68             html.append(macro.formatter.text(_(" %d %s ") % 
  69                 (diff[0], (diff[0] > 1 and _('days') or _('day')))))
  70         if diff[1] != 0:
  71             html.append(macro.formatter.text(_(" %dh ") % (diff[1], )))
  72         else:
  73             html.append(macro.formatter.text(_(" %dm ") % (diff[2], )))
  74         html.append(macro.formatter.text(_(" ago.")))
  75         html.append(macro.formatter.listitem(0))
  76     html.append(macro.formatter.number_list(0))
  77     html.append('</div>')
  78     
  79     return macro.formatter.rawHTML("".join(html))
  80 
  81 def time_diff(t1, t2):
  82     t = t1 - t2
  83     t,s = divmod(t,60)
  84     t,m = divmod(t,60)
  85     d,h = divmod(t,24)
  86     return (d,h,m,s)

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] (2008-12-04 21:30:46, 2.8 KB) [[attachment:BlikiSummary-v2.py]]
  • [get | view] (2007-01-19 05:57:11, 2.2 KB) [[attachment:BlikiSummary.py]]
  • [get | view] (2008-12-04 21:31:06, 30.9 KB) [[attachment:blikisummary2-screenshot.png]]
  • [get | view] (2008-12-04 21:31:50, 0.1 KB) [[attachment:de.BlikiSummary.po]]
 All files | Selected Files: delete move to page copy to page

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