Attachment 'gallery2image-1.3.5-8.py'
Download 1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - gallery2Image Actionmacro
4
5 PURPOSE::
6 This action macro is used to rotate, move to bak or to slide through 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. Probaly this does work in 1.3.5
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 2005-08-31 1.3.5-6 RB html code changed into a function :-)
36 some html bugs fixed too
37 instead of button text now images used (disabled buttons are grey color coded)
38 back link to callers page
39 whole page inserted into the common wiki page
40 code clean up.
41 2005-09-01 1.3.5-7 RB image paths changed to absoulte url
42 2005-10-29 1.3.5-8 RB the code of VS rewritten
43 for the slideshow changed to a javascript player learned from Ricocheting
44 image preloading for webnails and fullimages because webspeed could be slow
45 slide show is really fast by this
46 default duration is 1000msec
47 (runs under 1.5-150
48
49
50
51 """
52 Dependencies = []
53 import os,string,Image,StringIO
54 from MoinMoin import config, wikiutil
55 from MoinMoin.PageEditor import PageEditor
56 from MoinMoin import user, util
57 from MoinMoin.Page import Page
58 from MoinMoin.action import AttachFile
59 from MoinMoin.formatter.text_html import Formatter
60 from MoinMoin.parser import wiki
61
62
63 def option_list(this_image,pagename,text,request):
64 txt = ''
65
66 for s in text:
67 name = AttachFile.getAttachUrl(pagename,s,request)
68 if name == this_image:
69 txt += '<option selected value="%(name)s">%(alias)s' % {
70 "name":name,
71 "alias":s}
72
73 else:
74 txt += '<option value="%(name)s">%(alias)s' % {
75 "name":name,
76 "alias":s}
77
78 return txt
79
80 def html_js(this_image,counter):
81 html = '''
82 <SCRIPT LANGUAGE="JavaScript">
83 <!-- Original: Ricocheting (ricocheting@hotmail.com) -->
84 <!-- Web Site: http://www.ricocheting.com -->
85
86 <!-- This script and many more are available free online at -->
87 <!-- The JavaScript Source!! http://javascript.internet.com -->
88
89 <!-- Modifications by Reimar Bauer <R.Bauer@fz-juelich.de> -->
90 <!-- 2005-10-29 -->
91 <!-- Many thanks to Ricocheting, it is much easier as my own one. I like it -->
92 <!-- Some code added and exchanged for usage with Gallery2 -->
93
94
95 <!-- Begin
96 var rotate_delay = 1000; // delay in milliseconds (5000 = 5 secs)
97 current = %(counter)s;
98
99
100 theImages = new Array();
101 thewebImages = new Array();
102 thefullImages = new Array();
103
104 function preload() {
105
106 list=document.slideform.webnail_list.value;
107
108 value = list.split(",");
109 n=value.length;
110
111 for (i = 0; i < n-1; i++){
112 theImages[i] = new Image();
113 theImages[i].src = value[i];
114 }
115 thewebImages = theImages;
116
117 list=document.slideform.full_list.value;
118
119 value = list.split(",");
120 n=value.length;
121
122 for (i = 0; i < n-1; i++){
123 thefullImages[i] = new Image();
124 thefullImages[i].src = value[i];
125 }
126
127 }
128
129
130 function add_comments() {
131 alias_text = document.slideform.alias.value;
132 exif_date_text = document.slideform.exif_date.value;
133 index = document.slideform.slide.selectedIndex;
134 alias = alias_text.split("!,!");
135 exif = exif_date_text.split(",");
136 document.slideform.alias_text.value = alias[index] ;
137 document.slideform.exif_date_text.value = exif[index];
138 }
139
140 function next_slide() {
141 if (document.slideform.slide[current+1]) {
142 document.images.show.src = theImages[current+1].src;
143 document.slideform.slide.selectedIndex = ++current;
144 add_comments();
145 }
146 else first_slide();
147 }
148 function previous_slide() {
149 if (current-1 >= 0) {
150 document.images.show.src = theImages[current-1].src;
151 document.slideform.slide.selectedIndex = --current;
152 add_comments();
153 }
154 else last_slide();
155 }
156 function first_slide() {
157 current = 0;
158 document.images.show.src = theImages[0].src;
159 document.slideform.slide.selectedIndex = 0;
160 add_comments();
161 }
162 function last_slide() {
163 current = document.slideform.slide.length-1;
164 document.images.show.src = theImages[current].src;
165 document.slideform.slide.selectedIndex = current;
166 add_comments();
167 }
168
169 function switch_images() {
170 if (document.slideform.flag.value == "webnail") {
171 list=document.slideform.full_list.value;
172 name=document.slideform.full_name.value;
173 document.slideform.flag.value = "fullscreen"
174 theImages = thefullImages;
175 } else {
176 list=document.slideform.webnail_list.value;
177 name=document.slideform.webnail_name.value;
178 document.slideform.flag.value = "webnail"
179 theImages = thewebImages;
180 }
181
182 value = list.split(",");
183 alias = name.split(",");
184
185 n = value.length;
186
187 for (i = 0; i < n-1; i++){
188 document.slideform.slide[i].value=value[i];
189 document.slideform.slide[i].text=alias[i];
190 }
191 document.images.show.src = theImages[current].src;
192 }
193
194 function ap(text) {
195 document.slideform.slidebutton.value = (text == "Stop") ? "Start" : "Stop";
196 rotate();
197 }
198
199 function change() {
200 current = document.slideform.slide.selectedIndex;
201 document.images.show.src = theImages[current].src ;
202 add_comments();
203 }
204
205 function rotate() {
206 if (document.slideform.slidebutton.value == "Stop") {
207 current = (current == document.slideform.slide.length-1) ? 0 : current+1;
208 document.images.show.src = theImages[current].src;
209 document.slideform.slide.selectedIndex = current;
210 add_comments();
211 rotate_delay = document.slideform.duration.value;
212 window.setTimeout("rotate()", rotate_delay);
213 }
214 }
215
216 // End -->
217 </script> '''% {
218 'this_image':this_image,
219 'counter':counter}
220
221 return html
222
223 def html_show_image(request,pagename,url_wiki_page,full,alias,exif_date,target,idx):
224
225 option_webnail = option_list(AttachFile.getAttachUrl(pagename,target[idx],request),pagename,target,request)
226
227 this_full_list = ''
228 for s in full:
229 this_full_list += AttachFile.getAttachUrl(pagename,s,request)+','
230
231 this_webnail_list = ''
232 for s in target:
233 this_webnail_list += AttachFile.getAttachUrl(pagename,s,request)+','
234
235 html = '''
236 <body onLoad="preload()">
237 <center>
238 <form name=slideform method="POST">
239 <input type="hidden" name="full_list" value="%(this_full_list)s">
240 <input type="hidden" name="full_name" value="%(this_full_name)s">
241 <input type="hidden" name="flag" value="webnail">
242 <input type="hidden" name="webnail_list" value="%(this_webnail_list)s">
243 <input type="hidden" name="webnail_name" value="%(this_webnail_name)s">
244 <input type="hidden" name="alias" value="%(this_alias_list)s">
245 <input type="hidden" name="exif_date" value="%(this_exif_date_list)s">
246
247 <table cellspacing=1 cellpadding=4 bgcolor="#000000">
248 <tr>
249 <td align=center bgcolor="white">
250 </td>
251 </tr>
252 <tr>
253 <td align=center bgcolor="#C0C0C0">
254 <img src="%(server)s/wiki/modern/img/first.png" onclick="first_slide();" name="fs" title="first slide" >
255 <img src="%(server)s/wiki/modern/img/previous.png" onclick="previous_slide();" title="previous slide" >
256
257 <input type="input" name="duration" value="1000" size="5" title="Duration">
258 <input type="button" name="slidebutton" onClick="ap(this.value);" value="Start" title="AutoPlay">
259
260 <img src="%(server)s/wiki/modern/img/next.png" onClick="next_slide();" title="next slide" >
261 <img src="%(server)s/wiki/modern/img/last.png" onClick="last_slide();" title="last slide" >
262 <input type="image" value="submit" src="%(server)s/wiki/modern/img/back.png" title="return to %(pagename)s">
263 </td>
264 </tr>
265 <tr>
266 <td align=center bgcolor="white"">
267 <img src="%(this_image)s" name="show" onClick="switch_images();">
268 </td>
269 </tr>
270 <tr>
271 <td align=center bgcolor="#C0C0C0">
272 <select name="slide" onChange="change();" >
273 %(option_webnails)s
274 </select>
275 </td>
276 </tr>
277 <tr>
278 <td bgcolor="#C0C0C0">
279 <input type="button" name="alias_text" value="%(this_alias_text)s">
280 </td>
281 </tr>
282 <tr>
283 <td bgcolor="#C0C0C0">
284 <input type="button" name="exif_date_text" value="%(this_exif_date_text)s">
285 </td>
286 </tr>
287 </table>
288 </form>
289 </center>
290 ''' % {
291 "server" : 'http://'+request.server_name+':' + str(request.server_port),
292 "base_url" : request.getScriptname(),
293
294 "this_full_list" : this_full_list,
295 "this_full_name" : string.join(full,','),
296 "this_webnail_list" : this_webnail_list,
297 "this_webnail_name" : string.join(target,','),
298
299 "this_alias_text": alias[idx],
300 "this_alias_list" : string.join(alias,'!,!'),
301 "this_exif_date_text": exif_date[idx],
302 "this_exif_date_list" :string.join(exif_date,','),
303
304 "this_image" : AttachFile.getAttachUrl(pagename,target[idx],request),
305 "url_wiki_page" : url_wiki_page,
306 "pagename" : pagename,
307 "option_webnails" : option_webnail
308 }
309
310
311 return html
312
313 def to_wikiname(request,text):
314
315 #taken from test_parser_wiki
316 page = Page(request, 'ThisPageDoesNotExistsAndWillNeverBeReally')
317 page.formatter = Formatter(request)
318 request.formatter = page.formatter
319 page.formatter.setPage(page)
320 page.hilite_re = None
321
322 out=StringIO.StringIO()
323 request.redirect(out)
324 wikiizer = wiki.Parser(text.strip(),request)
325 wikiizer.format(page.formatter)
326 result = out.getvalue()
327 request.redirect()
328 del out
329
330 return result.strip()
331
332
333 action_name = __name__.split('.')[-1]
334
335 def execute(pagename, request):
336 """ Main dispatcher for the 'Gallery' action.
337 """
338 _ = request.getText
339
340 request.formatter = Formatter(request)
341 attachment_path = AttachFile.getAttachDir(request,pagename)
342 if request.form['do'][0] == 'VS' :
343 web = {}
344 images = string.split(request.form['target'][0],',')
345 target = images[0]
346 images = (images[1:])
347
348 full_image = string.split(request.form['full'][0],',')
349 full_target = full_image[0]
350 full_image = (full_image[1:])
351
352 all_description = string.split(request.form['alias'][0],'!,!')
353 this_description = all_description[0]
354 all_description = (all_description[1:])
355
356 all_exif_date = string.split(request.form['exif_date'][0],',')
357 this_exif_date = all_exif_date[0]
358 all_exif_date = (all_exif_date[1:])
359
360 z = 0
361 for img in images :
362 if target == img :
363 idx = z
364
365 z += 1
366 n = len(images)
367
368 ######## url_wiki_page #############################################################
369 text = pagename
370 url = pagename
371 url_wiki_page = wikiutil.link_tag(request, url, text = text,
372 formatter = request.formatter)
373
374 ############################################################################
375
376 attachment_path = AttachFile.getAttachDir(request,pagename)
377
378 web['src'] = AttachFile.getAttachUrl(pagename,target,request)
379 web['title'] = target
380 #web['width']="1024"
381
382
383 image_link=request.formatter.image(**web)
384
385
386 request.http_headers()
387
388 request.setContentLanguage(request.lang)
389
390 wikiutil.send_title(request, pagename,
391 pagename=pagename)
392 request.write(html_js(AttachFile.getAttachUrl(pagename,target[idx],request),idx))
393 request.write(request.formatter.startContent("content"))
394
395 html = html_show_image(request,pagename,url_wiki_page,full_image,all_description,all_exif_date,images,idx)
396
397 request.write(html)
398 request.write(request.formatter.endContent())
399 wikiutil.send_footer(request, pagename)
400 msg = None
401
402
403 elif request.form['do'][0] == 'PS' :
404 msg = None
405
406 elif request.form['do'][0] == 'BS' :
407
408 msg = "gone back" #None
409
410 elif request.user.may.delete(pagename):
411 # only users which are allowed to delete should use this tool
412
413 target=request.form['target'][0]
414 file, ext = os.path.splitext(target)
415
416 if ext == '.gif' or ext == '.png' :
417 img_type = 'PNG'
418 thumbfile = "thumbnail_%(file)s.png" % {"file" : file}
419 webnail = "webnail_%(file)s.png" % {"file" : file}
420 else:
421 img_type="JPEG"
422 thumbfile="thumbnail_%(file)s.jpg" % {"file" : file}
423 webnail="webnail_%(file)s.jpg" % {"file" : file}
424
425 thumb = os.path.join(attachment_path,thumbfile)
426 webf = os.path.join(attachment_path,webnail)
427 infile = os.path.join(attachment_path,target)
428
429 msg = None
430 if action_name in request.cfg.excluded_actions:
431 msg = _('File attachments are not allowed in this wiki!')
432
433 elif request.form['do'][0] == 'RM' :
434 if os.path.exists(infile + '.bak') :
435 os.unlink("%(file)s.bak" % {"file" : infile})
436 os.link(infile,"%(file)s.bak" % {"file" : infile})
437 os.unlink(infile)
438 os.unlink(webf)
439 os.unlink(thumb)
440
441 msg = _('%(target)s deleted, backup in place' % {
442 'target':target})
443
444 elif request.form['do'][0] == 'RL' :
445 im = Image.open(infile)
446 #os.unlink(infile)
447 im.rotate(90).save(infile,img_type)
448 nim = Image.open(infile)
449 nim.thumbnail((640,640), Image.ANTIALIAS)
450 #os.unlink(webf)
451 nim.save(webf, img_type)
452 nim.thumbnail((128, 128), Image.ANTIALIAS)
453 #os.unlink(thumb)
454 nim.save(thumb, img_type)
455 msg= _('%(target)s rotated to left 90 degrees' % {
456 'target':target})
457
458 elif request.form['do'][0] == 'RR' :
459 im = Image.open(infile)
460 #os.unlink(infile)
461 im.rotate(270).save(infile,img_type)
462
463
464 nim = Image.open(infile)
465
466 nim.thumbnail((640,640), Image.ANTIALIAS)
467 #os.unlink(webf)
468 nim.save(webf, img_type)
469 nim.thumbnail((128, 128), Image.ANTIALIAS)
470 #os.unlink(thumb)
471 nim.save(thumb, img_type)
472 msg= _('%(target)s rotated to right 90 degrees' % {
473 'target':target})
474
475 else:
476 msg = _('action not implemented: %s') % (request.form['do'][0],)
477 else:
478 msg = _('Your are not allowed to change images on this page: %s') % (pagename,)
479
480 if msg:
481 AttachFile.error_msg(pagename, request, msg)
482
483 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.