]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Fix for bug 127995: shows the size of attachments in the show bug and attachment...
authormyk%mozilla.org <>
Fri, 6 Feb 2004 02:14:01 +0000 (02:14 +0000)
committermyk%mozilla.org <>
Fri, 6 Feb 2004 02:14:01 +0000 (02:14 +0000)
Patch by Dave Swegen <dswegen@software.plasmon.com>
r=myk
a=myk

Attachment.pm
Bugzilla/Attachment.pm
Bugzilla/Template.pm
attachment.cgi
checksetup.pl
t/004template.t
t/008filter.t
template/en/default/attachment/edit.html.tmpl
template/en/default/attachment/list.html.tmpl
template/en/default/attachment/show-multiple.html.tmpl

index ea5cd531c0d9cc8eed24c4ff4e45732e932b1005..84979d3eaf82470770a4ff566820ec72455bd0aa 100644 (file)
@@ -77,7 +77,8 @@ sub query
   # of hashes in which each hash represents a single attachment.
   &::SendSQL("
               SELECT attach_id, DATE_FORMAT(creation_ts, '%Y.%m.%d %H:%i'),
-              mimetype, description, ispatch, isobsolete, isprivate, submitter_id
+              mimetype, description, ispatch, isobsolete, isprivate, 
+              submitter_id, LENGTH(thedata)
               FROM attachments WHERE bug_id = $bugid ORDER BY attach_id
             ");
   my @attachments = ();
@@ -85,8 +86,8 @@ sub query
     my %a;
     my $submitter_id;
     ($a{'attachid'}, $a{'date'}, $a{'contenttype'}, $a{'description'},
-     $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'}, $submitter_id) 
-        = &::FetchSQLData();
+     $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'}, $submitter_id, 
+     $a{'datasize'}) = &::FetchSQLData();
 
     # Retrieve a list of flags for this attachment.
     $a{'flags'} = Bugzilla::Flag::match({ 'attach_id' => $a{'attachid'} });
index ea5cd531c0d9cc8eed24c4ff4e45732e932b1005..84979d3eaf82470770a4ff566820ec72455bd0aa 100644 (file)
@@ -77,7 +77,8 @@ sub query
   # of hashes in which each hash represents a single attachment.
   &::SendSQL("
               SELECT attach_id, DATE_FORMAT(creation_ts, '%Y.%m.%d %H:%i'),
-              mimetype, description, ispatch, isobsolete, isprivate, submitter_id
+              mimetype, description, ispatch, isobsolete, isprivate, 
+              submitter_id, LENGTH(thedata)
               FROM attachments WHERE bug_id = $bugid ORDER BY attach_id
             ");
   my @attachments = ();
@@ -85,8 +86,8 @@ sub query
     my %a;
     my $submitter_id;
     ($a{'attachid'}, $a{'date'}, $a{'contenttype'}, $a{'description'},
-     $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'}, $submitter_id) 
-        = &::FetchSQLData();
+     $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'}, $submitter_id, 
+     $a{'datasize'}) = &::FetchSQLData();
 
     # Retrieve a list of flags for this attachment.
     $a{'flags'} = Bugzilla::Flag::match({ 'attach_id' => $a{'attachid'} });
index d370627d34f85f155f2622bfbe819113ad6b63d9..c123154bbebdd05855c19dbb4c20958734f25259 100644 (file)
@@ -258,6 +258,30 @@ sub create {
                 return $var;
             } ,
 
+            # Format a filesize in bytes to a human readable value
+            unitconvert => sub
+            {
+                my ($data) = @_;
+                my $retval = "";
+                my %units = (
+                    'KB' => 1024,
+                    'MB' => 1024 * 1024,
+                    'GB' => 1024 * 1024 * 1024,
+                );
+
+                if ($data < 1024) {
+                    return "$data bytes";
+                } 
+                else {
+                    my $u;
+                    foreach $u ('GB', 'MB', 'KB') {
+                        if ($data >= $units{$u}) {
+                            return sprintf("%.2f %s", $data/$units{$u}, $u);
+                        }
+                    }
+                }
+            },
+
             # Format a time for display (more info in Bugzilla::Util)
             time => \&Bugzilla::Util::format_time,
 
index fd9983841f75e1c0b97b79de834497a2fdcdcf38..8df562120023d7397c676daf8bde6d9ff2c2d281 100755 (executable)
@@ -746,7 +746,8 @@ sub viewall
         $privacy = "AND isprivate < 1 ";
     }
     SendSQL("SELECT attach_id, DATE_FORMAT(creation_ts, '%Y.%m.%d %H:%i'),
-            mimetype, description, ispatch, isobsolete, isprivate 
+            mimetype, description, ispatch, isobsolete, isprivate, 
+            LENGTH(thedata)
             FROM attachments WHERE bug_id = $::FORM{'bugid'} $privacy 
             ORDER BY attach_id");
   my @attachments; # the attachments array
@@ -754,8 +755,8 @@ sub viewall
   {
     my %a; # the attachment hash
     ($a{'attachid'}, $a{'date'}, $a{'contenttype'}, 
-     $a{'description'}, $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'}
-                                                               = FetchSQLData();
+     $a{'description'}, $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'},
+     $a{'datasize'}) = FetchSQLData();
     $a{'isviewable'} = isViewable($a{'contenttype'});
 
     # Add the hash representing the attachment to the array of attachments.
@@ -943,9 +944,9 @@ sub edit
   # Users cannot edit the content of the attachment itself.
 
   # Retrieve the attachment from the database.
-  SendSQL("SELECT description, mimetype, filename, bug_id, ispatch, isobsolete, isprivate 
+  SendSQL("SELECT description, mimetype, filename, bug_id, ispatch, isobsolete, isprivate, LENGTH(thedata)
            FROM attachments WHERE attach_id = $::FORM{'id'}");
-  my ($description, $contenttype, $filename, $bugid, $ispatch, $isobsolete, $isprivate) = FetchSQLData();
+  my ($description, $contenttype, $filename, $bugid, $ispatch, $isobsolete, $isprivate, $datasize) = FetchSQLData();
 
   my $isviewable = isViewable($contenttype);
 
@@ -980,6 +981,7 @@ sub edit
   $vars->{'ispatch'} = $ispatch; 
   $vars->{'isobsolete'} = $isobsolete; 
   $vars->{'isprivate'} = $isprivate; 
+  $vars->{'datasize'} = $datasize;
   $vars->{'isviewable'} = $isviewable; 
   $vars->{'attachments'} = \@bugattachments; 
   $vars->{'GetBugLink'} = \&GetBugLink;
index 4385accfc3f3b0e08b8df527ba47c0893510a346..9726986e0903e0ad6bbdc6457277037a71748081 100755 (executable)
@@ -1111,6 +1111,7 @@ END
                 quoteUrls => sub { return $_; },
                 bug_link => [ sub { return sub { return $_; } }, 1],
                 csv => sub { return $_; },
+                unitconvert => sub { return $_; },
                 time => sub { return $_; },
                 none => sub { return $_; } ,
                },
index 3b41282cc5ae5ffd446df36a838502bfefd61e9b..6c753c0bd793853eb57be6b1222b90ccff2904d1 100644 (file)
@@ -101,6 +101,7 @@ foreach my $include_path (@include_paths) {
             quoteUrls => sub { return $_ } ,
             bug_link => [ sub { return sub { return $_; } }, 1] ,
             csv       => sub { return $_ } ,
+            unitconvert => sub { return $_ },
             time      => sub { return $_ } ,
             none      => sub { return $_ } ,
         },
index 8e0ca2d0432dba88ed33900ac6d3ccf4020ca7dc..722802bb82adc7f774f7adbd94bb9dcf0f1c5b9e 100644 (file)
@@ -202,7 +202,8 @@ sub directive_ok {
     # Note: If a single directive prints two things, and only one is 
     # filtered, we may not catch that case.
     return 1 if $directive =~ /FILTER\ (html|csv|js|url_quote|css_class_quote|
-                                        quoteUrls|time|uri|xml|lower|none)/x;
+                                        quoteUrls|time|uri|xml|lower|
+                                        unitconvert|none)/x;
 
     return 0;
 }
index 6718421529bd6ccfd2cfa21fc2ae431c62de07dd..19cc06550429b576bc79a2c3139981c4739f2b2c 100644 (file)
 
         <b>Filename:</b><br>
           <input type="text" size="20" name="filename" value="[% filename FILTER html %]"><br>
+        <b>Size: </b>[% datasize FILTER unitconvert %]<br>
 
         <b>MIME Type:</b><br>
           <input type="text" size="20" name="contenttypeentry" value="[% contenttype FILTER html %]"><br>
index 407ef8dfb7eb13fabe849f281827f49c1440124a..1ef6cab12c916aaa596cfc061b05eaee8c909417 100644 (file)
@@ -25,6 +25,7 @@
     <th bgcolor="#cccccc" align="left">Attachment</th>
     <th bgcolor="#cccccc" align="left">Type</th>
     <th bgcolor="#cccccc" align="left">Created</th>
+    <th bgcolor="#cccccc" align="left">Size</th>
     [% IF show_attachment_flags %]
       <th bgcolor="#cccccc" align="left">Flags</th>
     [% END %]
@@ -47,6 +48,7 @@
       </td>
 
       <td valign="top">[% attachment.date FILTER time %]</td>
+      <td valign="top">[% attachment.datasize FILTER unitconvert %]</td>
 
       [% IF show_attachment_flags %]
         <td valign="top">
@@ -82,7 +84,7 @@
   [% END %]
 
   <tr>
-    <td colspan="[% show_attachment_flags ? 4 : 3 %]">
+    <td colspan="[% show_attachment_flags ? 5 : 4 %]">
       <a href="attachment.cgi?bugid=[% bugid %]&amp;action=enter">Create a New Attachment</a> (proposed patch, testcase, etc.)
     </td>
     [% IF attachments.size %]
index 3159b8e8726e628780bc08872003d3ebf8817a13..48f03dff133e1d7e2176a312f6ebfdc5fdecf1e8 100644 (file)
@@ -40,7 +40,7 @@
   <div align="center">
   <table class="attachment_info" cellspacing="0" cellpadding="4" border="1" width="75%">
     <tr>
-      <td valign="top" bgcolor="#cccccc" colspan="5">
+      <td valign="top" bgcolor="#cccccc" colspan="6">
         <big><b>Attachment #[% a.attachid %]</b></big>
       </td>
     </tr>
@@ -62,6 +62,7 @@
       </td>
 
       <td valign="top">[% a.date FILTER time %]</td>
+      <td valign="top">[% a.datasize FILTER unitconvert %]</td>
 
       <td valign="top">
         [% IF a.statuses.size == 0 %]