]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/attachment.pm
avoid uninitialised value warnings
[ikiwiki.git] / IkiWiki / Plugin / attachment.pm
index 5d918c43f0551baeb28c4b6b6b03035567e9ea73..2bb86b78dbf09eb34dfc13549c4f941a34d7a557 100644 (file)
@@ -20,7 +20,7 @@ sub formbuilder_setup (@) { #{{{
        my $form=$params{form};
        my $q=$params{cgi};
 
-       if ($form->field("do") eq "edit") {
+       if (defined $form->field("do") && $form->field("do") eq "edit") {
                $form->field(name => 'attachment', type => 'file');
                # These buttons are not put in the usual place, so
                # are not added to the normal formbuilder button list.
@@ -47,7 +47,13 @@ sub formbuilder_setup (@) { #{{{
 
                $form->field(name => "allowed_attachments", size => 50,
                        fieldset => "admin",
-                       comment => "(".htmllink("", "", "ikiwiki/PageSpec", noimageinline => 1).")");
+                       comment => "(".
+                               htmllink("", "", 
+                                       "ikiwiki/PageSpec/attachment", 
+                                       noimageinline => 1,
+                                       linktext => "Enhanced PageSpec",
+                               ).")"
+               );
                if (! IkiWiki::is_admin($user_name)) {
                        $form->field(name => "allowed_attachments", type => "hidden");
                }
@@ -70,7 +76,7 @@ sub formbuilder (@) { #{{{
        my $form=$params{form};
        my $q=$params{cgi};
 
-       return if $form->field("do") ne "edit";
+       return if ! defined $form->field("do") || $form->field("do") ne "edit";
 
        my $filename=$q->param('attachment');
        if (defined $filename && length $filename &&
@@ -318,11 +324,7 @@ sub match_mimetype ($$;@) { #{{{
                $mimetype="unknown";
        }
 
-       # turn glob into a safe regexp
-       my $regexp=quotemeta($wanted);
-       $regexp=~s/\\\*/.*/g;
-       $regexp=~s/\\\?/./g;
-
+       my $regexp=IkiWiki::glob2re($wanted);
        if ($mimetype!~/^$regexp$/i) {
                return IkiWiki::FailReason->new("file MIME type is $mimetype, not $wanted");
        }