Edgewall Software

MacroBazaar: redirect.py

File redirect.py, 914 bytes (added by haui at haumacher.de, 7 years ago)

Macro for redirects and page aliases. Descrition see: MacroBazaar

Line 
1# vim: expandtab tabstop=4
2from StringIO import StringIO
3import re
4import string
5from trac import WikiFormatter
6from trac.WikiFormatter import CommonFormatter
7
8def execute(hdf, args, env):
9    db = env.get_db_cnx()
10    out = StringIO()
11    fmt = CommonFormatter(hdf, env, db)
12    if args:
13        link = fmt._expand_module_link(args)
14        if link[0] != None:
15            # out.write("<tt>");
16            # out.write(link[0]);
17            # out.write("</tt>");
18            out.write("<script language=\"JavaScript\">\n")
19            out.write("document.location=\"")
20            out.write(link[0])
21            out.write("\";\n")
22            out.write("</script>")
23            return out.getvalue()
24        else:
25            out.write('<div class="system-message"><strong>Error: Redirection target not found.</strong></div>')
26    else:
27        out.write('<div class="system-message"><strong>Error: Missing redirection URL.</strong></div>')
28