paul@5 | 1 | # -*- coding: iso-8859-1 -*- |
paul@5 | 2 | """ |
paul@5 | 3 | MoinMoin - SiteUpdates Macro |
paul@5 | 4 | |
paul@5 | 5 | Inspired by the RecentChanges macro |
paul@5 | 6 | |
paul@5 | 7 | @copyright: 2007 by Paul Boddie <paul@boddie.org.uk> |
paul@27 | 8 | @license: GNU GPL (v2 or later), see COPYING.txt for details. |
paul@5 | 9 | """ |
paul@5 | 10 | |
paul@5 | 11 | from MoinMoin.Page import Page |
paul@5 | 12 | from MoinMoin.logfile import editlog |
paul@5 | 13 | |
paul@5 | 14 | Dependencies = [] |
paul@5 | 15 | |
paul@5 | 16 | MAX_ENTRIES = 5 |
paul@5 | 17 | |
paul@5 | 18 | def execute(macro, args): |
paul@5 | 19 | request = macro.request |
paul@5 | 20 | |
paul@5 | 21 | max_entries = MAX_ENTRIES |
paul@5 | 22 | args = args.split(",") |
paul@5 | 23 | if args: |
paul@5 | 24 | try: |
paul@5 | 25 | max_entries = int(args[0]) |
paul@5 | 26 | except ValueError: |
paul@5 | 27 | pass |
paul@5 | 28 | |
paul@5 | 29 | pages = {} |
paul@5 | 30 | log = editlog.EditLog(request) |
paul@5 | 31 | |
paul@5 | 32 | for line in log.reverse(): |
paul@5 | 33 | |
paul@5 | 34 | if not request.user.may.read(line.pagename): |
paul@5 | 35 | continue |
paul@5 | 36 | |
paul@5 | 37 | pages[line.pagename] = line |
paul@5 | 38 | |
paul@5 | 39 | if len(pages.keys()) >= max_entries: |
paul@5 | 40 | break |
paul@5 | 41 | |
paul@5 | 42 | output = [] |
paul@5 | 43 | |
paul@5 | 44 | if pages: |
paul@5 | 45 | output.append('<ul class="site-updates">\n') |
paul@5 | 46 | |
paul@5 | 47 | lines = pages.values() |
paul@5 | 48 | lines.sort() |
paul@5 | 49 | lines.reverse() |
paul@5 | 50 | |
paul@5 | 51 | for line in lines[:max_entries]: |
paul@5 | 52 | page = Page(request, line.pagename) |
paul@5 | 53 | link = page.link_to(request, text=page.split_title(request)) |
paul@5 | 54 | output.append('<li>%s</li>\n' % link) |
paul@5 | 55 | |
paul@5 | 56 | output.append('</ul>\n') |
paul@5 | 57 | |
paul@5 | 58 | return ''.join(output) |
paul@5 | 59 | |
paul@5 | 60 | # vim: tabstop=4 expandtab shiftwidth=4 |