diff options
Diffstat (limited to 'thumbnail/macro/ThumbnailGallery.py')
-rw-r--r-- | thumbnail/macro/ThumbnailGallery.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/thumbnail/macro/ThumbnailGallery.py b/thumbnail/macro/ThumbnailGallery.py new file mode 100644 index 0000000..038c3bc --- /dev/null +++ b/thumbnail/macro/ThumbnailGallery.py | |||
@@ -0,0 +1,47 @@ | |||
1 | import re | ||
2 | from MoinMoin import wikiutil | ||
3 | from MoinMoin.action import AttachFile | ||
4 | |||
5 | |||
6 | def macro_ThumbnailGallery(macro, page=None, regex=None, height=200, width=None, link=True): | ||
7 | _ = macro.request.getText | ||
8 | formatter = macro.formatter | ||
9 | pagename = page or macro.formatter.page.page_name | ||
10 | output = [] | ||
11 | |||
12 | if not regex: | ||
13 | regex = re.compile(".*\.(jpg|jpeg|png|gif)$") | ||
14 | else: | ||
15 | regex = re.compile(regex) | ||
16 | |||
17 | if not macro.request.user.may.read(pagename): | ||
18 | return _('You are not allowed to view attachments of this page.') | ||
19 | |||
20 | for attachment in AttachFile._get_files(macro.request, pagename): | ||
21 | if regex.match(attachment) is None: | ||
22 | continue | ||
23 | |||
24 | pagename, filename = AttachFile.absoluteName(attachment, pagename) | ||
25 | fname = wikiutil.taintfilename(filename) | ||
26 | |||
27 | if width: | ||
28 | size, dimension = width, "w" | ||
29 | else: | ||
30 | size, dimension = height, "h" | ||
31 | |||
32 | if AttachFile.exists(macro.request, pagename, fname): | ||
33 | url = AttachFile.getAttachUrl(pagename, fname, macro.request, do='get') | ||
34 | |||
35 | output.extend([ | ||
36 | macro.formatter.url(True, url) if link else "", | ||
37 | macro.formatter.image( | ||
38 | macro.request.href(pagename, { | ||
39 | "target": fname, | ||
40 | "action": "Thumbnail", | ||
41 | "do": "tc:{},{}".format(size, dimension) | ||
42 | })), | ||
43 | macro.formatter.url(False) if link else "", | ||
44 | " ", | ||
45 | ]) | ||
46 | |||
47 | return "".join(output) | ||