Attachment 'resizing_image_from_gui_20061222_patch.txt'
Download 1 # HG changeset patch
2 # User ReimarBauer <R.Bauer@fz-juelich.de>
3 # Node ID fc8309716597121ef100418d99f9947e483bfef4
4 # Parent 3c6f59cafbbe442f90171a8b0680be67eb320a67
5 resizing of images from gui using Image.
6
7 diff -r 3c6f59cafbbe -r fc8309716597 MoinMoin/converter/text_html_text_moin_wiki.py
8 --- a/MoinMoin/converter/text_html_text_moin_wiki.py Thu Dec 21 03:39:57 2006 +0100
9 +++ b/MoinMoin/converter/text_html_text_moin_wiki.py Fri Dec 22 14:13:46 2006 +0100
10 @@ -1179,13 +1179,28 @@ class convert_tree(visitor):
11 alt = None
12 if node.attributes.has_key("alt"):
13 alt = node.attributes.get("alt").nodeValue
14 -
15 + width = None
16 + if node.attributes.has_key("width"):
17 + width = node.attributes.get("width").nodeValue
18 + height = None
19 + if node.attributes.has_key("height"):
20 + height = node.attributes.get("height").nodeValue
21 # Attachment image
22 if (title and title.startswith("attachment:") and
23 wikiutil.isPicture(wikiutil.url_unquote(title[len("attachment:"):]))):
24 - self.text.extend([self.white_space,
25 - wikiutil.url_unquote(title),
26 - self.white_space])
27 + if height == None and width == None:
28 + self.text.extend([self.white_space,
29 + wikiutil.url_unquote(title),
30 + self.white_space])
31 + else:
32 + self.text.extend([self.white_space,
33 + "[[Image(%(file)s,width=%(width)s,height=%(height)s,alt=%(alt)s)]]" % {
34 + "file": wikiutil.url_unquote(title[len("attachment:"):]),
35 + "width": width,
36 + "height": height,
37 + "alt": alt,
38 + },
39 + self.white_space])
40 # Drawing image
41 elif title and title.startswith("drawing:"):
42 self.text.extend([self.white_space,
43 diff -r 3c6f59cafbbe -r fc8309716597 MoinMoin/formatter/text_gedit.py
44 --- a/MoinMoin/formatter/text_gedit.py Thu Dec 21 03:39:57 2006 +0100
45 +++ b/MoinMoin/formatter/text_gedit.py Fri Dec 22 14:13:46 2006 +0100
46 @@ -93,7 +93,33 @@ class Formatter(text_html.Formatter):
47 # Dynamic stuff / Plugins ############################################
48
49 def macro(self, macro_obj, name, args):
50 - if args is not None:
51 + if name == "Image" and args is not None:
52 + pagename = self.page.page_name
53 + if args:
54 + args = args.split(',')
55 + args = [arg.strip() for arg in args]
56 + else:
57 + args = []
58 + url = args[0]
59 + keywords = {}
60 + width = None
61 + height = None
62 + alt = None
63 + for arg in args:
64 + if arg.find('=') > -1:
65 + key, value = arg.split('=')
66 + if key == 'width':
67 + width = value
68 + if key == 'height':
69 + height = value
70 + if key == 'alt':
71 + alt = value
72 + if alt == None:
73 + alt = url
74 + return self.image(
75 + title="attachment:%s" % wikiutil.quoteWikinameURL(url),
76 + src=AttachFile.getAttachUrl(pagename, url, self.request, addts=1), width=width, height=height, alt=alt)
77 + elif args is not None:
78 result = "[[%s(%s)]]" % (name, args)
79 else:
80 result = "[[%s]]" % name
81 diff -r 3c6f59cafbbe -r fc8309716597 MoinMoin/macro/Image.py
82 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
83 +++ b/MoinMoin/macro/Image.py Fri Dec 22 14:13:46 2006 +0100
84 @@ -0,0 +1,100 @@
85 +# -*- coding: iso-8859-1 -*-
86 +"""
87 + MoinMoin - Image Macro V1.1
88 +
89 + This macro is used to display an image with the ability to resize
90 + and/or provide an alt text for it.
91 +
92 + Syntax:
93 + [[Image(image, [width=width, [height=height], [alt=""])]]
94 +
95 + Parameters:
96 + image: image attachment file name or the URL of an image
97 +
98 + Keyword Parameters:
99 + width: rendered image width (optional)
100 + height: rendered image heigth (optional)
101 + alt: text for img tag "alt" attribute (optional)
102 +
103 + Examples:
104 + [[Image(pic.png, height=100)]]
105 + [[Image(pic.png, alt=yourtext)]]
106 + [[Image(OtherWikiSite/pic.png, widht=50, alt=Your text here)]]
107 + [[Image(http://webcam.portalmuc.de/images/webcam/webcam_marienplatz.jpg, height=100)]]
108 +
109 + The Image macro is a simple modification of the ImageLink macro.
110 + ImageLink macro copyright:
111 + 2001 by Jeff Kunce,
112 + 2004 by Marcin Zalewski,
113 + 2004-2006 by Reimar Bauer (R.Bauer@fz-juelich.de),
114 + 2006 by Thomas Waldmann
115 +
116 + @copyright: 2006 by Oliver Siemoneit
117 + @license: GNU GPL, see COPYING for details.
118 +
119 + Changes:
120 + * Parameter values now also take "=None" e.g. "width=None"
121 + * RB bug fixed alt key for images must be defined always
122 +"""
123 +
124 +import os
125 +from MoinMoin import wikiutil, config
126 +from MoinMoin.action import AttachFile
127 +
128 +
129 +def _is_URL(text):
130 + """ Answer true if text is an URL.
131 + The method used here is pretty dumb. Improvements are welcome.
132 + """
133 + return '://' in text
134 +
135 +def execute(macro, args):
136 + request = macro.request
137 + _ = request.getText
138 + formatter = macro.formatter
139 + if args:
140 + args = args.split(',')
141 + args = [arg.strip() for arg in args]
142 + else:
143 + args = []
144 +
145 + argc = len(args)
146 + kw_count = 0
147 + kw = {} # create a dictionary for the formatter.image call
148 + for arg in args:
149 + if '=' in arg:
150 + key, value = arg.split('=', 1)
151 + if value != 'None':
152 + kw_count += 1
153 + kw[str(key)] = wikiutil.escape(value, quote=1)
154 + argc -= kw_count
155 + image = args[0]
156 + pagename, attname = AttachFile.absoluteName(image, formatter.page.page_name)
157 +
158 + if not kw.has_key('alt') or kw['alt'] == 'None':
159 + if _is_URL(image):
160 + # Get image name http://here.com/dir/image.png -> image.png
161 + kw['alt'] = wikiutil.taintfilename(formatter.text(image.split('/')[-1]))
162 + else:
163 + kw['alt'] = attname
164 +
165 + if not argc or argc and not args[0]:
166 + msg = 'Not enough arguments to Image macro! Calling syntax: [[Image(image, [width=width], [height=height], [alt=""])]]'
167 + return "%s%s%s" % (formatter.sysmsg(1), formatter.text(msg), formatter.sysmsg(0))
168 +
169 + if _is_URL(image):
170 + kw['src'] = image
171 + else:
172 + kw['src'] = AttachFile.getAttachUrl(pagename, attname, request)
173 + attachment_fname = AttachFile.getFilename(request, pagename, attname)
174 + if not os.path.exists(attachment_fname):
175 + linktext = _('Upload new attachment "%(filename)s"')
176 + return wikiutil.link_tag(request,
177 + ('%s?action=AttachFile&rename=%s' % (
178 + wikiutil.quoteWikinameURL(pagename),
179 + wikiutil.url_quote_plus(attname))),
180 + linktext % {'filename': attname})
181 +
182 + return formatter.image(**kw)
183 +
184 +
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.