view data/plugin/macro/qwebirc.py @ 625:f4e63b74b969

FormSubmit: adapt to werkzeug MultiDict
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 25 Mar 2013 17:47:30 +0100
parents 466dca86625d
children
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
"""
    MoinMoin - embed a qwebirc based IRC chat iframe

    Usage:
    ------
    <<qwebirc(server="freenode",channels="#moin")>>

    # . in nick name will give some random number:
    <<qwebirc(server="freenode",channels="#moin,#moin-dev",nick="moin.")>>

    # maybe nice for a wiki homepage:
    <<qwebirc(server="freenode",channels="#moin",nick="mynick",width=900,height=500)>>

    # choose a random nickname, but still show dialogue (so you can change it):
    <<qwebirc(server="freenode",channels="#moin,#moin-dev",randomnick=1,prompt=1)>>

    Configuration:
    --------------
    The macro has a (small) builtin list of qwebirc based chat servers, but you
    can use your own by defining it in your wiki config:

    qwebirc_servers = {
        # server name: web based service url
        'freenode': 'http://webchat.freenode.net/',
        # add your own ones here
    }

    For more information about qwebirc, see: http://www.qwebirc.org/

    @copyright: 2009 MoinMoin:ThomasWaldmann
    @license: GNU GPL, see COPYING for details.
"""

# "known" qwebirc servers, use cfg.qwebirc_servers to give more
builtin_servers = {
    'freenode': 'http://webchat.freenode.net/',
    'freenode-ssl': 'https://webchat.freenode.net/',
    'quakenet': 'http://webchat.quakenet.org/',
}


from MoinMoin import wikiutil


def macro_qwebirc(macro,
                  server=wikiutil.required_arg(unicode),
                  channels=wikiutil.required_arg(unicode),
                  nick=u'', randomnick=0, prompt=0, width=647, height=400):
    """ Embed a qwebirc based IRC chat iframe """
    request = macro.request
    cfg = request.cfg
    servers = getattr(cfg, 'qwebirc_servers', builtin_servers)

    try:
        base_url = servers[server]
    except KeyError:
        # unknown server (we only allow specific server urls to avoid XSS)
        return u'qwebirc: unknown server (choose from %r)' % servers.keys()

    qs = dict(width=width, height=height)
    if channels:
        qs['channels'] = channels
    if nick:
        qs['nick'] = nick
    if randomnick:
        qs['randomnick'] = randomnick
    if prompt:
        qs['prompt'] = prompt
    qs = wikiutil.makeQueryString(qs)
    html = u"""<iframe src="%(base_url)s?%(qs)s" width="%(width)d" height="%(height)d"></iframe>\n""" % locals()
    return macro.formatter.rawHTML(html)