+ my $extension;
+ my $format;
+
+ if ($base =~ m/\.([a-z0-9]+)$/) {
+ $extension = $1;
+ }
+ else {
+ error gettext("Unable to detect image type from extension");
+ }
+
+ # Never interpret well-known file extensions as any other format,
+ # in case the wiki configuration unwisely allows attaching
+ # arbitrary files named *.jpg, etc.
+ if ($extension =~ m/^(jpeg|jpg)$/is) {
+ $format = 'jpeg';
+ }
+ elsif ($extension =~ m/^(png)$/is) {
+ $format = 'png';
+ }
+ elsif ($extension =~ m/^(gif)$/is) {
+ $format = 'gif';
+ }
+ elsif ($extension =~ m/^(svg)$/is) {
+ $format = 'svg';
+ }
+ elsif ($extension =~ m/^(pdf)$/is) {
+ $format = 'pdf';
+ }
+ else {
+ # allow ImageMagick to auto-detect (potentially dangerous)
+ $format = '';
+ }
+
+ error sprintf(gettext("%s image processing disabled in img_allowed_formats configuration"), $format ? $format : "\"$extension\"") unless allowed($format ? $format : "everything");
+