changeset 439:c0ca7b5ba39b

qwebirc macro: make it more general, not only for freenode
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 03 Oct 2009 19:08:53 +0200
parents 3c8ef0289f41
children 24897c510f52
files data/plugin/macro/qwebirc.py
diffstat 1 files changed, 33 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/macro/qwebirc.py	Sat Oct 03 18:53:39 2009 +0200
+++ b/data/plugin/macro/qwebirc.py	Sat Oct 03 19:08:53 2009 +0200
@@ -1,19 +1,47 @@
 # -*- coding: iso-8859-1 -*-
 """
-    MoinMoin - embed a webchat.freenode.net IRC chat iframe
+    MoinMoin - embed a qwebirc based IRC chat iframe
 
     @copyright: 2009 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 
+# "known" qwebirc servers, you can use cfg.qwebirc_servers to give
+# your own dictionary:
+servers = {
+    'freenode': 'http://webchat.freenode.net/',
+}
+
+# default server (if none is specified in the macro call, you can use
+# cfg.qwebirc_server_default to give your own default server:
+server_default = 'freenode'
+
+
 from MoinMoin import wikiutil
 
-def macro_FreeNodeChat(macro, channels=u'', nick=u'', randomnick=0, prompt=0, width=647, height=400):
-    """ Embed a freenode web chat iframe
 
-        <<FreeNodeChat()>>
+def macro_qwebirc(macro, channels=u'', nick=u'', randomnick=0, prompt=0,
+                  width=647, height=400, server=u''):
+    """ Embed a qwebirc based IRC chat iframe
+
+        <<qwebirc()>>
     """
-    base_url = 'http://webchat.freenode.net/'
+    try:
+        servers = getattr(macro.request.cfg, 'qwebirc_servers')
+    except AttributeError:
+        pass # use "servers" from globals
+
+    if not server:
+        try:
+            server = getattr(cfg, 'qwebirc_server_default')
+        except AttributeError:
+            server = server_default
+    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