]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/img.pm
po: fix link() pagespec when used on translation pages
[ikiwiki.git] / IkiWiki / Plugin / img.pm
index d295b833b21b57ccfef5c5d985ae91281efb466b..5f97e38108ad22cfb9cde8dd9500d298201752be 100644 (file)
@@ -43,7 +43,8 @@ sub preprocess (@) {
                return '';
        }
 
-       push @{$links{$params{page}}}, $image;
+       add_link($params{page}, $image);
+
        # optimisation: detect scan mode, and avoid generating the image
        if (! defined wantarray) {
                return;
@@ -65,8 +66,10 @@ sub preprocess (@) {
        my $r;
 
        if ($params{size} ne 'full') {
+               add_depends($params{page}, $image);
+
                my ($w, $h) = ($params{size} =~ /^(\d*)x(\d*)$/);
-               error sprintf(gettext('bad size "%s"'), $params{size})
+               error sprintf(gettext('wrong size format "%s" (should be WxH)'), $params{size})
                        unless (defined $w && defined $h &&
                                (length $w || length $h));
 
@@ -102,8 +105,6 @@ sub preprocess (@) {
                $imglink = $file;
        }
 
-       add_depends($imglink, $params{page});
-
        my ($fileurl, $imgurl);
        if (! $params{preview}) {
                $fileurl=urlto($file, $params{destpage});
@@ -121,8 +122,9 @@ sub preprocess (@) {
        my $imgtag='<img src="'.$imgurl.
                '" width="'.$im->Get("width").
                '" height="'.$im->Get("height").'"'.
-               (exists $params{alt} ? '" alt="'.$params{alt}.'"' : '').
+               (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}.'"' : '').
                ' />';
@@ -133,11 +135,15 @@ sub preprocess (@) {
        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);
+       else {
+               my $b = bestlink($params{page}, $params{link});
+       
+               if (length $b) {
+                       add_depends($params{page}, $b);
+                       $imgtag=htmllink($params{page}, $params{destpage},
+                               $params{link}, linktext => $imgtag,
+                               noimageinline => 1);
+               }
        }
 
        if (exists $params{caption}) {