X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/78e34fbdc255fd3f71f5b43ce1acd1fa0678e1ce..aff9bf5a7ab21ea303c4882272e76630d05d40f2:/IkiWiki/Plugin/filecheck.pm?ds=inline diff --git a/IkiWiki/Plugin/filecheck.pm b/IkiWiki/Plugin/filecheck.pm index 6f71be301..8575ee108 100644 --- a/IkiWiki/Plugin/filecheck.pm +++ b/IkiWiki/Plugin/filecheck.pm @@ -3,7 +3,7 @@ package IkiWiki::Plugin::filecheck; use warnings; use strict; -use IkiWiki 2.00; +use IkiWiki 3.00; my %units=( #{{{ # size in bytes B => 1, @@ -37,9 +37,9 @@ my %units=( #{{{ # size in bytes # ikiwiki, if you find you need larger data quantities, either modify # yourself to add them, or travel back in time to 2008 and kill me. # -- Joey -); #}}} +); -sub parsesize ($) { #{{{ +sub parsesize ($) { my $size=shift; no warnings; @@ -51,9 +51,10 @@ sub parsesize ($) { #{{{ } } return $base; -} #}}} +} -sub humansize ($) { #{{{ +# This is provided for other plugins that want to convert back the other way. +sub humansize ($) { my $size=shift; foreach my $unit (reverse sort { $units{$a} <=> $units{$b} || $b cmp $a } keys %units) { @@ -62,13 +63,13 @@ sub humansize ($) { #{{{ } } return $size; # near zero, or negative -} #}}} +} package IkiWiki::PageSpec; -sub match_maxsize ($$;@) { #{{{ +sub match_maxsize ($$;@) { my $page=shift; - my $maxsize=eval{IkiWiki::Plugin::attachment::parsesize(shift)}; + my $maxsize=eval{IkiWiki::Plugin::filecheck::parsesize(shift)}; if ($@) { return IkiWiki::FailReason->new("unable to parse maxsize (or number too large)"); } @@ -85,11 +86,11 @@ sub match_maxsize ($$;@) { #{{{ else { return IkiWiki::SuccessReason->new("file not too large"); } -} #}}} +} -sub match_minsize ($$;@) { #{{{ +sub match_minsize ($$;@) { my $page=shift; - my $minsize=eval{IkiWiki::Plugin::attachment::parsesize(shift)}; + my $minsize=eval{IkiWiki::Plugin::filecheck::parsesize(shift)}; if ($@) { return IkiWiki::FailReason->new("unable to parse minsize (or number too large)"); } @@ -106,9 +107,9 @@ sub match_minsize ($$;@) { #{{{ else { return IkiWiki::SuccessReason->new("file not too small"); } -} #}}} +} -sub match_mimetype ($$;@) { #{{{ +sub match_mimetype ($$;@) { my $page=shift; my $wanted=shift; @@ -126,7 +127,10 @@ sub match_mimetype ($$;@) { #{{{ } my $mimetype=File::MimeInfo::Magic::magic($file); if (! defined $mimetype) { - $mimetype="unknown"; + $mimetype=File::MimeInfo::Magic::default($file); + if (! defined $mimetype) { + $mimetype="unknown"; + } } my $regexp=IkiWiki::glob2re($wanted); @@ -136,9 +140,9 @@ sub match_mimetype ($$;@) { #{{{ else { return IkiWiki::SuccessReason->new("file MIME type is $mimetype"); } -} #}}} +} -sub match_virusfree ($$;@) { #{{{ +sub match_virusfree ($$;@) { my $page=shift; my $wanted=shift; @@ -178,9 +182,9 @@ sub match_virusfree ($$;@) { #{{{ else { return IkiWiki::SuccessReason->new("file seems virusfree ($reason)"); } -} #}}} +} -sub match_ispage ($$;@) { #{{{ +sub match_ispage ($$;@) { my $filename=shift; if (defined IkiWiki::pagetype($filename)) { @@ -189,4 +193,4 @@ sub match_ispage ($$;@) { #{{{ else { return IkiWiki::FailReason->new("file is not a wiki page"); } -} #}}} +}