Attachment 'ViewLogs-1.0.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - ViewLogs macro Version 1.0, 18.01.2013
4
5 Syntax:
6 <<ViewLogs>>; <<ViewLogs()>>
7 <<ViewLogs(page=pagename)>> default is current page
8 <<ViewLogs(page='^regex_pagenames')>> all matching pages with logs
9
10 Prerequisites:
11
12 ViewLog class is imported from viewlog.py in
13 wiki/data/plugin/logfile. This folder must also contain the
14 standard __init__.py for plugin modules.
15
16 <<ViewLog>> marco must run on the page for views to be logged.
17
18 History:
19
20 Version 1.0 - 18.01.2013: initial version.
21
22 @copyright: 2013 Ian Riley <ian.riley@internode.on.net>
23
24 incorporting code from:
25
26 @copyright: 2006-2008 MoinMoin:ThomasWaldmann,
27 2007 MoinMoin:ReimarBauer
28 2000-2004 Juergen Hermann <jh@web.de>
29 2000-2001 Richard Jones <richard@bizarsoftware.com.au>
30
31 license: GNU GPL, see COPYING for details.
32 """
33
34 import os, re, time
35 from MoinMoin import user, wikiutil
36 from MoinMoin.Page import Page
37
38 macroname = {'macroname': __name__.split('.')[-1]}
39
40 def execute(macro, args):
41 request = macro.request
42 _ = request.getText
43 user = request.user
44
45 ViewLog = wikiutil.importWikiPlugin(request.cfg, 'logfile', 'viewlog', 'ViewLog')
46
47 thisPage = macro.formatter.page
48
49 args_dict = {'page': ''}
50 if args:
51 try:
52 args_parser = wikiutil.ParameterParser('%(page)s%(regex)s')
53 (count, args_dict) = args_parser.parse_parameters(args)
54 except:
55 return _('Error: %(macroname)s macro has bad arguments.') % macroname
56
57 targetPage = thisPage.page_name
58 val = args_dict['page']
59 if val and val.lower() not in ['page']:
60 targetPage = val
61
62 regex = False
63 val = args_dict['regex']
64 if val and val.lower() in ['1', 'true', 'regex']:
65 regex = True
66
67
68 # get list of pages to report
69 inc_name = wikiutil.AbsPageName(thisPage.page_name, targetPage)
70 pageList = [inc_name]
71 if inc_name.startswith("^"):
72 try:
73 inc_match = re.compile(inc_name)
74 except re.error:
75 pass # treat as plain page name
76 else:
77 # get user filtered readable page list
78 pageList = request.rootpage.getPageList(filter = inc_match.match)
79
80 # get user filtered admin-able page list
81 checkedList = []
82 for inc_name in pageList:
83 if request.user.may.admin(inc_name):
84 checkedList.append(inc_name)
85
86 existsList = []
87 for inc_name in checkedList:
88 inc_page = Page(request, inc_name)
89 page_name = inc_page.page_name
90 pagelog = inc_page.getPagePath('view-log', use_underlay=0, isfile=1)
91 if os.path.exists(pagelog):
92 existsList.append(page_name)
93
94 pageList = sorted(existsList)
95 if regex:
96 result = "'^(%s)'" % ('|'.join(pageList))
97 else:
98 result = ', '.join(pageList)
99
100 return result
101
You are not allowed to attach a file to this page.