+ my $q=$params{cgi};
+
+ 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');
+ # These buttons are not put in the usual place, so
+ # are not added to the normal formbuilder button list.
+ $form->tmpl_param("field-upload" => '<input name="_submit" type="submit" value="Upload Attachment" />');
+ $form->tmpl_param("field-link" => '<input name="_submit" type="submit" value="Insert Links" />');
+
+ # Add the toggle javascript; the attachments interface uses
+ # it to toggle visibility.
+ require IkiWiki::Plugin::toggle;
+ $form->tmpl_param("javascript" => IkiWiki::Plugin::toggle::include_javascript($params{page}, 1));
+ # Start with the attachments interface toggled invisible,
+ # but if it was used, keep it open.
+ if ($form->submitted ne "Upload Attachment" &&
+ (! defined $q->param("attachment_select") ||
+ ! length $q->param("attachment_select"))) {
+ $form->tmpl_param("attachments-class" => "toggleable");
+ }
+ else {
+ $form->tmpl_param("attachments-class" => "toggleable-open");
+ }
+ }
+}