view MoinMoin/macro/ @ 3085:fdb68a8f92da

fix wrong pagename when creating new pages on Mac OS X (ported from 1.6)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 23 Feb 2008 00:28:53 +0100
parents 388204baf00f
children 2a3a6cb34e45
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
    MoinMoin - RandomQuote Macro

    Selects a random quote from FortuneCookies or a given page.


        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 <>
    @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, wikiutil

Dependencies = ["time"]

def execute(macro, args):
    _ = macro.request.getText

    pagename = args or 'FortuneCookies'
        page = Page(macro.request, pagename)
        raw = page.get_raw_body()
        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} +

    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