Attachment 'gallery2image-1.3.5-4.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
31
32 """
33 Dependencies = []
34 import os,string,Image
35 from MoinMoin import config, wikiutil
36 from MoinMoin.PageEditor import PageEditor
37 from MoinMoin import user, util
38 from MoinMoin.Page import Page
39 from MoinMoin.action import AttachFile
40 from MoinMoin.formatter.text_html import Formatter
41
42 action_name = __name__.split('.')[-1]
43
44 def execute(pagename, request):
45 """ Main dispatcher for the 'Gallery' action.
46 """
47 _ = request.getText
48
49 request.formatter = Formatter(request)
50 if(request.form['do'][0] == 'VS'):
51 web={}
52 images=string.split(request.form['target'][0],',')
53 target=images[0]
54 images=(images[1:])
55 z=0
56 for img in images :
57 if (target == img):
58 previous=z-1
59 next=z+1
60
61 z=z+1
62 n=len(images)
63
64 ######## url_wiki_page #############################################################
65 text=pagename
66 url=pagename
67 url_wiki_page=wikiutil.link_tag(request, url, text=text,
68 formatter=request.formatter)
69 ############################################################################
70
71 attachment_path = AttachFile.getAttachDir(request,pagename)
72
73 web['src']=AttachFile.getAttachUrl(pagename,target,request)
74 web['title']=target
75 #web['width']="1024"
76
77
78 image_link=request.formatter.image(**web)
79
80
81 request.http_headers()
82
83 request.write('<html>')
84 request.write('<head>')
85 request.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">')
86 request.write('<meta name="robots" content="noindex,nofollow">')
87
88
89 request.write("<H2>%(pagename)s</H2>" % {
90 "pagename":url_wiki_page})
91
92
93 request.write("<TABLE BORDER=1 ALIGN=CENTER><TR><TD>")
94
95 if (previous >= 0):
96 webn_url="%(pagename)s?action=gallery2image&do=VS&target=%(webnail)s" % {
97 "pagename":pagename,
98 "webnail":images[0]+","+string.join(images,',')}
99 text='FIRST'
100 url=webn_url
101 first_img=wikiutil.link_tag(request, url, text=text,
102 formatter=request.formatter)
103
104 request.write("<TABLE ALIGN=LEFT><TR><TD>%(INPUT)s</TD></TR></TABLE> " % {
105 "INPUT":first_img})
106
107 if (next < n):
108 webn_url="%(pagename)s?action=gallery2image&do=VS&target=%(webnail)s" % {
109 "pagename":pagename,
110 "webnail":images[n-1]+","+string.join(images,',')}
111 text='LAST'
112 url=webn_url
113 last_img=wikiutil.link_tag(request, url, text=text,
114 formatter=request.formatter)
115
116 request.write("<TABLE ALIGN=RIGHT><TR><TD>%(INPUT)s</TD></TR></TABLE> " % {
117 "INPUT":last_img})
118
119 if (n > 1):
120 request.write("<TABLE ALIGN=CENTER><TR>")
121
122 if (previous >= 0):
123 webn_url="%(pagename)s?action=gallery2image&do=VS&target=%(webnail)s" % {
124 "pagename":pagename,
125 "webnail":images[previous]+","+string.join(images,',')}
126 text='PREVIOUS'
127 url=webn_url
128 previous_img=wikiutil.link_tag(request, url, text=text,
129 formatter=request.formatter)
130
131 request.write("<TD>%(INPUT)s</TD>" % {
132 "INPUT":previous_img})
133
134 if (next < n):
135 webn_url="%(pagename)s?action=gallery2image&do=VS&target=%(webnail)s" % {
136 "pagename":pagename,
137 "webnail":images[next]+","+string.join(images,',')}
138 text='NEXT'
139 url=webn_url
140 next_img=wikiutil.link_tag(request, url, text=text,
141 formatter=request.formatter)
142
143 request.write("<TD>%(INPUT)s</TD>" % {
144 "INPUT":next_img})
145
146
147 request.write("</TR></TABLE>")
148 request.write(image_link)
149 request.write("</TD></TR>")
150 request.write("<TR><TD>")
151 request.write("back to %(url_wiki_page)s" % {
152 "url_wiki_page":url_wiki_page})
153
154 request.write("</TD></TR></TABLE>")
155 request.write("</HTML>")
156
157 return
158
159 elif(request.form['do'][0] == 'PS'):
160 images=string.split(request.form['target'][0],',')
161 attachment_path = AttachFile.getAttachDir(request,pagename)
162 target=request.form['target'][0]
163
164 msg= _('not finished by now') #+ target
165
166 elif request.user.may.delete(pagename):
167 # only users which are allowed to delete should use this tool
168
169 target=request.form['target'][0]
170 file, ext = os.path.splitext(target)
171
172 if (ext == '.gif') or (ext == '.png'):
173 img_type='PNG'
174 thumbfile='thumbnail_'+file+".png"
175 webnail='webnail_'+file+".png"
176 else:
177 img_type="JPEG"
178 thumbfile='thumbnail_'+file+".jpg"
179 webnail='webnail_'+file+".jpg"
180
181
182 attachment_path = AttachFile.getAttachDir(request,pagename)
183 thumb=os.path.join(attachment_path,thumbfile)
184 webf=os.path.join(attachment_path,webnail)
185 infile=os.path.join(attachment_path,target)
186
187 msg = None
188 if action_name in request.cfg.excluded_actions:
189 msg = _('File attachments are not allowed in this wiki!')
190
191 elif (request.form['do'][0] == 'RM'):
192 if os.path.exists(infile+'.bak'):
193 os.unlink(infile+'.bak')
194 os.link(infile,infile+'.bak')
195 os.unlink(infile)
196 os.unlink(webf)
197 os.unlink(thumb)
198
199 msg= _('%(target)s deleted, backup in place' % {
200 'target':target})
201
202 elif (request.form['do'][0] == 'RL'):
203 im = Image.open(infile)
204 #os.unlink(infile)
205 im.rotate(90).save(infile,img_type)
206 nim = Image.open(infile)
207 nim.thumbnail((640,640), Image.ANTIALIAS)
208 #os.unlink(webf)
209 nim.save(webf, img_type)
210 nim.thumbnail((128, 128), Image.ANTIALIAS)
211 #os.unlink(thumb)
212 nim.save(thumb, img_type)
213 msg= _('%(target)s rotated to left 90 degrees' % {
214 'target':target})
215
216 elif (request.form['do'][0] == 'RR'):
217 im = Image.open(infile)
218 #os.unlink(infile)
219 im.rotate(270).save(infile,img_type)
220
221
222 nim = Image.open(infile)
223
224 nim.thumbnail((640,640), Image.ANTIALIAS)
225 #os.unlink(webf)
226 nim.save(webf, img_type)
227 nim.thumbnail((128, 128), Image.ANTIALIAS)
228 #os.unlink(thumb)
229 nim.save(thumb, img_type)
230 msg= _('%(target)s rotated to right 90 degrees' % {
231 'target':target})
232
233 else:
234 msg = _('action not implemented: %s') % (request.form['do'][0],)
235 else:
236 msg = _('Your are not allowed to change images on this page: %s') % (pagename,)
237
238 if msg:
239 AttachFile.error_msg(pagename, request, msg)
240
241 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.