The RecentBlogs action gives you a list of recent blog entries from the whole wiki, sorted in reverse chronological order. An optional parameter specifies how many entries to show.
-- AdamFeuer & SteveHowell
code
"""
MoinMoin - RecentBlogs action
Copyright (c) 2001 by Steve Howell <showell at zipcon dot com>
Copyright (c) 2002 by Adam Feuer <adamf at pobox dot com>
All rights reserved, see COPYING for details.
The RecentBlog action gives you a list of recent blog entries
from the whole wiki, sorted in reverse chronological order. An
optional parameter specifies how many entries to show.
"""
from MoinMoin import config, wikiutil
from MoinMoin.Page import Page
from MoinMoin.parser.wiki import Parser
import string, re
def execute(macro, args):
count = None
entries = allLogEntries()
entries.sort(dateCompare)
result = ""
if args:
count = string.atoi(args[0])
entries = entries[:count]
for entry in entries:
result = result + formatEntry(entry)
fakeCgiForm = {}
return Parser(result).format(macro.formatter, fakeCgiForm)
def formatEntry(entry):
(blog, page) = entry
return blog + "\n -- " + page + "----\n"
def allLogEntries():
all_pages = wikiutil.getPageList(config.text_dir)
all_pages.sort()
entries = []
for page in all_pages:
for blog in findLog(Page(page).get_raw_body()):
if not page in ('RecentBlogsCode', 'BlogEditCode'):
entries.append((blog, page))
return entries
def dateCompare(b1, b2):
date1 = findDate(b1[0])
date2 = findDate(b2[0])
return cmp(date2, date1)
entry_re=re.compile(r"##BEGIN BLOG(.*?)##-----",re.DOTALL)
def findLog(text):
return entry_re.findall(text)
# date_re = re.compile(r"\[\[DateTime(.*)\]\]")
date_re = re.compile(r"(2.* ..:..)")
def findDate(entry):
matchObj = date_re.search(entry)
try:
return matchObj.groups()[0]
except:
return "aaa"
comments on the code
Newer versions of MoinMoin should use a different regex for finding the dates within blog entries. -- SteveHowell
The code above didn't work on MoinMoin Release 1.0 [Revision 1.159]. To fix the problem I changed the return of execute() to: return Parser(result, macro.request).format(macro.formatter, fakeCgiForm)
I'm a nubie to wiki, but wouldn't it be more efficient to loop through the pages in reverse chrono order by mod date, and then drop out of the loop when count had been reached? that way we don't have to search pages that won't be included. --Jeremy Elliott (no wiki page yet)
The page's modification date doesn't necessarily relate to the latest blog entry on the page. You can edit a page that has been blogged. -- SteveHowell