diff options
Diffstat (limited to 'thumbnail/macro/Thumbnail.py')
-rw-r--r-- | thumbnail/macro/Thumbnail.py | 40 |
1 files changed, 40 insertions, 0 deletions
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 @@ | |||
1 | from MoinMoin import wikiutil | ||
2 | from MoinMoin.action import AttachFile | ||
3 | |||
4 | |||
5 | def macro_Thumbnail(macro, attachment, height=200, width=None, link=True): | ||
6 | _ = macro.request.getText | ||
7 | formatter = macro.formatter | ||
8 | |||
9 | pagename, filename = AttachFile.absoluteName(attachment, formatter.page.page_name) | ||
10 | fname = wikiutil.taintfilename(filename) | ||
11 | |||
12 | if not macro.request.user.may.read(pagename): | ||
13 | return _('You are not allowed to view attachments of this page.') | ||
14 | |||
15 | if width: | ||
16 | size, dimension = width, "w" | ||
17 | else: | ||
18 | size, dimension = height, "h" | ||
19 | |||
20 | if AttachFile.exists(macro.request, pagename, fname): | ||
21 | url = AttachFile.getAttachUrl(pagename, fname, macro.request, do='get') | ||
22 | |||
23 | output = [ | ||
24 | formatter.url(True, url) if link else "", | ||
25 | formatter.image( | ||
26 | macro.request.href(pagename, { | ||
27 | "target": fname, | ||
28 | "action": "Thumbnail", | ||
29 | "do": "tc:{},{}".format(size, dimension) | ||
30 | })), | ||
31 | formatter.url(False) if link else "", | ||
32 | ] | ||
33 | else: | ||
34 | output = [ | ||
35 | formatter.span(True, style="color: red"), | ||
36 | "No Image: {}".format(attachment), | ||
37 | formatter.span(False), | ||
38 | ] | ||
39 | |||
40 | return "".join(output) | ||