-sub match_maxsize ($$;@) { #{{{
- my $page=shift;
- my $maxsize=eval{IkiWiki::Plugin::attachment::parsesize(shift)};
- if ($@) {
- return IkiWiki::FailReason->new("unable to parse maxsize (or number too large)");
- }
-
- my %params=@_;
- my $file=exists $params{file} ? $params{file} : $IkiWiki::pagesources{$page};
- if (! defined $file) {
- return IkiWiki::FailReason->new("no file specified");
- }
-
- if (-s $file > $maxsize) {
- return IkiWiki::FailReason->new("file too large (".(-s $file)." > $maxsize)");
- }
- else {
- return IkiWiki::SuccessReason->new("file not too large");
- }
-} #}}}
-
-sub match_minsize ($$;@) { #{{{
- my $page=shift;
- my $minsize=eval{IkiWiki::Plugin::attachment::parsesize(shift)};
- if ($@) {
- return IkiWiki::FailReason->new("unable to parse minsize (or number too large)");
- }
-
- my %params=@_;
- my $file=exists $params{file} ? $params{file} : $IkiWiki::pagesources{$page};
- if (! defined $file) {
- return IkiWiki::FailReason->new("no file specified");
- }
-
- if (-s $file < $minsize) {
- return IkiWiki::FailReason->new("file too small");
- }
- else {
- return IkiWiki::SuccessReason->new("file not too small");
- }
-} #}}}
-
-sub match_mimetype ($$;@) { #{{{
- my $page=shift;
- my $wanted=shift;
-
- my %params=@_;
- my $file=exists $params{file} ? $params{file} : $IkiWiki::pagesources{$page};
- if (! defined $file) {
- return IkiWiki::FailReason->new("no file specified");
- }
-
- # Use ::magic to get the mime type, the idea is to only trust
- # data obtained by examining the actual file contents.
- eval q{use File::MimeInfo::Magic};
- if ($@) {
- return IkiWiki::FailReason->new("failed to load File::MimeInfo::Magic ($@); cannot check MIME type");
- }
- my $mimetype=File::MimeInfo::Magic::magic($file);
- if (! defined $mimetype) {
- $mimetype="unknown";
- }
-
- my $regexp=IkiWiki::glob2re($wanted);
- if ($mimetype!~/^$regexp$/i) {
- return IkiWiki::FailReason->new("file MIME type is $mimetype, not $wanted");
- }
- else {
- return IkiWiki::SuccessReason->new("file MIME type is $mimetype");
- }
-} #}}}
-
-sub match_virusfree ($$;@) { #{{{
- my $page=shift;
- my $wanted=shift;
-