Commit 1288cb37 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 301764: The file size indicates "0" when editing local attachments - Patch…

Bug 301764: The file size indicates "0" when editing local attachments - Patch by Frédéric Buclin <LpSolit@gmail.com> r=myk a=justdave
parent fa5ed8f8
...@@ -236,6 +236,21 @@ sub ispatch { ...@@ -236,6 +236,21 @@ sub ispatch {
=over =over
=item C<isurl>
whether or not the attachment is a URL
=back
=cut
sub isurl {
my $self = shift;
return $self->{isurl};
}
=over
=item C<isobsolete> =item C<isobsolete>
whether or not the attachment is obsolete whether or not the attachment is obsolete
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
# Alexander J. Vincent <ajvincent@juno.com> # Alexander J. Vincent <ajvincent@juno.com>
# Max Kanat-Alexander <mkanat@bugzilla.org> # Max Kanat-Alexander <mkanat@bugzilla.org>
# Greg Hendricks <ghendricks@novell.com> # Greg Hendricks <ghendricks@novell.com>
# Frédéric Buclin <LpSolit@gmail.com>
################################################################################ ################################################################################
# Script Initialization # Script Initialization
...@@ -37,9 +38,9 @@ use lib qw(.); ...@@ -37,9 +38,9 @@ use lib qw(.);
# Include the Bugzilla CGI and general utility library. # Include the Bugzilla CGI and general utility library.
require "globals.pl"; require "globals.pl";
use Bugzilla::Config qw(:locations);
# Use these modules to handle flags. use Bugzilla;
use Bugzilla::Config qw(:locations);
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Flag; use Bugzilla::Flag;
use Bugzilla::FlagType; use Bugzilla::FlagType;
...@@ -47,10 +48,12 @@ use Bugzilla::User; ...@@ -47,10 +48,12 @@ use Bugzilla::User;
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Bug; use Bugzilla::Bug;
use Bugzilla::Field; use Bugzilla::Field;
use Bugzilla::Attachment;
Bugzilla->login(); Bugzilla->login();
my $cgi = Bugzilla->cgi; my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh;
my $template = Bugzilla->template; my $template = Bugzilla->template;
my $vars = {}; my $vars = {};
...@@ -1107,64 +1110,40 @@ sub insert ...@@ -1107,64 +1110,40 @@ sub insert
# Any user is allowed to access this page, unless the attachment # Any user is allowed to access this page, unless the attachment
# is private and the user does not belong to the insider group. # is private and the user does not belong to the insider group.
# Validations are done later when the user submits changes. # Validations are done later when the user submits changes.
sub edit sub edit {
{
# Retrieve and validate parameters
my ($attach_id) = validateID(); my ($attach_id) = validateID();
my $dbh = Bugzilla->dbh;
# Retrieve the attachment from the database. my $attachment = Bugzilla::Attachment->get($attach_id);
SendSQL("SELECT description, mimetype, filename, bug_id, ispatch, isurl, my $isviewable = !$attachment->isurl && isViewable($attachment->contenttype);
isobsolete, isprivate, LENGTH(thedata)
FROM attachments
INNER JOIN attach_data
ON id = attach_id
WHERE attach_id = $attach_id");
my ($description, $contenttype, $filename, $bugid, $ispatch, $isurl, $isobsolete, $isprivate, $datasize) = FetchSQLData();
my $isviewable = !$isurl && isViewable($contenttype);
my $thedata;
if ($isurl) {
SendSQL("SELECT thedata FROM attach_data WHERE id = $attach_id");
($thedata) = FetchSQLData();
}
# Retrieve a list of attachments for this bug as well as a summary of the bug # Retrieve a list of attachments for this bug as well as a summary of the bug
# to use in a navigation bar across the top of the screen. # to use in a navigation bar across the top of the screen.
SendSQL("SELECT attach_id FROM attachments WHERE bug_id = $bugid ORDER BY attach_id"); my $bugattachments =
my @bugattachments; $dbh->selectcol_arrayref('SELECT attach_id FROM attachments
push(@bugattachments, FetchSQLData()) while (MoreSQLData()); WHERE bug_id = ? ORDER BY attach_id',
SendSQL("SELECT short_desc FROM bugs WHERE bug_id = $bugid"); undef, $attachment->bug_id);
my ($bugsummary) = FetchSQLData();
my ($bugsummary, $product_id, $component_id) =
$dbh->selectrow_array('SELECT short_desc, product_id, component_id
FROM bugs
WHERE bug_id = ?', undef, $attachment->bug_id);
# Get a list of flag types that can be set for this attachment. # Get a list of flag types that can be set for this attachment.
SendSQL("SELECT product_id, component_id FROM bugs WHERE bug_id = $bugid");
my ($product_id, $component_id) = FetchSQLData();
my $flag_types = Bugzilla::FlagType::match({ 'target_type' => 'attachment' , my $flag_types = Bugzilla::FlagType::match({ 'target_type' => 'attachment' ,
'product_id' => $product_id , 'product_id' => $product_id ,
'component_id' => $component_id }); 'component_id' => $component_id });
foreach my $flag_type (@$flag_types) { foreach my $flag_type (@$flag_types) {
$flag_type->{'flags'} = Bugzilla::Flag::match({ 'type_id' => $flag_type->{'id'}, $flag_type->{'flags'} = Bugzilla::Flag::match({ 'type_id' => $flag_type->{'id'},
'attach_id' => $attach_id, 'attach_id' => $attachment->id,
'is_active' => 1 }); 'is_active' => 1 });
} }
$vars->{'flag_types'} = $flag_types; $vars->{'flag_types'} = $flag_types;
$vars->{'any_flags_requesteeble'} = grep($_->{'is_requesteeble'}, @$flag_types); $vars->{'any_flags_requesteeble'} = grep($_->{'is_requesteeble'}, @$flag_types);
$vars->{'attachment'} = $attachment;
# Define the variables and functions that will be passed to the UI template.
$vars->{'attachid'} = $attach_id;
$vars->{'description'} = $description;
$vars->{'contenttype'} = $contenttype;
$vars->{'filename'} = $filename;
$vars->{'bugid'} = $bugid;
$vars->{'bugsummary'} = $bugsummary; $vars->{'bugsummary'} = $bugsummary;
$vars->{'ispatch'} = $ispatch;
$vars->{'isurl'} = $isurl;
$vars->{'isobsolete'} = $isobsolete;
$vars->{'isprivate'} = $isprivate;
$vars->{'datasize'} = $datasize;
$vars->{'thedata'} = $thedata;
$vars->{'isviewable'} = $isviewable; $vars->{'isviewable'} = $isviewable;
$vars->{'attachments'} = \@bugattachments; $vars->{'attachments'} = $bugattachments;
$vars->{'GetBugLink'} = \&GetBugLink; $vars->{'GetBugLink'} = \&GetBugLink;
# Determine if PatchReader is installed # Determine if PatchReader is installed
......
...@@ -17,14 +17,19 @@ ...@@ -17,14 +17,19 @@
# Rights Reserved. # Rights Reserved.
# #
# Contributor(s): Myk Melez <myk@mozilla.org> # Contributor(s): Myk Melez <myk@mozilla.org>
# Frédéric Buclin <LpSolit@gmail.com>
#%] #%]
[% PROCESS global/variables.none.tmpl %] [% PROCESS global/variables.none.tmpl %]
[%# Define strings that will serve as the title and header of this page %] [%# Define strings that will serve as the title and header of this page %]
[% title = BLOCK %]Edit Attachment #[% attachid %] for [% terms.Bug %] #[% bugid %][% END %] [% title = BLOCK %]
[% h1 = BLOCK %]Edit Attachment #[% attachid %] for Edit Attachment [% attachment.id %] for [% terms.Bug %] [%+ attachment.bug_id %]
[%+ GetBugLink(bugid, "$terms.Bug $bugid") %][% END %] [% END %]
[% h1 = BLOCK %]
Edit Attachment [% attachment.id %] for
[%+ GetBugLink(attachment.bug_id, "$terms.Bug ${attachment.bug_id}") %]
[% END %]
[% h2 = BLOCK %][% bugsummary FILTER html %][% END %] [% h2 = BLOCK %][% bugsummary FILTER html %][% END %]
[% PROCESS global/header.html.tmpl [% PROCESS global/header.html.tmpl
...@@ -99,7 +104,7 @@ ...@@ -99,7 +104,7 @@
if (!has_viewed_as_diff) { if (!has_viewed_as_diff) {
var viewDiffFrame = document.getElementById('viewDiffFrame'); var viewDiffFrame = document.getElementById('viewDiffFrame');
viewDiffFrame.src = viewDiffFrame.src =
'attachment.cgi?id=[% attachid %]&action=diff&headers=0'; 'attachment.cgi?id=[% attachment.id %]&action=diff&headers=0';
has_viewed_as_diff = 1; has_viewed_as_diff = 1;
} }
} }
...@@ -197,7 +202,7 @@ ...@@ -197,7 +202,7 @@
</script> </script>
<form method="post" action="attachment.cgi" onsubmit="normalizeComments();"> <form method="post" action="attachment.cgi" onsubmit="normalizeComments();">
<input type="hidden" name="id" value="[% attachid %]"> <input type="hidden" name="id" value="[% attachment.id %]">
<input type="hidden" name="action" value="update"> <input type="hidden" name="action" value="update">
<input type="hidden" name="contenttypemethod" value="manual"> <input type="hidden" name="contenttypemethod" value="manual">
...@@ -207,33 +212,40 @@ ...@@ -207,33 +212,40 @@
<td width="25%"> <td width="25%">
<small> <small>
<b>Description:</b><br> <b>Description:</b><br>
<textarea rows="3" cols="25" name="description" wrap="soft">[% description FILTER html %]</textarea><br> <textarea rows="3" cols="25" name="description" wrap="soft">
[%- attachment.description FILTER html %]</textarea><br>
[% IF isurl %]
<input type="hidden" name="filename" value="[% filename FILTER html %]"><br> [% IF attachment.isurl %]
<input type="hidden" name="contenttypeentry" value="[% contenttype FILTER html %]"><br> <input type="hidden" name="filename"
value="[% attachment.filename FILTER html %]"><br>
<input type="hidden" name="contenttypeentry"
value="[% attachment.contenttype FILTER html %]"><br>
[% ELSE %] [% ELSE %]
<b>Filename:</b><br> <b>Filename:</b><br>
<input type="text" size="20" name="filename" value="[% filename FILTER html %]"><br> <input type="text" size="20" name="filename"
<b>Size: </b>[% datasize FILTER unitconvert %]<br> value="[% attachment.filename FILTER html %]"><br>
<b>Size: </b>[% attachment.datasize FILTER unitconvert %]<br>
<b>MIME Type:</b><br> <b>MIME Type:</b><br>
<input type="text" size="20" name="contenttypeentry" value="[% contenttype FILTER html %]"><br> <input type="text" size="20" name="contenttypeentry"
value="[% attachment.contenttype FILTER html %]"><br>
<input type="checkbox" id="ispatch" name="ispatch" value="1" <input type="checkbox" id="ispatch" name="ispatch" value="1"
[% 'checked="checked"' IF ispatch %]> [% 'checked="checked"' IF attachment.ispatch %]>
<label for="ispatch">patch</label> <label for="ispatch">patch</label>
[% END %] [% END %]
<input type="checkbox" id="isobsolete" name="isobsolete" value="1" <input type="checkbox" id="isobsolete" name="isobsolete" value="1"
[% 'checked="checked"' IF isobsolete %]> [% 'checked="checked"' IF attachment.isobsolete %]>
<label for="isobsolete">obsolete</label><br> <label for="isobsolete">obsolete</label><br>
[% IF (Param("insidergroup") && UserInGroup(Param("insidergroup"))) %] [% IF (Param("insidergroup") && UserInGroup(Param("insidergroup"))) %]
<input type="checkbox" name="isprivate" value="1"[% " checked" IF isprivate %]> private<br><br> <input type="checkbox" name="isprivate" value="1"
[% " checked" IF attachment.isprivate %]> private<br><br>
[% ELSE %]<br> [% ELSE %]<br>
[% END %] [% END %]
[% IF flag_types.size > 0 %] [% IF flag_types.size > 0 %]
[% PROCESS "flag/list.html.tmpl" bug_id=bugid attach_id=attachid %]<br> [% PROCESS "flag/list.html.tmpl" bug_id = attachment.bug_id
attach_id = attachment.id %]<br>
[% END %] [% END %]
<div id="smallCommentFrame"> <div id="smallCommentFrame">
...@@ -243,19 +255,20 @@ ...@@ -243,19 +255,20 @@
<input type="submit" value="Submit"><br><br> <input type="submit" value="Submit"><br><br>
<strong>Actions:</strong> <strong>Actions:</strong>
<a href="attachment.cgi?id=[% attachid %]">View</a> <a href="attachment.cgi?id=[% attachment.id %]">View</a>
[% IF ispatch && patchviewerinstalled %] [% IF attachment.ispatch && patchviewerinstalled %]
| <a href="attachment.cgi?id=[% attachid %]&action=diff">Diff</a> | <a href="attachment.cgi?id=[% attachment.id %]&action=diff">Diff</a>
[% END %] [% END %]
</small> </small>
</td> </td>
[% IF isviewable %] [% IF isviewable %]
<td width="75%"> <td width="75%">
<textarea id="editFrame" name="comment" style="height: 400px; width: 100%; display: none;" cols="80" wrap="soft"></textarea> <textarea id="editFrame" name="comment" wrap="soft" cols="80"
<iframe id="viewFrame" src="attachment.cgi?id=[% attachid %]" style="height: 400px; width: 100%;"> style="height: 400px; width: 100%; display: none;"></textarea>
<iframe id="viewFrame" src="attachment.cgi?id=[% attachment.id %]" style="height: 400px; width: 100%;">
<b>You cannot view the attachment while editing it because your browser does not support IFRAMEs. <b>You cannot view the attachment while editing it because your browser does not support IFRAMEs.
<a href="attachment.cgi?id=[% attachid %]">View the attachment on a separate page</a>.</b> <a href="attachment.cgi?id=[% attachment.id %]">View the attachment on a separate page</a>.</b>
</iframe> </iframe>
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
...@@ -274,15 +287,15 @@ ...@@ -274,15 +287,15 @@
//--> //-->
</script> </script>
</td> </td>
[% ELSIF isurl %] [% ELSIF attachment.isurl %]
<td width="75%"> <td width="75%">
<a href="[% thedata FILTER html %]"> <a href="[% attachment.data FILTER html %]">
[% IF datasize < 120 %] [% IF attachment.datasize < 120 %]
[% thedata FILTER html %] [% attachment.data FILTER html %]
[% ELSE %] [% ELSE %]
[% thedata FILTER truncate(80) FILTER html %] [% attachment.data FILTER truncate(80) FILTER html %]
&nbsp;... &nbsp;...
[% thedata.match(".*(.{20})$").0 FILTER html %] [% attachment.data.match(".*(.{20})$").0 FILTER html %]
[% END %] [% END %]
</a> </a>
</td> </td>
...@@ -290,11 +303,11 @@ ...@@ -290,11 +303,11 @@
<td id="noview" width="50%"> <td id="noview" width="50%">
<p><b> <p><b>
Attachment is not viewable in your browser because its MIME type Attachment is not viewable in your browser because its MIME type
([% contenttype FILTER html %]) is not one that your browser is ([% attachment.contenttype FILTER html %]) is not one that your browser is
able to display. able to display.
</b></p> </b></p>
<p><b> <p><b>
<a href="attachment.cgi?id=[% attachid %]">Download the attachment</a>. <a href="attachment.cgi?id=[% attachment.id %]">Download the attachment</a>.
</b></p> </b></p>
</td> </td>
[% END %] [% END %]
...@@ -305,10 +318,10 @@ ...@@ -305,10 +318,10 @@
Attachments on this [% terms.Bug %]: Attachments on this [% terms.Bug %]:
[% FOREACH a = attachments %] [% FOREACH a = attachments %]
[% IF a == attachid %] [% IF a == attachment.id %]
#[% a %] [% a %]
[% ELSE %] [% ELSE %]
<a href="attachment.cgi?id=[% a %]&amp;action=edit">#[% a %]</a> <a href="attachment.cgi?id=[% a %]&amp;action=edit">[% a %]</a>
[% END %] [% END %]
[% " |" UNLESS loop.last() %] [% " |" UNLESS loop.last() %]
[% END %] [% END %]
......
...@@ -451,8 +451,8 @@ ...@@ -451,8 +451,8 @@
], ],
'attachment/edit.html.tmpl' => [ 'attachment/edit.html.tmpl' => [
'attachid', 'attachment.id',
'bugid', 'attachment.bug_id',
'a', 'a',
], ],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment