show_bug.cgi 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/usr/bin/env perl -wT
  2. # -*- Mode: perl; indent-tabs-mode: nil -*-
  3. #
  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/
  8. #
  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.
  13. #
  14. # The Original Code is the Bugzilla Bug Tracking System.
  15. #
  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.
  20. #
  21. # Contributor(s): Terry Weissman <terry@mozilla.org>
  22. use strict;
  23. use lib qw(. lib);
  24. use Bugzilla;
  25. use Bugzilla::Constants;
  26. use Bugzilla::Error;
  27. use Bugzilla::User;
  28. use Bugzilla::Keyword;
  29. use Bugzilla::Bug;
  30. my $cgi = Bugzilla->cgi;
  31. my $template = Bugzilla->template;
  32. my $vars = {};
  33. my $user = Bugzilla->login();
  34. my $format = $template->get_format("bug/show", scalar $cgi->param('format'),
  35. scalar $cgi->param('ctype'));
  36. # Editable, 'single' HTML bugs are treated slightly specially in a few places
  37. my $single = !$format->{format} && $format->{extension} eq 'html';
  38. # If we don't have an ID, _AND_ we're only doing a single bug, then prompt
  39. if (!$cgi->param('id') && $single) {
  40. print Bugzilla->cgi->header();
  41. $template->process("bug/choose.html.tmpl", $vars) ||
  42. ThrowTemplateError($template->error());
  43. exit;
  44. }
  45. my @bugs = ();
  46. my %marks;
  47. if ($single) {
  48. my $id = $cgi->param('id');
  49. # Its a bit silly to do the validation twice - that functionality should
  50. # probably move into Bug.pm at some point
  51. ValidateBugID($id);
  52. push @bugs, new Bugzilla::Bug($id);
  53. if (defined $cgi->param('mark')) {
  54. foreach my $range (split ',', $cgi->param('mark')) {
  55. if ($range =~ /^(\d+)-(\d+)$/) {
  56. foreach my $i ($1..$2) {
  57. $marks{$i} = 1;
  58. }
  59. } elsif ($range =~ /^(\d+)$/) {
  60. $marks{$1} = 1;
  61. }
  62. }
  63. }
  64. } else {
  65. foreach my $id ($cgi->param('id')) {
  66. # Be kind enough and accept URLs of the form: id=1,2,3.
  67. my @ids = split(/,/, $id);
  68. foreach (@ids) {
  69. my $bug = new Bugzilla::Bug($_);
  70. # This is basically a backwards-compatibility hack from when
  71. # Bugzilla::Bug->new used to set 'NotPermitted' if you couldn't
  72. # see the bug.
  73. if (!$bug->{error} && !$user->can_see_bug($bug->bug_id)) {
  74. $bug->{error} = 'NotPermitted';
  75. }
  76. push(@bugs, $bug);
  77. }
  78. }
  79. }
  80. # Determine if Patch Viewer is installed, for Diff link
  81. eval {
  82. require PatchReader;
  83. $vars->{'patchviewerinstalled'} = 1;
  84. };
  85. $vars->{'bugs'} = \@bugs;
  86. $vars->{'marks'} = \%marks;
  87. $vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count();
  88. my @bugids = map {$_->bug_id} grep {!$_->error} @bugs;
  89. $vars->{'bugids'} = join(", ", @bugids);
  90. # Next bug in list (if there is one)
  91. my @bug_list;
  92. if ($cgi->cookie("BUGLIST")) {
  93. @bug_list = split(/:/, $cgi->cookie("BUGLIST"));
  94. }
  95. $vars->{'bug_list'} = \@bug_list;
  96. # Work out which fields we are displaying (currently XML only.)
  97. # If no explicit list is defined, we show all fields. We then exclude any
  98. # on the exclusion list. This is so you can say e.g. "Everything except
  99. # attachments" without listing almost all the fields.
  100. my @fieldlist = (Bugzilla::Bug->fields, 'group', 'long_desc',
  101. 'attachment', 'attachmentdata', 'token');
  102. my %displayfields;
  103. if ($cgi->param("field")) {
  104. @fieldlist = $cgi->param("field");
  105. }
  106. unless (Bugzilla->user->in_group(Bugzilla->params->{"timetrackinggroup"})) {
  107. @fieldlist = grep($_ !~ /(^deadline|_time)$/, @fieldlist);
  108. }
  109. foreach (@fieldlist) {
  110. $displayfields{$_} = 1;
  111. }
  112. foreach ($cgi->param("excludefield")) {
  113. $displayfields{$_} = undef;
  114. }
  115. $vars->{'displayfields'} = \%displayfields;
  116. print $cgi->header($format->{'ctype'});
  117. $template->process($format->{'template'}, $vars)
  118. || ThrowTemplateError($template->error());