Attachment 'modified_attachment_image.py'
Download 1 # a modified attachment_image() in application_odt_psuedoformatter.py
2 # to allow inclusion of attachments sourced from other pages
3 # modified by IanRiley 2012.01.02
4
5 def attachment_image(self, url, *args, **kargs):
6 # prevent hacking (filenames like "../../../../etc/passwd")
7 # attachbasename = wikiutil.taintfilename( url )
8
9 # The above prevents including attachments from other wiki pages,
10 # resulting in an untrapped error at line 151 in RenderAsOpenDocument.py.
11 # An alternative (remember to import os above):
12
13 pagename, filename = AttachFile.absoluteName(url, self.pagename)
14 fname = wikiutil.taintfilename(filename)
15 fpath = AttachFile.getFilename(self.request, pagename, fname)
16 if os.path.exists(fpath):
17 attachbasename = fname
18 else:
19 attachbasename = None
20
21 # accept only the most popular web image types
22 (mimetype, extension) = self.getMimetype( attachbasename )
23 if not mimetype.startswith( "image/" ): return ""
24
25 # get real path in filesystem
26 # use pagename from AttachFile.absoluteName not self.pagename
27 attachfilename = AttachFile.getFilename(self.request, pagename, attachbasename)
28
29 # create internal name and store filename->internal name mapping, but only once
30 if attachfilename in self.attachments:
31 internalName = self.attachments[ attachfilename ]
32 else:
33 if self.isIncluded:
34 # Will be replaced by calling formatter
35 includeId = '<<INCLUDE_ID>>'
36 else:
37 includeId = ''
38
39 internalName = str( self.getNextAttachmentCounter() )
40 internalName = "Pictures/" + includeId + (12 - len(internalName) ) * "0" + internalName + "." + extension
41 self.attachments[ attachfilename ] = internalName
42
43 # embed image
44 self.open( 'draw:frame' )
45 imageNode = self.open( 'draw:image' )
46 imageNode.setAttribute( 'xlink:href', self.attachments[attachfilename] )
47 imageNode.setAttribute( 'xlink:type', 'simple' )
48 imageNode.setAttribute( 'xlink:show', 'embed' )
49 imageNode.setAttribute( 'xlink:actuate', 'onLoad' )
50 self.close( 'draw:image' )
51 self.close( 'draw:frame' )
52 return ""
53
54
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.