]> scripts.mit.edu Git - www/ikiwiki.git/blobdiff - IkiWiki/Plugin/attachment.pm
attachment: Support adding attachments to pages even as they are being created.
[www/ikiwiki.git] / IkiWiki / Plugin / attachment.pm
index f1a9b19394701ea82558513ecc423b451ba2ddc4..2d1fe51cf090b0f70595104217bd8d01b34ab0f9 100644 (file)
@@ -94,7 +94,8 @@ sub formbuilder_setup (@) { #{{{
        my $form=$params{form};
        my $q=$params{cgi};
 
-       if (defined $form->field("do") && $form->field("do") eq "edit") {
+       if (defined $form->field("do") && ($form->field("do") eq "edit" ||
+           $form->field("do") eq "create")) {
                # Add attachment field, set type to multipart.
                $form->enctype(&CGI::MULTIPART);
                $form->field(name => 'attachment', type => 'file');
@@ -158,7 +159,7 @@ sub formbuilder (@) { #{{{
        my $form=$params{form};
        my $q=$params{cgi};
 
-       return if ! defined $form->field("do") || $form->field("do") ne "edit";
+       return if ! defined $form->field("do") || ($form->field("do") ne "edit" && $form->field("do") ne "create") ;
 
        my $filename=$q->param('attachment');
        if (defined $filename && length $filename &&
@@ -181,8 +182,7 @@ sub formbuilder (@) { #{{{
                        }
                }
 
-               $filename=IkiWiki::linkpage(
-                       IkiWiki::possibly_foolish_untaint(
+               $filename=linkpage(IkiWiki::possibly_foolish_untaint(
                                attachment_location($form->field('page')).
                                IkiWiki::basename($filename)));
                if (IkiWiki::file_pruned($filename, $config{srcdir})) {
@@ -271,7 +271,7 @@ sub attachment_list ($) { #{{{
 
        my @ret;
        foreach my $f (values %pagesources) {
-               if (! defined IkiWiki::pagetype($f) &&
+               if (! defined pagetype($f) &&
                    $f=~m/^\Q$loc\E[^\/]+$/ &&
                    -e "$config{srcdir}/$f") {
                        push @ret, {