]> git.donarmstrong.com Git - debbugs.git/blob - cgi/pkgindex.cgi
855e3fb8599e1fa89b084ef9934b5da86f0b9015
[debbugs.git] / cgi / pkgindex.cgi
1 #!/usr/bin/perl -wT
2
3 use warnings;
4 use strict;
5 use POSIX qw(strftime nice);
6
7 use Debbugs::Config qw(:globals :text :config);
8 use CGI::Simple;
9 use Debbugs::CGI qw(:util :url :html);
10 use Debbugs::Common qw(getmaintainers getparsedaddrs);
11 use Debbugs::Bugs qw(count_bugs);
12 use Debbugs::Status qw(:status);
13 use Debbugs::Packages qw(getpkgsrc);
14 use Debbugs::Text qw(:templates);
15
16 nice(5);
17
18 my $q = new CGI::Simple;
19 my %param = cgi_parameters(query   => $q,
20                            single  => [qw(indexon repeatmerged archive sortby),
21                                        qw(skip max_results first),
22                                       ],
23                            default => {indexon      => 'pkg',
24                                        repeatmerged => 'yes',
25                                        archive      => 'no',
26                                        sortby       => 'alpha',
27                                        skip         => 0,
28                                        max_results  => 100,
29                                       },
30                           );
31
32 if (defined $param{first}) {
33      # rip out all non-words from first
34      $param{first} =~ s/\W//g;
35 }
36 if (defined $param{next}) {
37      $param{skip}+=$param{max_results};
38 }
39 elsif (defined $param{prev}) {
40      $param{skip}-=$param{max_results};
41      $param{skip} = 0 if $param{skip} < 0;
42 }
43
44 my $indexon = $param{indexon};
45 if ($param{indexon} !~ m/^(pkg|src|maint|submitter|tag)$/) {
46     quitcgi("You have to choose something to index on");
47 }
48
49 my $repeatmerged = $param{repeatmerged} eq 'yes';
50 my $archive = $param{archive} eq "yes";
51 my $sortby = $param{sortby};
52 if ($sortby !~ m/^(alpha|count)$/) {
53     quitcgi("Don't know how to sort like that");
54 }
55
56 my $Archived = $archive ? " Archived" : "";
57
58 my %maintainers = %{&getmaintainers()};
59 my %strings = ();
60
61 my $dtime = strftime "%a, %e %b %Y %T UTC", gmtime;
62
63 my %count;
64 my $tag;
65 my $note;
66 my %htmldescrip = ();
67 my %sortkey = ();
68 if ($indexon eq "pkg") {
69   $tag = "package";
70   %count = count_bugs(function => sub {my %d=@_; return splitpackages($d{"pkg"})});
71   if (defined $param{first}) {
72        %count = map {
73             if (/^\Q$param{first}\E/) {
74                  ($_,$count{$_});
75             }
76             else {
77                  ();
78             } 
79        } keys %count;
80   }
81   $note = "<p>Note that with multi-binary packages there may be other\n";
82   $note .= "reports filed under the different binary package names.</p>\n";
83   foreach my $pkg (keys %count) {
84     $sortkey{$pkg} = lc $pkg;
85     $htmldescrip{$pkg} = sprintf('<a href="%s">%s</a> (%s)',
86                            package_links(package => $pkg, links_only=>1),
87                            html_escape($pkg),
88                            htmlize_maintlinks(sub { $_[0] == 1 ? 'maintainer: '
89                                                            : 'maintainers: ' },
90                                           $maintainers{$pkg}));
91   }
92 } elsif ($indexon eq "src") {
93   $tag = "source package";
94   my $pkgsrc = getpkgsrc();
95   if (defined $param{first}) {
96        %count = map {
97             if (/^\Q$param{first}\E/) {
98                  ($_,$count{$_});
99             }
100             else {
101                  ();
102             } 
103        } keys %count;
104   }
105   %count = count_bugs(function => sub {my %d=@_;
106                           return map {
107                             $pkgsrc->{$_} || $_
108                           } splitpackages($d{"pkg"});
109                          });
110   $note = "";
111   foreach my $src (keys %count) {
112     $sortkey{$src} = lc $src;
113     $htmldescrip{$src} = sprintf('<a href="%s">%s</a> (%s)',
114                            package_links(src => $src, links_only=>1),
115                            html_escape($src),
116                            htmlize_maintlinks(sub { $_[0] == 1 ? 'maintainer: '
117                                                            : 'maintainers: ' },
118                                           $maintainers{$src}));
119   }
120 } elsif ($indexon eq "maint") {
121   $tag = "maintainer";
122   my %email2maint = ();
123   %count = count_bugs(function => sub {my %d=@_;
124                           return map {
125                             my @me = getparsedaddrs($maintainers{$_});
126                             foreach my $addr (@me) {
127                               $email2maint{$addr->address} = $addr->format
128                                 unless exists $email2maint{$addr->address};
129                             }
130                             map { $_->address } @me;
131                           } splitpackages($d{"pkg"});
132                          });
133   if (defined $param{first}) {
134        %count = map {
135             if (/^\Q$param{first}\E/) {
136                  ($_,$count{$_});
137             }
138             else {
139                  ();
140             } 
141        } keys %count;
142   }
143   $note = "<p>Note that maintainers may use different Maintainer fields for\n";
144   $note .= "different packages, so there may be other reports filed under\n";
145   $note .= "different addresses.</p>\n";
146   foreach my $maint (keys %count) {
147     $sortkey{$maint} = lc $email2maint{$maint} || "(unknown)";
148     $htmldescrip{$maint} = htmlize_maintlinks('', $email2maint{$maint});
149   }
150 } elsif ($indexon eq "submitter") {
151   $tag = "submitter";
152   my %fullname = ();
153   %count = count_bugs(function => sub {my %d=@_;
154                           my @se = getparsedaddrs($d{"submitter"} || "");
155                           foreach my $addr (@se) {
156                             $fullname{$addr->address} = $addr->format
157                               unless exists $fullname{$addr->address};
158                           }
159                           map { $_->address } @se;
160                          });
161   if (defined $param{first}) {
162        %count = map {
163             if (/^\Q$param{first}\E/) {
164                  ($_,$count{$_});
165             }
166             else {
167                  ();
168             } 
169        } keys %count;
170   }
171   foreach my $sub (keys %count) {
172     $sortkey{$sub} = lc $fullname{$sub};
173     $htmldescrip{$sub} = sprintf('<a href="%s">%s</a>',
174                            submitterurl($sub),
175                            html_escape($fullname{$sub}));
176   }
177   $note = "<p>Note that people may use different email accounts for\n";
178   $note .= "different bugs, so there may be other reports filed under\n";
179   $note .= "different addresses.</p>\n";
180 } elsif ($indexon eq "tag") {
181   $tag = "tag";
182   %count = count_bugs(function => sub {my %d=@_; return split ' ', $d{tags}; });
183   if (defined $param{first}) {
184        %count = map {
185             if (/^\Q$param{first}\E/) {
186                  ($_,$count{$_});
187             }
188             else {
189                  ();
190             } 
191        } keys %count;
192   }
193   $note = "";
194   foreach my $keyword (keys %count) {
195     $sortkey{$keyword} = lc $keyword;
196     $htmldescrip{$keyword} = sprintf('<a href="%s">%s</a>',
197                                tagurl($keyword),
198                                html_escape($keyword));
199   }
200 }
201
202 my $result = "<ul>\n";
203 my @orderedentries;
204 if ($sortby eq "count") {
205   @orderedentries = sort { $count{$a} <=> $count{$b} } keys %count;
206 } else { # sortby alpha
207   @orderedentries = sort { $sortkey{$a} cmp $sortkey{$b} } keys %count;
208 }
209 my $skip = $param{skip};
210 my $max_results = $param{max_results};
211 foreach my $x (@orderedentries) {
212      if (not defined $param{first}) {
213           $skip-- and next if $skip > 0;
214           last if --$max_results < 0;
215      }
216   $result .= "<li>" . $htmldescrip{$x} . " has $count{$x} " .
217             ($count{$x} == 1 ? "bug" : "bugs") . "</li>\n";
218 }
219 $result .= "</ul>\n";
220
221 print "Content-Type: text/html\n\n";
222
223 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
224 print "<HTML><HEAD>\n" . 
225     "<TITLE>$gProject$Archived $gBug reports by $tag</TITLE>\n" .
226     qq(<LINK REL="stylesheet" HREF="$gWebHostBugDir/css/bugs.css" TYPE="text/css">) .
227     "</HEAD>\n" .
228     '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
229     "\n";
230 print "<H1>" . "$gProject$Archived $gBug report logs by $tag" .
231       "</H1>\n";
232
233 print $note;
234 print <<END;
235 <form>
236 <input type="hidden" name="skip" value="$param{skip}">
237 <input type="hidden" name="max_results" value="$param{max_results}">
238 <input type="hidden" name="indexon" value="$param{indexon}">
239 <input type="hidden" name="repeatmerged" value="$param{repeatmerged}">
240 <input type="hidden" name="archive" value="$param{archive}">
241 <input type="hidden" name="sortby" value="$param{sortby}">
242 END
243 if (defined $param{first}) {
244      print qq(<input type="hidden" name="first" value="$param{first}">\n);
245 }
246 else {
247      print q(<p>);
248      if ($param{skip} > 0) {
249           print q(<input type="submit" name="prev" value="Prev">);
250      }
251      if (keys %count > ($param{skip} + $param{max_results})) {
252           print q(<input type="submit" name="next" value="Next">);
253      }
254      print qq(</p>\n);
255 }
256 print $result;
257
258 print "<hr>\n";
259 print fill_in_template(template=>'html/html_tail',
260                        hole_var => {'&strftime' => \&POSIX::strftime,
261                                    },
262                       );
263 print "</body></html>\n";