]> git.donarmstrong.com Git - debbugs.git/blobdiff - cgi/pkgindex.cgi
the libraries are now in the lib directory
[debbugs.git] / cgi / pkgindex.cgi
index 8adbfb86c18714eba413c515d1dd387b2acad717..f0ac8d0b6c86b486ea4c8b993e4777adf155e906 100755 (executable)
@@ -4,12 +4,37 @@ use warnings;
 use strict;
 use POSIX qw(strftime nice);
 
-use Debbugs::Config;
+# 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] !~ /^\//) {
+    }
+}
+use if defined $debbugs_dir, lib => $debbugs_dir.'/lib/';
+
+use Debbugs::Config qw(:globals :text :config);
 use CGI::Simple;
 use Debbugs::CGI qw(:util :url :html);
-use Debbugs::Common qw(getmaintainers);
+use Debbugs::Common qw(getmaintainers getparsedaddrs);
 use Debbugs::Bugs qw(count_bugs);
 use Debbugs::Status qw(:status);
+use Debbugs::Packages qw(getpkgsrc);
+use Debbugs::Text qw(:templates);
 
 nice(5);
 
@@ -41,14 +66,14 @@ elsif (defined $param{prev}) {
 
 my $indexon = $param{indexon};
 if ($param{indexon} !~ m/^(pkg|src|maint|submitter|tag)$/) {
-    quitcgi("You have to choose something to index on");
+    quitcgi("You have to choose something to index on", '400 Bad Request');
 }
 
 my $repeatmerged = $param{repeatmerged} eq 'yes';
 my $archive = $param{archive} eq "yes";
 my $sortby = $param{sortby};
 if ($sortby !~ m/^(alpha|count)$/) {
-    quitcgi("Don't know how to sort like that");
+    quitcgi("Don't know how to sort like that", '400 Bad Request');
 }
 
 my $Archived = $archive ? " Archived" : "";
@@ -57,9 +82,6 @@ my %maintainers = %{&getmaintainers()};
 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/;
 
 my %count;
 my $tag;
@@ -68,7 +90,9 @@ my %htmldescrip = ();
 my %sortkey = ();
 if ($indexon eq "pkg") {
   $tag = "package";
-  %count = count_bugs(function => sub {my %d=@_; return splitpackages($d{"pkg"})});
+  %count = count_bugs(function => sub {my %d=@_; return splitpackages($d{"pkg"})},
+                    archive => $archive,
+                    );
   if (defined $param{first}) {
        %count = map {
            if (/^\Q$param{first}\E/) {
@@ -84,11 +108,9 @@ if ($indexon eq "pkg") {
   foreach my $pkg (keys %count) {
     $sortkey{$pkg} = lc $pkg;
     $htmldescrip{$pkg} = sprintf('<a href="%s">%s</a> (%s)',
-                           pkg_url(pkg => $pkg),
-                           html_escape($pkg),
-                           htmlize_maintlinks(sub { $_[0] == 1 ? 'maintainer: '
-                                                           : 'maintainers: ' },
-                                          $maintainers{$pkg}));
+                                package_links(package => $pkg, links_only=>1),
+                                html_escape($pkg),
+                                package_links(maint=>$maintainers{$pkg}//['']));
   }
 } elsif ($indexon eq "src") {
   $tag = "source package";
@@ -103,20 +125,20 @@ if ($indexon eq "pkg") {
            } 
        } keys %count;
   }
-  %count = countbugs(function => sub {my %d=@_;
+  %count = count_bugs(function => sub {my %d=@_;
                           return map {
                             $pkgsrc->{$_} || $_
                           } splitpackages($d{"pkg"});
-                         });
+                         },
+                    archive => $archive,
+                    );
   $note = "";
   foreach my $src (keys %count) {
     $sortkey{$src} = lc $src;
     $htmldescrip{$src} = sprintf('<a href="%s">%s</a> (%s)',
-                           srcurl($src),
+                           package_links(src => $src, links_only=>1),
                            html_escape($src),
-                           htmlize_maintlinks(sub { $_[0] == 1 ? 'maintainer: '
-                                                           : 'maintainers: ' },
-                                          $maintainers{$src}));
+                                package_links(maint => $maintainers{$src}//['']));
   }
 } elsif ($indexon eq "maint") {
   $tag = "maintainer";
@@ -130,7 +152,9 @@ if ($indexon eq "pkg") {
                             }
                             map { $_->address } @me;
                           } splitpackages($d{"pkg"});
-                         });
+                         },
+                    archive => $archive,
+                    );
   if (defined $param{first}) {
        %count = map {
            if (/^\Q$param{first}\E/) {
@@ -146,7 +170,7 @@ if ($indexon eq "pkg") {
   $note .= "different addresses.</p>\n";
   foreach my $maint (keys %count) {
     $sortkey{$maint} = lc $email2maint{$maint} || "(unknown)";
-    $htmldescrip{$maint} = htmlize_maintlinks('', $email2maint{$maint});
+    $htmldescrip{$maint} = package_links(maint => $email2maint{$maint}//['']);
   }
 } elsif ($indexon eq "submitter") {
   $tag = "submitter";
@@ -158,7 +182,9 @@ if ($indexon eq "pkg") {
                               unless exists $fullname{$addr->address};
                           }
                           map { $_->address } @se;
-                         });
+                         },
+                    archive => $archive,
+                    );
   if (defined $param{first}) {
        %count = map {
            if (/^\Q$param{first}\E/) {
@@ -180,7 +206,9 @@ if ($indexon eq "pkg") {
   $note .= "different addresses.</p>\n";
 } elsif ($indexon eq "tag") {
   $tag = "tag";
-  %count = count_bugs(function => sub {my %d=@_; return split ' ', $d{tags}; });
+  %count = count_bugs(function => sub {my %d=@_; return split ' ', $d{tags}; },
+                     archive => $archive,
+                    );
   if (defined $param{first}) {
        %count = map {
            if (/^\Q$param{first}\E/) {
@@ -221,41 +249,16 @@ $result .= "</ul>\n";
 
 print "Content-Type: text/html\n\n";
 
-print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
-print "<HTML><HEAD>\n" . 
-    "<TITLE>$debbugs::gProject$Archived $debbugs::gBug reports by $tag</TITLE>\n" .
-    "</HEAD>\n" .
-    '<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">' .
-    "\n";
-print "<H1>" . "$debbugs::gProject$Archived $debbugs::gBug report logs by $tag" .
-      "</H1>\n";
-
-print $note;
-print <<END;
-<form>
-<input type="hidden" name="skip" value="$param{skip}">
-<input type="hidden" name="max_results" value="$param{max_results}">
-<input type="hidden" name="indexon" value="$param{indexon}">
-<input type="hidden" name="repeatmerged" value="$param{repeatmerged}">
-<input type="hidden" name="archive" value="$param{archive}">
-<input type="hidden" name="sortby" value="$param{sortby}">
-END
-if (defined $param{first}) {
-     print qq(<input type="hidden" name="first" value="$param{first}">\n);
-}
-else {
-     print q(<p>);
-     if ($param{skip} > 0) {
-         print q(<input type="submit" name="prev" value="Prev">);
-     }
-     if (keys %count > ($param{skip} + $param{max_results})) {
-         print q(<input type="submit" name="next" value="Next">);
-     }
-     print qq(</p>\n);
-}
-print $result;
-
-print "<hr>\n";
-print "<p>$tail_html";
+print fill_in_template(template=>'cgi/pkgindex.tmpl',
+                      variables => {count => \%count,
+                                    param => \%param,
+                                    result => $result,
+                                    html_escape => \&Debbugs::CGI::html_escape,
+                                    archived => $Archived,
+                                    note => $note,
+                                    tag => $tag,
+                                   },
+                       hole_var => {'&strftime' => \&POSIX::strftime,
+                                   },
+                      );
 
-print "</body></html>\n";