Attachment 'EO-1.5.3-2.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - EO Macro
4
5 PURPOSE:
6 This macro is used to Embed an Object into a wiki page. Optional size of the object
7 could be adjusted. Further keywords are dependent on the kind of application
8
9 CALLING SEQUENCE:
10 [[EO(attachment[,width=width][,height=heigt])]]
11
12 INPUTS:
13 attachment:image name of attachment
14
15 KEYWORD PARAMETERS:
16 width: width of the embedded image, default is 100% of window
17 height: height of the embedded image, default is 100% of window
18
19 application/x-shockwave-flash:
20 play: true is default
21 loop: true is default
22 quality: high is default (medium,low)
23
24 EXAMPLE:
25 [[EO]]
26 [[EO(example.swf)]]
27 [[EO(example.swf,width=637,height=392)]]
28 [[EO(SlideShow/example.swf,width=637,height=392)]]
29 [[EO(SlideShow/example.swf,width=637,height=392,play=false)]]
30 [[EO(SlideShow/example.swf,width=637,height=392,play=false,loop=false)]]
31 [[EO(SlideShow/example.swf,width=637,height=392,play=false,loop=low)]]
32
33 PROCEDURE:
34 This routine requires attachment enabled. If the attachment isn't downloaded at all
35 the attachment line is shown.
36 If you give only one size argument e.g. width only the other one is calculated
37
38 By the swftools it is possible to get the swf size returned. I don't know if it is
39 possible to get sizes for svg, pdf and others detected too, that's the reason why
40 I haven't added it by now.
41
42 Please add needed mimetypes as objects.
43
44 It must be in "MoinMoin/macro"
45
46 Please remove the version number from the file name!
47
48 MODIFICATION HISTORY:
49 @copyright: 2006 by Reimar Bauer (R.Bauer@fz-juelich.de)
50 initial version: 1.5.0-1
51 2006-05-04 TomSi: added mp3 support
52 2006-05-09 RB code refactored, fixed a taintfilename bug
53
54 """
55 import os, mimetypes
56 from MoinMoin import wikiutil
57 from MoinMoin.action import AttachFile
58
59 def execute(macro, args):
60 request = macro.request
61 _ = request.getText
62 formatter = macro.formatter
63 if args:
64 args = args.split(',')
65 args = [arg.strip() for arg in args]
66 else:
67 args = []
68
69 argc = len(args)
70 kw_count = 0
71 kw = {} # create a dictionary
72 kw["width"] = "100%"
73 kw["height"] = "100%"
74 kw["play"] = "true"
75 kw["loop"] = "true"
76 kw["quality"] = "high"
77
78 for arg in args :
79 if '=' in arg:
80 kw_count += 1
81 key, value = arg.split('=', 1)
82 kw[str(key)] = wikiutil.escape(value, quote=1)
83
84 argc -= kw_count
85
86 if not argc:
87 msg='Not enough arguments to EO macro! Try [[EO(attachment [,width=width] [,height=heigt])]]'
88 return "%s%s%s" % (formatter.sysmsg(1), formatter.text(msg), formatter.sysmsg(0))
89 else:
90 target = args[0]
91
92 target = wikiutil.taintfilename(target)
93 pagename, attname = AttachFile.absoluteName(target, formatter.page.page_name)
94 attachment_fname = AttachFile.getFilename(request, pagename, attname)
95
96 if not os.path.exists(attachment_fname):
97 linktext = _('Upload new attachment "%(filename)s"')
98 return wikiutil.link_tag(request,
99 ('%s?action=AttachFile&rename=%s' % (
100 wikiutil.quoteWikinameURL(pagename),
101 wikiutil.url_quote_plus(attname))),
102 linktext % {'filename': attname})
103
104 url = AttachFile.getAttachUrl(pagename,attname,request)
105
106 mime_type, enc = mimetypes.guess_type(attname)
107
108 if mime_type == "application/x-shockwave-flash":
109 return '''
110 <OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
111 WIDTH="%(width)s"
112 HEIGHT="%(height)s"
113 CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=6,0,23,0">
114 <PARAM NAME="MOVIE" VALUE="%(file)s">
115 <PARAM NAME="PLAY" VALUE="%(play)s">
116 <PARAM NAME="LOOP" VALUE="%(loop)s">
117 <PARAM NAME="QUALITY" VALUE="%(quality)s">
118 <EMBED SRC="%(file)s" WIDTH="%(width)s" HEIGHT="%(height)s"
119 PLAY="%(play)s" ALIGN="" LOOP="%(loop)s" QUALITY="%(quality)s"
120 TYPE="application/x-shockwave-flash"
121 PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
122 </EMBED>
123 </OBJECT>''' % {
124 "width": kw["width"],
125 "height": kw["height"],
126 "play": kw["play"],
127 "loop": kw["loop"],
128 "quality": kw["quality"],
129 "file": url}
130
131 elif mime_type == "image/svg+xml":
132 return '''
133 <OBJECT CLASSID=""
134 WIDTH="%(width)s"
135 HEIGHT="%(height)s"
136 CODEBASE="http://purl.org/dc/dcmitype/StillImage">
137 <EMBED SRC="%(file)s" WIDTH="%(width)s" HEIGHT="%(height)s"
138 TYPE="image/svg+xml">
139 </EMBED>
140 </OBJECT>''' % {
141 "width": kw["width"],
142 "height": kw["height"],
143 "file": url}
144
145 elif mime_type == "application/pdf":
146 return '''
147 <OBJECT CLASSID=""
148 WIDTH="%(width)s"
149 HEIGHT="%(height)s"
150 CODEBASE="http://www.adobe.com">
151 <EMBED SRC="%(file)s" WIDTH="%(width)s" HEIGHT="%(height)s"
152 TYPE="application/pdf">
153 </EMBED>
154 </OBJECT>''' % {
155 "width": kw["width"],
156 "height": kw["height"],
157 "file": url}
158
159 elif mime_type == "audio/mpeg":
160 return '''
161 <OBJECT CLASSID=""
162 WIDTH="%(width)s"
163 HEIGHT="%(height)s"
164 <EMBED SRC="%(file)s" HEIGHT="0" REPEAT="TRUE" AUTOSTART="TRUE" WIDTH="0" OP="TRUE"
165 TYPE="audio/mpeg">
166 </EMBED>
167 </OBJECT>''' % {
168 "width": kw["width"],
169 "height": kw["height"],
170 "file": url}
171
172 else:
173 msg = 'Not supported mimetype %(mimetype)s ' % {"mimetype":mime_type}
174 return "%s%s%s" % (macro.formatter.sysmsg(1),
175 macro.formatter.text(msg),
176 macro.formatter.sysmsg(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.You are not allowed to attach a file to this page.