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