зеркало из https://github.com/mozilla/pjs.git
Bugzilla now has the ability to store patches and other attachments with bugs.
This commit is contained in:
Родитель
a5c27c4761
Коммит
b82b6a5752
|
@ -119,6 +119,54 @@ sub ProcessFormFields {
|
|||
}
|
||||
|
||||
|
||||
sub ProcessMultipartFormFields {
|
||||
my ($boundary) = (@_);
|
||||
$boundary =~ s/^-*//;
|
||||
my $remaining = $ENV{"CONTENT_LENGTH"};
|
||||
my $inheader = 1;
|
||||
my $itemname = "";
|
||||
# open(DEBUG, ">debug") || die "Can't open debugging thing";
|
||||
# print DEBUG "Boundary is '$boundary'\n";
|
||||
while ($remaining > 0 && ($_ = <STDIN>)) {
|
||||
$remaining -= length($_);
|
||||
# print DEBUG "< $_";
|
||||
if ($_ =~ m/^-*$boundary/) {
|
||||
# print DEBUG "Entered header\n";
|
||||
$inheader = 1;
|
||||
$itemname = "";
|
||||
next;
|
||||
}
|
||||
|
||||
if ($inheader) {
|
||||
if (m/^\s*$/) {
|
||||
$inheader = 0;
|
||||
# print DEBUG "left header\n";
|
||||
$::FORM{$itemname} = "";
|
||||
}
|
||||
if (m/^Content-Disposition:\s*form-data\s*;\s*name\s*=\s*"([^\"]+)"/i) {
|
||||
$itemname = $1;
|
||||
# print DEBUG "Found itemname $itemname\n";
|
||||
if (m/;\s*filename\s*=\s*"([^\"]+)"/i) {
|
||||
$::FILENAME{$itemname} = $1;
|
||||
}
|
||||
}
|
||||
|
||||
next;
|
||||
}
|
||||
$::FORM{$itemname} .= $_;
|
||||
}
|
||||
delete $::FORM{""};
|
||||
# Get rid of trailing newlines.
|
||||
foreach my $i (keys %::FORM) {
|
||||
chomp($::FORM{$i});
|
||||
$::FORM{$i} =~ s/\r$//;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sub FormData {
|
||||
my ($field) = (@_);
|
||||
return $::FORM{$field};
|
||||
|
@ -475,10 +523,18 @@ if (defined $ENV{"REQUEST_METHOD"}) {
|
|||
} else {
|
||||
$::buffer = "";
|
||||
}
|
||||
ProcessFormFields $::buffer;
|
||||
} else {
|
||||
read STDIN, $::buffer, $ENV{"CONTENT_LENGTH"} || die "Couldn't get form data";
|
||||
if ($ENV{"CONTENT_TYPE"} =~
|
||||
m@multipart/form-data; boundary=\s*([^; ]+)@) {
|
||||
ProcessMultipartFormFields($1);
|
||||
$::buffer = "";
|
||||
} else {
|
||||
read STDIN, $::buffer, $ENV{"CONTENT_LENGTH"} ||
|
||||
die "Couldn't get form data";
|
||||
ProcessFormFields $::buffer;
|
||||
}
|
||||
}
|
||||
ProcessFormFields $::buffer;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,6 +10,9 @@ query the CVS tree. For example,
|
|||
will tell you what has been changed in the last week.
|
||||
|
||||
|
||||
4/8/99 Added ability to store patches with bugs. This requires a new table
|
||||
to store the data, so you will need to run the "makeattachmenttable.sh" script.
|
||||
|
||||
3/25/99 Unfortunately, the HTML::FromText CPAN module had too many bugs, and
|
||||
so I had to roll my own. We no longer use the HTML::FromText CPAN module.
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ use diagnostics;
|
|||
use strict;
|
||||
|
||||
|
||||
my %knownattachments;
|
||||
|
||||
# This routine quoteUrls contains inspirations from the HTML::FromText CPAN
|
||||
# module by Gareth Rees <garethr@cre.canon.co.uk>. It has been heavily hacked,
|
||||
# all that is really recognizable from the original is bits of the regular
|
||||
|
@ -73,6 +75,14 @@ sub quoteUrls {
|
|||
$item = qq{<A HREF="${base}show_bug.cgi?id=$num">$item</A>};
|
||||
$things[$count++] = $item;
|
||||
}
|
||||
while ($text =~ s/Created an attachment \(id=(\d+)\)/"##$count##"/e) {
|
||||
my $item = $&;
|
||||
my $num = $1;
|
||||
if (exists $knownattachments{$num}) {
|
||||
$item = qq{<A HREF="showattachment.cgi?attach_id=$num">$item</A>};
|
||||
}
|
||||
$things[$count++] = $item;
|
||||
}
|
||||
|
||||
$text = value_quote($text);
|
||||
|
||||
|
@ -277,6 +287,20 @@ if (Param("usestatuswhiteboard")) {
|
|||
</TR>";
|
||||
}
|
||||
|
||||
print "<tr><td align=right><B>Attachments:</b></td>\n";
|
||||
SendSQL("select attach_id, creation_ts, description from attachments where bug_id = $::FORM{'id'}");
|
||||
while (MoreSQLData()) {
|
||||
my ($id, $date, $desc) = (FetchSQLData());
|
||||
if ($date =~ /^(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
|
||||
$date = "$3/$4/$2 $5:$6";
|
||||
}
|
||||
my $link = "showattachment.cgi?attach_id=$id";
|
||||
$desc = value_quote($desc);
|
||||
print qq{<td><a href="$link">$date</a></td><td colspan=4>$desc</td></tr><tr><td></td>};
|
||||
$knownattachments{$id} = 1;
|
||||
}
|
||||
print "<td colspan=6><a href=createattachment.cgi?id=$::FORM{'id'}>Create a new attachment</a> (proposed patch, testcase, etc.)</td></tr>\n";
|
||||
|
||||
|
||||
print "
|
||||
</TABLE>
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
#!/usr/bonsaitools/bin/perl -w
|
||||
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License
|
||||
# Version 1.0 (the "License"); you may not use this file except in
|
||||
# compliance with the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS"
|
||||
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing rights and limitations
|
||||
# under the License.
|
||||
#
|
||||
# The Original Code is the Bugzilla Bug Tracking System.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape Communications
|
||||
# Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
# Netscape Communications Corporation. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s): Terry Weissman <terry@mozilla.org>
|
||||
# David Gardiner <david.gardiner@unisa.edu.au>
|
||||
|
||||
use diagnostics;
|
||||
use strict;
|
||||
|
||||
require "CGI.pl";
|
||||
|
||||
use vars %::COOKIE, %::FILENAME;
|
||||
|
||||
sub Punt {
|
||||
my ($str) = (@_);
|
||||
print "$str<P>Please hit <b>Back</b> and try again.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
confirm_login();
|
||||
|
||||
print "Content-type: text/html\n\n";
|
||||
|
||||
my $id = $::FORM{'id'};
|
||||
|
||||
PutHeader("Create an attachment", "Create attachment", "Bug $id");
|
||||
|
||||
|
||||
if (!defined($::FORM{'data'})) {
|
||||
print qq{
|
||||
<form method=post ENCTYPE="multipart/form-data">
|
||||
<input type=hidden name=id value=$id>
|
||||
To attach a file to <a href="show_bug.cgi?id=$id">bug $id</a>, place it in a
|
||||
file on your local machine, and enter the path to that file here:<br>
|
||||
<input type=file name=data size=60>
|
||||
<P>
|
||||
Please also provide a one-line description of this attachment:<BR>
|
||||
<input name=description size=60>
|
||||
<BR>
|
||||
What kind of file is this?
|
||||
<br><input type=radio name=type value=patch>Patch file (text/plain, diffs)
|
||||
<br><input type=radio name=type value="text/plain">Plain text (text/plain)
|
||||
<br><input type=radio name=type value="text/html">HTML source (text/html)
|
||||
<br><input type=radio name=type value="application/octet-stream">Binary file (application/octet-stream)
|
||||
<br><input type=radio name=type value="other">Other (enter mime type: <input name=othertype size=30>)
|
||||
<P>
|
||||
<input type=submit value="Submit">
|
||||
</form>
|
||||
<P>
|
||||
};
|
||||
} else {
|
||||
if ($::FORM{'data'} eq "" || !defined $::FILENAME{'data'}) {
|
||||
Punt("No file was provided, or it was empty.");
|
||||
}
|
||||
my $desc = trim($::FORM{'description'});
|
||||
if ($desc eq "") {
|
||||
Punt("You must provide a description of your attachment.");
|
||||
}
|
||||
my $ispatch = 0;
|
||||
my $mimetype = $::FORM{'type'};
|
||||
if (!defined $mimetype) {
|
||||
Punt("You must select which kind of file you have.");
|
||||
}
|
||||
$mimetype = trim($mimetype);
|
||||
if ($mimetype eq "patch") {
|
||||
$mimetype = "text/plain";
|
||||
$ispatch = 1;
|
||||
}
|
||||
if ($mimetype eq "other") {
|
||||
$mimetype = $::FORM{'othertype'};
|
||||
}
|
||||
if ($mimetype !~ m@^(\w|-)+/(\w|-)+$@) {
|
||||
Punt("You must select a legal mime type. '<tt>$mimetype</tt>' simply will not do.");
|
||||
}
|
||||
SendSQL("insert into attachments (bug_id, filename, description, mimetype, ispatch, thedata) values ($id," .
|
||||
SqlQuote($::FILENAME{'data'}) . ", " . SqlQuote($desc) . ", " .
|
||||
SqlQuote($mimetype) . ", $ispatch, " .
|
||||
SqlQuote($::FORM{'data'}) . ")");
|
||||
SendSQL("select LAST_INSERT_ID()");
|
||||
my $attachid = FetchOneColumn();
|
||||
AppendComment($id, $::COOKIE{"Bugzilla_login"},
|
||||
"Created an attachment (id=$attachid)\n$desc\n");
|
||||
print "Your attachment has been created.";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
print qq{
|
||||
<P>
|
||||
<a href="show_bug.cgi?id=$id">Go back to bug $id</a><br>
|
||||
<a href="query.cgi">Go back to the query page</a><br>
|
||||
};
|
|
@ -0,0 +1,45 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License
|
||||
# Version 1.0 (the "License"); you may not use this file except in
|
||||
# compliance with the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS"
|
||||
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing rights and limitations
|
||||
# under the License.
|
||||
#
|
||||
# The Original Code is the Bugzilla Bug Tracking System.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape Communications
|
||||
# Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
# Netscape Communications Corporation. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s): Terry Weissman <terry@mozilla.org>
|
||||
|
||||
mysql > /dev/null 2>/dev/null << OK_ALL_DONE
|
||||
|
||||
use bugs;
|
||||
|
||||
drop table attachments;
|
||||
OK_ALL_DONE
|
||||
|
||||
mysql << OK_ALL_DONE
|
||||
use bugs;
|
||||
|
||||
create table attachments (
|
||||
attach_id mediumint not null auto_increment primary key,
|
||||
bug_id mediumint not null,
|
||||
creation_ts timestamp,
|
||||
description mediumtext not null,
|
||||
mimetype mediumtext not null,
|
||||
ispatch tinyint,
|
||||
filename mediumtext not null,
|
||||
thedata longblob not null,
|
||||
|
||||
index(bug_id),
|
||||
index(creation_ts)
|
||||
);
|
||||
|
||||
OK_ALL_DONE
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bonsaitools/bin/perl -w
|
||||
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License
|
||||
# Version 1.0 (the "License"); you may not use this file except in
|
||||
# compliance with the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS"
|
||||
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing rights and limitations
|
||||
# under the License.
|
||||
#
|
||||
# The Original Code is the Bugzilla Bug Tracking System.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape Communications
|
||||
# Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
# Netscape Communications Corporation. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s): Terry Weissman <terry@mozilla.org>
|
||||
# David Gardiner <david.gardiner@unisa.edu.au>
|
||||
|
||||
use diagnostics;
|
||||
use strict;
|
||||
|
||||
require "CGI.pl";
|
||||
|
||||
ConnectToDatabase();
|
||||
|
||||
my @row;
|
||||
if (defined $::FORM{'attach_id'}) {
|
||||
SendSQL("select mimetype, filename, thedata from attachments where attach_id = $::FORM{'attach_id'}");
|
||||
@row = FetchSQLData();
|
||||
}
|
||||
if (!@row) {
|
||||
print "Content-type: text/html\n\n";
|
||||
PutHeader("Bad ID");
|
||||
print "Please hit back and try again.\n";
|
||||
exit;
|
||||
}
|
||||
print qq{Content-type: $row[0]; name="$row[1]"; \n\n$row[2]};
|
||||
|
||||
|
Загрузка…
Ссылка в новой задаче