From 4aaa43a0ad9ff683668c141f5f26a51612de2152 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Mon, 18 May 2015 20:25:46 -0700 Subject: Initial import --- thumbnail/macro/Thumbnail.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 thumbnail/macro/Thumbnail.py (limited to 'thumbnail/macro/Thumbnail.py') diff --git a/thumbnail/macro/Thumbnail.py b/thumbnail/macro/Thumbnail.py new file mode 100644 index 0000000..0603435 --- /dev/null +++ b/thumbnail/macro/Thumbnail.py @@ -0,0 +1,40 @@ +from MoinMoin import wikiutil +from MoinMoin.action import AttachFile + + +def macro_Thumbnail(macro, attachment, height=200, width=None, link=True): + _ = macro.request.getText + formatter = macro.formatter + + pagename, filename = AttachFile.absoluteName(attachment, formatter.page.page_name) + fname = wikiutil.taintfilename(filename) + + if not macro.request.user.may.read(pagename): + return _('You are not allowed to view attachments of this page.') + + if width: + size, dimension = width, "w" + else: + size, dimension = height, "h" + + if AttachFile.exists(macro.request, pagename, fname): + url = AttachFile.getAttachUrl(pagename, fname, macro.request, do='get') + + output = [ + formatter.url(True, url) if link else "", + formatter.image( + macro.request.href(pagename, { + "target": fname, + "action": "Thumbnail", + "do": "tc:{},{}".format(size, dimension) + })), + formatter.url(False) if link else "", + ] + else: + output = [ + formatter.span(True, style="color: red"), + "No Image: {}".format(attachment), + formatter.span(False), + ] + + return "".join(output) -- cgit v1.2.3