Attachment 'ImageLink-1.2.3.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - ImageLink Macro
   4 
   5     PURPOSE:
   6         This macro is used to set a link as WikiName for an attached image. Optional the size of the
   7 	image could be adjusted.
   8 
   9     CALLING SEQUENCE:
  10         [[ImageLink(attachment,WikiName,[width,[height]])]]
  11 
  12     INPUTS:
  13         attachment:image name of attachment
  14 	WikiName: the page to set the link to
  15 
  16     OPTIONAL INPUTS:
  17         width: width of the embedded image
  18 	height: height of the embedded image
  19 
  20     EXAMPLE:
  21       [[ImageLink(plot.gif,FrontPage,20,20)]]
  22       [[ImageLink(plot.gif,FrontPage)]]
  23 
  24     PROCEDURE:
  25       This routine requires attachment enabled. If the attachment isn't downloaded at all
  26       the attachment line is shown.
  27 
  28       It must be in "MoinMoin/macro"
  29 
  30 
  31     @copyright: 2004 by Reimar Bauer (R.Bauer@fz-juelich.de)
  32     @license: GNU GPL, see COPYING for details.
  33 """
  34 
  35 #Dependencies = []
  36 
  37 from MoinMoin.action import AttachFile
  38 import string,os
  39 
  40 
  41 def execute(macro, args):
  42 
  43    width=''
  44    height=''
  45    n_args=string.count(args,',')+1
  46 
  47    sargs=args.split(',')
  48    attname=string.join(sargs[0],'')
  49    link=string.join(sargs[1],'')
  50 
  51 
  52    pagename=macro.formatter.page.page_name
  53    url=AttachFile.getAttachUrl(pagename,attname,macro.request)
  54 
  55    attach_dir=AttachFile.getAttachDir(pagename,create=1)
  56    if not os.path.isfile(attach_dir+'/'+attname):
  57       return '<a href="/'+pagename+'?action=AttachFile&amp;rename='+attname+'">Upload new attachment "'+attname+'"</a>'
  58 
  59 
  60    substring=''
  61    if (n_args >= 3):
  62      width=string.join(sargs[2],'')
  63      substring=' width="'+width+'"'
  64    if (n_args == 4):
  65       height=string.join(sargs[3],'')
  66       substring=substring+' height="'+height+'"'
  67 
  68 
  69    return '<a title="'+link+'" href='+link+'> <img src="' + url+'"'+' '+substring+'> </a>'

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] (2004-09-18 14:03:39, 2.6 KB) [[attachment:ImageLink-1.2.3-2.py]]
  • [get | view] (2004-09-20 07:19:06, 3.3 KB) [[attachment:ImageLink-1.2.3-3.py]]
  • [get | view] (2004-09-11 07:34:46, 1.7 KB) [[attachment:ImageLink-1.2.3.py]]
 All files | Selected Files: delete move to page copy to page

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