1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later version. See the
3 # file README and COPYING for more information.
5 # [Other people have contributed to this file; their copyrights should
7 # Copyright 2008 by Don Armstrong <don@donarmstrong.com>.
10 package Debbugs::CGI::Pkgreport;
14 Debbugs::CGI::Pkgreport -- specific routines for the pkgreport cgi script
30 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
31 use base qw(Exporter);
34 use Params::Validate qw(validate_with :types);
36 use Debbugs::Config qw(:config :globals);
37 use Debbugs::CGI qw(:url :html :util);
38 use Debbugs::Common qw(:misc :util :date);
39 use Debbugs::Status qw(:status);
40 use Debbugs::Bugs qw(bug_filter);
41 use Debbugs::Packages qw(:mapping);
43 use Debbugs::Text qw(:templates);
45 use POSIX qw(strftime);
49 ($VERSION) = q$Revision: 494 $ =~ /^Revision:\s+([^\s+])/;
50 $DEBUG = 0 unless defined $DEBUG;
53 %EXPORT_TAGS = (html => [qw(short_bug_status_html pkg_htmlizebugs),
55 qw(pkg_htmlselectyesno pkg_htmlselectsuite),
56 qw(buglinklist pkg_htmlselectarch)
58 misc => [qw(generate_package_info make_order_list),
60 qw(get_bug_order_index determine_ordering),
64 Exporter::export_ok_tags(keys %EXPORT_TAGS);
65 $EXPORT_TAGS{all} = [@EXPORT_OK];
68 =head2 generate_package_info
70 generate_package_info($srcorbin,$package)
72 Generates the informational bits for a package and returns it
76 sub generate_package_info{
77 my %param = validate_with(params => \@_,
78 spec => {binary => {type => BOOLEAN,
81 package => {type => SCALAR|ARRAYREF,
83 options => {type => HASHREF,
85 bugs => {type => ARRAYREF,
90 my $output_scalar = '';
91 my $output = globify_scalar(\$output_scalar);
93 my $package = $param{package};
95 my %pkgsrc = %{getpkgsrc()};
96 my $srcforpkg = $package;
97 if ($param{binary} and exists $pkgsrc{$package}
98 and defined $pkgsrc{$package}) {
99 $srcforpkg = $pkgsrc{$package};
102 my $showpkg = html_escape($package);
103 my $maintainers = getmaintainers();
104 my $maint = $maintainers->{$srcforpkg};
105 if (defined $maint) {
106 print {$output} '<p>';
107 print {$output} (($maint =~ /,/)? "Maintainer for $showpkg is "
108 : "Maintainers for $showpkg are ") .
109 package_links(maint => $maint);
110 print {$output} ".</p>\n";
113 print {$output} "<p>There is no maintainer for $showpkg. ".
114 "Please do not report new bugs against this package.</p>\n";
116 my @pkgs = getsrcpkgs($srcforpkg);
117 @pkgs = grep( !/^\Q$package\E$/, @pkgs );
120 if ($param{binary}) {
121 print {$output} "<p>You may want to refer to the following packages that are part of the same source:\n";
124 print {$output} "<p>You may want to refer to the following individual bug pages:\n";
126 #push @pkgs, $src if ( $src && !grep(/^\Q$src\E$/, @pkgs) );
127 print {$output} scalar package_links(package=>[@pkgs]);
128 print {$output} ".\n";
131 my $pseudodesc = getpseudodesc();
132 if ($package and defined($pseudodesc) and exists($pseudodesc->{$package})) {
133 push @references, "to the <a href=\"http://$config{web_domain}/pseudo-packages$config{html_suffix}\">".
134 "list of other pseudo-packages</a>";
136 elsif (not defined $maint and not @{$param{bugs}}) {
137 print {$output} "<p>There is no record of the " . html_escape($package) .
138 ($param{binary} ? " package" : " source package") .
139 ", and no bugs have been filed against it.</p>";
142 if ($package and defined $config{package_pages} and length $config{package_pages}) {
143 push @references, sprintf "to the <a href=\"%s\">%s package page</a>",
144 html_escape("http://$config{package_pages}/$package"), html_escape("$package");
146 if (defined $config{subscription_domain} and
147 length $config{subscription_domain}) {
148 my $ptslink = $param{binary} ? $srcforpkg : $package;
149 push @references, q(to the <a href="http://).html_escape("$config{subscription_domain}/$ptslink").q(">Package Tracking System</a>);
151 # Only output this if the source listing is non-trivial.
152 if ($param{binary} and $srcforpkg) {
154 "to the source package ".
155 package_links(src=>$srcforpkg,
156 options => $param{options}) .
161 $references[$#references] = "or $references[$#references]" if @references > 1;
162 print {$output} "<p>You might like to refer ", join(", ", @references), ".</p>\n";
164 if (defined $maint) {
165 print {$output} "<p>If you find a bug not listed here, please\n";
166 printf {$output} "<a href=\"%s\">report it</a>.</p>\n",
167 html_escape("http://$config{web_domain}/Reporting$config{html_suffix}");
169 return $output_scalar;
173 =head2 short_bug_status_html
175 print short_bug_status_html(status => read_bug(bug => 5),
181 =item status -- status hashref as returned by read_bug
183 =item options -- hashref of options to pass to package_links (defaults
186 =item bug_options -- hashref of options to pass to bug_links (default
189 =item snippet -- optional snippet of information about the bug to
199 sub short_bug_status_html {
200 my %param = validate_with(params => \@_,
201 spec => {status => {type => HASHREF,
203 options => {type => HASHREF,
206 bug_options => {type => HASHREF,
209 snippet => {type => SCALAR,
215 my %status = %{$param{status}};
217 $status{tags_array} = [sort(split(/\s+/, $status{tags}))];
218 $status{date_text} = strftime('%a, %e %b %Y %T UTC', gmtime($status{date}));
219 $status{mergedwith_array} = [split(/ /,$status{mergedwith})];
221 my @blockedby= split(/ /, $status{blockedby});
222 $status{blockedby_array} = [];
223 if (@blockedby && $status{"pending"} ne 'fixed' && ! length($status{done})) {
224 for my $b (@blockedby) {
225 my %s = %{get_bug_status($b)};
226 next if $s{"pending"} eq 'fixed' || length $s{done};
227 push @{$status{blockedby_array}},{bug_num => $b, subject => $s{subject}, status => \%s};
231 my @blocks= split(/ /, $status{blocks});
232 $status{blocks_array} = [];
233 if (@blocks && $status{"pending"} ne 'fixed' && ! length($status{done})) {
234 for my $b (@blocks) {
235 my %s = %{get_bug_status($b)};
236 next if $s{"pending"} eq 'fixed' || length $s{done};
237 push @{$status{blocks_array}}, {bug_num => $b, subject => $s{subject}, status => \%s};
240 my $days = bug_archiveable(bug => $status{id},
244 $status{archive_days} = $days;
245 return fill_in_template(template => 'cgi/short_bug_status',
246 variables => {status => \%status,
247 isstrongseverity => \&Debbugs::Status::isstrongseverity,
248 html_escape => \&Debbugs::CGI::html_escape,
249 looks_like_number => \&Scalar::Util::looks_like_number,
251 hole_var => {'&package_links' => \&Debbugs::CGI::package_links,
252 '&bug_links' => \&Debbugs::CGI::bug_links,
253 '&version_url' => \&Debbugs::CGI::version_url,
254 '&secs_to_english' => \&Debbugs::Common::secs_to_english,
255 '&strftime' => \&POSIX::strftime,
256 '&maybelink' => \&Debbugs::CGI::maybelink,
262 sub pkg_htmlizebugs {
263 my %param = validate_with(params => \@_,
264 spec => {bugs => {type => ARRAYREF,
266 names => {type => ARRAYREF,
268 title => {type => ARRAYREF,
270 prior => {type => ARRAYREF,
272 order => {type => ARRAYREF,
274 ordering => {type => SCALAR,
276 bugusertags => {type => HASHREF,
279 bug_rev => {type => BOOLEAN,
282 bug_order => {type => SCALAR,
284 repeatmerged => {type => BOOLEAN,
287 include => {type => ARRAYREF,
290 exclude => {type => ARRAYREF,
293 this => {type => SCALAR,
296 options => {type => HASHREF,
299 dist => {type => SCALAR,
304 my @bugs = @{$param{bugs}};
309 my $footer = "<h2 class=\"outstanding\">Summary</h2>\n";
311 my @dummy = ($gRemoveAge); #, @gSeverityList, @gSeverityDisplay); #, $gHTMLExpireNote);
314 return "<HR><H2>No reports found!</H2></HR>\n";
317 if ( $param{bug_rev} ) {
318 @bugs = sort {$b<=>$a} @bugs;
321 @bugs = sort {$a<=>$b} @bugs;
326 'show_list_header' => 1,
327 'show_list_footer' => 1,
331 # Make the include/exclude map
334 for my $include (make_list($param{include})) {
335 next unless defined $include;
336 my ($key,$value) = split /\s*:\s*/,$include,2;
337 unless (defined $value) {
341 push @{$include{$key}}, split /\s*,\s*/, $value;
343 for my $exclude (make_list($param{exclude})) {
344 next unless defined $exclude;
345 my ($key,$value) = split /\s*:\s*/,$exclude,2;
346 unless (defined $value) {
350 push @{$exclude{$key}}, split /\s*,\s*/, $value;
353 foreach my $bug (@bugs) {
354 my %status = %{get_bug_status(bug=>$bug,
355 (exists $param{dist}?(dist => $param{dist}):()),
356 bugusertags => $param{bugusertags},
357 (exists $param{version}?(version => $param{version}):()),
358 (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
361 next if bug_filter(bug => $bug,
363 repeat_merged => $param{repeatmerged},
364 seen_merged => \%seenmerged,
365 (keys %include ? (include => \%include):()),
366 (keys %exclude ? (exclude => \%exclude):()),
369 my $html = "<li>"; #<a href=\"%s\">#%d: %s</a>\n<br>",
370 #bug_url($bug), $bug, html_escape($status{subject});
371 $html .= short_bug_status_html(status => \%status,
372 options => $param{options},
374 push @status, [ $bug, \%status, $html ];
376 if ($param{bug_order} eq 'age') {
378 @status = sort {$a->[1]{log_modified} <=> $b->[1]{log_modified}} @status;
380 elsif ($param{bug_order} eq 'agerev') {
381 @status = sort {$b->[1]{log_modified} <=> $a->[1]{log_modified}} @status;
383 for my $entry (@status) {
385 for my $i (0..$#{$param{prior}}) {
386 my $v = get_bug_order_index($param{prior}[$i], $entry->[1]);
387 $count{"g_${i}_${v}"}++;
390 $section{$key} .= $entry->[2];
395 if ($param{ordering} eq "raw") {
396 $result .= "<UL class=\"bugs\">\n" . join("", map( { $_->[ 2 ] } @status ) ) . "</UL>\n";
399 $header .= "<div class=\"msgreceived\">\n<ul>\n";
400 my @keys_in_order = ("");
401 for my $o (@{$param{order}}) {
402 push @keys_in_order, "X";
403 while ((my $k = shift @keys_in_order) ne "X") {
406 push @keys_in_order, "${k}_${k2}";
410 for my $order (@keys_in_order) {
411 next unless defined $section{$order};
412 my @ttl = split /_/, $order;
414 my $title = $param{title}[0]->[$ttl[0]] . " bugs";
417 $title .= join("; ", grep {($_ || "") ne ""}
418 map { $param{title}[$_]->[$ttl[$_]] } 1..$#ttl);
420 $title = html_escape($title);
422 my $count = $count{"_$order"};
423 my $bugs = $count == 1 ? "bug" : "bugs";
425 $header .= "<li><a href=\"#$order\">$title</a> ($count $bugs)</li>\n";
426 if ($common{show_list_header}) {
427 my $count = $count{"_$order"};
428 my $bugs = $count == 1 ? "bug" : "bugs";
429 $result .= "<H2 CLASS=\"outstanding\"><a name=\"$order\"></a>$title ($count $bugs)</H2>\n";
432 $result .= "<H2 CLASS=\"outstanding\">$title</H2>\n";
434 $result .= "<div class=\"msgreceived\">\n<UL class=\"bugs\">\n";
435 $result .= "\n\n\n\n";
436 $result .= $section{$order};
437 $result .= "\n\n\n\n";
438 $result .= "</UL>\n</div>\n";
440 $header .= "</ul></div>\n";
442 $footer .= "<div class=\"msgreceived\">\n<ul>\n";
443 for my $i (0..$#{$param{prior}}) {
444 my $local_result = '';
445 foreach my $key ( @{$param{order}[$i]} ) {
446 my $count = $count{"g_${i}_$key"};
447 next if !$count or !$param{title}[$i]->[$key];
448 $local_result .= "<li>$count $param{title}[$i]->[$key]</li>\n";
450 if ( $local_result ) {
451 $footer .= "<li>$param{names}[$i]<ul>\n$local_result</ul></li>\n";
454 $footer .= "</ul>\n</div>\n";
457 $result = $header . $result if ( $common{show_list_header} );
458 $result .= $footer if ( $common{show_list_footer} );
463 return fill_in_template(template=>'cgi/pkgreport_javascript',
467 sub pkg_htmlselectyesno {
468 my ($name, $n, $y, $default) = @_;
469 return sprintf('<select name="%s"><option value=no%s>%s</option><option value=yes%s>%s</option></select>', $name, ($default ? "" : " selected"), $n, ($default ? " selected" : ""), $y);
472 sub pkg_htmlselectsuite {
473 my $id = sprintf "b_%d_%d_%d", $_[0], $_[1], $_[2];
474 my @suites = ("stable", "testing", "unstable", "experimental");
475 my %suiteaka = ("stable", "etch", "testing", "lenny", "unstable", "sid");
476 my $defaultsuite = "unstable";
478 my $result = sprintf '<select name=dist id="%s">', $id;
479 for my $s (@suites) {
480 $result .= sprintf '<option value="%s"%s>%s%s</option>',
481 $s, ($defaultsuite eq $s ? " selected" : ""),
482 $s, (defined $suiteaka{$s} ? " (" . $suiteaka{$s} . ")" : "");
484 $result .= '</select>';
488 sub pkg_htmlselectarch {
489 my $id = sprintf "b_%d_%d_%d", $_[0], $_[1], $_[2];
490 my @arches = qw(alpha amd64 arm hppa i386 ia64 m68k mips mipsel powerpc s390 sparc);
492 my $result = sprintf '<select name=arch id="%s">', $id;
493 $result .= '<option value="any">any architecture</option>';
494 for my $a (@arches) {
495 $result .= sprintf '<option value="%s">%s</option>', $a, $a;
497 $result .= '</select>';
503 return html_escape(pkg_url(map {exists $param{$_}?($_,$param{$_}):()}
504 qw(archive repeatmerged mindays maxdays),
505 qw(version dist arch package src tag maint submitter)
510 sub make_order_list {
514 if ($vfull =~ m/^([^:]+):(.*)$/) {
516 for my $vv (split /,/, $2) {
521 for my $v (split /,/, $vfull) {
522 next unless $v =~ m/.=./;
526 push @x, ""; # catch all
530 sub get_bug_order_index {
536 %tags = map { $_, 1 } split / /, $status->{"tags"}
537 if defined $status->{"tags"};
539 for my $el (@${order}) {
542 for my $item (split /[+]/, $el) {
543 my ($f, $v) = split /=/, $item, 2;
544 next unless (defined $f and defined $v);
546 $isokay = 1 if (defined $status->{$f} and $v eq $status->{$f});
547 $isokay = 1 if ($f eq "tag" && defined $tags{$v});
562 my ($prefix, $infix, @els) = @_;
563 return '' if not @els;
564 return $prefix . bug_linklist($infix,'submitter',@els);
568 # sets: my @names; my @prior; my @title; my @order;
570 sub determine_ordering {
571 my %param = validate_with(params => \@_,
572 spec => {cats => {type => HASHREF,
574 param => {type => HASHREF,
576 ordering => {type => SCALARREF,
578 names => {type => ARRAYREF,
580 pend_rev => {type => BOOLEAN,
583 sev_rev => {type => BOOLEAN,
586 prior => {type => ARRAYREF,
588 title => {type => ARRAYREF,
590 order => {type => ARRAYREF,
594 $param{cats}{status}[0]{ord} = [ reverse @{$param{cats}{status}[0]{ord}} ]
595 if ($param{pend_rev});
596 $param{cats}{severity}[0]{ord} = [ reverse @{$param{cats}{severity}[0]{ord}} ]
597 if ($param{sev_rev});
600 if (defined $param{param}{"pri0"}) {
603 while (defined $param{param}{"pri$i"}) {
606 my ($pri) = make_list($param{param}{"pri$i"});
607 if ($pri =~ m/^([^:]*):(.*)$/) {
608 $h->{"nam"} = $1; # overridden later if necesary
609 $h->{"pri"} = [ map { "$1=$_" } (split /,/, $2) ];
612 $h->{"pri"} = [ split /,/, $pri ];
615 ($h->{"nam"}) = make_list($param{param}{"nam$i"})
616 if (defined $param{param}{"nam$i"});
617 $h->{"ord"} = [ map {split /\s*,\s*/} make_list($param{param}{"ord$i"}) ]
618 if (defined $param{param}{"ord$i"});
619 $h->{"ttl"} = [ map {split /\s*,\s*/} make_list($param{param}{"ttl$i"}) ]
620 if (defined $param{param}{"ttl$i"});
625 $param{cats}{"_"} = [@c];
626 ${$param{ordering}} = "_";
629 ${$param{ordering}} = "normal" unless defined $param{cats}{${$param{ordering}}};
635 for my $c (@{$cats->{$o}}) {
636 if (ref($c) eq "HASH") {
640 push @res, get_ordering($cats, $c);
645 my @cats = get_ordering($param{cats}, ${$param{ordering}});
649 $expr =~ s/[+]/ and /g;
650 $expr =~ s/[a-z]+=//g;
657 push @{$param{prior}}, $c->{"pri"};
658 push @{$param{names}}, ($c->{"nam"} || "Bug attribute #" . $i);
659 if (defined $c->{"ord"}) {
660 push @{$param{order}}, $c->{"ord"};
663 push @{$param{order}}, [ 0..$#{$param{prior}[-1]} ];
665 my @t = @{ $c->{"ttl"} } if defined $c->{ttl};
666 if (@t < $#{$param{prior}[-1]}) {
667 push @t, map { toenglish($param{prior}[-1][$_]) } @t..($#{$param{prior}[-1]});
669 push @t, $c->{"def"} || "";
670 push @{$param{title}}, [@t];