Attachment 'DateLastModified.py'

Download

   1 {{{#!python
   2 """
   3     MoinMoin - DateLastModified Macro
   4 
   5     This macro displays the last modified date of the page.
   6 
   7     Some logic taken from Page.py and AttentionPages.py
   8 
   9     @copyright: 2006 by Greg Heartsfield <scsibug@imap.cc>
  10     @license: GNU GPL, see COPYING for details.
  11 """
  12 
  13 import string, time, os
  14 from MoinMoin.Page import Page
  15 from MoinMoin import user, config, wikiutil
  16 
  17 Dependencies = ['pages']
  18 
  19 def execute(macro, args):
  20     request = macro.request
  21     page = macro.formatter.page
  22     log = page._last_edited(request)
  23     if log:
  24         editor = log.getEditor(request)
  25         mtime = wikiutil.version2timestamp(log.ed_time_usecs)
  26     else:
  27         editor = ''
  28         mtime = os.path.getmtime(page._text_filename())
  29     now = time.time()
  30     delta = int(now - float(mtime)) / 60 # minutes since update
  31     if delta < 0:
  32         delta = 0 # fix display glitch when NFS time is ahead of local machine time
  33     if delta < 1440:
  34         mod = "%dh&nbsp;%dm&nbsp;ago"%(delta/60, delta%60)
  35     elif delta < 43200:
  36         mod = "%dd&nbsp;%dh&nbsp;ago"%(delta/1440, (delta/60)%24)
  37     else:
  38         mod = request.user.getFormattedDateTime(mtime)
  39     return mod
  40 
  41 
  42 
  43 
  44 
  45 }}}

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-01-29 15:04:33, 1.2 KB) [[attachment:DateLastModified.py]]
 All files | Selected Files: delete move to page copy to page

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