use warnings;
use strict;
-use IkiWiki 2.00;
+use IkiWiki 3.00;
my %imgdefaults;
-sub import { #{{{
+sub import {
+ hook(type => "getsetup", id => "img", call => \&getsetup);
hook(type => "preprocess", id => "img", call => \&preprocess, scan => 1);
-} #}}}
+}
-sub preprocess (@) { #{{{
+sub getsetup () {
+ return
+ plugin => {
+ safe => 1,
+ rebuild => undef,
+ },
+}
+
+sub preprocess (@) {
my ($image) = $_[0] =~ /$config{wiki_file_regexp}/; # untaint
my %params=@_;
return '';
}
- push @{$links{$params{page}}}, $image;
+ add_link($params{page}, $image);
+
# optimisation: detect scan mode, and avoid generating the image
if (! defined wantarray) {
return;
my $file = bestlink($params{page}, $image);
my $srcfile = srcfile($file, 1);
- if (! defined $srcfile) {
- error(sprintf(gettext("%s not found"), $image));
+ if (! length $file || ! defined $srcfile) {
+ return htmllink($params{page}, $params{destpage}, $image);
}
my $dir = $params{page};
my $r;
if ($params{size} ne 'full') {
- my ($w, $h) = ($params{size} =~ /^(\d+)x(\d+)$/);
- error sprintf(gettext('bad size "%s"'), $params{size})
- unless (defined $w && defined $h);
+ add_depends($params{page}, $image);
+
+ my ($w, $h) = ($params{size} =~ /^(\d*)x(\d*)$/);
+ error sprintf(gettext('wrong size format "%s" (should be WxH)'), $params{size})
+ unless (defined $w && defined $h &&
+ (length $w || length $h));
my $outfile = "$config{destdir}/$dir/${w}x${h}-$base";
$imglink = "$dir/${w}x${h}-$base";
$imglink = $file;
}
- add_depends($imglink, $params{page});
-
my ($fileurl, $imgurl);
if (! $params{preview}) {
$fileurl=urlto($file, $params{destpage});
}
my $imgtag='<img src="'.$imgurl.
- '" alt="'.(exists $params{alt} ? $params{alt} : '').
'" width="'.$im->Get("width").
'" height="'.$im->Get("height").'"'.
+ (exists $params{alt} ? ' alt="'.$params{alt}.'"' : '').
(exists $params{title} ? ' title="'.$params{title}.'"' : '').
+ (exists $params{align} ? ' align="'.$params{align}.'"' : '').
(exists $params{class} ? ' class="'.$params{class}.'"' : '').
(exists $params{id} ? ' id="'.$params{id}.'"' : '').
' />';
else {
return $imgtag;
}
-} #}}}
+}
1