]> git.donarmstrong.com Git - debbugs.git/blob - cgi/pkgreport.cgi
Merge branch 'mouseify'
[debbugs.git] / cgi / pkgreport.cgi
1 #!/usr/bin/perl -T
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.
6 #
7 # [Other people have contributed to this file; their copyrights should
8 # go here too.]
9 # Copyright 2004-2006 by Anthony Towns <ajt@debian.org>
10 # Copyright 2007 by Don Armstrong <don@donarmstrong.com>.
11
12
13 use warnings;
14 use strict;
15
16 # Sanitize environent for taint
17 BEGIN{
18     delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
19 }
20
21 # if we're running out of git, we want to use the git base directory as the
22 # first INC directory. If you're not running out of git, don't do that.
23 use File::Basename qw(dirname);
24 use Cwd qw(abs_path);
25 our $debbugs_dir;
26 BEGIN {
27     $debbugs_dir =
28         abs_path(dirname(abs_path(__FILE__)) . '/../');
29     # clear the taint; we'll assume that the absolute path to __FILE__ is the
30     # right path if there's a .git directory there
31     ($debbugs_dir) = $debbugs_dir =~ /([[:print:]]+)/;
32     if (defined $debbugs_dir and
33         -d $debbugs_dir . '/.git/') {
34     } else {
35         undef $debbugs_dir;
36     }
37     # if the first directory in @INC is not an absolute directory, assume that
38     # someone has overridden us via -I.
39     if ($INC[0] !~ /^\//) {
40         undef $debbugs_dir;
41     }
42 }
43 use if defined $debbugs_dir, lib => $debbugs_dir;
44
45 binmode(STDOUT,':encoding(UTF-8)');
46 use POSIX qw(strftime nice);
47 use List::AllUtils qw(uniq);
48
49 use Debbugs::Config qw(:globals :text :config);
50
51 use Debbugs::User;
52
53 use Debbugs::Common qw(getparsedaddrs make_list getmaintainers getpseudodesc);
54
55 use Debbugs::Bugs qw(get_bugs bug_filter newest_bug);
56 use Debbugs::Packages qw(source_to_binary binary_to_source get_versions);
57 use Debbugs::Collection::Bug;
58
59 use Debbugs::Status qw(splitpackages);
60
61 use Debbugs::CGI qw(:all);
62
63 use Debbugs::CGI::Pkgreport qw(:all);
64
65 use Debbugs::Text qw(:templates);
66
67 use Debbugs::DB;
68
69 my $s;
70 my @schema_arg = ();
71 if (defined $config{database}) {
72     $s = Debbugs::DB->connect($config{database}) or
73         die "Unable to connect to DB";
74     @schema_arg = ('schema',$s);
75 }
76
77 use CGI::Simple;
78 my $q = new CGI::Simple;
79
80 if ($q->request_method() eq 'HEAD') {
81      print $q->header(-type => "text/html",
82                       -charset => 'utf-8',
83                      );
84      exit 0;
85 }
86
87 my $default_params = {ordering => 'normal',
88                       archive  => 0,
89                       repeatmerged => 0,
90                       include      => [],
91                       exclude      => [],
92                      };
93
94 our %param = cgi_parameters(query => $q,
95                             single => [qw(ordering archive repeatmerged),
96                                        qw(bug-rev pend-rev sev-rev),
97                                        qw(maxdays mindays version),
98                                        qw(data which dist),
99                                        qw(noaffects),
100                                       ],
101                             default => $default_params,
102                            );
103
104 my ($form_options,$param) = ({},undef);
105 ($form_options,$param)= form_options_and_normal_param(\%param)
106      if $param{form_options};
107
108 %param = %{$param} if defined $param;
109
110 if (exists $param{form_options} and defined $param{form_options}) {
111      delete $param{form_options};
112      delete $param{submit} if exists $param{submit};
113      for my $default (keys %{$default_params}) {
114           if (exists $param{$default} and
115               not ref($default_params->{$default}) and
116               $default_params->{$default} eq $param{$default}
117              ) {
118                delete $param{$default};
119           }
120      }
121      for my $incexc (qw(include exclude)) {
122           next unless exists $param{$incexc};
123           # normalize tag to tags
124           $param{$incexc} = [map {s/^tag:/tags:/; $_} grep /\S\:\S/, make_list($param{$incexc})];
125      }
126      for my $key (keys %package_search_keys) {
127           next unless exists $param{key};
128           $param{$key} = [map {split /\s*,\s*/} make_list($param{$key})];
129      }
130      # kill off keys for which empty values are meaningless
131      for my $key (qw(package src submitter affects severity status dist)) {
132           next unless exists $param{$key};
133           $param{$key} = [grep {defined $_ and length $_}
134                           make_list($param{$key})];
135      }
136      print $q->redirect(munge_url('pkgreport.cgi?',%param));
137      exit 0;
138 }
139
140 # normalize innclude/exclude keys; currently this is in two locations,
141 # which is suboptimal. Closes: #567407
142 for my $incexc (qw(include exclude)) {
143     next unless exists $param{$incexc};
144     # normalize tag to tags
145     $param{$incexc} = [map {s/^tag:/tags:/; $_} make_list($param{$incexc})];
146 }
147
148
149
150 # map from yes|no to 1|0
151 for my $key (qw(repeatmerged bug-rev pend-rev sev-rev)) {
152      if (exists $param{$key}){
153           if ($param{$key} =~ /^no$/i) {
154                $param{$key} = 0;
155           }
156           elsif ($param{$key}) {
157                $param{$key} = 1;
158           }
159      }
160 }
161
162 if (lc($param{archive}) eq 'no') {
163      $param{archive} = 0;
164 }
165 elsif (lc($param{archive}) eq 'yes') {
166      $param{archive} = 1;
167 }
168
169 # fixup dist
170 if (exists $param{dist} and $param{dist} eq '') {
171      delete $param{dist};
172 }
173
174 my $include = $param{'&include'} || $param{'include'} || "";
175 my $exclude = $param{'&exclude'} || $param{'exclude'} || "";
176
177 my $users = $param{'users'} || "";
178
179 my $ordering = $param{'ordering'};
180 my $raw_sort = ($param{'raw'} || "no") eq "yes";
181 my $old_view = ($param{'oldview'} || "no") eq "yes";
182 my $age_sort = ($param{'age'} || "no") eq "yes";
183 unless (defined $ordering) {
184    $ordering = "normal";
185    $ordering = "oldview" if $old_view;
186    $ordering = "raw" if $raw_sort;
187    $ordering = 'age' if $age_sort;
188 }
189 $param{ordering} = $ordering;
190
191 our ($bug_order) = $ordering =~ /(age(?:rev)?)/;
192 $bug_order = '' if not defined $bug_order;
193
194 my $bug_rev = ($param{'bug-rev'} || "no") eq "yes";
195 my $pend_rev = ($param{'pend-rev'} || "no") eq "yes";
196 my $sev_rev = ($param{'sev-rev'} || "no") eq "yes";
197
198 my @inc_exc_mapping = ({name   => 'pending',
199                         incexc => 'include',
200                         key    => 'pend-inc',
201                        },
202                        {name   => 'pending',
203                         incexc => 'exclude',
204                         key    => 'pend-exc',
205                        },
206                        {name   => 'severity',
207                         incexc => 'include',
208                         key    => 'sev-inc',
209                        },
210                        {name   => 'severity',
211                         incexc => 'exclude',
212                         key    => 'sev-exc',
213                        },
214                        {name   => 'subject',
215                         incexc => 'include',
216                         key    => 'includesubj',
217                        },
218                        {name   => 'subject',
219                         incexc => 'exclude',
220                         key    => 'excludesubj',
221                        },
222                       );
223 for my $incexcmap (@inc_exc_mapping) {
224      push @{$param{$incexcmap->{incexc}}}, map {"$incexcmap->{name}:$_"}
225           map{split /\s*,\s*/} make_list($param{$incexcmap->{key}})
226                if exists $param{$incexcmap->{key}};
227      delete $param{$incexcmap->{key}};
228 }
229
230
231 my $maxdays = ($param{'maxdays'} || -1);
232 my $mindays = ($param{'mindays'} || 0);
233 my $version = $param{'version'} || undef;
234
235
236 our %hidden = map { $_, 1 } qw(status severity classification);
237 our %cats = (
238     "status" => [ {
239         "nam" => "Status",
240         "pri" => [map { "pending=$_" }
241             qw(pending forwarded pending-fixed fixed done absent)],
242         "ttl" => ["Outstanding","Forwarded","Pending Upload",
243                   "Fixed in NMU","Resolved","From other Branch"],
244         "def" => "Unknown Pending Status",
245         "ord" => [0,1,2,3,4,5,6],
246     } ],
247     "severity" => [ {
248         "nam" => "Severity",
249         "pri" => [map { "severity=$_" } @gSeverityList],
250         "ttl" => [map { $gSeverityDisplay{$_} } @gSeverityList],
251         "def" => "Unknown Severity",
252         "ord" => [0..@gSeverityList],
253     } ],
254     "classification" => [ {
255         "nam" => "Classification",
256         "pri" => [qw(pending=pending+tag=wontfix 
257                      pending=pending+tag=moreinfo
258                      pending=pending+tag=patch
259                      pending=pending+tag=confirmed
260                      pending=pending)],
261         "ttl" => ["Will Not Fix","More information needed",
262                   "Patch Available","Confirmed"],
263         "def" => "Unclassified",
264         "ord" => [2,3,4,1,0,5],
265     } ],
266     "oldview" => [ qw(status severity) ],
267              "normal" => [ qw(status severity classification) ],
268              raw => [{nam => 'Raw',def => 'Raw'}],
269 );
270
271 if (exists $param{which} and exists $param{data}) {
272      $param{$param{which}} = [exists $param{$param{which}}?(make_list($param{$param{which}})):(),
273                               make_list($param{data}),
274                              ];
275      delete $param{which};
276      delete $param{data};
277 }
278
279 if (defined $param{maintenc}) {
280      $param{maint} = maint_decode($param{maintenc});
281      delete $param{maintenc}
282 }
283
284 if (exists $param{pkg}) {
285      $param{package} = $param{pkg};
286      delete $param{pkg};
287 }
288
289 if (not grep {exists $param{$_}} keys %package_search_keys and exists $param{users}) {
290      $param{usertag} = [make_list($param{users})];
291 }
292
293 my %bugusertags;
294 my %ut;
295 my %seen_users;
296
297 my @users;
298 for my $user (map {split /[\s*,\s*]+/} make_list($param{users}||[])) {
299     next unless length($user);
300     push @users, $user;
301     add_user($user,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
302 }
303
304 if (defined $param{usertag}) {
305      for my $usertag (make_list($param{usertag})) {
306           my %select_ut = ();
307           my ($u, $t) = split /:/, $usertag, 2;
308           Debbugs::User::read_usertags(\%select_ut, $u);
309           unless (defined $t && $t ne "") {
310                $t = join(",", keys(%select_ut));
311            }
312           push @users,$u;
313           add_user($u,\%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
314           push @{$param{tag}}, split /,/, $t;
315      }
316 }
317
318 quitcgi("You have to choose something to select by", '400 Bad Request')
319   unless grep {exists $param{$_}} keys %package_search_keys;
320
321
322 my $Archived = $param{archive} ? " Archived" : "";
323
324 my $this = munge_url('pkgreport.cgi?',
325                       %param,
326                      );
327
328 my %indexentry;
329 my %strings = ();
330
331 my @bugs;
332
333 # addusers for source and binary packages being searched for
334 if (defined $config{usertag_package_domain}) {
335     my @possible_packages;
336     if (exists $param{package} and
337         defined $param{package}
338        ) {
339         # For binary packages, add the binary package and corresponding source package
340         push @possible_packages,
341             make_list($param{package});
342         push @possible_packages,
343             binary_to_source(source_only => 1,
344                              binary=>$param{package},
345                              @schema_arg,
346                             );
347     }
348     if (exists $param{src} and
349         defined $param{src}
350        ) {
351         # For source packages, add the source package and corresponding binary packages
352         push @possible_packages,
353             make_list($param{src});
354         push @possible_packages,
355             source_to_binary(binary_only => 1,
356                              source => $param{src},
357                              dist => [@{$config{distributions}}],
358                              @schema_arg,
359                             );
360     }
361     for my $package (@possible_packages) {
362         next unless defined $package and length $package;
363         push @users,
364             $package.'@'.$config{usertag_package_domain};
365         add_user($package.'@'.$config{usertag_package_domain},
366                  \%ut,\%bugusertags,\%seen_users,\%cats,\%hidden);
367     }
368 }
369
370 # walk through the keys and make the right get_bugs query.
371
372 my $form_option_variables = {};
373 $form_option_variables->{search_key_order} = [@package_search_key_order];
374
375 # Set the title sanely and clean up parameters
376 my @title;
377 my @temp = @package_search_key_order;
378 while (my ($key,$value) = splice @temp, 0, 2) {
379      next unless exists $param{$key};
380      my @entries = ();
381      for my $entry (make_list($param{$key})) {
382           # we'll handle newest below
383           my $extra = '';
384           if (exists $param{dist} and ($key eq 'package' or $key eq 'src')) {
385                my %versions = get_versions(package => $entry,
386                                            (exists $param{dist}?(dist => $param{dist}):()),
387                                            (exists $param{arch}?(arch => $param{arch}):(arch => $config{default_architectures})),
388                                            ($key eq 'src'?(arch => q(source)):()),
389                                            no_source_arch => 1,
390                                            return_archs => 1,
391                                            @schema_arg,
392                                           );
393                my $verdesc;
394                if (keys %versions > 1) {
395                     $verdesc = 'versions '. join(', ',
396                                     map { $_ .' ['.join(', ',
397                                                     sort @{$versions{$_}}
398                                                    ).']';
399                                    } keys %versions);
400                }
401                else {
402                     $verdesc = 'version '.join(', ',
403                                                keys %versions
404                                               );
405                }
406                $extra= " ($verdesc)" if keys %versions;
407           }
408           if ($key eq 'maint' and $entry eq '') {
409                push @entries, "no one (packages without maintainers)"
410           }
411           else {
412                push @entries, $entry.$extra;
413           }
414      }
415      if ($key eq 'newest') {
416          push @title, 'in '.join(' or ',@entries).' newest reports';
417      } else {
418          push @title,$value.' '.join(' or ', @entries) if @entries;
419      }
420 }
421
422 my $title = $gBugs.' '.join(' and ', map {/ or /?"($_)":$_} @title);
423 @title = ();
424
425 #yeah for magick!
426 @bugs = get_bugs((map {exists $param{$_}?($_,$param{$_}):()}
427                   keys %package_search_keys, 'archive'),
428                  usertags => \%ut,
429                  @schema_arg,
430                 );
431
432 # shove in bugs which affect this package if there is a package or a
433 # source given (by default), but no affects options given
434 if (not exists $param{affects} and not exists $param{noaffects} and
435     (exists $param{src} or
436      exists $param{package})) {
437     push @bugs, get_bugs((map {my $key = $_;
438                                exists $param{$key}?($key =~ /^(?:package|src)$/?'affects':$key,
439                                                   ($key eq 'src'?[map {"src:$_"}make_list($param{$key})]:$param{$_})):()}
440                           grep {$_ ne 'newest'}
441                           keys %package_search_keys, 'archive'),
442                          usertags => \%ut,
443                          @schema_arg,
444                         );
445 }
446
447 # filter out included or excluded bugs
448
449
450 if (defined $param{version}) {
451      $title .= " at version $param{version}";
452 }
453 elsif (defined $param{dist}) {
454      $title .= " in $param{dist}";
455 }
456
457 $title = html_escape($title);
458
459 my @names; my @prior; my @order;
460 determine_ordering(cats => \%cats,
461                    param => \%param,
462                    ordering => \$ordering,
463                    names => \@names,
464                    prior => \@prior,
465                    title => \@title,
466                    order => \@order,
467                   );
468
469 # strip out duplicate bugs
470 my %bugs;
471 @bugs{@bugs} = @bugs;
472 @bugs = keys %bugs;
473
474 my $bugs = Debbugs::Collection::Bug->
475     new(bugs => \@bugs,
476         @schema_arg,
477         users => [map {my $u = Debbugs::User->new($_);
478                        $u->has_bug_tags()?($u):()
479                    } @users],
480        );
481
482 $bugs->load_related_packages_and_versions();
483
484 my $result = pkg_htmlizebugs(bugs => $bugs,
485                              names => \@names,
486                              title => \@title,
487                              order => \@order,
488                              prior => \@prior,
489                              ordering => $ordering,
490                              bugusertags => \%bugusertags,
491                              bug_rev => $bug_rev,
492                              bug_order => $bug_order,
493                              repeatmerged => $param{repeatmerged},
494                              include => $include,
495                              exclude => $exclude,
496                              this => $this,
497                              options => \%param,
498                              @schema_arg,
499                              (exists $param{dist})?(dist    => $param{dist}):(),
500                             );
501
502 print "Cache-Control: public, max-age=300\n";
503 print "Content-Type: text/html; charset=utf-8\n\n";
504
505 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
506 print "<HTML><HEAD>\n" . 
507     "<TITLE>$title -- $gProject$Archived $gBug report logs</TITLE>\n" .
508     qq(<link rel="stylesheet" href="$gWebHostBugDir/css/bugs.css" type="text/css">) .
509     "</HEAD>\n" .
510     '<BODY onload="pagemain();">' .
511     "\n";
512 print qq(<DIV id="status_mask"></DIV>\n);
513 print "<H1>" . "$gProject$Archived $gBug report logs: $title" .
514       "</H1>\n";
515
516 my $showresult = 1;
517
518 my $pkg = $param{package} if defined $param{package};
519 my $src = $param{src} if defined $param{src};
520
521 my $pseudodesc = getpseudodesc();
522 if (defined $pseudodesc and defined $pkg and exists $pseudodesc->{$pkg}) {
523      delete $param{dist};
524 }
525
526 # output information about the packages
527
528 for my $package (make_list($param{package}||[])) {
529      print generate_package_info(binary => 1,
530                                  package => $package,
531                                  options => \%param,
532                                  bugs    => \@bugs,
533                                  @schema_arg,
534                                 );
535 }
536 for my $package (make_list($param{src}||[])) {
537      print generate_package_info(binary => 0,
538                                  package => $package,
539                                  options => \%param,
540                                  bugs    => \@bugs,
541                                  @schema_arg,
542                                 );
543 }
544
545 if (exists $param{maint} or exists $param{maintenc}) {
546     print "<p>Note that maintainers may use different Maintainer fields for\n";
547     print "different packages, so there may be other reports filed under\n";
548     print "different addresses.\n";
549 }
550 if (exists $param{submitter}) {
551     print "<p>Note that people may use different email accounts for\n";
552     print "different bugs, so there may be other reports filed under\n";
553     print "different addresses.\n";
554 }
555
556 print $result;
557
558 print fill_in_template(template=>'cgi/pkgreport_javascript');
559
560 print qq(<h2 class="outstanding"><!--<a class="options" href="javascript:toggle(1)">-->Options<!--</a>--></h2>\n);
561
562 $param{orderings} =
563     [uniq((grep {!$hidden{$_}} keys %cats),
564           $param{ordering})];
565 print option_form(template => 'cgi/pkgreport_options',
566                   param    => \%param,
567                   form_options => $form_options,
568                   variables => $form_option_variables,
569                  );
570
571 print "<hr>\n";
572 print fill_in_template(template=>'html/html_tail',
573                        hole_var => {'&strftime' => \&POSIX::strftime,
574                                    },
575                       );
576 print "</body></html>\n";
577