# HG changeset patch # User ReimarBauer # Node ID fc8309716597121ef100418d99f9947e483bfef4 # Parent 3c6f59cafbbe442f90171a8b0680be67eb320a67 resizing of images from gui using Image. diff -r 3c6f59cafbbe -r fc8309716597 MoinMoin/converter/text_html_text_moin_wiki.py --- a/MoinMoin/converter/text_html_text_moin_wiki.py Thu Dec 21 03:39:57 2006 +0100 +++ b/MoinMoin/converter/text_html_text_moin_wiki.py Fri Dec 22 14:13:46 2006 +0100 @@ -1179,13 +1179,28 @@ class convert_tree(visitor): alt = None if node.attributes.has_key("alt"): alt = node.attributes.get("alt").nodeValue - + width = None + if node.attributes.has_key("width"): + width = node.attributes.get("width").nodeValue + height = None + if node.attributes.has_key("height"): + height = node.attributes.get("height").nodeValue # Attachment image if (title and title.startswith("attachment:") and wikiutil.isPicture(wikiutil.url_unquote(title[len("attachment:"):]))): - self.text.extend([self.white_space, - wikiutil.url_unquote(title), - self.white_space]) + if height == None and width == None: + self.text.extend([self.white_space, + wikiutil.url_unquote(title), + self.white_space]) + else: + self.text.extend([self.white_space, + "[[Image(%(file)s,width=%(width)s,height=%(height)s,alt=%(alt)s)]]" % { + "file": wikiutil.url_unquote(title[len("attachment:"):]), + "width": width, + "height": height, + "alt": alt, + }, + self.white_space]) # Drawing image elif title and title.startswith("drawing:"): self.text.extend([self.white_space, diff -r 3c6f59cafbbe -r fc8309716597 MoinMoin/formatter/text_gedit.py --- a/MoinMoin/formatter/text_gedit.py Thu Dec 21 03:39:57 2006 +0100 +++ b/MoinMoin/formatter/text_gedit.py Fri Dec 22 14:13:46 2006 +0100 @@ -93,7 +93,33 @@ class Formatter(text_html.Formatter): # Dynamic stuff / Plugins ############################################ def macro(self, macro_obj, name, args): - if args is not None: + if name == "Image" and args is not None: + pagename = self.page.page_name + if args: + args = args.split(',') + args = [arg.strip() for arg in args] + else: + args = [] + url = args[0] + keywords = {} + width = None + height = None + alt = None + for arg in args: + if arg.find('=') > -1: + key, value = arg.split('=') + if key == 'width': + width = value + if key == 'height': + height = value + if key == 'alt': + alt = value + if alt == None: + alt = url + return self.image( + title="attachment:%s" % wikiutil.quoteWikinameURL(url), + src=AttachFile.getAttachUrl(pagename, url, self.request, addts=1), width=width, height=height, alt=alt) + elif args is not None: result = "[[%s(%s)]]" % (name, args) else: result = "[[%s]]" % name diff -r 3c6f59cafbbe -r fc8309716597 MoinMoin/macro/Image.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MoinMoin/macro/Image.py Fri Dec 22 14:13:46 2006 +0100 @@ -0,0 +1,100 @@ +# -*- coding: iso-8859-1 -*- +""" + MoinMoin - Image Macro V1.1 + + This macro is used to display an image with the ability to resize + and/or provide an alt text for it. + + Syntax: + [[Image(image, [width=width, [height=height], [alt=""])]] + + Parameters: + image: image attachment file name or the URL of an image + + Keyword Parameters: + width: rendered image width (optional) + height: rendered image heigth (optional) + alt: text for img tag "alt" attribute (optional) + + Examples: + [[Image(pic.png, height=100)]] + [[Image(pic.png, alt=yourtext)]] + [[Image(OtherWikiSite/pic.png, widht=50, alt=Your text here)]] + [[Image(http://webcam.portalmuc.de/images/webcam/webcam_marienplatz.jpg, height=100)]] + + The Image macro is a simple modification of the ImageLink macro. + ImageLink macro copyright: + 2001 by Jeff Kunce, + 2004 by Marcin Zalewski, + 2004-2006 by Reimar Bauer (R.Bauer@fz-juelich.de), + 2006 by Thomas Waldmann + + @copyright: 2006 by Oliver Siemoneit + @license: GNU GPL, see COPYING for details. + + Changes: + * Parameter values now also take "=None" e.g. "width=None" + * RB bug fixed alt key for images must be defined always +""" + +import os +from MoinMoin import wikiutil, config +from MoinMoin.action import AttachFile + + +def _is_URL(text): + """ Answer true if text is an URL. + The method used here is pretty dumb. Improvements are welcome. + """ + return '://' in text + +def execute(macro, args): + request = macro.request + _ = request.getText + formatter = macro.formatter + if args: + args = args.split(',') + args = [arg.strip() for arg in args] + else: + args = [] + + argc = len(args) + kw_count = 0 + kw = {} # create a dictionary for the formatter.image call + for arg in args: + if '=' in arg: + key, value = arg.split('=', 1) + if value != 'None': + kw_count += 1 + kw[str(key)] = wikiutil.escape(value, quote=1) + argc -= kw_count + image = args[0] + pagename, attname = AttachFile.absoluteName(image, formatter.page.page_name) + + if not kw.has_key('alt') or kw['alt'] == 'None': + if _is_URL(image): + # Get image name http://here.com/dir/image.png -> image.png + kw['alt'] = wikiutil.taintfilename(formatter.text(image.split('/')[-1])) + else: + kw['alt'] = attname + + if not argc or argc and not args[0]: + msg = 'Not enough arguments to Image macro! Calling syntax: [[Image(image, [width=width], [height=height], [alt=""])]]' + return "%s%s%s" % (formatter.sysmsg(1), formatter.text(msg), formatter.sysmsg(0)) + + if _is_URL(image): + kw['src'] = image + else: + kw['src'] = AttachFile.getAttachUrl(pagename, attname, request) + attachment_fname = AttachFile.getFilename(request, pagename, attname) + if not os.path.exists(attachment_fname): + linktext = _('Upload new attachment "%(filename)s"') + return wikiutil.link_tag(request, + ('%s?action=AttachFile&rename=%s' % ( + wikiutil.quoteWikinameURL(pagename), + wikiutil.url_quote_plus(attname))), + linktext % {'filename': attname}) + + return formatter.image(**kw) + +