- return '<a href="'.
- IkiWiki::abs2rel($file, IkiWiki::dirname($params{destpage})).
- '"><img src="'.
- IkiWiki::abs2rel($imglink, IkiWiki::dirname($params{destpage})).
- '" alt="'.$alt.'" width="'.$im->Get("width").
- '" height="'.$im->Get("height").'" /></a>';
+ my ($fileurl, $imgurl);
+ if (! $params{preview}) {
+ $fileurl=urlto($file, $params{destpage});
+ $imgurl=urlto($imglink, $params{destpage});
+ }
+ else {
+ $fileurl="$config{url}/$file";
+ $imgurl="$config{url}/$imglink";
+ }
+
+ if (! defined($im->Get("width")) || ! defined($im->Get("height"))) {
+ error sprintf(gettext("failed to determine size of image %s"), $file)
+ }
+
+ my $imgtag='<img src="'.$imgurl.
+ '" alt="'.(exists $params{alt} ? $params{alt} : '').
+ '" width="'.$im->Get("width").
+ '" height="'.$im->Get("height").'"'.
+ (exists $params{title} ? ' title="'.$params{title}.'"' : '').
+ (exists $params{class} ? ' class="'.$params{class}.'"' : '').
+ (exists $params{id} ? ' id="'.$params{id}.'"' : '').
+ ' />';
+
+ if (! defined $params{link} || lc($params{link}) eq 'yes') {
+ $imgtag='<a href="'.$fileurl.'">'.$imgtag.'</a>';
+ }
+ elsif ($params{link} =~ /^\w+:\/\//) {
+ $imgtag='<a href="'.$params{link}.'">'.$imgtag.'</a>';
+ }
+ elsif (length bestlink($params{page}, $params{link})) {
+ add_depends($params{page}, $params{link});
+ $imgtag=htmllink($params{page}, $params{destpage},
+ $params{link}, linktext => $imgtag,
+ noimageinline => 1);
+ }
+
+ if (exists $params{caption}) {
+ return '<table class="img">'.
+ '<caption>'.$params{caption}.'</caption>'.
+ '<tr><td>'.$imgtag.'</td></tr>'.
+ '</table>';
+ }
+ else {
+ return $imgtag;
+ }