1998-09-16 01:49:26 +04:00
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
1999-11-02 02:33:56 +03:00
|
|
|
# The contents of this file are subject to the Mozilla Public
|
|
|
|
# License Version 1.1 (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.
|
|
|
|
#
|
1998-09-16 01:49:26 +04:00
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
1999-11-02 02:33:56 +03:00
|
|
|
#
|
1998-09-16 01:49:26 +04:00
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
1999-11-02 02:33:56 +03:00
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
1998-09-16 01:49:26 +04:00
|
|
|
# Contributor(s): Terry Weissman <terry@mozilla.org>
|
2000-03-29 01:31:24 +04:00
|
|
|
# Dan Mosedale <dmose@mozilla.org>
|
2002-08-27 08:28:05 +04:00
|
|
|
# Jacob Steenhagen <jake@bugzilla.org>
|
2002-11-19 10:19:34 +03:00
|
|
|
# Bradley Baetz <bbaetz@student.usyd.edu.au>
|
2001-11-17 13:29:55 +03:00
|
|
|
# Christopher Aillon <christopher@aillon.com>
|
2005-02-25 01:43:28 +03:00
|
|
|
# Joel Peshkin <bugreport@peshkin.net>
|
|
|
|
# Dave Lawrence <dkl@redhat.com>
|
2005-06-15 07:55:00 +04:00
|
|
|
# Max Kanat-Alexander <mkanat@bugzilla.org>
|
1998-09-16 01:49:26 +04:00
|
|
|
|
|
|
|
# Contains some global variables and routines used throughout bugzilla.
|
|
|
|
|
|
|
|
use strict;
|
1999-10-19 03:57:58 +04:00
|
|
|
|
2003-01-14 23:00:11 +03:00
|
|
|
use Bugzilla::DB qw(:DEFAULT :deprecated);
|
2002-11-24 22:56:34 +03:00
|
|
|
use Bugzilla::Constants;
|
2002-08-19 17:59:45 +04:00
|
|
|
use Bugzilla::Util;
|
2002-08-29 13:25:54 +04:00
|
|
|
# Bring ChmodDataFile in until this is all moved to the module
|
2003-11-22 06:50:42 +03:00
|
|
|
use Bugzilla::Config qw(:DEFAULT ChmodDataFile $localconfig $datadir);
|
2005-01-01 16:44:16 +03:00
|
|
|
use Bugzilla::BugMail;
|
2005-02-25 02:42:48 +03:00
|
|
|
use Bugzilla::User;
|
2002-08-19 17:59:45 +04:00
|
|
|
|
1999-10-19 03:57:58 +04:00
|
|
|
# Shut up misguided -w warnings about "used only once". For some reason,
|
|
|
|
# "use vars" chokes on me when I try it here.
|
|
|
|
|
|
|
|
sub globals_pl_sillyness {
|
|
|
|
my $zz;
|
|
|
|
$zz = @main::default_column_list;
|
2002-02-14 04:25:25 +03:00
|
|
|
$zz = @main::enterable_products;
|
2000-01-15 01:35:49 +03:00
|
|
|
$zz = %main::keywordsbyname;
|
1999-10-19 03:57:58 +04:00
|
|
|
$zz = @main::legal_bug_status;
|
|
|
|
$zz = @main::legal_components;
|
2000-01-15 01:35:49 +03:00
|
|
|
$zz = @main::legal_keywords;
|
1999-10-19 03:57:58 +04:00
|
|
|
$zz = @main::legal_opsys;
|
|
|
|
$zz = @main::legal_platform;
|
|
|
|
$zz = @main::legal_priority;
|
|
|
|
$zz = @main::legal_product;
|
|
|
|
$zz = @main::legal_severity;
|
|
|
|
$zz = @main::legal_target_milestone;
|
|
|
|
$zz = @main::legal_versions;
|
|
|
|
$zz = @main::milestoneurl;
|
2002-02-14 04:25:25 +03:00
|
|
|
$zz = %main::proddesc;
|
2004-08-21 01:49:20 +04:00
|
|
|
$zz = %main::classdesc;
|
1999-10-19 03:57:58 +04:00
|
|
|
$zz = @main::prodmaxvotes;
|
2002-02-03 12:28:48 +03:00
|
|
|
$zz = $main::template;
|
2002-03-12 16:55:07 +03:00
|
|
|
$zz = $main::userid;
|
2002-02-03 12:28:48 +03:00
|
|
|
$zz = $main::vars;
|
1999-10-19 03:57:58 +04:00
|
|
|
}
|
|
|
|
|
2000-01-29 23:22:44 +03:00
|
|
|
#
|
|
|
|
# Here are the --LOCAL-- variables defined in 'localconfig' that we'll use
|
|
|
|
# here
|
|
|
|
#
|
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
# XXX - Move this to Bugzilla::Config once code which uses these has moved out
|
|
|
|
# of globals.pl
|
2003-11-22 06:50:42 +03:00
|
|
|
do $localconfig;
|
2000-01-29 23:22:44 +03:00
|
|
|
|
2000-05-20 05:22:07 +04:00
|
|
|
use DBI;
|
1998-09-16 01:49:26 +04:00
|
|
|
|
|
|
|
use Date::Format; # For time2str().
|
2000-01-21 00:31:22 +03:00
|
|
|
use Date::Parse; # For str2time().
|
1998-09-16 01:49:26 +04:00
|
|
|
|
2002-03-12 16:55:07 +03:00
|
|
|
# Use standard Perl libraries for cross-platform file/directory manipulation.
|
|
|
|
use File::Spec;
|
|
|
|
|
2001-10-23 19:44:53 +04:00
|
|
|
# Some environment variables are not taint safe
|
2002-11-22 03:36:13 +03:00
|
|
|
delete @::ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
|
2001-07-04 08:41:27 +04:00
|
|
|
|
2002-03-23 06:51:05 +03:00
|
|
|
# Cwd.pm in perl 5.6.1 gives a warning if $::ENV{'PATH'} isn't defined
|
|
|
|
# Set this to '' so that we don't get warnings cluttering the logs on every
|
|
|
|
# system call
|
|
|
|
$::ENV{'PATH'} = '';
|
|
|
|
|
2002-03-28 10:57:05 +03:00
|
|
|
# Ignore SIGTERM and SIGPIPE - this prevents DB corruption. If the user closes
|
|
|
|
# their browser window while a script is running, the webserver sends these
|
|
|
|
# signals, and we don't want to die half way through a write.
|
|
|
|
$::SIG{TERM} = 'IGNORE';
|
|
|
|
$::SIG{PIPE} = 'IGNORE';
|
|
|
|
|
2003-08-06 05:46:14 +04:00
|
|
|
# The following subroutine is for debugging purposes only.
|
|
|
|
# Uncommenting this sub and the $::SIG{__DIE__} trap underneath it will
|
|
|
|
# cause any fatal errors to result in a call stack trace to help track
|
|
|
|
# down weird errors.
|
|
|
|
#sub die_with_dignity {
|
|
|
|
# use Carp; # for confess()
|
|
|
|
# my ($err_msg) = @_;
|
|
|
|
# print $err_msg;
|
|
|
|
# confess($err_msg);
|
|
|
|
#}
|
|
|
|
#$::SIG{__DIE__} = \&die_with_dignity;
|
2001-07-04 08:41:27 +04:00
|
|
|
|
2000-01-22 07:24:42 +03:00
|
|
|
sub GetFieldID {
|
|
|
|
my ($f) = (@_);
|
|
|
|
SendSQL("SELECT fieldid FROM fielddefs WHERE name = " . SqlQuote($f));
|
|
|
|
my $fieldid = FetchOneColumn();
|
2002-08-10 11:34:17 +04:00
|
|
|
die "Unknown field id: $f" if !$fieldid;
|
2000-01-22 07:24:42 +03:00
|
|
|
return $fieldid;
|
|
|
|
}
|
1998-09-16 01:49:26 +04:00
|
|
|
|
2002-08-29 13:25:54 +04:00
|
|
|
# XXXX - this needs to go away
|
1998-09-16 01:49:26 +04:00
|
|
|
sub GenerateVersionTable {
|
2005-03-10 11:07:34 +03:00
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
2002-08-12 09:43:05 +04:00
|
|
|
SendSQL("SELECT versions.value, products.name " .
|
|
|
|
"FROM versions, products " .
|
|
|
|
"WHERE products.id = versions.product_id " .
|
|
|
|
"ORDER BY versions.value");
|
1998-09-16 01:49:26 +04:00
|
|
|
my @line;
|
|
|
|
my %varray;
|
|
|
|
my %carray;
|
|
|
|
while (@line = FetchSQLData()) {
|
|
|
|
my ($v,$p1) = (@line);
|
|
|
|
if (!defined $::versions{$p1}) {
|
|
|
|
$::versions{$p1} = [];
|
|
|
|
}
|
|
|
|
push @{$::versions{$p1}}, $v;
|
|
|
|
$varray{$v} = 1;
|
|
|
|
}
|
2002-08-12 09:43:05 +04:00
|
|
|
SendSQL("SELECT components.name, products.name " .
|
|
|
|
"FROM components, products " .
|
|
|
|
"WHERE products.id = components.product_id " .
|
|
|
|
"ORDER BY components.name");
|
1998-09-16 01:49:26 +04:00
|
|
|
while (@line = FetchSQLData()) {
|
|
|
|
my ($c,$p) = (@line);
|
|
|
|
if (!defined $::components{$p}) {
|
|
|
|
$::components{$p} = [];
|
|
|
|
}
|
|
|
|
my $ref = $::components{$p};
|
|
|
|
push @$ref, $c;
|
|
|
|
$carray{$c} = 1;
|
|
|
|
}
|
|
|
|
|
2004-08-21 01:49:20 +04:00
|
|
|
SendSQL("SELECT products.name, classifications.name " .
|
|
|
|
"FROM products, classifications " .
|
|
|
|
"WHERE classifications.id = products.classification_id " .
|
|
|
|
"ORDER BY classifications.name");
|
|
|
|
while (@line = FetchSQLData()) {
|
|
|
|
my ($p,$c) = (@line);
|
|
|
|
if (!defined $::classifications{$c}) {
|
|
|
|
$::classifications{$c} = [];
|
|
|
|
}
|
|
|
|
my $ref = $::classifications{$c};
|
|
|
|
push @$ref, $p;
|
|
|
|
}
|
|
|
|
|
2000-03-24 03:43:40 +03:00
|
|
|
my $dotargetmilestone = 1; # This used to check the param, but there's
|
|
|
|
# enough code that wants to pretend we're using
|
|
|
|
# target milestones, even if they don't get
|
|
|
|
# shown to the user. So we cache all the data
|
|
|
|
# about them anyway.
|
1999-02-03 05:46:51 +03:00
|
|
|
|
|
|
|
my $mpart = $dotargetmilestone ? ", milestoneurl" : "";
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2005-05-02 22:52:02 +04:00
|
|
|
SendSQL("SELECT name, description FROM classifications ORDER BY name");
|
2004-08-21 01:49:20 +04:00
|
|
|
while (@line = FetchSQLData()) {
|
|
|
|
my ($n, $d) = (@line);
|
|
|
|
$::classdesc{$n} = $d;
|
|
|
|
}
|
|
|
|
|
2005-05-02 22:52:02 +04:00
|
|
|
SendSQL("SELECT name, description, votesperuser, disallownew$mpart " .
|
|
|
|
"FROM products ORDER BY name");
|
1998-10-07 00:23:40 +04:00
|
|
|
while (@line = FetchSQLData()) {
|
1999-10-08 03:54:52 +04:00
|
|
|
my ($p, $d, $votesperuser, $dis, $u) = (@line);
|
1998-10-07 00:23:40 +04:00
|
|
|
$::proddesc{$p} = $d;
|
2003-11-07 00:55:25 +03:00
|
|
|
if (!$dis && scalar($::components{$p})) {
|
2002-02-14 04:25:25 +03:00
|
|
|
push @::enterable_products, $p;
|
1999-03-03 21:16:24 +03:00
|
|
|
}
|
1999-02-03 05:46:51 +03:00
|
|
|
if ($dotargetmilestone) {
|
|
|
|
$::milestoneurl{$p} = $u;
|
|
|
|
}
|
1999-10-08 03:54:52 +04:00
|
|
|
$::prodmaxvotes{$p} = $votesperuser;
|
1998-10-07 00:23:40 +04:00
|
|
|
}
|
|
|
|
|
2005-03-10 11:07:34 +03:00
|
|
|
@::log_columns = $dbh->bz_table_columns('bugs');
|
1998-09-16 01:49:26 +04:00
|
|
|
|
2000-01-22 07:24:42 +03:00
|
|
|
foreach my $i ("bug_id", "creation_ts", "delta_ts", "lastdiffed") {
|
1998-09-16 01:49:26 +04:00
|
|
|
my $w = lsearch(\@::log_columns, $i);
|
|
|
|
if ($w >= 0) {
|
|
|
|
splice(@::log_columns, $w, 1);
|
|
|
|
}
|
|
|
|
}
|
1999-03-24 01:32:21 +03:00
|
|
|
@::log_columns = (sort(@::log_columns));
|
1998-09-16 01:49:26 +04:00
|
|
|
|
2005-02-25 01:43:28 +03:00
|
|
|
@::legal_priority = get_legal_field_values("priority");
|
|
|
|
@::legal_severity = get_legal_field_values("bug_severity");
|
|
|
|
@::legal_platform = get_legal_field_values("rep_platform");
|
|
|
|
@::legal_opsys = get_legal_field_values("op_sys");
|
|
|
|
@::legal_bug_status = get_legal_field_values("bug_status");
|
|
|
|
@::legal_resolution = get_legal_field_values("resolution");
|
2000-07-14 07:20:17 +04:00
|
|
|
|
|
|
|
# 'settable_resolution' is the list of resolutions that may be set
|
|
|
|
# directly by hand in the bug form. Start with the list of legal
|
|
|
|
# resolutions and remove 'MOVED' and 'DUPLICATE' because setting
|
|
|
|
# bugs to those resolutions requires a special process.
|
|
|
|
#
|
|
|
|
@::settable_resolution = @::legal_resolution;
|
|
|
|
my $w = lsearch(\@::settable_resolution, "DUPLICATE");
|
1998-09-16 01:49:26 +04:00
|
|
|
if ($w >= 0) {
|
2000-07-14 07:20:17 +04:00
|
|
|
splice(@::settable_resolution, $w, 1);
|
|
|
|
}
|
|
|
|
my $z = lsearch(\@::settable_resolution, "MOVED");
|
|
|
|
if ($z >= 0) {
|
|
|
|
splice(@::settable_resolution, $z, 1);
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
my @list = sort { uc($a) cmp uc($b)} keys(%::versions);
|
|
|
|
@::legal_product = @list;
|
|
|
|
|
2003-04-25 01:17:31 +04:00
|
|
|
require File::Temp;
|
|
|
|
my ($fh, $tmpname) = File::Temp::tempfile("versioncache.XXXXX",
|
2003-11-22 06:50:42 +03:00
|
|
|
DIR => "$datadir");
|
2003-04-25 01:17:31 +04:00
|
|
|
|
|
|
|
print $fh "#\n";
|
|
|
|
print $fh "# DO NOT EDIT!\n";
|
|
|
|
print $fh "# This file is automatically generated at least once every\n";
|
|
|
|
print $fh "# hour by the GenerateVersionTable() sub in globals.pl.\n";
|
|
|
|
print $fh "# Any changes you make will be overwritten.\n";
|
|
|
|
print $fh "#\n";
|
2001-10-20 03:49:37 +04:00
|
|
|
|
2002-10-16 14:49:56 +04:00
|
|
|
require Data::Dumper;
|
2003-04-25 04:47:17 +04:00
|
|
|
print $fh (Data::Dumper->Dump([\@::log_columns, \%::versions],
|
|
|
|
['*::log_columns', '*::versions']));
|
1998-09-16 01:49:26 +04:00
|
|
|
|
|
|
|
foreach my $i (@list) {
|
|
|
|
if (!defined $::components{$i}) {
|
2001-07-01 06:00:56 +04:00
|
|
|
$::components{$i} = [];
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
@::legal_versions = sort {uc($a) cmp uc($b)} keys(%varray);
|
2003-04-25 04:47:17 +04:00
|
|
|
print $fh (Data::Dumper->Dump([\@::legal_versions, \%::components],
|
|
|
|
['*::legal_versions', '*::components']));
|
1998-09-16 01:49:26 +04:00
|
|
|
@::legal_components = sort {uc($a) cmp uc($b)} keys(%carray);
|
2002-08-29 13:25:54 +04:00
|
|
|
|
2003-04-25 04:47:17 +04:00
|
|
|
print $fh (Data::Dumper->Dump([\@::legal_components, \@::legal_product,
|
|
|
|
\@::legal_priority, \@::legal_severity,
|
|
|
|
\@::legal_platform, \@::legal_opsys,
|
|
|
|
\@::legal_bug_status, \@::legal_resolution],
|
|
|
|
['*::legal_components', '*::legal_product',
|
|
|
|
'*::legal_priority', '*::legal_severity',
|
|
|
|
'*::legal_platform', '*::legal_opsys',
|
|
|
|
'*::legal_bug_status', '*::legal_resolution']));
|
2002-08-29 13:25:54 +04:00
|
|
|
|
2003-04-25 04:47:17 +04:00
|
|
|
print $fh (Data::Dumper->Dump([\@::settable_resolution, \%::proddesc,
|
2004-08-21 01:49:20 +04:00
|
|
|
\%::classifications, \%::classdesc,
|
2003-04-25 04:47:17 +04:00
|
|
|
\@::enterable_products, \%::prodmaxvotes],
|
|
|
|
['*::settable_resolution', '*::proddesc',
|
2004-08-21 01:49:20 +04:00
|
|
|
'*::classifications', '*::classdesc',
|
2003-04-25 04:47:17 +04:00
|
|
|
'*::enterable_products', '*::prodmaxvotes']));
|
1998-09-16 01:49:26 +04:00
|
|
|
|
1999-02-03 05:46:51 +03:00
|
|
|
if ($dotargetmilestone) {
|
2000-03-21 19:47:06 +03:00
|
|
|
# reading target milestones in from the database - matthew@zeroknowledge.com
|
2002-08-12 09:43:05 +04:00
|
|
|
SendSQL("SELECT milestones.value, products.name " .
|
|
|
|
"FROM milestones, products " .
|
|
|
|
"WHERE products.id = milestones.product_id " .
|
|
|
|
"ORDER BY milestones.sortkey, milestones.value");
|
2000-03-21 19:47:06 +03:00
|
|
|
my @line;
|
|
|
|
my %tmarray;
|
|
|
|
@::legal_target_milestone = ();
|
|
|
|
while(@line = FetchSQLData()) {
|
|
|
|
my ($tm, $pr) = (@line);
|
|
|
|
if (!defined $::target_milestone{$pr}) {
|
|
|
|
$::target_milestone{$pr} = [];
|
|
|
|
}
|
|
|
|
push @{$::target_milestone{$pr}}, $tm;
|
|
|
|
if (!exists $tmarray{$tm}) {
|
|
|
|
$tmarray{$tm} = 1;
|
|
|
|
push(@::legal_target_milestone, $tm);
|
|
|
|
}
|
1999-01-28 00:17:10 +03:00
|
|
|
}
|
2000-03-21 19:47:06 +03:00
|
|
|
|
2003-04-25 04:47:17 +04:00
|
|
|
print $fh (Data::Dumper->Dump([\%::target_milestone,
|
|
|
|
\@::legal_target_milestone,
|
|
|
|
\%::milestoneurl],
|
|
|
|
['*::target_milestone',
|
|
|
|
'*::legal_target_milestone',
|
|
|
|
'*::milestoneurl']));
|
1999-01-28 00:17:10 +03:00
|
|
|
}
|
2000-01-07 00:16:15 +03:00
|
|
|
|
|
|
|
SendSQL("SELECT id, name FROM keyworddefs ORDER BY name");
|
|
|
|
while (MoreSQLData()) {
|
|
|
|
my ($id, $name) = FetchSQLData();
|
2000-07-14 19:31:43 +04:00
|
|
|
push(@::legal_keywords, $name);
|
2000-07-14 00:04:15 +04:00
|
|
|
$name = lc($name);
|
2000-01-07 00:16:15 +03:00
|
|
|
$::keywordsbyname{$name} = $id;
|
|
|
|
}
|
2002-08-29 13:25:54 +04:00
|
|
|
|
2003-04-25 04:47:17 +04:00
|
|
|
print $fh (Data::Dumper->Dump([\@::legal_keywords, \%::keywordsbyname],
|
|
|
|
['*::legal_keywords', '*::keywordsbyname']));
|
2000-01-07 00:16:15 +03:00
|
|
|
|
2003-04-25 01:17:31 +04:00
|
|
|
print $fh "1;\n";
|
|
|
|
close $fh;
|
2002-08-29 13:25:54 +04:00
|
|
|
|
2005-07-13 02:35:04 +04:00
|
|
|
rename ($tmpname, "$datadir/versioncache")
|
|
|
|
|| die "Can't rename $tmpname to versioncache";
|
2003-11-22 06:50:42 +03:00
|
|
|
ChmodDataFile("$datadir/versioncache", 0666);
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-14 00:04:15 +04:00
|
|
|
sub GetKeywordIdFromName {
|
|
|
|
my ($name) = (@_);
|
|
|
|
$name = lc($name);
|
|
|
|
return $::keywordsbyname{$name};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-08 01:26:49 +04:00
|
|
|
$::VersionTableLoaded = 0;
|
1998-09-16 01:49:26 +04:00
|
|
|
sub GetVersionTable {
|
2001-06-08 01:26:49 +04:00
|
|
|
return if $::VersionTableLoaded;
|
2005-01-27 23:08:34 +03:00
|
|
|
my $mtime = file_mod_time("$datadir/versioncache");
|
2003-11-22 06:50:42 +03:00
|
|
|
if (!defined $mtime || $mtime eq "" || !-r "$datadir/versioncache") {
|
1998-09-16 01:49:26 +04:00
|
|
|
$mtime = 0;
|
|
|
|
}
|
|
|
|
if (time() - $mtime > 3600) {
|
2004-03-18 06:57:05 +03:00
|
|
|
use Bugzilla::Token;
|
|
|
|
Bugzilla::Token::CleanTokenTable() if Bugzilla->dbwritesallowed;
|
1998-09-16 01:49:26 +04:00
|
|
|
GenerateVersionTable();
|
|
|
|
}
|
2003-11-22 06:50:42 +03:00
|
|
|
require "$datadir/versioncache";
|
1998-09-16 01:49:26 +04:00
|
|
|
if (!defined %::versions) {
|
|
|
|
GenerateVersionTable();
|
2003-11-22 06:50:42 +03:00
|
|
|
do "$datadir/versioncache";
|
1998-09-16 01:49:26 +04:00
|
|
|
|
|
|
|
if (!defined %::versions) {
|
2003-11-22 06:50:42 +03:00
|
|
|
die "Can't generate file $datadir/versioncache";
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
}
|
2001-06-08 01:26:49 +04:00
|
|
|
$::VersionTableLoaded = 1;
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
2001-07-11 09:29:21 +04:00
|
|
|
sub GenerateRandomPassword {
|
2004-04-23 01:15:28 +04:00
|
|
|
my $size = (shift or 10); # default to 10 chars if nothing specified
|
|
|
|
return join("", map{ ('0'..'9','a'..'z','A'..'Z')[rand 62] } (1..$size));
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
2002-11-24 22:56:34 +03:00
|
|
|
#
|
|
|
|
# This function checks if there are any entry groups defined.
|
|
|
|
# If called with no arguments, it identifies
|
|
|
|
# entry groups for all products. If called with a product
|
|
|
|
# id argument, it checks for entry groups associated with
|
|
|
|
# one particular product.
|
|
|
|
sub AnyEntryGroups {
|
|
|
|
my $product_id = shift;
|
|
|
|
$product_id = 0 unless ($product_id);
|
|
|
|
return $::CachedAnyEntryGroups{$product_id}
|
|
|
|
if defined($::CachedAnyEntryGroups{$product_id});
|
2005-02-18 19:14:27 +03:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2002-11-24 22:56:34 +03:00
|
|
|
PushGlobalSQLState();
|
|
|
|
my $query = "SELECT 1 FROM group_control_map WHERE entry != 0";
|
|
|
|
$query .= " AND product_id = $product_id" if ($product_id);
|
2005-02-18 19:14:27 +03:00
|
|
|
$query .= " " . $dbh->sql_limit(1);
|
2002-11-24 22:56:34 +03:00
|
|
|
SendSQL($query);
|
2003-01-23 10:43:06 +03:00
|
|
|
if (MoreSQLData()) {
|
|
|
|
$::CachedAnyEntryGroups{$product_id} = MoreSQLData();
|
|
|
|
FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $::CachedAnyEntryGroups{$product_id};
|
|
|
|
} else {
|
|
|
|
return undef;
|
|
|
|
}
|
2002-11-24 22:56:34 +03:00
|
|
|
}
|
|
|
|
#
|
|
|
|
# This function checks if there are any default groups defined.
|
|
|
|
# If so, then groups may have to be changed when bugs move from
|
|
|
|
# one bug to another.
|
|
|
|
sub AnyDefaultGroups {
|
|
|
|
return $::CachedAnyDefaultGroups if defined($::CachedAnyDefaultGroups);
|
2005-02-18 19:14:27 +03:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2002-11-24 22:56:34 +03:00
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT 1 FROM group_control_map, groups WHERE " .
|
|
|
|
"groups.id = group_control_map.group_id " .
|
|
|
|
"AND isactive != 0 AND " .
|
|
|
|
"(membercontrol = " . CONTROLMAPDEFAULT .
|
|
|
|
" OR othercontrol = " . CONTROLMAPDEFAULT .
|
2005-02-18 19:14:27 +03:00
|
|
|
") " . $dbh->sql_limit(1));
|
2002-11-24 22:56:34 +03:00
|
|
|
$::CachedAnyDefaultGroups = MoreSQLData();
|
|
|
|
FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $::CachedAnyDefaultGroups;
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# This function checks if, given a product id, the user can edit
|
|
|
|
# bugs in this product at all.
|
|
|
|
sub CanEditProductId {
|
|
|
|
my ($productid) = @_;
|
2005-02-18 19:14:27 +03:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2002-11-24 22:56:34 +03:00
|
|
|
my $query = "SELECT group_id FROM group_control_map " .
|
|
|
|
"WHERE product_id = $productid " .
|
|
|
|
"AND canedit != 0 ";
|
2004-07-31 06:27:26 +04:00
|
|
|
if (%{Bugzilla->user->groups}) {
|
2002-11-24 22:56:34 +03:00
|
|
|
$query .= "AND group_id NOT IN(" .
|
2003-06-03 13:48:15 +04:00
|
|
|
join(',', values(%{Bugzilla->user->groups})) . ") ";
|
2002-11-24 22:56:34 +03:00
|
|
|
}
|
2005-02-18 19:14:27 +03:00
|
|
|
$query .= $dbh->sql_limit(1);
|
2002-11-24 22:56:34 +03:00
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL($query);
|
|
|
|
my ($result) = FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return (!defined($result));
|
|
|
|
}
|
|
|
|
|
2004-08-21 01:49:20 +04:00
|
|
|
sub IsInClassification {
|
|
|
|
my ($classification,$productname) = @_;
|
|
|
|
|
|
|
|
if (! Param('useclassification')) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
my $query = "SELECT classifications.name " .
|
|
|
|
"FROM products,classifications " .
|
|
|
|
"WHERE products.classification_id=classifications.id ";
|
|
|
|
$query .= "AND products.name = " . SqlQuote($productname);
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL($query);
|
|
|
|
my ($ret) = FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return ($ret eq $classification);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-12 06:07:10 +04:00
|
|
|
# This function determines whether or not a user can enter
|
|
|
|
# bugs into the named product.
|
2002-11-24 22:56:34 +03:00
|
|
|
sub CanEnterProduct {
|
2005-05-12 06:07:10 +04:00
|
|
|
my ($productname, $verbose) = @_;
|
2005-02-18 19:14:27 +03:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2005-05-12 06:07:10 +04:00
|
|
|
|
|
|
|
return unless defined($productname);
|
|
|
|
trick_taint($productname);
|
|
|
|
|
|
|
|
# First check whether or not the user has access to that product.
|
2002-11-24 22:56:34 +03:00
|
|
|
my $query = "SELECT group_id IS NULL " .
|
|
|
|
"FROM products " .
|
|
|
|
"LEFT JOIN group_control_map " .
|
|
|
|
"ON group_control_map.product_id = products.id " .
|
|
|
|
"AND group_control_map.entry != 0 ";
|
2004-07-31 06:27:26 +04:00
|
|
|
if (%{Bugzilla->user->groups}) {
|
2002-11-24 22:56:34 +03:00
|
|
|
$query .= "AND group_id NOT IN(" .
|
2003-06-03 13:48:15 +04:00
|
|
|
join(',', values(%{Bugzilla->user->groups})) . ") ";
|
2002-11-24 22:56:34 +03:00
|
|
|
}
|
2005-05-12 06:07:10 +04:00
|
|
|
$query .= "WHERE products.name = ? " .
|
2005-02-18 19:14:27 +03:00
|
|
|
$dbh->sql_limit(1);
|
2005-05-12 06:07:10 +04:00
|
|
|
|
|
|
|
my $has_access = $dbh->selectrow_array($query, undef, $productname);
|
|
|
|
if (!$has_access) {
|
|
|
|
# Do we require the exact reason why we cannot enter
|
|
|
|
# bugs into that product? Returning -1 explicitely
|
|
|
|
# means the user has no access to the product or the
|
|
|
|
# product does not exist.
|
|
|
|
return (defined($verbose)) ? -1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check if the product is open for new bugs and has
|
2005-07-07 18:08:43 +04:00
|
|
|
# at least one component and has at least one version.
|
|
|
|
my ($allow_new_bugs, $has_version) =
|
|
|
|
$dbh->selectrow_array('SELECT CASE WHEN disallownew = 0 THEN 1 ELSE 0 END, ' .
|
|
|
|
'versions.value IS NOT NULL ' .
|
|
|
|
'FROM products INNER JOIN components ' .
|
|
|
|
'ON components.product_id = products.id ' .
|
|
|
|
'LEFT JOIN versions ' .
|
|
|
|
'ON versions.product_id = products.id ' .
|
|
|
|
'WHERE products.name = ? ' .
|
|
|
|
$dbh->sql_limit(1), undef, $productname);
|
|
|
|
|
|
|
|
|
|
|
|
if (defined $verbose) {
|
|
|
|
# Return (undef, undef) if the product has no components,
|
|
|
|
# Return (?, 0) if the product has no versions,
|
|
|
|
# Return (0, ?) if the product is closed for new bug entry,
|
|
|
|
# Return (1, 1) if the user can enter bugs into the product,
|
|
|
|
return ($allow_new_bugs, $has_version);
|
|
|
|
} else {
|
|
|
|
# Return undef if the product has no components
|
|
|
|
# Return 0 if the product has no versions, or is closed for bug entry
|
|
|
|
# Return 1 if the user can enter bugs into the product
|
|
|
|
return ($allow_new_bugs && $has_version);
|
|
|
|
}
|
2005-05-12 06:07:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Call CanEnterProduct() and display an error message
|
|
|
|
# if the user cannot enter bugs into that product.
|
|
|
|
sub CanEnterProductOrWarn {
|
|
|
|
my ($product) = @_;
|
|
|
|
|
|
|
|
if (!defined($product)) {
|
|
|
|
ThrowUserError("no_products");
|
|
|
|
}
|
2005-07-07 18:08:43 +04:00
|
|
|
my ($allow_new_bugs, $has_version) = CanEnterProduct($product, 1);
|
2005-05-12 06:07:10 +04:00
|
|
|
trick_taint($product);
|
|
|
|
|
2005-07-07 18:08:43 +04:00
|
|
|
if (!defined $allow_new_bugs) {
|
|
|
|
ThrowUserError("missing_version_or_component",
|
|
|
|
{ product => $product,
|
|
|
|
missing_item => 'Component' })
|
|
|
|
} elsif (!$allow_new_bugs) {
|
2005-05-12 06:07:10 +04:00
|
|
|
ThrowUserError("product_disabled", { product => $product});
|
2005-07-07 18:08:43 +04:00
|
|
|
} elsif ($allow_new_bugs < 0) {
|
2005-05-12 06:07:10 +04:00
|
|
|
ThrowUserError("entry_access_denied", { product => $product});
|
2005-07-07 18:08:43 +04:00
|
|
|
} elsif (!$has_version) {
|
|
|
|
ThrowUserError("missing_version_or_component",
|
|
|
|
{ product => $product,
|
|
|
|
missing_item => 'Version' });
|
2005-05-12 06:07:10 +04:00
|
|
|
}
|
2005-07-07 18:08:43 +04:00
|
|
|
return 1;
|
2002-11-24 22:56:34 +03:00
|
|
|
}
|
|
|
|
|
2004-07-10 11:44:12 +04:00
|
|
|
sub GetEnterableProducts {
|
|
|
|
my @products;
|
|
|
|
# XXX rewrite into pure SQL instead of relying on legal_products?
|
|
|
|
foreach my $p (@::legal_product) {
|
|
|
|
if (CanEnterProduct($p)) {
|
|
|
|
push @products, $p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (@products);
|
|
|
|
}
|
|
|
|
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2002-11-24 22:56:34 +03:00
|
|
|
#
|
|
|
|
# This function returns an alphabetical list of product names to which
|
2003-04-25 09:41:29 +04:00
|
|
|
# the user can enter bugs. If the $by_id parameter is true, also retrieves IDs
|
|
|
|
# and pushes them onto the list as id, name [, id, name...] for easy slurping
|
|
|
|
# into a hash by the calling code.
|
2002-12-10 17:17:05 +03:00
|
|
|
sub GetSelectableProducts {
|
2004-08-21 01:49:20 +04:00
|
|
|
my ($by_id,$by_classification) = @_;
|
2003-04-25 09:41:29 +04:00
|
|
|
|
|
|
|
my $extra_sql = $by_id ? "id, " : "";
|
|
|
|
|
2005-03-10 10:49:41 +03:00
|
|
|
my $extra_from_sql = $by_classification ? " INNER JOIN classifications"
|
|
|
|
. " ON classifications.id = products.classification_id" : "";
|
2004-08-21 01:49:20 +04:00
|
|
|
|
|
|
|
my $query = "SELECT $extra_sql products.name " .
|
|
|
|
"FROM products $extra_from_sql " .
|
2002-11-24 22:56:34 +03:00
|
|
|
"LEFT JOIN group_control_map " .
|
2002-12-10 17:17:05 +03:00
|
|
|
"ON group_control_map.product_id = products.id ";
|
|
|
|
if (Param('useentrygroupdefault')) {
|
|
|
|
$query .= "AND group_control_map.entry != 0 ";
|
|
|
|
} else {
|
|
|
|
$query .= "AND group_control_map.membercontrol = " .
|
|
|
|
CONTROLMAPMANDATORY . " ";
|
|
|
|
}
|
2004-07-31 06:27:26 +04:00
|
|
|
if (%{Bugzilla->user->groups}) {
|
2002-11-24 22:56:34 +03:00
|
|
|
$query .= "AND group_id NOT IN(" .
|
2003-06-03 13:48:15 +04:00
|
|
|
join(',', values(%{Bugzilla->user->groups})) . ") ";
|
2002-11-24 22:56:34 +03:00
|
|
|
}
|
2004-08-21 01:49:20 +04:00
|
|
|
$query .= "WHERE group_id IS NULL ";
|
|
|
|
if ($by_classification) {
|
|
|
|
$query .= "AND classifications.name = ";
|
|
|
|
$query .= SqlQuote($by_classification) . " ";
|
|
|
|
}
|
|
|
|
$query .= "ORDER BY name";
|
2002-11-24 22:56:34 +03:00
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL($query);
|
|
|
|
my @products = ();
|
2003-04-25 09:41:29 +04:00
|
|
|
push(@products, FetchSQLData()) while MoreSQLData();
|
2002-11-24 22:56:34 +03:00
|
|
|
PopGlobalSQLState();
|
|
|
|
return (@products);
|
|
|
|
}
|
|
|
|
|
2002-12-10 17:17:05 +03:00
|
|
|
# GetSelectableProductHash
|
2002-11-25 08:38:09 +03:00
|
|
|
# returns a hash containing
|
|
|
|
# legal_products => an enterable product list
|
2003-04-25 09:41:29 +04:00
|
|
|
# legal_(components|versions|milestones) =>
|
|
|
|
# the list of components, versions, and milestones of enterable products
|
|
|
|
# (components|versions|milestones)_by_product
|
|
|
|
# => a hash of component lists for each enterable product
|
|
|
|
# Milestones only get returned if the usetargetmilestones parameter is set.
|
2002-12-10 17:17:05 +03:00
|
|
|
sub GetSelectableProductHash {
|
2003-04-25 09:41:29 +04:00
|
|
|
# The hash of selectable products and their attributes that gets returned
|
|
|
|
# at the end of this function.
|
|
|
|
my $selectables = {};
|
|
|
|
|
|
|
|
my %products = GetSelectableProducts(1);
|
|
|
|
|
|
|
|
$selectables->{legal_products} = [sort values %products];
|
|
|
|
|
|
|
|
# Run queries that retrieve the list of components, versions,
|
|
|
|
# and target milestones (if used) for the selectable products.
|
|
|
|
my @tables = qw(components versions);
|
|
|
|
push(@tables, 'milestones') if Param('usetargetmilestone');
|
|
|
|
|
2002-11-25 08:38:09 +03:00
|
|
|
PushGlobalSQLState();
|
2003-04-25 09:41:29 +04:00
|
|
|
foreach my $table (@tables) {
|
|
|
|
my %values;
|
|
|
|
my %values_by_product;
|
|
|
|
|
2004-12-11 03:05:41 +03:00
|
|
|
if (scalar(keys %products)) {
|
|
|
|
# Why oh why can't we standardize on these names?!?
|
|
|
|
my $fld = ($table eq "components" ? "name" : "value");
|
|
|
|
|
|
|
|
my $query = "SELECT $fld, product_id FROM $table WHERE product_id " .
|
|
|
|
"IN (" . join(",", keys %products) . ") ORDER BY $fld";
|
|
|
|
SendSQL($query);
|
|
|
|
|
|
|
|
while (MoreSQLData()) {
|
|
|
|
my ($name, $product_id) = FetchSQLData();
|
|
|
|
next unless $name;
|
|
|
|
$values{$name} = 1;
|
|
|
|
push @{$values_by_product{$products{$product_id}}}, $name;
|
|
|
|
}
|
2002-11-25 08:38:09 +03:00
|
|
|
}
|
2003-04-25 09:41:29 +04:00
|
|
|
|
|
|
|
$selectables->{"legal_$table"} = [sort keys %values];
|
|
|
|
$selectables->{"${table}_by_product"} = \%values_by_product;
|
2002-11-25 08:38:09 +03:00
|
|
|
}
|
|
|
|
PopGlobalSQLState();
|
2003-04-25 09:41:29 +04:00
|
|
|
|
|
|
|
return $selectables;
|
2002-11-25 08:38:09 +03:00
|
|
|
}
|
|
|
|
|
2004-08-21 01:49:20 +04:00
|
|
|
#
|
|
|
|
# This function returns an alphabetical list of classifications that has products the user can enter bugs.
|
|
|
|
sub GetSelectableClassifications {
|
|
|
|
my @selectable_classes = ();
|
|
|
|
|
2004-12-05 17:18:59 +03:00
|
|
|
foreach my $c (sort keys %::classdesc) {
|
2004-08-21 01:49:20 +04:00
|
|
|
if ( scalar(GetSelectableProducts(0,$c)) > 0) {
|
|
|
|
push(@selectable_classes,$c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (@selectable_classes);
|
|
|
|
}
|
2002-11-25 08:38:09 +03:00
|
|
|
|
2001-07-11 09:29:21 +04:00
|
|
|
|
|
|
|
sub ValidatePassword {
|
|
|
|
# Determines whether or not a password is valid (i.e. meets Bugzilla's
|
2002-10-06 15:52:37 +04:00
|
|
|
# requirements for length and content).
|
2001-07-11 09:29:21 +04:00
|
|
|
# If a second password is passed in, this function also verifies that
|
|
|
|
# the two passwords match.
|
|
|
|
my ($password, $matchpassword) = @_;
|
|
|
|
|
2002-10-06 15:52:37 +04:00
|
|
|
if (length($password) < 3) {
|
2005-03-05 03:18:48 +03:00
|
|
|
ThrowUserError("password_too_short");
|
2002-10-06 15:52:37 +04:00
|
|
|
} elsif (length($password) > 16) {
|
2005-03-05 03:18:48 +03:00
|
|
|
ThrowUserError("password_too_long");
|
2004-03-03 08:19:28 +03:00
|
|
|
} elsif ((defined $matchpassword) && ($password ne $matchpassword)) {
|
2005-03-05 03:18:48 +03:00
|
|
|
ThrowUserError("passwords_dont_match");
|
2001-07-11 09:29:21 +04:00
|
|
|
}
|
2000-04-21 22:45:55 +04:00
|
|
|
}
|
1998-09-16 01:49:26 +04:00
|
|
|
|
|
|
|
sub DBID_to_name {
|
|
|
|
my ($id) = (@_);
|
2005-03-15 08:20:48 +03:00
|
|
|
return "__UNKNOWN__" if !defined $id;
|
2001-07-04 08:41:27 +04:00
|
|
|
# $id should always be a positive integer
|
|
|
|
if ($id =~ m/^([1-9][0-9]*)$/) {
|
|
|
|
$id = $1;
|
|
|
|
} else {
|
|
|
|
$::cachedNameArray{$id} = "__UNKNOWN__";
|
|
|
|
}
|
1998-09-16 01:49:26 +04:00
|
|
|
if (!defined $::cachedNameArray{$id}) {
|
2001-03-20 00:03:52 +03:00
|
|
|
PushGlobalSQLState();
|
2005-05-02 22:52:02 +04:00
|
|
|
SendSQL("SELECT login_name FROM profiles WHERE userid = $id");
|
1998-09-16 01:49:26 +04:00
|
|
|
my $r = FetchOneColumn();
|
2001-03-20 00:03:52 +03:00
|
|
|
PopGlobalSQLState();
|
2000-05-08 22:23:55 +04:00
|
|
|
if (!defined $r || $r eq "") {
|
1998-09-16 01:49:26 +04:00
|
|
|
$r = "__UNKNOWN__";
|
|
|
|
}
|
|
|
|
$::cachedNameArray{$id} = $r;
|
|
|
|
}
|
|
|
|
return $::cachedNameArray{$id};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub DBNameToIdAndCheck {
|
2002-04-25 01:41:51 +04:00
|
|
|
my ($name) = (@_);
|
2005-02-25 02:42:48 +03:00
|
|
|
my $result = login_to_id($name);
|
1998-09-16 01:49:26 +04:00
|
|
|
if ($result > 0) {
|
|
|
|
return $result;
|
|
|
|
}
|
2002-04-25 01:41:51 +04:00
|
|
|
|
2005-03-05 03:18:48 +03:00
|
|
|
ThrowUserError("invalid_username", { name => $name });
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
2004-08-21 01:49:20 +04:00
|
|
|
sub get_classification_id {
|
|
|
|
my ($classification) = @_;
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT id FROM classifications WHERE name = " . SqlQuote($classification));
|
|
|
|
my ($classification_id) = FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $classification_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_classification_name {
|
|
|
|
my ($classification_id) = @_;
|
|
|
|
die "non-numeric classification_id '$classification_id' passed to get_classification_name"
|
|
|
|
unless ($classification_id =~ /^\d+$/);
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT name FROM classifications WHERE id = $classification_id");
|
|
|
|
my ($classification) = FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $classification;
|
|
|
|
}
|
2002-09-22 21:15:13 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-08-12 09:43:05 +04:00
|
|
|
sub get_product_id {
|
|
|
|
my ($prod) = @_;
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT id FROM products WHERE name = " . SqlQuote($prod));
|
|
|
|
my ($prod_id) = FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $prod_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_product_name {
|
|
|
|
my ($prod_id) = @_;
|
|
|
|
die "non-numeric prod_id '$prod_id' passed to get_product_name"
|
|
|
|
unless ($prod_id =~ /^\d+$/);
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT name FROM products WHERE id = $prod_id");
|
|
|
|
my ($prod) = FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $prod;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_component_id {
|
|
|
|
my ($prod_id, $comp) = @_;
|
2004-02-13 23:24:51 +03:00
|
|
|
return undef unless ($prod_id && ($prod_id =~ /^\d+$/));
|
2002-08-12 09:43:05 +04:00
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT id FROM components " .
|
|
|
|
"WHERE product_id = $prod_id AND name = " . SqlQuote($comp));
|
|
|
|
my ($comp_id) = FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $comp_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_component_name {
|
|
|
|
my ($comp_id) = @_;
|
|
|
|
die "non-numeric comp_id '$comp_id' passed to get_component_name"
|
|
|
|
unless ($comp_id =~ /^\d+$/);
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT name FROM components WHERE id = $comp_id");
|
|
|
|
my ($comp) = FetchSQLData();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $comp;
|
|
|
|
}
|
|
|
|
|
2000-03-10 21:01:32 +03:00
|
|
|
# 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
|
|
|
|
# expressions.
|
2002-07-03 06:45:13 +04:00
|
|
|
# This has been rewritten to be faster, mainly by substituting 'as we go'.
|
|
|
|
# If you want to modify this routine, read the comments carefully
|
2000-03-10 21:01:32 +03:00
|
|
|
|
|
|
|
sub quoteUrls {
|
2002-02-20 02:22:24 +03:00
|
|
|
my ($text) = (@_);
|
2000-03-10 21:01:32 +03:00
|
|
|
return $text unless $text;
|
|
|
|
|
2002-07-03 06:45:13 +04:00
|
|
|
# We use /g for speed, but uris can have other things inside them
|
|
|
|
# (http://foo/bug#3 for example). Filtering that out filters valid
|
|
|
|
# bug refs out, so we have to do replacements.
|
|
|
|
# mailto can't contain space or #, so we don't have to bother for that
|
|
|
|
# Do this by escaping \0 to \1\0, and replacing matches with \0\0$count\0\0
|
|
|
|
# \0 is used because its unliklely to occur in the text, so the cost of
|
|
|
|
# doing this should be very small
|
|
|
|
# Also, \0 won't appear in the value_quote'd bug title, so we don't have
|
|
|
|
# to worry about bogus substitutions from there
|
|
|
|
|
|
|
|
# escape the 2nd escape char we're using
|
|
|
|
my $chr1 = chr(1);
|
|
|
|
$text =~ s/\0/$chr1\0/g;
|
|
|
|
|
|
|
|
# However, note that adding the title (for buglinks) can affect things
|
|
|
|
# In particular, attachment matches go before bug titles, so that titles
|
|
|
|
# with 'attachment 1' don't double match.
|
|
|
|
# Dupe checks go afterwards, because that uses ^ and \Z, which won't occur
|
|
|
|
# if it was subsituted as a bug title (since that always involve leading
|
|
|
|
# and trailing text)
|
|
|
|
|
|
|
|
# Because of entities, its easier (and quicker) to do this before escaping
|
2000-03-10 21:01:32 +03:00
|
|
|
|
|
|
|
my @things;
|
2002-07-03 06:45:13 +04:00
|
|
|
my $count = 0;
|
|
|
|
my $tmp;
|
|
|
|
|
|
|
|
# non-mailto protocols
|
2004-01-14 21:07:32 +03:00
|
|
|
my $protocol_re = qr/(afs|cid|ftp|gopher|http|https|irc|mid|news|nntp|prospero|telnet|view-source|wais)/i;
|
2002-07-03 06:45:13 +04:00
|
|
|
|
|
|
|
$text =~ s~\b(${protocol_re}: # The protocol:
|
|
|
|
[^\s<>\"]+ # Any non-whitespace
|
|
|
|
[\w\/]) # so that we end in \w or /
|
|
|
|
~($tmp = html_quote($1)) &&
|
|
|
|
($things[$count++] = "<a href=\"$tmp\">$tmp</a>") &&
|
|
|
|
("\0\0" . ($count-1) . "\0\0")
|
|
|
|
~egox;
|
|
|
|
|
|
|
|
# We have to quote now, otherwise our html is itsself escaped
|
|
|
|
# THIS MEANS THAT A LITERAL ", <, >, ' MUST BE ESCAPED FOR A MATCH
|
|
|
|
|
|
|
|
$text = html_quote($text);
|
|
|
|
|
|
|
|
# mailto:
|
|
|
|
# Use |<nothing> so that $1 is defined regardless
|
|
|
|
$text =~ s~\b(mailto:|)?([\w\.\-\+\=]+\@[\w\-]+(?:\.[\w\-]+)+)\b
|
|
|
|
~<a href=\"mailto:$2\">$1$2</a>~igx;
|
|
|
|
|
2004-05-12 09:08:28 +04:00
|
|
|
# attachment links - handle both cases separately for simplicity
|
2002-07-03 06:45:13 +04:00
|
|
|
$text =~ s~((?:^Created\ an\ |\b)attachment\s*\(id=(\d+)\))
|
2004-05-12 09:08:28 +04:00
|
|
|
~($things[$count++] = GetAttachmentLink($2, $1)) &&
|
|
|
|
("\0\0" . ($count-1) . "\0\0")
|
2003-07-27 05:16:45 +04:00
|
|
|
~egmx;
|
2002-07-03 06:45:13 +04:00
|
|
|
|
|
|
|
$text =~ s~\b(attachment\s*\#?\s*(\d+))
|
2004-05-12 09:08:28 +04:00
|
|
|
~($things[$count++] = GetAttachmentLink($2, $1)) &&
|
|
|
|
("\0\0" . ($count-1) . "\0\0")
|
2004-03-22 09:45:21 +03:00
|
|
|
~egmxi;
|
2002-07-03 06:45:13 +04:00
|
|
|
|
|
|
|
# This handles bug a, comment b type stuff. Because we're using /g
|
|
|
|
# we have to do this in one pattern, and so this is semi-messy.
|
|
|
|
# Also, we can't use $bug_re?$comment_re? because that will match the
|
|
|
|
# empty string
|
|
|
|
my $bug_re = qr/bug\s*\#?\s*(\d+)/i;
|
|
|
|
my $comment_re = qr/comment\s*\#?\s*(\d+)/i;
|
|
|
|
$text =~ s~\b($bug_re(?:\s*,?\s*$comment_re)?|$comment_re)
|
|
|
|
~ # We have several choices. $1 here is the link, and $2-4 are set
|
|
|
|
# depending on which part matched
|
|
|
|
(defined($2) ? GetBugLink($2,$1,$3) :
|
|
|
|
"<a href=\"#c$4\">$1</a>")
|
|
|
|
~egox;
|
|
|
|
|
|
|
|
# Duplicate markers
|
|
|
|
$text =~ s~(?<=^\*\*\*\ This\ bug\ has\ been\ marked\ as\ a\ duplicate\ of\ )
|
|
|
|
(\d+)
|
|
|
|
(?=\ \*\*\*\Z)
|
|
|
|
~GetBugLink($1, $1)
|
|
|
|
~egmx;
|
|
|
|
|
|
|
|
# Now remove the encoding hacks
|
|
|
|
$text =~ s/\0\0(\d+)\0\0/$things[$1]/eg;
|
|
|
|
$text =~ s/$chr1\0/\0/g;
|
2000-03-10 21:01:32 +03:00
|
|
|
|
2001-01-25 01:24:06 +03:00
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
|
2003-07-27 05:16:45 +04:00
|
|
|
# GetAttachmentLink creates a link to an attachment,
|
|
|
|
# including its title.
|
|
|
|
|
|
|
|
sub GetAttachmentLink {
|
|
|
|
my ($attachid, $link_text) = @_;
|
|
|
|
detaint_natural($attachid) ||
|
|
|
|
die "GetAttachmentLink() called with non-integer attachment number";
|
|
|
|
|
|
|
|
# If we've run GetAttachmentLink() for this attachment before,
|
|
|
|
# %::attachlink will contain an anonymous array ref of relevant
|
|
|
|
# values. If not, we need to get the information from the database.
|
|
|
|
if (! defined $::attachlink{$attachid}) {
|
|
|
|
# Make sure any unfetched data from a currently running query
|
|
|
|
# is saved off rather than overwritten
|
|
|
|
PushGlobalSQLState();
|
|
|
|
|
|
|
|
SendSQL("SELECT bug_id, isobsolete, description
|
|
|
|
FROM attachments WHERE attach_id = $attachid");
|
|
|
|
|
|
|
|
if (MoreSQLData()) {
|
|
|
|
my ($bugid, $isobsolete, $desc) = FetchSQLData();
|
|
|
|
my $title = "";
|
|
|
|
my $className = "";
|
2004-08-04 20:17:10 +04:00
|
|
|
if (Bugzilla->user->can_see_bug($bugid)) {
|
2003-07-27 05:16:45 +04:00
|
|
|
$title = $desc;
|
|
|
|
}
|
|
|
|
if ($isobsolete) {
|
|
|
|
$className = "bz_obsolete";
|
|
|
|
}
|
|
|
|
$::attachlink{$attachid} = [value_quote($title), $className];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
# Even if there's nothing in the database, we want to save a blank
|
|
|
|
# anonymous array in the %::attachlink hash so the query doesn't get
|
|
|
|
# run again next time we're called for this attachment number.
|
|
|
|
$::attachlink{$attachid} = [];
|
|
|
|
}
|
|
|
|
# All done with this sidetrip
|
|
|
|
PopGlobalSQLState();
|
|
|
|
}
|
|
|
|
|
|
|
|
# Now that we know we've got all the information we're gonna get, let's
|
|
|
|
# return the link (which is the whole reason we were called :)
|
|
|
|
my ($title, $className) = @{$::attachlink{$attachid}};
|
2004-07-24 04:20:43 +04:00
|
|
|
# $title will be undefined if the attachment didn't exist in the database.
|
2003-07-27 05:16:45 +04:00
|
|
|
if (defined $title) {
|
2005-04-26 20:38:35 +04:00
|
|
|
my $linkval = "attachment.cgi?id=$attachid&action=edit";
|
|
|
|
return qq{<a href="$linkval" class="$className" title="$title">$link_text</a>};
|
2003-07-27 05:16:45 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return qq{$link_text};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-03 06:45:13 +04:00
|
|
|
# GetBugLink creates a link to a bug, including its title.
|
2002-09-06 07:59:06 +04:00
|
|
|
# It takes either two or three parameters:
|
2002-07-03 06:45:13 +04:00
|
|
|
# - The bug number
|
|
|
|
# - The link text, to place between the <a>..</a>
|
|
|
|
# - An optional comment number, for linking to a particular
|
|
|
|
# comment in the bug
|
2001-01-25 01:24:06 +03:00
|
|
|
|
|
|
|
sub GetBugLink {
|
2002-07-03 06:45:13 +04:00
|
|
|
my ($bug_num, $link_text, $comment_num) = @_;
|
2005-05-12 21:52:46 +04:00
|
|
|
if (! defined $bug_num || $bug_num eq "") {
|
|
|
|
return "<missing bug number>";
|
|
|
|
}
|
|
|
|
my $quote_bug_num = html_quote($bug_num);
|
|
|
|
detaint_natural($bug_num) || return "<invalid bug number: $quote_bug_num>";
|
2001-11-12 16:43:59 +03:00
|
|
|
|
|
|
|
# If we've run GetBugLink() for this bug number before, %::buglink
|
|
|
|
# will contain an anonymous array ref of relevent values, if not
|
|
|
|
# we need to get the information from the database.
|
|
|
|
if (! defined $::buglink{$bug_num}) {
|
|
|
|
# Make sure any unfetched data from a currently running query
|
|
|
|
# is saved off rather than overwritten
|
|
|
|
PushGlobalSQLState();
|
2001-01-25 01:24:06 +03:00
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT bugs.bug_status, resolution, short_desc " .
|
2001-11-12 16:43:59 +03:00
|
|
|
"FROM bugs WHERE bugs.bug_id = $bug_num");
|
|
|
|
|
|
|
|
# If the bug exists, save its data off for use later in the sub
|
|
|
|
if (MoreSQLData()) {
|
2002-09-22 21:15:13 +04:00
|
|
|
my ($bug_state, $bug_res, $bug_desc) = FetchSQLData();
|
2001-11-12 16:43:59 +03:00
|
|
|
# Initialize these variables to be "" so that we don't get warnings
|
|
|
|
# if we don't change them below (which is highly likely).
|
|
|
|
my ($pre, $title, $post) = ("", "", "");
|
2000-12-12 06:47:40 +03:00
|
|
|
|
2001-11-12 16:43:59 +03:00
|
|
|
$title = $bug_state;
|
2005-02-08 19:22:26 +03:00
|
|
|
if ($bug_state eq 'UNCONFIRMED') {
|
2001-11-12 16:43:59 +03:00
|
|
|
$pre = "<i>";
|
|
|
|
$post = "</i>";
|
|
|
|
}
|
|
|
|
elsif (! IsOpenedState($bug_state)) {
|
2004-03-17 02:53:01 +03:00
|
|
|
$pre = '<span class="bz_closed">';
|
2001-11-12 16:43:59 +03:00
|
|
|
$title .= " $bug_res";
|
2004-03-17 02:53:01 +03:00
|
|
|
$post = '</span>';
|
2001-11-12 16:43:59 +03:00
|
|
|
}
|
2004-08-04 20:17:10 +04:00
|
|
|
if (Bugzilla->user->can_see_bug($bug_num)) {
|
2001-11-12 16:43:59 +03:00
|
|
|
$title .= " - $bug_desc";
|
|
|
|
}
|
|
|
|
$::buglink{$bug_num} = [$pre, value_quote($title), $post];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
# Even if there's nothing in the database, we want to save a blank
|
|
|
|
# anonymous array in the %::buglink hash so the query doesn't get
|
|
|
|
# run again next time we're called for this bug number.
|
|
|
|
$::buglink{$bug_num} = [];
|
|
|
|
}
|
|
|
|
# All done with this sidetrip
|
|
|
|
PopGlobalSQLState();
|
|
|
|
}
|
2001-01-25 01:24:06 +03:00
|
|
|
|
2001-11-12 16:43:59 +03:00
|
|
|
# Now that we know we've got all the information we're gonna get, let's
|
|
|
|
# return the link (which is the whole reason we were called :)
|
|
|
|
my ($pre, $title, $post) = @{$::buglink{$bug_num}};
|
|
|
|
# $title will be undefined if the bug didn't exist in the database.
|
|
|
|
if (defined $title) {
|
2002-07-03 06:45:13 +04:00
|
|
|
my $linkval = "show_bug.cgi?id=$bug_num";
|
|
|
|
if (defined $comment_num) {
|
|
|
|
$linkval .= "#c$comment_num";
|
|
|
|
}
|
|
|
|
return qq{$pre<a href="$linkval" title="$title">$link_text</a>$post};
|
2001-11-12 16:43:59 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return qq{$link_text};
|
|
|
|
}
|
2000-03-10 21:01:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
sub GetLongDescriptionAsText {
|
2000-01-22 07:24:42 +03:00
|
|
|
my ($id, $start, $end) = (@_);
|
2000-01-21 00:31:22 +03:00
|
|
|
my $result = "";
|
|
|
|
my $count = 0;
|
2002-08-20 01:17:28 +04:00
|
|
|
my $anyprivate = 0;
|
2005-02-25 02:37:48 +03:00
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
my ($query) = ("SELECT profiles.login_name, " .
|
|
|
|
$dbh->sql_date_format('longdescs.bug_when', '%Y.%m.%d %H:%i') . ", " .
|
2005-02-09 20:30:20 +03:00
|
|
|
" longdescs.thetext, longdescs.isprivate, " .
|
|
|
|
" longdescs.already_wrapped " .
|
2002-02-20 02:22:24 +03:00
|
|
|
"FROM longdescs, profiles " .
|
|
|
|
"WHERE profiles.userid = longdescs.who " .
|
|
|
|
"AND longdescs.bug_id = $id ");
|
2000-01-22 07:24:42 +03:00
|
|
|
|
2005-03-11 22:45:03 +03:00
|
|
|
# $start will be undef for New bugs, and defined for pre-existing bugs.
|
|
|
|
if ($start) {
|
|
|
|
# If $start is not NULL, obtain the count-index
|
2005-02-25 20:57:16 +03:00
|
|
|
# of this comment for the leading "Comment #xxx" line.)
|
2005-03-11 22:45:03 +03:00
|
|
|
SendSQL("SELECT count(*) FROM longdescs " .
|
|
|
|
" WHERE bug_id = $id AND bug_when <= '$start'");
|
2005-01-21 07:09:51 +03:00
|
|
|
($count) = (FetchSQLData());
|
2005-03-11 22:45:03 +03:00
|
|
|
|
|
|
|
$query .= " AND longdescs.bug_when > '$start'"
|
|
|
|
. " AND longdescs.bug_when <= '$end' ";
|
2000-01-22 07:24:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$query .= "ORDER BY longdescs.bug_when";
|
|
|
|
SendSQL($query);
|
2000-01-21 00:31:22 +03:00
|
|
|
while (MoreSQLData()) {
|
2005-02-09 20:30:20 +03:00
|
|
|
my ($who, $when, $text, $isprivate, $work_time, $already_wrapped) =
|
|
|
|
(FetchSQLData());
|
2000-01-21 00:31:22 +03:00
|
|
|
if ($count) {
|
2005-02-25 20:57:16 +03:00
|
|
|
$result .= "\n\n------- Comment #$count from $who".Param('emailsuffix')." ".
|
2002-11-27 19:00:44 +03:00
|
|
|
Bugzilla::Util::format_time($when) . " -------\n";
|
2000-01-21 00:31:22 +03:00
|
|
|
}
|
2002-08-20 01:17:28 +04:00
|
|
|
if (($isprivate > 0) && Param("insidergroup")) {
|
|
|
|
$anyprivate = 1;
|
|
|
|
}
|
2005-02-09 20:30:20 +03:00
|
|
|
$result .= ($already_wrapped ? $text : wrap_comment($text));
|
2000-01-21 00:31:22 +03:00
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
|
2002-08-20 01:17:28 +04:00
|
|
|
return ($result, $anyprivate);
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
2005-02-25 01:43:28 +03:00
|
|
|
# Returns a list of all the legal values for a field that has a
|
|
|
|
# list of legal values, like rep_platform or resolution.
|
|
|
|
sub get_legal_field_values {
|
|
|
|
my ($field) = @_;
|
|
|
|
my $dbh = Bugzilla->dbh;
|
2005-02-27 04:11:22 +03:00
|
|
|
my $result_ref = $dbh->selectcol_arrayref(
|
2005-04-12 05:27:57 +04:00
|
|
|
"SELECT value FROM $field
|
|
|
|
WHERE isactive = ?
|
|
|
|
ORDER BY sortkey, value", undef, (1));
|
2005-02-25 01:43:28 +03:00
|
|
|
return @$result_ref;
|
1998-09-16 01:49:26 +04:00
|
|
|
}
|
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
sub BugInGroupId {
|
|
|
|
my ($bugid, $groupid) = (@_);
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT bug_id != 0 FROM bug_group_map
|
|
|
|
WHERE bug_id = $bugid
|
|
|
|
AND group_id = $groupid");
|
2001-08-11 05:18:24 +04:00
|
|
|
my $bugingroup = FetchOneColumn();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $bugingroup;
|
|
|
|
}
|
|
|
|
|
2000-03-10 19:25:03 +03:00
|
|
|
sub GroupExists {
|
|
|
|
my ($groupname) = (@_);
|
2002-06-03 17:36:39 +04:00
|
|
|
PushGlobalSQLState();
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT id FROM groups WHERE name=" . SqlQuote($groupname));
|
|
|
|
my $id = FetchOneColumn();
|
2002-06-03 17:36:39 +04:00
|
|
|
PopGlobalSQLState();
|
2002-09-22 21:15:13 +04:00
|
|
|
return $id;
|
2000-03-10 19:25:03 +03:00
|
|
|
}
|
1999-03-11 19:30:54 +03:00
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
sub GroupNameToId {
|
2001-08-11 05:18:24 +04:00
|
|
|
my ($groupname) = (@_);
|
|
|
|
PushGlobalSQLState();
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT id FROM groups WHERE name=" . SqlQuote($groupname));
|
|
|
|
my $id = FetchOneColumn();
|
2001-08-11 05:18:24 +04:00
|
|
|
PopGlobalSQLState();
|
2002-09-22 21:15:13 +04:00
|
|
|
return $id;
|
2001-08-11 05:18:24 +04:00
|
|
|
}
|
|
|
|
|
2002-09-22 21:15:13 +04:00
|
|
|
sub GroupIdToName {
|
|
|
|
my ($groupid) = (@_);
|
|
|
|
PushGlobalSQLState();
|
|
|
|
SendSQL("SELECT name FROM groups WHERE id = $groupid");
|
|
|
|
my $name = FetchOneColumn();
|
|
|
|
PopGlobalSQLState();
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-06 07:16:52 +04:00
|
|
|
# Determines whether or not a group is active by checking
|
|
|
|
# the "isactive" column for the group in the "groups" table.
|
2002-09-22 21:15:13 +04:00
|
|
|
# Note: This function selects groups by id rather than by name.
|
2001-06-06 07:16:52 +04:00
|
|
|
sub GroupIsActive {
|
2002-09-22 21:15:13 +04:00
|
|
|
my ($groupid) = (@_);
|
|
|
|
$groupid ||= 0;
|
2002-06-03 17:36:39 +04:00
|
|
|
PushGlobalSQLState();
|
2002-09-22 21:15:13 +04:00
|
|
|
SendSQL("SELECT isactive FROM groups WHERE id=$groupid");
|
2001-06-06 07:16:52 +04:00
|
|
|
my $isactive = FetchOneColumn();
|
2002-06-03 17:36:39 +04:00
|
|
|
PopGlobalSQLState();
|
2001-06-06 07:16:52 +04:00
|
|
|
return $isactive;
|
|
|
|
}
|
|
|
|
|
2000-01-23 04:03:15 +03:00
|
|
|
# Determines if the given bug_status string represents an "Opened" bug. This
|
2002-09-06 07:59:06 +04:00
|
|
|
# routine ought to be parameterizable somehow, as people tend to introduce
|
2000-01-23 04:03:15 +03:00
|
|
|
# new states into Bugzilla.
|
|
|
|
|
|
|
|
sub IsOpenedState {
|
|
|
|
my ($state) = (@_);
|
2001-09-15 01:50:08 +04:00
|
|
|
if (grep($_ eq $state, OpenStates())) {
|
2000-01-23 04:03:15 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-09-15 01:50:08 +04:00
|
|
|
# This sub will return an array containing any status that
|
|
|
|
# is considered an open bug.
|
|
|
|
|
|
|
|
sub OpenStates {
|
2005-02-08 19:22:26 +03:00
|
|
|
return ('NEW', 'REOPENED', 'ASSIGNED', 'UNCONFIRMED');
|
2001-09-15 01:50:08 +04:00
|
|
|
}
|
|
|
|
|
2000-01-23 04:03:15 +03:00
|
|
|
|
2002-05-30 05:44:33 +04:00
|
|
|
###############################################################################
|
2002-03-12 16:55:07 +03:00
|
|
|
|
2002-09-18 03:28:24 +04:00
|
|
|
# Constructs a format object from URL parameters. You most commonly call it
|
|
|
|
# like this:
|
2004-03-27 00:00:11 +03:00
|
|
|
# my $format = GetFormat("foo/bar", scalar($cgi->param('format')),
|
|
|
|
# scalar($cgi->param('ctype')));
|
2003-03-22 04:17:02 +03:00
|
|
|
|
2002-09-18 03:28:24 +04:00
|
|
|
sub GetFormat {
|
|
|
|
my ($template, $format, $ctype) = @_;
|
2002-12-20 10:21:43 +03:00
|
|
|
|
2002-09-18 03:28:24 +04:00
|
|
|
$ctype ||= "html";
|
2002-10-07 10:44:07 +04:00
|
|
|
$format ||= "";
|
2002-12-20 10:21:43 +03:00
|
|
|
|
2002-09-18 03:28:24 +04:00
|
|
|
# Security - allow letters and a hyphen only
|
|
|
|
$ctype =~ s/[^a-zA-Z\-]//g;
|
|
|
|
$format =~ s/[^a-zA-Z\-]//g;
|
2002-09-27 03:25:12 +04:00
|
|
|
trick_taint($ctype);
|
|
|
|
trick_taint($format);
|
2002-12-20 10:21:43 +03:00
|
|
|
|
2002-09-18 03:28:24 +04:00
|
|
|
$template .= ($format ? "-$format" : "");
|
|
|
|
$template .= ".$ctype.tmpl";
|
2002-12-20 10:21:43 +03:00
|
|
|
|
2003-03-22 04:17:02 +03:00
|
|
|
# Now check that the template actually exists. We only want to check
|
|
|
|
# if the template exists; any other errors (eg parse errors) will
|
2004-03-29 02:49:16 +04:00
|
|
|
# end up being detected later.
|
2003-03-22 04:17:02 +03:00
|
|
|
eval {
|
|
|
|
Bugzilla->template->context->template($template);
|
|
|
|
};
|
|
|
|
# This parsing may seem fragile, but its OK:
|
|
|
|
# http://lists.template-toolkit.org/pipermail/templates/2003-March/004370.html
|
|
|
|
# Even if it is wrong, any sort of error is going to cause a failure
|
|
|
|
# eventually, so the only issue would be an incorrect error message
|
|
|
|
if ($@ && $@->info =~ /: not found$/) {
|
|
|
|
ThrowUserError("format_not_found", { 'format' => $format,
|
|
|
|
'ctype' => $ctype,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
# Else, just return the info
|
2002-12-20 10:21:43 +03:00
|
|
|
return
|
|
|
|
{
|
|
|
|
'template' => $template ,
|
|
|
|
'extension' => $ctype ,
|
2003-05-05 05:15:38 +04:00
|
|
|
'ctype' => Bugzilla::Constants::contenttypes->{$ctype} ,
|
2002-09-18 03:28:24 +04:00
|
|
|
};
|
2002-03-12 16:55:07 +03:00
|
|
|
}
|
|
|
|
|
2002-12-20 10:21:43 +03:00
|
|
|
############# Live code below here (that is, not subroutine defs) #############
|
2002-02-03 12:28:48 +03:00
|
|
|
|
2002-12-20 10:21:43 +03:00
|
|
|
use Bugzilla;
|
2002-07-26 22:16:39 +04:00
|
|
|
|
2003-02-07 10:19:15 +03:00
|
|
|
$::template = Bugzilla->template();
|
2002-03-01 09:01:12 +03:00
|
|
|
|
2002-12-20 10:21:43 +03:00
|
|
|
$::vars = {};
|
2002-02-03 12:28:48 +03:00
|
|
|
|
1998-09-16 01:49:26 +04:00
|
|
|
1;
|