]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Fix for bug 63601: Recommend filename when downloading attachments (except in IE4...
authorjustdave%syndicomm.com <>
Sat, 21 Sep 2002 23:57:07 +0000 (23:57 +0000)
committerjustdave%syndicomm.com <>
Sat, 21 Sep 2002 23:57:07 +0000 (23:57 +0000)
Patch by Daniel Raichle <draichle@gmx.net> and Dave Miller <justdave@syndicomm.com>
r= bbaetz, gerv

attachment.cgi
checksetup.pl
template/en/default/attachment/edit.html.tmpl

index fcbe86a78aa3643a5381b844efdc5776842cdc69..3b29a321e0d45bc315a59899c7b26084fe633099 100755 (executable)
@@ -20,6 +20,8 @@
 #
 # Contributor(s): Terry Weissman <terry@mozilla.org>
 #                 Myk Melez <myk@mozilla.org>
+#                 Daniel Raichle <draichle@gmx.net>
+#                 Dave Miller <justdave@syndicomm.com>
 
 ################################################################################
 # Script Initialization
@@ -338,13 +340,23 @@ sub view
     # Display an attachment.
 
     # Retrieve the attachment content and its content type from the database.
-    SendSQL("SELECT mimetype, thedata FROM attachments WHERE attach_id = $::FORM{'id'}");
-    my ($contenttype, $thedata) = FetchSQLData();
+    SendSQL("SELECT mimetype, filename, thedata FROM attachments WHERE attach_id = $::FORM{'id'}");
+    my ($contenttype, $filename, $thedata) = FetchSQLData();
+
+    # Determine if the browser supports the Content-Disposition header or not
+    my $usedisposition = 1; # assume yes, unless we discover otherwise
+    if ($::ENV{HTTP_USER_AGENT} =~ /^Mozilla.*MSIE (\d+)/) {
+        if ($1 < 5) { $usedisposition = 0; } # MSIE < 5.0 chokes on it
+    }
     
     # Return the appropriate HTTP response headers.
-    print "Content-Type: $contenttype\n\n";
+    $filename =~ s/^.*[\/\\]//;
+    my $filesize = length($thedata);
+    print qq{Content-Type: $contenttype; name="$filename"\n};
+    print qq{Content-Disposition: attachment; filename=$filename\n} if $usedisposition;
+    print qq{Content-Length: $filesize\n};
+    print qq{\n$thedata};
 
-    print $thedata;
 }
 
 
@@ -529,9 +541,9 @@ sub edit
   # Users cannot edit the content of the attachment itself.
 
   # Retrieve the attachment from the database.
-  SendSQL("SELECT description, mimetype, bug_id, ispatch, isobsolete, isprivate 
+  SendSQL("SELECT description, mimetype, filename, bug_id, ispatch, isobsolete, isprivate 
            FROM attachments WHERE attach_id = $::FORM{'id'}");
-  my ($description, $contenttype, $bugid, $ispatch, $isobsolete, $isprivate) = FetchSQLData();
+  my ($description, $contenttype, $filename, $bugid, $ispatch, $isobsolete, $isprivate) = FetchSQLData();
 
   # Flag attachment as to whether or not it can be viewed (as opposed to
   # being downloaded).  Currently I decide it is viewable if its content
@@ -577,6 +589,7 @@ sub edit
   $vars->{'attachid'} = $::FORM{'id'}; 
   $vars->{'description'} = $description; 
   $vars->{'contenttype'} = $contenttype; 
+  $vars->{'filename'} = $filename;
   $vars->{'bugid'} = $bugid; 
   $vars->{'bugsummary'} = $bugsummary; 
   $vars->{'ispatch'} = $ispatch; 
@@ -614,10 +627,10 @@ sub update
            attachstatusdefs READ , fielddefs READ , bugs_activity WRITE");
   # Get a copy of the attachment record before we make changes
   # so we can record those changes in the activity table.
-  SendSQL("SELECT description, mimetype, ispatch, isobsolete, isprivate 
+  SendSQL("SELECT description, mimetype, filename, ispatch, isobsolete, isprivate
            FROM attachments WHERE attach_id = $::FORM{'id'}");
-  my ($olddescription, $oldcontenttype, $oldispatch, $oldisobsolete, 
-      $oldisprivate ) = FetchSQLData();
+  my ($olddescription, $oldcontenttype, $oldfilename, $oldispatch,
+      $oldisobsolete, $oldisprivate) = FetchSQLData();
 
   # Get the list of old status flags.
   SendSQL("SELECT    attachstatusdefs.name 
@@ -657,12 +670,14 @@ sub update
   # Quote the description and content type for use in the SQL UPDATE statement.
   my $quoteddescription = SqlQuote($::FORM{'description'});
   my $quotedcontenttype = SqlQuote($::FORM{'contenttype'});
+  my $quotedfilename = SqlQuote($::FORM{'filename'});
 
   # Update the attachment record in the database.
   # Sets the creation timestamp to itself to avoid it being updated automatically.
   SendSQL("UPDATE  attachments 
            SET     description = $quoteddescription , 
                    mimetype = $quotedcontenttype , 
+                   filename = $quotedfilename ,
                    ispatch = $::FORM{'ispatch'} , 
                    isobsolete = $::FORM{'isobsolete'} ,
                    isprivate = $::FORM{'isprivate'} 
@@ -682,6 +697,12 @@ sub update
     SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added) 
              VALUES ($bugid, $::FORM{'id'}, $::userid, NOW(), $fieldid, $quotedoldcontenttype, $quotedcontenttype)");
   }
+  if ($oldfilename ne $::FORM{'filename'}) {
+    my $quotedoldfilename = SqlQuote($oldfilename);
+    my $fieldid = GetFieldID('attachments.filename');
+    SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added) 
+             VALUES ($bugid, $::FORM{'id'}, $::userid, NOW(), $fieldid, $quotedoldfilename, $quotedfilename)");
+  }
   if ($oldispatch ne $::FORM{'ispatch'}) {
     my $fieldid = GetFieldID('attachments.ispatch');
     SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added) 
index 803d64d141e316a00aca91530929d700f2f29bf9..c00301742c01af3fdf884887be91046449cdaaa5 100755 (executable)
@@ -1805,6 +1805,7 @@ AddFDef("dependson", "BugsThisDependsOn", 0);
 AddFDef("blocked", "OtherBugsDependingOnThis", 0);
 AddFDef("attachments.description", "Attachment description", 0);
 AddFDef("attachments.thedata", "Attachment data", 0);
+AddFDef("attachments.filename", "Attachment filename", 0);
 AddFDef("attachments.mimetype", "Attachment mime type", 0);
 AddFDef("attachments.ispatch", "Attachment is patch", 0);
 AddFDef("attachments.isobsolete", "Attachment is obsolete", 0);
index c9bc7c1cd3cefba4dfe96586a51ac6c8af05b221..ec2616bf95c2ffcfa712fd79ca36341ba284e540 100644 (file)
         <b>Description:</b><br>
           <textarea rows="3" cols="25" name="description" wrap="soft">[% description FILTER html %]</textarea><br>
 
+        <b>Filename:</b><br>
+          <input type="text" size="20" name="filename" value="[% filename FILTER html %]"><br>
+
         <b>MIME Type:</b><br>
           <input type="text" size="20" name="contenttypeentry" value="[% contenttype FILTER html %]"><br>