Attachment 'ScheduledPages-1.0.py'
Download
Toggle line numbers
1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - ScheduledPages Version 1.0, 12.02.2019
4
5 Creates a list of pages that have been scheduled using processing
6 instructions, either as '#format schedule' (see plugin parser
7 [[schedule.py]]) or '#schedule' (also see [[PiSchedule]] and modified
8 page.py with new the processing instruction, #schedule, and special page
9 type `hidden`).
10
11 The numbered list includes a link to the scheduled page followed by
12 scheduling arguments and status. If it is currently viewable by read-only
13 users, then 'show = True'. If it is set to silent (i.e. users are not warned
14 the page is not visible by of the scheduling, then 'silent = True'). If the
15 scheduling arguments have a syntax error, then a warning is given. In such
16 cases, the [[schedule.py|schedule]] parser makes the conservative decision
17 to set 'show = False'. However, if not scheduling arguments were given the
18 list says, 'schedule = none' and 'show = True'.
19
20 If the page has been indirectly scheduled by pointing to a Schedule page
21 (e.g., #schedule SomethingSchedule), then the schedule is preceded by this
22 information as 'source = !SomethingSchedule' with the Schedule page name as
23 an active link to that page.
24
25 The list can be sorted either alphabetically by page name (default) or
26 chronolocially by the schedule arguments, i.e. the release ('after') date.
27
28 Syntax:
29 <<ScheduledPages>>
30
31 @copyright: 2019 Ian Riley <ian@riley.asia>
32 license: GNU GPL, see COPYING for details.
33
34 Based on:
35 WantedPages macro
36 @copyright: 2001 Juergen Hermann <jh@web.de>
37 license: GNU GPL, see COPYING for details.
38
39 """
40 import operator
41 from MoinMoin import wikiutil
42
43 Dependencies = ["pages"]
44
45 def macro_ScheduledPages(macro):
46 request = macro.request
47 _ = request.getText
48
49 # prevent recursion
50 if request.mode_getpagelinks:
51 return ''
52 if request.isSpiderAgent: # reduce bot cpu usage
53 return ''
54
55 # Get allpages switch from the form
56 sortpages = int(request.values.get('sortpages', 0)) != 0
57
58 # Control bar - sort the list of pages
59 label = (_('Sort chronologically'), _('Sort alphabectically'))[sortpages]
60 page = macro.formatter.page
61 controlbar = macro.formatter.div(1, css_class="controlbar") + \
62 page.link_to(request, label, querystr={'sortpages': '%s' % (sortpages and '0' or '1')}) + \
63 macro.formatter.div(0)
64
65 # get page dict readable by current user
66 pages = request.rootpage.getPageDict()
67
68 # build a dict of scheduled pages
69 scheduled = {}
70 for name, page in pages.items():
71 # skip system pages
72 if wikiutil.isSystemPage(request, name):
73 continue
74
75 # get scheduled pages in page dict
76 if page.parse_processing_instructions().get('format', False) == 'schedule':
77 args = page.parse_processing_instructions().get('formatargs', None)
78 scheduled[name] = args
79 #pi-format takes priority over pi-schedule
80 elif page.parse_processing_instructions().get('schedule', False):
81 args = page.parse_processing_instructions().get('schedule', None)
82 scheduled[name] = args
83
84 # Check for the extreme case when there are no scheduled pages
85 if not scheduled:
86 return u"%s<p>%s</p>" % (controlbar, _("No scheduled pages in this wiki."))
87
88 Scheduler = wikiutil.searchAndImportPlugin(macro.cfg, "parser", "schedule")
89 checker = Scheduler('', request).process_schedule_args
90 for name, args in scheduled.items():
91 show, silent, info_msg, err_msg, argstr = checker(name, args)
92 if silent:
93 argstr = argstr.replace('silent', '').strip()
94 if argstr.startswith(' [['):
95 argstr = "none%s" % argstr
96 scheduled[name] = "schedule = %s, show = %s, silent = %s" % (argstr, show, silent)
97 scheduled[name] = scheduled[name].replace('True', '<font color="green">True</font>')
98 scheduled[name] = scheduled[name].replace('False', '<font color="red">False</font>')
99 if err_msg:
100 scheduled[name] = '%s : <strong class="error">Error in schedule, so page not shown</strong>' % scheduled[name]
101
102 # Return a list of schedule page
103 sorted_pages = sorted(scheduled.items(), key=operator.itemgetter(sortpages))
104 result = []
105 result.append(macro.formatter.number_list(1))
106 for name, args in sorted_pages:
107 if not name:
108 continue
109 result.append(macro.formatter.listitem(1))
110 # Add link to the scheduled page
111 result.append(macro.formatter.pagelink(1, name, generated=1))
112 result.append(macro.formatter.text(name))
113 result.append(macro.formatter.pagelink(0, name))
114 if not '[[' in args:
115 result.append("<p>%s</p>" % args)
116 else:
117 args1, source = args.split(' [[')
118 source, args2 = source.split(']]')
119 result.append("<p>source = ")
120 result.append(macro.formatter.pagelink(1, source, generated=1))
121 result.append(macro.formatter.text(source))
122 result.append(macro.formatter.pagelink(0, source))
123 result.append(", %s%s</p>" % (args1, args2))
124 result.append(macro.formatter.listitem(0))
125 result.append(macro.formatter.number_list(0))
126
127 return u'%s%s' % (controlbar, u''.join(result))
You are not allowed to attach a file to this page.