]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/img.pm
improve error message
[ikiwiki.git] / IkiWiki / Plugin / img.pm
index 7b89ab6730faed3693f2d0eb59afa38a5194e854..44d67bd8375057e77d5853ee93cdd7943108ed14 100644 (file)
@@ -5,24 +5,24 @@ package IkiWiki::Plugin::img;
 
 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 getsetup () { #{{{
+sub getsetup () {
        return
                plugin => {
                        safe => 1,
                        rebuild => undef,
                },
-} #}}}
+}
 
-sub preprocess (@) { #{{{
+sub preprocess (@) {
        my ($image) = $_[0] =~ /$config{wiki_file_regexp}/; # untaint
        my %params=@_;
 
@@ -43,7 +43,7 @@ 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;
@@ -66,7 +66,7 @@ sub preprocess (@) { #{{{
 
        if ($params{size} ne 'full') {
                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));
 
@@ -119,10 +119,11 @@ sub preprocess (@) { #{{{
        }
 
        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}.'"' : '').
                ' />';
@@ -149,6 +150,6 @@ sub preprocess (@) { #{{{
        else {
                return $imgtag;
        }
-} #}}}
+}
 
 1