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