"""
    MoinMoin - action for interfacing with cgi:irc

    Copyright (c) 2002 by Thomas Waldmann
    All rights reserved, see COPYING for details.

    This action allows you to have an easy way to login into an irc channel.
    You need to have cgi:irc installed (get it from http://www.cgiirc.visionhost.net/).
    Then change the irc_url setting in the execute function (see a few lines below).
    This should be all needed to make it work.
"""

# Imports
from MoinMoin import config, user, webapi, wikiutil
from MoinMoin.i18n import _


def execute(pagename, request):
    # change here:
    #    irc_url = config.irc_url
    irc_url = "chat/irc.cgi"

    # javascript code needed for cgi:irc
    js = """
<script language="JavaScript"><!--
function setjs() {
 if(navigator.product == 'Gecko') {
   document.loginform["interface"].value = 'mozilla';
 }else if(navigator.appName == 'Microsoft Internet Explorer' &&
window["ietest"] && window["ietest"].innerHTML) {
   document.loginform["interface"].value = 'ie';
 }else if(window.opera) {
   document.loginform["interface"].value = 'opera';
 }
}
//-->
</script>
"""
    # automatically submit form
    bodyopts='onload="setjs();document.loginform.submit()"'

    # use wiki user name as nick name for IRC
    nick = wikiutil.quoteWikiname(('',user.current.name)[user.current.valid])
    button = _(' Chat ')


    formhtml = """
<form method="POST" action="%(irc_url)s" name="loginform" onsubmit="setjs();return true;" id="ietest">
<input type="hidden" name="interface" value="nonjs">
<input type="hidden" name="Nickname" value="%(nick)s">
<input type="submit" name="button" value="%(button)s">
</form>""" % locals()


    # send header
    webapi.http_headers(request)

    # send head and body
    print """
<html>
<head>
%(js)s
</head>
<body %(bodyopts)s>
%(formhtml)s
""" % locals()
    
    # end tags are sent automagically
    