]> git.donarmstrong.com Git - debbugs.git/blobdiff - cgi/pkgreport.cgi
Merge branch 'mouseify'
[debbugs.git] / cgi / pkgreport.cgi
index 3750949728c8dbbe38672d0d25d89445743383e1..3855928e042a941d388bf74bbd9b4045c912ca18 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -wT
+#!/usr/bin/perl -T
 # This script is part of debbugs, and is released
 # under the terms of the GPL version 2, or any later
 # version at your option.
 use warnings;
 use strict;
 
+# Sanitize environent for taint
+BEGIN{
+    delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
+}
+
+# if we're running out of git, we want to use the git base directory as the
+# first INC directory. If you're not running out of git, don't do that.
+use File::Basename qw(dirname);
+use Cwd qw(abs_path);
+our $debbugs_dir;
+BEGIN {
+    $debbugs_dir =
+       abs_path(dirname(abs_path(__FILE__)) . '/../');
+    # clear the taint; we'll assume that the absolute path to __FILE__ is the
+    # right path if there's a .git directory there
+    ($debbugs_dir) = $debbugs_dir =~ /([[:print:]]+)/;
+    if (defined $debbugs_dir and
+       -d $debbugs_dir . '/.git/') {
+    } else {
+       undef $debbugs_dir;
+    }
+    # if the first directory in @INC is not an absolute directory, assume that
+    # someone has overridden us via -I.
+    if ($INC[0] !~ /^\//) {
+       undef $debbugs_dir;
+    }
+}
+use if defined $debbugs_dir, lib => $debbugs_dir;
+
+binmode(STDOUT,':encoding(UTF-8)');
 use POSIX qw(strftime nice);
+use List::AllUtils qw(uniq);
 
 use Debbugs::Config qw(:globals :text :config);
 
@@ -22,7 +53,10 @@ use Debbugs::User;
 use Debbugs::Common qw(getparsedaddrs make_list getmaintainers getpseudodesc);
 
 use Debbugs::Bugs qw(get_bugs bug_filter newest_bug);
-use Debbugs::Packages qw(getsrcpkgs getpkgsrc get_versions);
+use Debbugs::Packages qw(source_to_binary binary_to_source get_versions);
+use Debbugs::Collection::Bug;
+
+use Debbugs::Status qw(splitpackages);
 
 use Debbugs::CGI qw(:all);
 
@@ -30,6 +64,16 @@ use Debbugs::CGI::Pkgreport qw(:all);
 
 use Debbugs::Text qw(:templates);
 
+use Debbugs::DB;
+
+my $s;
+my @schema_arg = ();
+if (defined $config{database}) {
+    $s = Debbugs::DB->connect($config{database}) or
+        die "Unable to connect to DB";
+    @schema_arg = ('schema',$s);
+}
+
 use CGI::Simple;
 my $q = new CGI::Simple;
 
@@ -51,7 +95,8 @@ our %param = cgi_parameters(query => $q,
                            single => [qw(ordering archive repeatmerged),
                                       qw(bug-rev pend-rev sev-rev),
                                       qw(maxdays mindays version),
-                                      qw(data which dist newest),
+                                      qw(data which dist),
+                                      qw(noaffects),
                                      ],
                            default => $default_params,
                           );
@@ -75,12 +120,33 @@ if (exists $param{form_options} and defined $param{form_options}) {
      }
      for my $incexc (qw(include exclude)) {
          next unless exists $param{$incexc};
-         $param{$incexc} = [grep /\S\:\S/, make_list($param{$incexc})];
+         # normalize tag to tags
+         $param{$incexc} = [map {s/^tag:/tags:/; $_} grep /\S\:\S/, make_list($param{$incexc})];
+     }
+     for my $key (keys %package_search_keys) {
+         next unless exists $param{key};
+         $param{$key} = [map {split /\s*,\s*/} make_list($param{$key})];
+     }
+     # kill off keys for which empty values are meaningless
+     for my $key (qw(package src submitter affects severity status dist)) {
+         next unless exists $param{$key};
+         $param{$key} = [grep {defined $_ and length $_}
+                         make_list($param{$key})];
      }
      print $q->redirect(munge_url('pkgreport.cgi?',%param));
      exit 0;
 }
 
+# normalize innclude/exclude keys; currently this is in two locations,
+# which is suboptimal. Closes: #567407
+for my $incexc (qw(include exclude)) {
+    next unless exists $param{$incexc};
+    # normalize tag to tags
+    $param{$incexc} = [map {s/^tag:/tags:/; $_} make_list($param{$incexc})];
+}
+
+
+
 # map from yes|no to 1|0
 for my $key (qw(repeatmerged bug-rev pend-rev sev-rev)) {
      if (exists $param{$key}){
@@ -100,6 +166,10 @@ elsif (lc($param{archive}) eq 'yes') {
      $param{archive} = 1;
 }
 
+# fixup dist
+if (exists $param{dist} and $param{dist} eq '') {
+     delete $param{dist};
+}
 
 my $include = $param{'&include'} || $param{'include'} || "";
 my $exclude = $param{'&exclude'} || $param{'exclude'} || "";
@@ -161,8 +231,7 @@ for my $incexcmap (@inc_exc_mapping) {
 my $maxdays = ($param{'maxdays'} || -1);
 my $mindays = ($param{'mindays'} || 0);
 my $version = $param{'version'} || undef;
-# XXX Once the options/selection is rewritten, this should go away
-my $dist = $param{dist} || undef;
+
 
 our %hidden = map { $_, 1 } qw(status severity classification);
 our %cats = (
@@ -195,7 +264,8 @@ our %cats = (
         "ord" => [2,3,4,1,0,5],
     } ],
     "oldview" => [ qw(status severity) ],
-    "normal" => [ qw(status severity classification) ],
+            "normal" => [ qw(status severity classification) ],
+            raw => [{nam => 'Raw',def => 'Raw'}],
 );
 
 if (exists $param{which} and exists $param{data}) {
@@ -211,21 +281,24 @@ if (defined $param{maintenc}) {
      delete $param{maintenc}
 }
 
+if (exists $param{pkg}) {
+     $param{package} = $param{pkg};
+     delete $param{pkg};
+}
 
 if (not grep {exists $param{$_}} keys %package_search_keys and exists $param{users}) {
      $param{usertag} = [make_list($param{users})];
 }
 
-if (exists $param{pkg}) {
-     $param{package} = $param{pkg};
-     delete $param{pkg};
-}
+my %bugusertags;
+my %ut;
+my %seen_users;
 
-our %bugusertags;
-our %ut;
+my @users;
 for my $user (map {split /[\s*,\s*]+/} make_list($param{users}||[])) {
     next unless length($user);
-    add_user($user);
+    push @users, $user;
+    add_user($user,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
 }
 
 if (defined $param{usertag}) {
@@ -235,13 +308,15 @@ if (defined $param{usertag}) {
          Debbugs::User::read_usertags(\%select_ut, $u);
          unless (defined $t && $t ne "") {
               $t = join(",", keys(%select_ut));
-         }
-         add_user($u);
+          }
+         push @users,$u;
+         add_user($u,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
          push @{$param{tag}}, split /,/, $t;
      }
 }
 
-quitcgi("You have to choose something to select by") unless grep {exists $param{$_}} keys %package_search_keys;
+quitcgi("You have to choose something to select by", '400 Bad Request')
+  unless grep {exists $param{$_}} keys %package_search_keys;
 
 
 my $Archived = $param{archive} ? " Archived" : "";
@@ -253,66 +328,45 @@ my $this = munge_url('pkgreport.cgi?',
 my %indexentry;
 my %strings = ();
 
-my $dtime = strftime "%a, %e %b %Y %T UTC", gmtime;
-my $tail_html = $gHTMLTail;
-$tail_html = $gHTMLTail;
-$tail_html =~ s/SUBSTITUTE_DTIME/$dtime/;
-
-our %seen_users;
-sub add_user {
-    my $ut = \%ut;
-    my $u = shift;
-
-    return if $seen_users{$u};
-    $seen_users{$u} = 1;
-
-    my $user = Debbugs::User::get_user($u);
+my @bugs;
 
-    my %vis = map { $_, 1 } @{$user->{"visible_cats"}};
-    for my $c (keys %{$user->{"categories"}}) {
-        $cats{$c} = $user->{"categories"}->{$c};
-       $hidden{$c} = 1 unless defined $vis{$c};
+# addusers for source and binary packages being searched for
+if (defined $config{usertag_package_domain}) {
+    my @possible_packages;
+    if (exists $param{package} and
+       defined $param{package}
+       ) {
+       # For binary packages, add the binary package and corresponding source package
+       push @possible_packages,
+           make_list($param{package});
+       push @possible_packages,
+           binary_to_source(source_only => 1,
+                            binary=>$param{package},
+                            @schema_arg,
+                           );
     }
-
-    for my $t (keys %{$user->{"tags"}}) {
-        $ut->{$t} = [] unless defined $ut->{$t};
-        push @{$ut->{$t}}, @{$user->{"tags"}->{$t}};
+    if (exists $param{src} and
+       defined $param{src}
+       ) {
+       # For source packages, add the source package and corresponding binary packages
+       push @possible_packages,
+           make_list($param{src});
+       push @possible_packages,
+           source_to_binary(binary_only => 1,
+                            source => $param{src},
+                            dist => [@{$config{distributions}}],
+                            @schema_arg,
+                           );
     }
-
-    %bugusertags = ();
-    for my $t (keys %{$ut}) {
-        for my $b (@{$ut->{$t}}) {
-            $bugusertags{$b} = [] unless defined $bugusertags{$b};
-            push @{$bugusertags{$b}}, $t;
-        }
+    for my $package (@possible_packages) {
+       next unless defined $package and length $package;
+       push @users,
+           $package.'@'.$config{usertag_package_domain};
+       add_user($package.'@'.$config{usertag_package_domain},
+                \%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
     }
-#    set_option("bugusertags", \%bugusertags);
 }
 
-my @bugs;
-
-# addusers for source and binary packages being searched for
-my $pkgsrc = getpkgsrc();
-my $srcpkg = getsrcpkgs();
-for my $package (# For binary packages, add the binary package
-                # and corresponding source package
-                make_list($param{package}||[]),
-                (map {defined $pkgsrc->{$_}?($pkgsrc->{$_}):()}
-                 make_list($param{package}||[]),
-                ),
-                # For source packages, add the source package
-                # and corresponding binary packages
-                make_list($param{src}||[]),
-                (map {defined $srcpkg->{$_}?($srcpkg->{$_}):()}
-                 make_list($param{src}||[]),
-                ),
-               ) {
-     next unless defined $package;
-     add_user($package.'@'.$config{usertag_package_domain})
-         if defined $config{usertag_package_domain};
-}
-
-
 # walk through the keys and make the right get_bugs query.
 
 my $form_option_variables = {};
@@ -324,8 +378,8 @@ my @temp = @package_search_key_order;
 while (my ($key,$value) = splice @temp, 0, 2) {
      next unless exists $param{$key};
      my @entries = ();
-     $param{$key} = [map {split /\s*,\s*/} make_list($param{$key})];
      for my $entry (make_list($param{$key})) {
+         # we'll handle newest below
          my $extra = '';
          if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
               my %versions = get_versions(package => $entry,
@@ -334,6 +388,7 @@ while (my ($key,$value) = splice @temp, 0, 2) {
                                           ($key eq 'src'?(arch => q(source)):()),
                                           no_source_arch => 1,
                                           return_archs => 1,
+                                          @schema_arg,
                                          );
               my $verdesc;
               if (keys %versions > 1) {
@@ -350,39 +405,48 @@ while (my ($key,$value) = splice @temp, 0, 2) {
               }
               $extra= " ($verdesc)" if keys %versions;
          }
-         push @entries, $entry.$extra;
+         if ($key eq 'maint' and $entry eq '') {
+              push @entries, "no one (packages without maintainers)"
+         }
+         else {
+              push @entries, $entry.$extra;
+         }
+     }
+     if ($key eq 'newest') {
+        push @title, 'in '.join(' or ',@entries).' newest reports';
+     } else {
+        push @title,$value.' '.join(' or ', @entries) if @entries;
      }
-     push @title,$value.' '.join(' or ', @entries);
 }
+
 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
 @title = ();
 
-# we have to special case the maint="" search, unfortunatly.
-if (defined $param{maint} and $param{maint} eq "" or ref($param{maint}) and not @{$param{maint}}) {
-     my %maintainers = %{getmaintainers()};
-     @bugs = get_bugs(function =>
-                     sub {my %d=@_;
-                          foreach my $try (splitpackages($d{"pkg"})) {
-                               return 1 if not exists $maintainers{$try};
-                          }
-                          return 0;
-                     }
-                    );
-     $title = $gBugs.' in packages with no maintainer';
-}
-elsif (defined $param{newest}) {
-     my $newest_bug = newest_bug();
-     @bugs = ($newest_bug - $param{newest} + 1) .. $newest_bug;
-     $title = @bugs.' newest '.$gBugs;
-}
-else {
-     #yeah for magick!
-     @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
-                      keys %package_search_keys, 'archive'),
-                     usertags => \%ut,
-                    );
+#yeah for magick!
+@bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
+                 keys %package_search_keys, 'archive'),
+                usertags => \%ut,
+                @schema_arg,
+               );
+
+# shove in bugs which affect this package if there is a package or a
+# source given (by default), but no affects options given
+if (not exists $param{affects} and not exists $param{noaffects} and
+    (exists $param{src} or
+     exists $param{package})) {
+    push @bugs, get_bugs((map {my $key = $_;
+                              exists $param{$key}?($key =~ /^(?:package|src)$/?'affects':$key,
+                                                 ($key eq 'src'?[map {"src:$_"}make_list($param{$key})]:$param{$_})):()}
+                         grep {$_ ne 'newest'}
+                         keys %package_search_keys, 'archive'),
+                        usertags => \%ut,
+                        @schema_arg,
+                       );
 }
 
+# filter out included or excluded bugs
+
+
 if (defined $param{version}) {
      $title .= " at version $param{version}";
 }
@@ -407,7 +471,17 @@ my %bugs;
 @bugs{@bugs} = @bugs;
 @bugs = keys %bugs;
 
-my $result = pkg_htmlizebugs(bugs => \@bugs,
+my $bugs = Debbugs::Collection::Bug->
+    new(bugs => \@bugs,
+       @schema_arg,
+       users => [map {my $u = Debbugs::User->new($_);
+                      $u->has_bug_tags()?($u):()
+                  } @users],
+       );
+
+$bugs->load_related_packages_and_versions();
+
+my $result = pkg_htmlizebugs(bugs => $bugs,
                             names => \@names,
                             title => \@title,
                             order => \@order,
@@ -421,8 +495,11 @@ my $result = pkg_htmlizebugs(bugs => \@bugs,
                             exclude => $exclude,
                             this => $this,
                             options => \%param,
+                             @schema_arg,
+                            (exists $param{dist})?(dist    => $param{dist}):(),
                            );
 
+print "Cache-Control: public, max-age=300\n";
 print "Content-Type: text/html; charset=utf-8\n\n";
 
 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
@@ -432,6 +509,7 @@ print "<HTML><HEAD>\n" .
     "</HEAD>\n" .
     '<BODY onload="pagemain();">' .
     "\n";
+print qq(<DIV id="status_mask"></DIV>\n);
 print "<H1>" . "$gProject$Archived $gBug report logs: $title" .
       "</H1>\n";
 
@@ -445,13 +523,14 @@ if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {
      delete $param{dist};
 }
 
-# output infomration about the packages
+# output information about the packages
 
 for my $package (make_list($param{package}||[])) {
      print generate_package_info(binary => 1,
                                 package => $package,
                                 options => \%param,
                                 bugs    => \@bugs,
+                                @schema_arg,
                                );
 }
 for my $package (make_list($param{src}||[])) {
@@ -459,6 +538,7 @@ for my $package (make_list($param{src}||[])) {
                                 package => $package,
                                 options => \%param,
                                 bugs    => \@bugs,
+                                @schema_arg,
                                );
 }
 
@@ -473,145 +553,25 @@ if (exists $param{submitter}) {
     print "different addresses.\n";
 }
 
-# my $archive_links;
-# my @archive_links;
-# my %archive_values = (both => 'archived and unarchived',
-#                    0    => 'not archived',
-#                    1    => 'archived',
-#                   );
-# while (my ($key,$value) = each %archive_values) {
-#      next if $key eq lc($param{archive});
-#      push @archive_links, qq(<a href=").
-#        html_escape(pkg_url((
-#                     map {
-#                          $_ eq 'archive'?():($_,$param{$_})
-#                     } keys %param),
-#                          archive => $key
-#                         )).qq(">$value reports </a>);
-# }
-# print '<p>See the '.join (' or ',@archive_links)."</p>\n";
-
 print $result;
 
-print pkg_javascript() . "\n";
+print fill_in_template(template=>'cgi/pkgreport_javascript');
 
 print qq(<h2 class="outstanding"><!--<a class="options" href="javascript:toggle(1)">-->Options<!--</a>--></h2>\n);
 
+$param{orderings} =
+    [uniq((grep {!$hidden{$_}} keys %cats),
+         $param{ordering})];
 print option_form(template => 'cgi/pkgreport_options',
                  param    => \%param,
                  form_options => $form_options,
                  variables => $form_option_variables,
                 );
 
-# print "<h2 class=\"outstanding\"><a class=\"options\" href=\"javascript:toggle(1)\">Options</a></h2>\n";
-# print "<div id=\"a_1\">\n";
-# printf "<form action=\"%s\" method=POST>\n", myurl();
-# 
-# print "<table class=\"forms\">\n";
-# 
-# my ($checked_any, $checked_sui, $checked_ver) = ("", "", "");
-# if (defined $dist) {
-#   $checked_sui = "CHECKED";
-# } elsif (defined $version) {
-#   $checked_ver = "CHECKED";
-# } else {
-#   $checked_any = "CHECKED";
-# }
-# 
-# print "<tr><td>Show bugs applicable to</td>\n";
-# print "    <td><input id=\"b_1_1\" name=vt value=none type=radio onchange=\"enable(1);\" $checked_any>anything</td></tr>\n";
-# print "<tr><td></td>";
-# 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";
-# 
-# if (defined $pkg) {
-#     my $v = html_escape($version) || "";
-#     my $pkgsane = html_escape($pkg->[0]);
-#     print "<tr><td></td>";
-#     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";
-# } elsif (defined $src) {
-#     my $v = html_escape($version) || "";
-#     my $srcsane = html_escape($src->[0]);
-#     print "<tr><td></td>";
-#     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";
-# }
-# print "<tr><td>&nbsp;</td></tr>\n";
-# 
-# my $includetags = html_escape(join(" ", grep { !m/^subj:/i } map {split /[\s,]+/} ref($include)?@{$include}:$include));
-# my $excludetags = html_escape(join(" ", grep { !m/^subj:/i } map {split /[\s,]+/} ref($exclude)?@{$exclude}:$exclude));
-# my $includesubj = html_escape(join(" ", map { s/^subj://i; $_ } grep { m/^subj:/i } map {split /[\s,]+/} ref($include)?@{$include}:$include));
-# my $excludesubj = html_escape(join(" ", map { s/^subj://i; $_ } grep { m/^subj:/i } map {split /[\s,]+/} ref($exclude)?@{$exclude}:$exclude));
-# my $vismindays = ($mindays == 0 ? "" : $mindays);
-# my $vismaxdays = ($maxdays == -1 ? "" : $maxdays);
-# 
-# my $sel_rmy = ($param{repeatmerged} ? " selected" : "");
-# my $sel_rmn = ($param{repeatmerged} ? "" : " selected");
-# my $sel_ordraw = ($ordering eq "raw" ? " selected" : "");
-# my $sel_ordold = ($ordering eq "oldview" ? " selected" : "");
-# my $sel_ordnor = ($ordering eq "normal" ? " selected" : "");
-# my $sel_ordage = ($ordering eq "age" ? " selected" : "");
-# 
-# my $chk_bugrev = ($bug_rev ? " checked" : "");
-# my $chk_pendrev = ($pend_rev ? " checked" : "");
-# my $chk_sevrev = ($sev_rev ? " checked" : "");
-# 
-# print <<EOF;
-# <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>
-# <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>
-# <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>
-# 
-# <tr><td>&nbsp;</td></tr>
-# 
-# <tr><td>Merged bugs should be</td><td>
-# <select name=repeatmerged>
-# <option value=yes$sel_rmy>displayed separately</option>
-# <option value=no$sel_rmn>combined</option>
-# </select>
-# <tr><td>Categorise bugs by</td><td>
-# <select name=ordering>
-# <option value=raw$sel_ordraw>bug number only</option>
-# <option value=old$sel_ordold>status and severity</option>
-# <option value=normal$sel_ordnor>status, severity and classification</option>
-# <option value=age$sel_ordage>status, severity, classification, and age</option>
-# EOF
-# 
-# {
-# my $any = 0;
-# my $o = $param{"ordering"} || "";
-# for my $n (keys %cats) {
-#     next if ($n eq "normal" || $n eq "oldview");
-#     next if defined $hidden{$n};
-#     unless ($any) {
-#         $any = 1;
-#      print "<option disabled>------</option>\n";
-#     }
-#     my @names = map { ref($_) eq "HASH" ? $_->{"nam"} : $_ } @{$cats{$n}};
-#     my $name;
-#     if (@names == 1) { $name = $names[0]; }
-#     else { $name = " and " . pop(@names); $name = join(", ", @names) . $name; }
-# 
-#     printf "<option value=\"%s\"%s>%s</option>\n",
-#         $n, ($o eq $n ? " selected" : ""), $name;
-# }
-# }
-# 
-# print "</select></td></tr>\n";
-# 
-# printf "<tr><td>Order bugs by</td><td>%s</td></tr>\n",
-#     pkg_htmlselectyesno("pend-rev", "outstanding bugs first", "done bugs first", $pend_rev);
-# printf "<tr><td></td><td>%s</td></tr>\n",
-#     pkg_htmlselectyesno("sev-rev", "highest severity first", "lowest severity first", $sev_rev);
-# printf "<tr><td></td><td>%s</td></tr>\n",
-#     pkg_htmlselectyesno("bug-rev", "oldest bugs first", "newest bugs first", $bug_rev);
-# 
-# print <<EOF;
-# <tr><td>&nbsp;</td></tr>
-# <tr><td colspan=2><input value="Reload page" type="submit"> with new settings</td></tr>
-# EOF
-# 
-# print "</table></form></div>\n";
-
 print "<hr>\n";
-print "<p>$tail_html";
-
+print fill_in_template(template=>'html/html_tail',
+                      hole_var => {'&strftime' => \&POSIX::strftime,
+                                  },
+                     );
 print "</body></html>\n";