/usr/share/pyshared/MoinMoin/macro/RandomQuote.py is in python-moinmoin 1.9.3-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | # -*- coding: iso-8859-1 -*-
"""
MoinMoin - RandomQuote Macro
Selects a random quote from FortuneCookies or a given page.
Usage:
<<RandomQuote()>>
<<RandomQuote(WikiTips)>>
Comments:
It will look for list delimiters on the page in question.
It will ignore anything that is not in an "*" list.
@copyright: 2002-2004 Juergen Hermann <jh@web.de>
@license: GNU GPL, see COPYING for details.
Originally written by Thomas Waldmann.
Gustavo Niemeyer added wiki markup parsing of the quotes.
"""
import random
from MoinMoin.Page import Page
Dependencies = ["time"]
def macro_RandomQuote(macro, pagename=u'FortuneCookies'):
_ = macro.request.getText
if macro.request.user.may.read(pagename):
page = Page(macro.request, pagename)
raw = page.get_raw_body()
else:
raw = ""
# this selects lines looking like a list item
# !!! TODO: make multi-line quotes possible (optionally split by "----" or something)
quotes = raw.splitlines()
quotes = [quote.strip() for quote in quotes]
quotes = [quote[2:] for quote in quotes if quote.startswith('* ')]
if not quotes:
return (macro.formatter.highlight(1) +
_('No quotes on %(pagename)s.') % {'pagename': pagename} +
macro.formatter.highlight(0))
quote = random.choice(quotes)
page.set_raw_body(quote, 1)
quote = macro.request.redirectedOutput(page.send_page,
content_only=1, content_id="RandomQuote")
return quote
|