1 # -*- coding: iso-8859-1 -*-
3 MoinMoin - RandomPage Macro
5 @copyright: 2000 Juergen Hermann <jh@web.de>
6 @license: GNU GPL, see COPYING for details.
12 from MoinMoin.Page import Page
14 Dependencies = ["time"]
16 def macro_RandomPage(macro, links=1):
17 request = macro.request
18 links = max(links, 1) # at least 1 link
20 # Get full page unfiltered page list - very fast!
21 all_pages = request.rootpage.getPageList(user='', exists=0)
23 # Now select random page from the full list, and if it exists and we
27 while found < links and all_pages:
28 # Take one random page from the list
29 pagename = random.choice(all_pages)
30 all_pages.remove(pagename)
32 # Filter out deleted pages or pages the user may not read.
33 page = Page(request, pagename)
34 if page.exists() and request.user.may.read(pagename):
35 pages.append(pagename)
43 # return a single page link
46 return (f.pagelink(1, name, generated=1) +
50 # return a list of page links
55 write(f.bullet_list(1))
58 write(f.pagelink(1, name, generated=1))
60 write(f.pagelink(0, name))
62 write(f.bullet_list(0))
64 result = ''.join(result)