+sub attachment_location ($) {
+ my $page=shift;
+
+ # Put the attachment in a subdir of the page it's attached
+ # to, unless that page is an "index" page.
+ $page=~s/(^|\/)index//;
+ $page.="/" if length $page;
+
+ return $page;
+}
+
+sub attachment_list ($) {
+ my $loc=attachment_location(shift);
+
+ my @ret;
+ foreach my $f (values %pagesources) {
+ print STDERR ">>$f\n" if ! defined IkiWiki::pagetype($f);
+ if (! defined IkiWiki::pagetype($f) &&
+ $f=~m/^\Q$loc\E[^\/]+$/ &&
+ -e "$config{srcdir}/$f") {
+ push @ret, {
+ "field-select" => '<input type="checkbox" name="attachment_select" value="'.$f.'">',
+ link => $f,
+ size => (stat(_))[7],
+ mtime => displaytime($IkiWiki::pagemtime{$f}),
+ };
+ }
+ }
+
+ return @ret;
+}
+