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 # Generate links random pagelinks. If links is 1, linktext can be used to
17 # override the link text.
18 def macro_RandomPage(macro, links=1, linktext=None):
19 request = macro.request
20 links = max(links, 1) # at least 1 link
22 # Get full page unfiltered page list - very fast!
23 all_pages = request.rootpage.getPageList(user='', exists=0)
25 # Now select random page from the full list, and if it exists and we
29 while found < links and all_pages:
30 # Take one random page from the list
31 pagename = random.choice(all_pages)
32 all_pages.remove(pagename)
34 # Filter out deleted pages or pages the user may not read.
35 page = Page(request, pagename)
36 if page.exists() and request.user.may.read(pagename):
37 pages.append(pagename)
45 # return a single page link
48 return (f.pagelink(1, name, generated=1) +
49 f.text(linktext or name) +
52 # return a list of page links
57 write(f.bullet_list(1))
60 write(f.pagelink(1, name, generated=1))
62 write(f.pagelink(0, name))
64 write(f.bullet_list(0))
66 result = ''.join(result)