Attachment 'NewWindow.py'

Download

   1 # -*- coding: utf-8 -*-
   2 """
   3     MoinMoin - NewWindow Macro
   4 
   5     PURPOSE:
   6         This macro is used to create a link which opens in a new browser window
   7 
   8     CALLING SEQUENCE:
   9         [[NewWindow(target,[description],[link attributes])]]
  10 
  11     INPUTS:
  12         target: the target to link to (external link or pagename)
  13         description: the name for the link
  14         link attributes: normal html attributes for the link (like title='')
  15 
  16     EXAMPLE:
  17         [[NewWindow("FrontPage","to FrontPage",title="open FrontPage in new window")]]
  18         [[NewWindow(http://thor,Thor,style="background-color:yellow")]]
  19         [[NewWindow(http://thor,Thor)]]
  20         [[NewWindow(http://www.google.com)]]
  21 
  22     MODIFICATION HISTORY:
  23         @copyright: 2005 by Mat (mat AT matware DOT de)
  24         @license: GNU GPL, see COPYING for details.
  25 """
  26 
  27 from MoinMoin import wikiutil, util
  28 def execute(macro, text):
  29     if text:
  30         args = text.split(',')
  31     else:
  32         msg =  'Usage: [[NewWindow(link, linktext, [attributes])]]'
  33         return macro.formatter.sysmsg(1) + macro.formatter.text(msg) + macro.formatter.sysmsg(0)
  34 
  35     numberOfArgs = len(args)
  36     href = args[0].replace('"','').strip('')
  37 
  38     if numberOfArgs > 1:
  39         text = args[1].replace('"','').strip('')
  40     else:
  41         text = href
  42 
  43     if numberOfArgs > 2:
  44         attribs = ''
  45         for a in args[2:]:
  46             a = a.split('=')
  47             a[1] = a[1].replace('"','')
  48 
  49             attribs = '%s %s="%s"' % (attribs, a[0], a[1])
  50     else:
  51         attribs = ''
  52 
  53     if href.startswith('http://') or href.startswith('https://') or href.startswith('ftp://'):
  54         # external link
  55         html = '''<a href="%(href)s" target="_blank"%(attribs)s>%(img)s</a>&nbsp;<a href="%(href)s" target="_blank"%(attribs)s>%(text)s</a>''' % {
  56             'img':     util.web.getLinkIcon(macro.request, macro.formatter, "www"),
  57             'href':    href,
  58             'attribs': attribs,
  59             'text':    text,
  60         }
  61     else:
  62         # wiki link
  63         html = '<a href="%(href)s" target="_blank"%(attribs)s>%(text)s</a>' % {
  64             'href':    macro.request.getScriptname() + '/' + wikiutil.quoteWikinameURL(href),
  65             'attribs': attribs,
  66             'text':    text,
  67         }
  68 
  69     return html

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2005-03-12 17:53:33, 2.2 KB) [[attachment:NewWindow.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.