2 # This script is part of debbugs, and is released
3 # under the terms of the GPL version 2, or any later
4 # version at your option.
5 # See the file README and COPYING for more information.
7 # [Other people have contributed to this file; their copyrights should
9 # Copyright 2004-2006 by Anthony Towns <ajt@debian.org>
10 # Copyright 2007 by Don Armstrong <don@donarmstrong.com>.
16 use POSIX qw(strftime nice);
18 use Debbugs::Config qw(:globals :text :config);
22 use Debbugs::Common qw(getparsedaddrs make_list getmaintainers getpseudodesc);
24 use Debbugs::Bugs qw(get_bugs bug_filter newest_bug);
25 use Debbugs::Packages qw(getsrcpkgs getpkgsrc get_versions);
27 use Debbugs::CGI qw(:all);
29 use Debbugs::CGI::Pkgreport qw(:all);
31 use Debbugs::Text qw(:templates);
34 my $q = new CGI::Simple;
36 if ($q->request_method() eq 'HEAD') {
37 print $q->header(-type => "text/html",
43 my $default_params = {ordering => 'normal',
50 our %param = cgi_parameters(query => $q,
51 single => [qw(ordering archive repeatmerged),
52 qw(bug-rev pend-rev sev-rev),
53 qw(maxdays mindays version),
54 qw(data which dist newest),
56 default => $default_params,
59 my ($form_options,$param) = ({},undef);
60 ($form_options,$param)= form_options_and_normal_param(\%param)
61 if $param{form_options};
63 %param = %{$param} if defined $param;
65 if (exists $param{form_options} and defined $param{form_options}) {
66 delete $param{form_options};
67 delete $param{submit} if exists $param{submit};
68 for my $default (keys %{$default_params}) {
69 if (exists $param{$default} and
70 not ref($default_params->{$default}) and
71 $default_params->{$default} eq $param{$default}
73 delete $param{$default};
76 for my $incexc (qw(include exclude)) {
77 next unless exists $param{$incexc};
78 $param{$incexc} = [grep /\S\:\S/, make_list($param{$incexc})];
80 # kill off keys for which empty values are meaningless
81 for my $key (qw(package src submitter severity status dist)) {
82 next unless exists $param{$key};
83 $param{$key} = [grep {length $_} make_list($param{$key})];
85 print $q->redirect(munge_url('pkgreport.cgi?',%param));
89 # map from yes|no to 1|0
90 for my $key (qw(repeatmerged bug-rev pend-rev sev-rev)) {
91 if (exists $param{$key}){
92 if ($param{$key} =~ /^no$/i) {
95 elsif ($param{$key}) {
101 if (lc($param{archive}) eq 'no') {
104 elsif (lc($param{archive}) eq 'yes') {
109 if (exists $param{dist} and $param{dist} eq '') {
113 my $include = $param{'&include'} || $param{'include'} || "";
114 my $exclude = $param{'&exclude'} || $param{'exclude'} || "";
116 my $users = $param{'users'} || "";
118 my $ordering = $param{'ordering'};
119 my $raw_sort = ($param{'raw'} || "no") eq "yes";
120 my $old_view = ($param{'oldview'} || "no") eq "yes";
121 my $age_sort = ($param{'age'} || "no") eq "yes";
122 unless (defined $ordering) {
123 $ordering = "normal";
124 $ordering = "oldview" if $old_view;
125 $ordering = "raw" if $raw_sort;
126 $ordering = 'age' if $age_sort;
128 $param{ordering} = $ordering;
130 our ($bug_order) = $ordering =~ /(age(?:rev)?)/;
131 $bug_order = '' if not defined $bug_order;
133 my $bug_rev = ($param{'bug-rev'} || "no") eq "yes";
134 my $pend_rev = ($param{'pend-rev'} || "no") eq "yes";
135 my $sev_rev = ($param{'sev-rev'} || "no") eq "yes";
137 my @inc_exc_mapping = ({name => 'pending',
155 key => 'includesubj',
159 key => 'excludesubj',
162 for my $incexcmap (@inc_exc_mapping) {
163 push @{$param{$incexcmap->{incexc}}}, map {"$incexcmap->{name}:$_"}
164 map{split /\s*,\s*/} make_list($param{$incexcmap->{key}})
165 if exists $param{$incexcmap->{key}};
166 delete $param{$incexcmap->{key}};
170 my $maxdays = ($param{'maxdays'} || -1);
171 my $mindays = ($param{'mindays'} || 0);
172 my $version = $param{'version'} || undef;
175 our %hidden = map { $_, 1 } qw(status severity classification);
179 "pri" => [map { "pending=$_" }
180 qw(pending forwarded pending-fixed fixed done absent)],
181 "ttl" => ["Outstanding","Forwarded","Pending Upload",
182 "Fixed in NMU","Resolved","From other Branch"],
183 "def" => "Unknown Pending Status",
184 "ord" => [0,1,2,3,4,5,6],
188 "pri" => [map { "severity=$_" } @gSeverityList],
189 "ttl" => [map { $gSeverityDisplay{$_} } @gSeverityList],
190 "def" => "Unknown Severity",
191 "ord" => [0..@gSeverityList],
193 "classification" => [ {
194 "nam" => "Classification",
195 "pri" => [qw(pending=pending+tag=wontfix
196 pending=pending+tag=moreinfo
197 pending=pending+tag=patch
198 pending=pending+tag=confirmed
200 "ttl" => ["Will Not Fix","More information needed",
201 "Patch Available","Confirmed"],
202 "def" => "Unclassified",
203 "ord" => [2,3,4,1,0,5],
205 "oldview" => [ qw(status severity) ],
206 "normal" => [ qw(status severity classification) ],
209 if (exists $param{which} and exists $param{data}) {
210 $param{$param{which}} = [exists $param{$param{which}}?(make_list($param{$param{which}})):(),
211 make_list($param{data}),
213 delete $param{which};
217 if (defined $param{maintenc}) {
218 $param{maint} = maint_decode($param{maintenc});
219 delete $param{maintenc}
223 if (not grep {exists $param{$_}} keys %package_search_keys and exists $param{users}) {
224 $param{usertag} = [make_list($param{users})];
227 if (exists $param{pkg}) {
228 $param{package} = $param{pkg};
234 for my $user (map {split /[\s*,\s*]+/} make_list($param{users}||[])) {
235 next unless length($user);
239 if (defined $param{usertag}) {
240 for my $usertag (make_list($param{usertag})) {
242 my ($u, $t) = split /:/, $usertag, 2;
243 Debbugs::User::read_usertags(\%select_ut, $u);
244 unless (defined $t && $t ne "") {
245 $t = join(",", keys(%select_ut));
248 push @{$param{tag}}, split /,/, $t;
252 quitcgi("You have to choose something to select by") unless grep {exists $param{$_}} keys %package_search_keys;
255 my $Archived = $param{archive} ? " Archived" : "";
257 my $this = munge_url('pkgreport.cgi?',
264 my $dtime = strftime "%a, %e %b %Y %T UTC", gmtime;
265 my $tail_html = $gHTMLTail;
266 $tail_html = $gHTMLTail;
267 $tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
274 return if $seen_users{$u};
277 my $user = Debbugs::User::get_user($u);
279 my %vis = map { $_, 1 } @{$user->{"visible_cats"}};
280 for my $c (keys %{$user->{"categories"}}) {
281 $cats{$c} = $user->{"categories"}->{$c};
282 $hidden{$c} = 1 unless defined $vis{$c};
285 for my $t (keys %{$user->{"tags"}}) {
286 $ut->{$t} = [] unless defined $ut->{$t};
287 push @{$ut->{$t}}, @{$user->{"tags"}->{$t}};
291 for my $t (keys %{$ut}) {
292 for my $b (@{$ut->{$t}}) {
293 $bugusertags{$b} = [] unless defined $bugusertags{$b};
294 push @{$bugusertags{$b}}, $t;
297 # set_option("bugusertags", \%bugusertags);
302 # addusers for source and binary packages being searched for
303 my $pkgsrc = getpkgsrc();
304 my $srcpkg = getsrcpkgs();
305 for my $package (# For binary packages, add the binary package
306 # and corresponding source package
307 make_list($param{package}||[]),
308 (map {defined $pkgsrc->{$_}?($pkgsrc->{$_}):()}
309 make_list($param{package}||[]),
311 # For source packages, add the source package
312 # and corresponding binary packages
313 make_list($param{src}||[]),
314 (map {defined $srcpkg->{$_}?($srcpkg->{$_}):()}
315 make_list($param{src}||[]),
318 next unless defined $package;
319 add_user($package.'@'.$config{usertag_package_domain})
320 if defined $config{usertag_package_domain};
324 # walk through the keys and make the right get_bugs query.
326 my $form_option_variables = {};
327 $form_option_variables->{search_key_order} = [@package_search_key_order];
329 # Set the title sanely and clean up parameters
331 my @temp = @package_search_key_order;
332 while (my ($key,$value) = splice @temp, 0, 2) {
333 next unless exists $param{$key};
335 $param{$key} = [map {split /\s*,\s*/} make_list($param{$key})];
336 for my $entry (grep {defined $_ and length $_ } make_list($param{$key})) {
338 if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
339 my %versions = get_versions(package => $entry,
340 (exists $param{dist}?(dist => $param{dist}):()),
341 (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
342 ($key eq 'src'?(arch => q(source)):()),
347 if (keys %versions > 1) {
348 $verdesc = 'versions '. join(', ',
349 map { $_ .' ['.join(', ',
350 sort @{$versions{$_}}
355 $verdesc = 'version '.join(', ',
359 $extra= " ($verdesc)" if keys %versions;
361 push @entries, $entry.$extra;
363 push @title,$value.' '.join(' or ', @entries) if @entries;
365 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
368 # we have to special case the maint="" search, unfortunatly.
369 if (defined $param{maint} and $param{maint} eq "" or ref($param{maint}) and not @{$param{maint}}) {
370 my %maintainers = %{getmaintainers()};
371 @bugs = get_bugs(function =>
373 foreach my $try (splitpackages($d{"pkg"})) {
374 return 1 if not exists $maintainers{$try};
379 $title = $gBugs.' in packages with no maintainer';
381 elsif (defined $param{newest}) {
382 my $newest_bug = newest_bug();
383 @bugs = ($newest_bug - $param{newest} + 1) .. $newest_bug;
384 $title = @bugs.' newest '.$gBugs;
388 @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
389 keys %package_search_keys, 'archive'),
394 if (defined $param{version}) {
395 $title .= " at version $param{version}";
397 elsif (defined $param{dist}) {
398 $title .= " in $param{dist}";
401 $title = html_escape($title);
403 my @names; my @prior; my @order;
404 determine_ordering(cats => \%cats,
406 ordering => \$ordering,
413 # strip out duplicate bugs
415 @bugs{@bugs} = @bugs;
418 my $result = pkg_htmlizebugs(bugs => \@bugs,
423 ordering => $ordering,
424 bugusertags => \%bugusertags,
426 bug_order => $bug_order,
427 repeatmerged => $param{repeatmerged},
432 (exists $param{dist})?(dist => $param{dist}):(),
435 print "Content-Type: text/html; charset=utf-8\n\n";
437 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
438 print "<HTML><HEAD>\n" .
439 "<TITLE>$title -- $gProject$Archived $gBug report logs</TITLE>\n" .
440 qq(<link rel="stylesheet" href="$gWebHostBugDir/css/bugs.css" type="text/css">) .
442 '<BODY onload="pagemain();">' .
444 print "<H1>" . "$gProject$Archived $gBug report logs: $title" .
449 my $pkg = $param{package} if defined $param{package};
450 my $src = $param{src} if defined $param{src};
452 my $pseudodesc = getpseudodesc();
453 if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {
457 # output infomration about the packages
459 for my $package (make_list($param{package}||[])) {
460 print generate_package_info(binary => 1,
466 for my $package (make_list($param{src}||[])) {
467 print generate_package_info(binary => 0,
474 if (exists $param{maint} or exists $param{maintenc}) {
475 print "<p>Note that maintainers may use different Maintainer fields for\n";
476 print "different packages, so there may be other reports filed under\n";
477 print "different addresses.\n";
479 if (exists $param{submitter}) {
480 print "<p>Note that people may use different email accounts for\n";
481 print "different bugs, so there may be other reports filed under\n";
482 print "different addresses.\n";
487 # my %archive_values = (both => 'archived and unarchived',
488 # 0 => 'not archived',
491 # while (my ($key,$value) = each %archive_values) {
492 # next if $key eq lc($param{archive});
493 # push @archive_links, qq(<a href=").
494 # html_escape(pkg_url((
496 # $_ eq 'archive'?():($_,$param{$_})
499 # )).qq(">$value reports </a>);
501 # print '<p>See the '.join (' or ',@archive_links)."</p>\n";
505 print pkg_javascript() . "\n";
507 print qq(<h2 class="outstanding"><!--<a class="options" href="javascript:toggle(1)">-->Options<!--</a>--></h2>\n);
509 print option_form(template => 'cgi/pkgreport_options',
511 form_options => $form_options,
512 variables => $form_option_variables,
515 # print "<h2 class=\"outstanding\"><a class=\"options\" href=\"javascript:toggle(1)\">Options</a></h2>\n";
516 # print "<div id=\"a_1\">\n";
517 # printf "<form action=\"%s\" method=POST>\n", myurl();
519 # print "<table class=\"forms\">\n";
521 # my ($checked_any, $checked_sui, $checked_ver) = ("", "", "");
522 # if (defined $dist) {
523 # $checked_sui = "CHECKED";
524 # } elsif (defined $version) {
525 # $checked_ver = "CHECKED";
527 # $checked_any = "CHECKED";
530 # print "<tr><td>Show bugs applicable to</td>\n";
531 # print " <td><input id=\"b_1_1\" name=vt value=none type=radio onchange=\"enable(1);\" $checked_any>anything</td></tr>\n";
532 # print "<tr><td></td>";
533 # print " <td><input id=\"b_1_2\" name=vt value=bysuite type=radio onchange=\"enable(1);\" $checked_sui>" . pkg_htmlselectsuite(1,2,1) . " for " . pkg_htmlselectarch(1,2,2) . "</td></tr>\n";
535 # if (defined $pkg) {
536 # my $v = html_escape($version) || "";
537 # my $pkgsane = html_escape($pkg->[0]);
538 # print "<tr><td></td>";
539 # print " <td><input id=\"b_1_3\" name=vt value=bypkg type=radio onchange=\"enable(1);\" $checked_ver>$pkgsane version <input id=\"b_1_3_1\" name=version value=\"$v\"></td></tr>\n";
540 # } elsif (defined $src) {
541 # my $v = html_escape($version) || "";
542 # my $srcsane = html_escape($src->[0]);
543 # print "<tr><td></td>";
544 # print " <td><input name=vt value=bysrc type=radio onchange=\"enable(1);\" $checked_ver>$srcsane version <input id=\"b_1_3_1\" name=version value=\"$v\"></td></tr>\n";
546 # print "<tr><td> </td></tr>\n";
548 # my $includetags = html_escape(join(" ", grep { !m/^subj:/i } map {split /[\s,]+/} ref($include)?@{$include}:$include));
549 # my $excludetags = html_escape(join(" ", grep { !m/^subj:/i } map {split /[\s,]+/} ref($exclude)?@{$exclude}:$exclude));
550 # my $includesubj = html_escape(join(" ", map { s/^subj://i; $_ } grep { m/^subj:/i } map {split /[\s,]+/} ref($include)?@{$include}:$include));
551 # my $excludesubj = html_escape(join(" ", map { s/^subj://i; $_ } grep { m/^subj:/i } map {split /[\s,]+/} ref($exclude)?@{$exclude}:$exclude));
552 # my $vismindays = ($mindays == 0 ? "" : $mindays);
553 # my $vismaxdays = ($maxdays == -1 ? "" : $maxdays);
555 # my $sel_rmy = ($param{repeatmerged} ? " selected" : "");
556 # my $sel_rmn = ($param{repeatmerged} ? "" : " selected");
557 # my $sel_ordraw = ($ordering eq "raw" ? " selected" : "");
558 # my $sel_ordold = ($ordering eq "oldview" ? " selected" : "");
559 # my $sel_ordnor = ($ordering eq "normal" ? " selected" : "");
560 # my $sel_ordage = ($ordering eq "age" ? " selected" : "");
562 # my $chk_bugrev = ($bug_rev ? " checked" : "");
563 # my $chk_pendrev = ($pend_rev ? " checked" : "");
564 # my $chk_sevrev = ($sev_rev ? " checked" : "");
567 # <tr><td>Only include bugs tagged with </td><td><input name=include value="$includetags"> or that have <input name=includesubj value="$includesubj"> in their subject</td></tr>
568 # <tr><td>Exclude bugs tagged with </td><td><input name=exclude value="$excludetags"> or that have <input name=excludesubj value="$excludesubj"> in their subject</td></tr>
569 # <tr><td>Only show bugs older than</td><td><input name=mindays value="$vismindays" size=5> days, and younger than <input name=maxdays value="$vismaxdays" size=5> days</td></tr>
571 # <tr><td> </td></tr>
573 # <tr><td>Merged bugs should be</td><td>
574 # <select name=repeatmerged>
575 # <option value=yes$sel_rmy>displayed separately</option>
576 # <option value=no$sel_rmn>combined</option>
578 # <tr><td>Categorise bugs by</td><td>
579 # <select name=ordering>
580 # <option value=raw$sel_ordraw>bug number only</option>
581 # <option value=old$sel_ordold>status and severity</option>
582 # <option value=normal$sel_ordnor>status, severity and classification</option>
583 # <option value=age$sel_ordage>status, severity, classification, and age</option>
588 # my $o = $param{"ordering"} || "";
589 # for my $n (keys %cats) {
590 # next if ($n eq "normal" || $n eq "oldview");
591 # next if defined $hidden{$n};
594 # print "<option disabled>------</option>\n";
596 # my @names = map { ref($_) eq "HASH" ? $_->{"nam"} : $_ } @{$cats{$n}};
598 # if (@names == 1) { $name = $names[0]; }
599 # else { $name = " and " . pop(@names); $name = join(", ", @names) . $name; }
601 # printf "<option value=\"%s\"%s>%s</option>\n",
602 # $n, ($o eq $n ? " selected" : ""), $name;
606 # print "</select></td></tr>\n";
608 # printf "<tr><td>Order bugs by</td><td>%s</td></tr>\n",
609 # pkg_htmlselectyesno("pend-rev", "outstanding bugs first", "done bugs first", $pend_rev);
610 # printf "<tr><td></td><td>%s</td></tr>\n",
611 # pkg_htmlselectyesno("sev-rev", "highest severity first", "lowest severity first", $sev_rev);
612 # printf "<tr><td></td><td>%s</td></tr>\n",
613 # pkg_htmlselectyesno("bug-rev", "oldest bugs first", "newest bugs first", $bug_rev);
616 # <tr><td> </td></tr>
617 # <tr><td colspan=2><input value="Reload page" type="submit"> with new settings</td></tr>
620 # print "</table></form></div>\n";
623 print "<p>$tail_html";
625 print "</body></html>\n";