+#!/bin/sh
+
+. "$_EXEC/cgilite/cgilite.sh"
+. "$_EXEC/acl.sh"
+. "$_EXEC/tools.sh"
+
+[ $# = 0 ] && set -- "*"
+
+printf '<div class="macro gallery">'
+for glob in "$@"; do
+ page="${glob%/*}"
+ [ "$page" = "$glob" ] && page=./
+ [ ! "$page" ] && page=/
+
+ acl_read "$(page_abs "${page}")" \
+ && attachment_glob "$glob"
+done \
+| grep -xiE '.*\.jpe?g|.*\.png|.*\.gif' \
+| sort -u \
+| while read attachment; do
+ case $attachment in
+ */*)
+ printf '<a href="%s"><img src="%s"></a>' \
+ "${attachment%/*}/[attachment]/${attachment##*/}" "${attachment}"
+ ;;
+ *)
+ printf '<a href="%s"><img src="%s"></a>' \
+ "[attachment]/${attachment}" "${attachment}"
+ ;;
+ esac
+done
+printf '</div>'