NeilStevens: To make the FrontPage more useful, I'd like it to automatically show the last-changed date on certain links, like Announcements. This will likely require a new macro.

MayLith: It would be handy to use a macro like that for any page that contains thread links. For example, very old, unchanged threads might be reviewed for conversion into documentation, etc.

SoulWynd: Try this:

LastChanged.py

"""
  Usage:
  [[LastChanged(PageName)]] - Returns the PageName last modified date
  
  -SoulWynd
"""

from MoinMoin.Page import Page

Dependencies = []

def execute(macro, args):
    pagename = args or macro.formatter.page.page_name
    page = Page(pagename)
            
    return page.mtime_printable(macro.request)

Keep in mind this is my first attempt at python, I think it should work tho. Oh yeah, you should place the LastChanged.py file inside the macro directory if I understood correctly of how these files are loaded. I don't think you need to change anything for it to load, just recompile or whatever you have to do to add a new file.

NeilStevens: Great work, thanks. The only change I needed to make: page.mtime_printable needs a request as an argument, so that line became  return page.mtime_printable(macro.request) 

SoulWynd: Thanks, I'm glad it worked with little trouble. I was going for a diferent approach before, so I forgot to remove the  import cStringIO  ... I don't think that's needed anymore. Forgot to mention, I could try doing a similar macro that shows the time difference between the edit time and time(). Like what RecentChanges does... 0h 2m ago for an example.

NeilStevens: Yeah, PageAge() would probably be useful, too.

SoulWynd: Working on it.

All done, PageAge.py

"""
  Usage:
  [[PageAge(PageName)]] - Returns the PageName's age
  [[PageAge()]] - Returns self's age
  
  -SoulWynd
"""

import time
from MoinMoin.Page import Page

Dependencies = []

def execute(macro, args):
    pagename = args or macro.formatter.page.page_name
    page = Page(pagename)
    dif = (int(time.time()) - page.mtime()) / 60
    if dif < 1440:
        ret = '%dh&nbsp;%dm&nbsp;ago' % (dif/60, dif%60)
    elif tdiff < 43200:
        ret = '%dd&nbsp;%dh&nbsp;ago' % (dif/1440, (dif/60)%24)
    else:
        ret = '%dy&nbsp;%dm&nbsp;ago' % (dif/518400, (dif/43200)%12)
    
    return ret


ReenenLaurie: I tried using [[LastChanged(["/Things that affect barehand?"])]] but it wouldn't work. I also tried it with other formats (like GeneralDiscussion/Things that affect barehand?) though it didn't work either. [[LastChanges(GeneralDiscussion)]] worked, but that's (obviously) not what I wanted.

SoulWynd: Pssst, use the full pathname [[LastChanged(GeneralDiscussion/Things that affect barehand?)]] :)

Example:

GeneralDiscussion/Things that affect barehand? Last changed at 2004-08-22 19:55:01

ReenenLaurie: Thanks! I used "'s with it.

SoulWynd: Fixed a small bug, 'or self' doesn't work on this case. Both codes are updated and fixed (hopefully).

NeilStevens: I will update LastChanged and install PageAge now. See Wiki Development for how to access the changes I made to these macros.

NeilStevens (later): I'm removing PageAge. It doesn't work as expected because of cached pages.

SoulWynd: Changing dependencies to Dependencies = ["time"] should to the trick for both macros so you don't have to refresh them every time.

NeilStevens: Oh that sounds wonderful. I will have to reevaluate these macros and their uses. Thank you.

SoulWynd: On another good news, I found Diff for windows:

--- PageAge.py  2004-08-02 04:52:37.258020800 -0300
+++ PageAge.py  2004-09-07 22:02:26.402923200 -0300
@@ -9,7 +9,7 @@
 import time
 from MoinMoin.Page import Page
 
-Dependencies = []
+Dependencies = ["time"]
 
 def execute(macro, args):
     pagename = args or self

Along with patch and a few other utils, here's the sourceforge page -> http://sourceforge.net/projects/gnuwin32/

NeilStevens: Mmmm.. unified diff...

NeilStevens: Applying now, thank you.

SoulWynd: No problem. I'm just considering making it more 'english' friendly and more dynamic. The downside is that it will take more space of display on the page. So instead of showing 0y 1m for the FrontPage it would show something on the lines of "1 month and 12 days". Sounds better?

NeilStevens: Sure thing. Just let us know whenever you come up with anything.

SoulWynd: There you go :)

"""
  Usage:
  [[PageAge(PageName)]] - Returns the PageName's age
  [[PageAge()]] - Returns self's age
  
  -SoulWynd
"""

import time
from MoinMoin.Page import Page

Dependencies = ["time"]

def execute(macro, args):
    pagename = args or self
    page = Page(pagename)
    time_str = ['year', 'month', 'week', 'day', 'hour', 'minute', 'second']
    time_val = [29030400, 2419200, 604800, 86400, 3600, 60, 1]
    ret = ''
    dif = int(time.time()) - page.mtime()
    t = 0
    
    for x in range(len(time_str)):
        if dif > time_val[x]:
            t = t + 1
            value = dif / time_val[x]
            dif = dif - (value * time_val[x])
            if t == 1:
                ret = ret + str(value) + ' ' + time_str[x]
            else:
                ret = ret + ' and ' + str(value) + ' ' + time_str[x]
            if value > 1:
                ret = ret + 's'
            if t == 2:
                return ret
    
    # Just in case we have a page updated in the last few seconds.
    return ret

This should work, have fun.

Wiki Suggestions/Wanted Macro: A way to show the timestamp of a linked page (last edited 2004-10-06 19:04:20 by SoulWynd)