Attachment 'ImageLink-1.3.3-7.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. If no WikiName is given the attachment is linked to the image itselfs.
   8 
   9     CALLING SEQUENCE:
  10         [[ImageLink(attachment|URL,[WikiName|URL],[width=width,[height=heigt]])]]
  11 
  12     INPUTS:
  13         attachment:image name of attachment or the URL to an image
  14 
  15     OPTIONAL INPUTS:
  16         WikiName: the page to set the link to or the URL to link to
  17 
  18 
  19     KEYWORD PARAMETERS:
  20         width: width of the embedded image
  21         height: height of the embedded image
  22 
  23     EXAMPLE:
  24         [[ImageLink(plot.png,FrontPage,width=20,height=20)]]
  25         [[ImageLink(plot.png,FrontPage,height=20)]]
  26         [[ImageLink(plot.png,FrontPage)]]
  27         [[ImageLink(plot.png,width=20,height=20)]]
  28         [[ImageLink(plot.png,width=20)]]
  29         [[ImageLink(plot.png)]]
  30         [[ImageLink(http://localhost/wiki/modern/img/to_slide.png,http://localhost/StartSeite,width=50)]]
  31         [[ImageLink(http://localhost/wiki/modern/img/to_slide.png,FrontPage,width=50)]]
  32         [[ImageLink(plot.png,http://localhost/StartSeite,width=50)]]
  33         [[ImageLink(http://localhost/wiki/modern/img/to_slide.png)]]
  34         [[ImageLink(http://localhost/wiki/modern/img/to_slide.png,alt=whateveryouwant)]]
  35 
  36     PROCEDURE:
  37         This routine requires attachment enabled. If the attachment isn't downloaded at all
  38          the attachment line is shown.
  39          If you give only one image size argument e.g. width only the other one is calculated
  40 
  41         It must be in "MoinMoin/macro"
  42 
  43         Please remove the version number from the file name!
  44 
  45         From JeffKunce ImageLink.py I have copied _is_URL to this routine. I have no better idea too.
  46 
  47     HISTORY:
  48       The first published version on MoinMoin I know of ImageLink was written by JeffKunce in 2001.
  49 
  50     MODIFICATION HISTORY:
  51         @copyright: 2004 by Reimar Bauer (R.Bauer@fz-juelich.de)
  52         @license: GNU GPL, see COPYING for details.
  53 
  54     Marcin Zalewski:
  55         Some things that were causing problems on my wiki are changed
  56             (wikiutil.link_tag and macro.formatter.pagelink implemented)
  57 
  58         Marcin Zalewski:
  59             Added title attribute to the created link. One could generalize that to
  60             add arbitrary attributes.
  61 
  62             One could also add class attributes to <a> and/or
  63             <img> elements. I do not see the need for such modifications. If however this is
  64             to be done in the future one would need to add 'html_class' key to the kw dictionary
  65             with a corresponding value to add class to <img> element. To add class to <a> element
  66             one needs to add 'css_class' key with a corresponding value to the dictionary passed to
  67             pagelink call.
  68        Reimar Bauer:
  69             2004-12-23 Adopted to MoinMoin Version 1.3.1-1
  70             2004-12-23 SYNTAX CHANGE Version 1.3.1-2
  71                    width and height and probably other keywords must be called as keywords (e.g. height=20)
  72             2004-12-31 Version 1.3.1-3 code clean up
  73             2005-01-16 Bug fixed in the errorhandler found and patch code from Malte Helmert
  74 	    2005-03-05 Version 1.3.3-5 Bug fixed found by cypress
  75 	                               ''If I put [[ImageLink(moinmoin.png)]] it bombs''
  76             2005-03-28 Version 1.3.3-6 feature request added by CDPark:
  77                         ''Can we use an external image? And an external target? ''
  78             2005-04-16 Version 1.3.3-7 no default alt tag definition requested by  CDPark and AlexanderSchremmer
  79 
  80 
  81 """
  82 
  83 from MoinMoin.action import AttachFile
  84 from MoinMoin import wikiutil, config
  85 import os,string
  86 
  87 def _is_URL(aString):
  88     '''answer true if aString is a URL.
  89     The method used here is pretty dumb. Improvements are welcome.
  90     jjk  03/28/01'''
  91     return string.find(aString, '://')>0
  92 
  93 
  94 def execute(macro, text):
  95 
  96     kw ={} # create a dictionary for the formatter.image call
  97 
  98     if text:
  99         args=text.split(',')
 100     else:
 101         args=[]
 102 
 103     number_args=len(args)
 104     count=0
 105     for a in args :
 106         if (a.find('=') > -1):
 107             count=count+1
 108             key=a.split('=')
 109             kw[str(key[0])]=wikiutil.escape(string.join(key[1],''), quote=1)
 110 
 111     number_args=number_args-count
 112 
 113     if (number_args < 1):
 114         msg='Not enough arguments to ImageLink macro! Try [[ImageLink(attachment,[WikiName],[width=width,[height=heigt]])]]'
 115         return macro.formatter.sysmsg(1)+macro.formatter.text(msg)+ macro.formatter.sysmsg(0)
 116 
 117 
 118     attname=wikiutil.taintfilename(macro.formatter.text(args[0]))
 119     if (number_args == 2) :
 120         wikiname=args[1]
 121     current_pagename=macro.formatter.page.page_name
 122     kw['src']=AttachFile.getAttachUrl(current_pagename,attname,macro.request)
 123     attachment_path = os.path.join(AttachFile.getAttachDir(macro.request,current_pagename), attname)
 124 
 125 
 126     if not _is_URL(args[0]):
 127 
 128         if not os.path.exists(attachment_path):
 129             import urllib
 130             linktext = macro.request.getText('Upload new attachment "%(filename)s"')
 131             return wikiutil.link_tag(macro.request,
 132                                  '%s?action=AttachFile&amp;rename=%s' %
 133                                  (wikiutil.quoteWikinameFS(current_pagename),
 134                                  urllib.quote_plus(attname)),
 135                                  linktext % {'filename': attname})
 136 
 137     if (number_args == 1):
 138         if _is_URL(args[0]):
 139            kw['src']=args[0]
 140            image_link=macro.formatter.image(**kw)
 141            return macro.formatter.url(1,kw['src'] )+image_link +macro.formatter.url(0)
 142         else:
 143             kw['title']=attname
 144             image_link=macro.formatter.image(**kw)
 145             return macro.formatter.url(1,kw['src'] )+image_link +macro.formatter.url(0)
 146 
 147     if (number_args == 2 ):
 148         if _is_URL(args[0]):
 149             kw['src']=args[0]
 150         else:
 151             kw['title']=wikiname
 152 
 153         image_link=macro.formatter.image(**kw)
 154         if _is_URL(args[1]):
 155            kw['src']=args[1]
 156            return macro.formatter.url(1,kw['src'] )+image_link+macro.formatter.url(0)
 157         else:
 158            return macro.formatter.pagelink(1,wikiname)+image_link+macro.formatter.url(0)

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] (2006-06-27 13:22:40, 447.6 KB) [[attachment:Ein Prosit]]
  • [get | view] (2005-04-16 21:38:31, 6.2 KB) [[attachment:ImageLink-1.3.3-7.py]]
  • [get | view] (2005-04-17 15:33:24, 6.6 KB) [[attachment:ImageLink-1.3.3-8.py]]
  • [get | view] (2005-04-21 16:09:30, 6.9 KB) [[attachment:ImageLink-1.3.3-9.py]]
  • [get | view] (2005-12-19 19:47:34, 7.1 KB) [[attachment:ImageLink-1.5.0-10.py]]
  • [get | view] (2006-02-15 17:42:37, 7.2 KB) [[attachment:ImageLink-1.5.2-11.py]]
  • [get | view] (2006-02-22 22:26:50, 7.3 KB) [[attachment:ImageLink-1.5.2-12.py]]
  • [get | view] (2006-03-11 22:20:23, 6.6 KB) [[attachment:ImageLink-1.5.3.py]]
  • [get | view] (2008-01-25 19:57:41, 10.0 KB) [[attachment:ImageLink-1.6.0.py]]
  • [get | view] (2006-03-11 22:46:46, 61.8 KB) [[attachment:München.png]]
 All files | Selected Files: delete move to page copy to page

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