Attachment 'gallery2image-1.3.5-5.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - gallery2Image Actionmacro
4
5 PURPOSE:
6 This action macro is used to rotate the images from Gallery2
7
8 CALLING SEQUENCE:
9 called by Gallery2 POST Method
10
11 PROCEDURE:
12 see Gallery2
13
14 Please remove the version number from this file
15
16 RESTRICTIONS:
17 spaces in file names are not supported. I don't know how to escape them right.
18
19 MODIFICATION HISTORY:
20 Version 1.3.3.-1
21 @copyright: 2005 by Reimar Bauer (R.Bauer@fz-juelich.de)
22 @license: GNU GPL, see COPYING for details.
23 2005-06-24: 1.3.3.-2 feature reqeust of CraigJohnson added
24 os.path.join used to join platform independent pathes
25 os.unlink removed to get it more platform independend
26 2005-08-06: 1.3.5-3 RB VS mode added
27 by one step back or forward could be toggled through the selected slides
28 and the first and last one could be selected too
29 2005-08-07 1.3.5-4 RB bug fixed for cgi-bin call. formatting of tables adjusted
30 2005-08-13 1.3.5-5 RB code change from GET to POST
31 forms instead of link
32 toggle between webnail and image by click on image
33 alias (description) and exif_date added
34 this version needs Gallery2-1.3.5-7.py
35
36
37
38
39 """
40 Dependencies = []
41 import os,string,Image,StringIO
42 from MoinMoin import config, wikiutil
43 from MoinMoin.PageEditor import PageEditor
44 from MoinMoin import user, util
45 from MoinMoin.Page import Page
46 from MoinMoin.action import AttachFile
47 from MoinMoin.formatter.text_html import Formatter
48 from MoinMoin.parser import wiki
49
50 def to_wikiname(request,text):
51
52 #taken from test_parser_wiki
53 page = Page(request, 'ThisPageDoesNotExistsAndWillNeverBeReally')
54 page.formatter = Formatter(request)
55 request.formatter = page.formatter
56 page.formatter.setPage(page)
57 page.hilite_re = None
58
59 out=StringIO.StringIO()
60 request.redirect(out)
61 wikiizer = wiki.Parser(text.strip(),request)
62 wikiizer.format(page.formatter)
63 naw=out.getvalue()
64 request.redirect()
65 del out
66
67 return naw.strip()
68
69
70 action_name = __name__.split('.')[-1]
71
72 def execute(pagename, request):
73 """ Main dispatcher for the 'Gallery' action.
74 """
75 _ = request.getText
76
77 request.formatter = Formatter(request)
78 if(request.form['do'][0] == 'VS'):
79 web={}
80 images=string.split(request.form['target'][0],',')
81 target=images[0]
82 images=(images[1:])
83
84 full_image=string.split(request.form['full'][0],',')
85 full_target=full_image[0]
86 full_image=(full_image[1:])
87
88 all_description=string.split(request.form['alias'][0],'!,!')
89 this_description=all_description[0]
90 all_description=(all_description[1:])
91
92 all_exif_date=string.split(request.form['exif_date'][0],',')
93 this_exif_date=all_exif_date[0]
94 all_exif_date=(all_exif_date[1:])
95
96 z=0
97 for img in images :
98 if (target == img):
99 previous=z-1
100 next=z+1
101
102 z=z+1
103 n=len(images)
104
105 ######## url_wiki_page #############################################################
106 text=pagename
107 url=pagename
108 url_wiki_page=wikiutil.link_tag(request, url, text=text,
109 formatter=request.formatter)
110 ############################################################################
111
112 attachment_path = AttachFile.getAttachDir(request,pagename)
113
114 web['src']=AttachFile.getAttachUrl(pagename,target,request)
115 web['title']=target
116 #web['width']="1024"
117
118
119 image_link=request.formatter.image(**web)
120
121
122 request.http_headers()
123
124 request.write('<html>')
125 request.write('<head>')
126 request.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">')
127 request.write('<meta name="robots" content="noindex,nofollow">')
128
129
130 request.write("<H2>%(pagename)s</H2>" % {
131 "pagename":url_wiki_page})
132
133
134 request.write("<TABLE BORDER=1 ALIGN=CENTER><TR><TD>")
135
136 if (previous >= 0):
137 url='<form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">' % {
138 'baseurl': request.getScriptname(),
139 'pagename': wikiutil.quoteWikinameURL(pagename)}
140
141 url=url+'<input type="hidden" name="action" value="gallery2image">'
142 url=url+'<input type="hidden" name="do" value="VS">'
143 url=url+'<input type="hidden" name="full" value="'+full_image[0]+","+string.join(full_image,',')+'">'
144 url=url+'<input type="hidden" name="alias" value="'+all_description[0]+'!,!'+string.join(all_description,'!,!')+'">'
145 url=url+'<input type="hidden" name="exif_date" value="'+all_exif_date[0]+','+string.join(all_exif_date,',')+'">'
146 url=url+'<input type="hidden" name="target" value="'+images[0]+","+string.join(images,',')+'">'
147 url=url+'<input type="submit" value="FIRST" >'
148 url=url+'</FORM>'
149
150
151 request.write("<TABLE ALIGN=LEFT><TR><TD>%(INPUT)s</TD></TR></TABLE> " % {
152 "INPUT":url})
153
154
155
156 if (next < n):
157
158
159 url='<form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">' % {
160 'baseurl': request.getScriptname(),
161 'pagename': wikiutil.quoteWikinameURL(pagename)}
162
163 url=url+'<input type="hidden" name="action" value="gallery2image">'
164 url=url+'<input type="hidden" name="do" value="VS">'
165 url=url+'<input type="hidden" name="full" value="'+full_image[n-1]+","+string.join(full_image,',')+'">'
166 url=url+'<input type="hidden" name="alias" value="'+all_description[n-1]+'!,!'+string.join(all_description,'!,!')+'">'
167 url=url+'<input type="hidden" name="exif_date" value="'+all_exif_date[n-1]+','+string.join(all_exif_date,',')+'">'
168 url=url+'<input type="hidden" name="target" value="'+images[n-1]+","+string.join(images,',')+'">'
169 url=url+'<input type="submit" value="LAST" >'
170 url=url+'</FORM>'
171
172 request.write("<TABLE ALIGN=RIGHT><TR><TD>%(INPUT)s</TD></TR></TABLE> " % {
173 "INPUT":url})
174
175
176
177 if (n > 1):
178
179 request.write("<TABLE ALIGN=CENTER><TR>")
180
181
182 if (previous >= 0):
183 url='<form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">' % {
184 'baseurl': request.getScriptname(),
185 'pagename': wikiutil.quoteWikinameURL(pagename)}
186
187 url=url+'<input type="hidden" name="action" value="gallery2image">'
188 url=url+'<input type="hidden" name="do" value="VS">'
189 url=url+'<input type="hidden" name="full" value="'+full_image[previous]+","+string.join(full_image,',')+'">'
190 url=url+'<input type="hidden" name="alias" value="'+all_description[previous]+'!,!'+string.join(all_description,'!,!')+'">'
191 url=url+'<input type="hidden" name="exif_date" value="'+all_exif_date[previous]+','+string.join(all_exif_date,',')+'">'
192 url=url+'<input type="hidden" name="target" value="'+images[previous]+","+string.join(images,',')+'">'
193 url=url+'<input type="submit" value="PREVIOUS" >'
194 url=url+'</FORM>'
195
196 request.write("<TD>%(INPUT)s</TD>" % {
197 "INPUT":url})
198
199
200
201 if (next < n):
202 url='<form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data">' % {
203 'baseurl': request.getScriptname(),
204 'pagename': wikiutil.quoteWikinameURL(pagename)}
205
206 url=url+'<input type="hidden" name="action" value="gallery2image">'
207 url=url+'<input type="hidden" name="do" value="VS">'
208 url=url+'<input type="hidden" name="full" value="'+full_image[next]+","+string.join(full_image,',')+'">'
209 url=url+'<input type="hidden" name="exif_date" value="'+all_exif_date[next]+','+string.join(all_exif_date,',')+'">'
210 url=url+'<input type="hidden" name="alias" value="'+all_description[next]+'!,!'+string.join(all_description,'!,!')+'">'
211 url=url+'<input type="hidden" name="target" value="'+images[next]+","+string.join(images,',')+'">'
212 url=url+'<input type="submit" value="NEXT" >'
213 url=url+'</FORM>'
214
215 request.write("<TD>%(INPUT)s</TD>" % {
216 "INPUT":url})
217
218
219 request.write("</TR></TABLE>")
220
221 url='<form action="%(baseurl)s/%(pagename)s" method="POST" enctype="multipart/form-data"><TT>' % {
222 'baseurl': request.getScriptname(),
223 'pagename': wikiutil.quoteWikinameURL(pagename)}
224
225 url=url+'<input type="hidden" name="action" value="gallery2image">'
226 url=url+'<input type="hidden" name="do" value="VS">'
227 url=url+'<input type="hidden" name="full" value="'+target+","+string.join(images,',')+'">'
228 url=url+'<input type="hidden" name="alias" value="'+this_description+'!,!'+string.join(all_description,'!,!')+'">'
229 url=url+'<input type="hidden" name="exif_date" value="'+this_exif_date+','+string.join(all_exif_date,',')+'">'
230 #url=url+'<input type="hidden" name="full" value='+full_image[next]+","+string.join(full_image,',')+'>'
231 url=url+'<input type="hidden" name="target" value="'+full_target+","+string.join(full_image,',')+'">'
232 url=url+'<input type="image" value="submit" src="'+AttachFile.getAttachUrl(pagename,target,request)+'">'
233 url=url+'</FORM>'
234
235
236 request.write(url)
237
238 request.write("</TD></TR>")
239 request.write("<TR><TD>")
240
241 request.write(to_wikiname(request,this_description))
242
243 request.write("</TD></TR>")
244 request.write("<TR><TD>")
245
246 request.write(this_exif_date)
247
248 request.write("</TD></TR>")
249 request.write("<TR><TD>")
250 request.write("back to %(url_wiki_page)s" % {
251 "url_wiki_page":url_wiki_page})
252
253 request.write("</TD></TR></TABLE>")
254 request.write("</HTML>")
255
256 return
257
258 elif(request.form['do'][0] == 'PS'):
259 images=string.split(request.form['target'][0],',')
260 attachment_path = AttachFile.getAttachDir(request,pagename)
261 target=request.form['target'][0]
262
263 msg= _('not finished by now') #+ target
264
265 elif request.user.may.delete(pagename):
266 # only users which are allowed to delete should use this tool
267
268 target=request.form['target'][0]
269 file, ext = os.path.splitext(target)
270
271 if (ext == '.gif') or (ext == '.png'):
272 img_type='PNG'
273 thumbfile='thumbnail_'+file+".png"
274 webnail='webnail_'+file+".png"
275 else:
276 img_type="JPEG"
277 thumbfile='thumbnail_'+file+".jpg"
278 webnail='webnail_'+file+".jpg"
279
280
281 attachment_path = AttachFile.getAttachDir(request,pagename)
282 thumb=os.path.join(attachment_path,thumbfile)
283 webf=os.path.join(attachment_path,webnail)
284 infile=os.path.join(attachment_path,target)
285
286 msg = None
287 if action_name in request.cfg.excluded_actions:
288 msg = _('File attachments are not allowed in this wiki!')
289
290 elif (request.form['do'][0] == 'RM'):
291 if os.path.exists(infile+'.bak'):
292 os.unlink(infile+'.bak')
293 os.link(infile,infile+'.bak')
294 os.unlink(infile)
295 os.unlink(webf)
296 os.unlink(thumb)
297
298 msg= _('%(target)s deleted, backup in place' % {
299 'target':target})
300
301 elif (request.form['do'][0] == 'RL'):
302 im = Image.open(infile)
303 #os.unlink(infile)
304 im.rotate(90).save(infile,img_type)
305 nim = Image.open(infile)
306 nim.thumbnail((640,640), Image.ANTIALIAS)
307 #os.unlink(webf)
308 nim.save(webf, img_type)
309 nim.thumbnail((128, 128), Image.ANTIALIAS)
310 #os.unlink(thumb)
311 nim.save(thumb, img_type)
312 msg= _('%(target)s rotated to left 90 degrees' % {
313 'target':target})
314
315 elif (request.form['do'][0] == 'RR'):
316 im = Image.open(infile)
317 #os.unlink(infile)
318 im.rotate(270).save(infile,img_type)
319
320
321 nim = Image.open(infile)
322
323 nim.thumbnail((640,640), Image.ANTIALIAS)
324 #os.unlink(webf)
325 nim.save(webf, img_type)
326 nim.thumbnail((128, 128), Image.ANTIALIAS)
327 #os.unlink(thumb)
328 nim.save(thumb, img_type)
329 msg= _('%(target)s rotated to right 90 degrees' % {
330 'target':target})
331
332 else:
333 msg = _('action not implemented: %s') % (request.form['do'][0],)
334 else:
335 msg = _('Your are not allowed to change images on this page: %s') % (pagename,)
336
337 if msg:
338 AttachFile.error_msg(pagename, request, msg)
339
340 return()
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.