]> git.donarmstrong.com Git - debbugs.git/blobdiff - cgi/pkgreport.cgi
Merge branch 'mouseify'
[debbugs.git] / cgi / pkgreport.cgi
index d29c3abc7ff56943a7a0a2196be16e5560bda857..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.
@@ -18,10 +18,33 @@ BEGIN{
     delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
 }
 
-# STDOUT should be in utf8 mode
-binmode(STDOUT,':utf8');
+# 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);
 
@@ -30,7 +53,8 @@ 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);
 
@@ -40,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;
 
@@ -61,7 +95,7 @@ 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,
@@ -230,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}) {
@@ -259,8 +294,10 @@ my %bugusertags;
 my %ut;
 my %seen_users;
 
+my @users;
 for my $user (map {split /[\s*,\s*]+/} make_list($param{users}||[])) {
     next unless length($user);
+    push @users, $user;
     add_user($user,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
 }
 
@@ -271,13 +308,15 @@ if (defined $param{usertag}) {
          Debbugs::User::read_usertags(\%select_ut, $u);
          unless (defined $t && $t ne "") {
               $t = join(",", keys(%select_ut));
-         }
+          }
+         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" : "";
@@ -292,28 +331,42 @@ my %strings = ();
 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},
-             \%ut,\%bugusertags,\%seen_users,\%cats,\%hidden)
-         if defined $config{usertag_package_domain};
+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,
+                           );
+    }
+    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,
+                           );
+    }
+    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);
+    }
 }
 
-
 # walk through the keys and make the right get_bugs query.
 
 my $form_option_variables = {};
@@ -327,7 +380,6 @@ while (my ($key,$value) = splice @temp, 0, 2) {
      my @entries = ();
      for my $entry (make_list($param{$key})) {
          # we'll handle newest below
-         next if $key eq 'newest';
          my $extra = '';
          if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
               my %versions = get_versions(package => $entry,
@@ -336,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) {
@@ -359,15 +412,11 @@ while (my ($key,$value) = splice @temp, 0, 2) {
               push @entries, $entry.$extra;
          }
      }
-     push @title,$value.' '.join(' or ', @entries) if @entries;
-}
-if (defined $param{newest}) {
-     my $newest_bug = newest_bug();
-     @bugs = ($newest_bug - $param{newest} + 1) .. $newest_bug;
-     push @title, 'in '.@bugs.' newest reports';
-     $param{bugs} = [exists $param{bugs}?make_list($param{bugs}):(),
-                    @bugs,
-                   ];
+     if ($key eq 'newest') {
+        push @title, 'in '.join(' or ',@entries).' newest reports';
+     } else {
+        push @title,$value.' '.join(' or ', @entries) if @entries;
+     }
 }
 
 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
@@ -375,9 +424,9 @@ my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
 
 #yeah for magick!
 @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
-                 grep {$_ ne 'newest'}
                  keys %package_search_keys, 'archive'),
                 usertags => \%ut,
+                @schema_arg,
                );
 
 # shove in bugs which affect this package if there is a package or a
@@ -391,6 +440,7 @@ if (not exists $param{affects} and not exists $param{noaffects} and
                          grep {$_ ne 'newest'}
                          keys %package_search_keys, 'archive'),
                         usertags => \%ut,
+                        @schema_arg,
                        );
 }
 
@@ -421,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,
@@ -435,9 +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";
@@ -468,6 +530,7 @@ for my $package (make_list($param{package}||[])) {
                                 package => $package,
                                 options => \%param,
                                 bugs    => \@bugs,
+                                @schema_arg,
                                );
 }
 for my $package (make_list($param{src}||[])) {
@@ -475,6 +538,7 @@ for my $package (make_list($param{src}||[])) {
                                 package => $package,
                                 options => \%param,
                                 bugs    => \@bugs,
+                                @schema_arg,
                                );
 }
 
@@ -495,6 +559,9 @@ 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,