Rubber-stamped by Brady Eidson.
[webbrowser.git] / BugsSite / show_bug.cgi
blob3bc5cd44a179d9f7e213f8be16b64943986155ec
1 #!/usr/bin/env perl -wT
2 # -*- Mode: perl; indent-tabs-mode: nil -*-
4 # The contents of this file are subject to the Mozilla Public
5 # License Version 1.1 (the "License"); you may not use this file
6 # except in compliance with the License. You may obtain a copy of
7 # the License at http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS
10 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 # implied. See the License for the specific language governing
12 # rights and limitations under the License.
14 # The Original Code is the Bugzilla Bug Tracking System.
16 # The Initial Developer of the Original Code is Netscape Communications
17 # Corporation. Portions created by Netscape are
18 # Copyright (C) 1998 Netscape Communications Corporation. All
19 # Rights Reserved.
21 # Contributor(s): Terry Weissman <terry@mozilla.org>
23 use strict;
25 use lib qw(. lib);
27 use Bugzilla;
28 use Bugzilla::Constants;
29 use Bugzilla::Error;
30 use Bugzilla::User;
31 use Bugzilla::Keyword;
32 use Bugzilla::Bug;
34 my $cgi = Bugzilla->cgi;
35 my $template = Bugzilla->template;
36 my $vars = {};
38 my $user = Bugzilla->login();
40 # Editable, 'single' HTML bugs are treated slightly specially in a few places
41 my $single = !$cgi->param('format')
42 && (!$cgi->param('ctype') || $cgi->param('ctype') eq 'html');
44 # If we don't have an ID, _AND_ we're only doing a single bug, then prompt
45 if (!$cgi->param('id') && $single) {
46 print Bugzilla->cgi->header();
47 $template->process("bug/choose.html.tmpl", $vars) ||
48 ThrowTemplateError($template->error());
49 exit;
52 my $format = $template->get_format("bug/show", scalar $cgi->param('format'),
53 scalar $cgi->param('ctype'));
55 my @bugs = ();
56 my %marks;
58 if ($single) {
59 my $id = $cgi->param('id');
60 # Its a bit silly to do the validation twice - that functionality should
61 # probably move into Bug.pm at some point
62 ValidateBugID($id);
63 push @bugs, new Bugzilla::Bug($id);
64 if (defined $cgi->param('mark')) {
65 foreach my $range (split ',', $cgi->param('mark')) {
66 if ($range =~ /^(\d+)-(\d+)$/) {
67 foreach my $i ($1..$2) {
68 $marks{$i} = 1;
70 } elsif ($range =~ /^(\d+)$/) {
71 $marks{$1} = 1;
75 } else {
76 foreach my $id ($cgi->param('id')) {
77 # Be kind enough and accept URLs of the form: id=1,2,3.
78 my @ids = split(/,/, $id);
79 foreach (@ids) {
80 my $bug = new Bugzilla::Bug($_);
81 # This is basically a backwards-compatibility hack from when
82 # Bugzilla::Bug->new used to set 'NotPermitted' if you couldn't
83 # see the bug.
84 if (!$bug->{error} && !$user->can_see_bug($bug->bug_id)) {
85 $bug->{error} = 'NotPermitted';
87 push(@bugs, $bug);
92 # Determine if Patch Viewer is installed, for Diff link
93 eval {
94 require PatchReader;
95 $vars->{'patchviewerinstalled'} = 1;
98 $vars->{'bugs'} = \@bugs;
99 $vars->{'marks'} = \%marks;
100 $vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
102 my @bugids = map {$_->bug_id} grep {!$_->error} @bugs;
103 $vars->{'bugids'} = join(", ", @bugids);
105 # Next bug in list (if there is one)
106 my @bug_list;
107 if ($cgi->cookie("BUGLIST")) {
108 @bug_list = split(/:/, $cgi->cookie("BUGLIST"));
111 $vars->{'bug_list'} = \@bug_list;
113 # Work out which fields we are displaying (currently XML only.)
114 # If no explicit list is defined, we show all fields. We then exclude any
115 # on the exclusion list. This is so you can say e.g. "Everything except
116 # attachments" without listing almost all the fields.
117 my @fieldlist = (Bugzilla::Bug->fields, 'group', 'long_desc',
118 'attachment', 'attachmentdata', 'token');
119 my %displayfields;
121 if ($cgi->param("field")) {
122 @fieldlist = $cgi->param("field");
125 unless (Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"})) {
126 @fieldlist = grep($_ !~ /(^deadline|_time)$/, @fieldlist);
129 foreach (@fieldlist) {
130 $displayfields{$_} = 1;
133 foreach ($cgi->param("excludefield")) {
134 $displayfields{$_} = undef;
137 $vars->{'displayfields'} = \%displayfields;
139 print $cgi->header($format->{'ctype'});
141 $template->process("$format->{'template'}", $vars)
142 || ThrowTemplateError($template->error());