]> git.deb.at Git - deb/packages.git/commitdiff
Merge branch 'debian-refactor' into ubuntu-master
authorFrank Lichtenheld <frank@lichtenheld.de>
Mon, 18 Jun 2007 21:04:36 +0000 (23:04 +0200)
committerFrank Lichtenheld <frank@lichtenheld.de>
Mon, 18 Jun 2007 21:04:36 +0000 (23:04 +0200)
24 files changed:
bin/create_index_pages
bin/parse-debtags-voc
cgi-bin/dispatcher.pl
lib/Packages/Dispatcher.pm [new file with mode: 0755]
lib/Packages/DoDownload.pm
lib/Packages/DoFilelist.pm
lib/Packages/DoIndex.pm
lib/Packages/DoNewPkg.pm
lib/Packages/DoSearch.pm
lib/Packages/DoSearchContents.pm
lib/Packages/DoShow.pm
lib/Packages/Template.pm
templates/html/download.tmpl
templates/html/error.tmpl
templates/html/foot.tmpl
templates/html/index.tmpl
templates/html/newpkg.tmpl
templates/html/search.tmpl
templates/html/search_contents.tmpl
templates/html/show.tmpl
templates/html/suite_index.tmpl
templates/html/tag_index.tmpl
templates/rfc822/foot.tmpl [deleted file]
templates/rss/foot.tmpl [deleted file]

index 79d6e9e78b016bba7c35c93811abdad842263451..2c62033ddce7a22d6a3155b906ad7b99ce214904 100755 (executable)
@@ -71,7 +71,7 @@ foreach my $s (@SUITES) {
 
        my %content = ( subsections => [], suite => $s,
                        lang => $lang, charset => $charset,
-                       suites => \@SUITES );
+                       used_langs => \@LANGUAGES, suites => \@SUITES );
        $content{make_search_url} = sub { return &Packages::CGI::make_search_url(@_) };
        $content{make_url} = sub { return &Packages::CGI::make_url(@_) };
         # needed to work around the limitations of the the FILTER syntax
@@ -93,7 +93,6 @@ foreach my $s (@SUITES) {
        open $pages{$key}{$lang}{index}{fh}, '>', "$wwwdir/$key/index.$lang.html.new"
            or die "can't open index file for output: $!";
        print {$pages{$key}{$lang}{index}{fh}} $template->page( 'suite_index', \%content );
-       print {$pages{$key}{$lang}{index}{fh}} $template->trailer( 'index', $lang, \@LANGUAGES );
        close $pages{$key}{$lang}{index}{fh} or
            warn "can't close index file $wwwdir/$key/index.$lang.html.new: $!";
        rename( "$wwwdir/$key/index.$lang.html.new",
@@ -103,7 +102,6 @@ foreach my $s (@SUITES) {
        open $pages{$key}{$lang}{source_index}{fh}, '>', "$wwwdir/source/$key/index.$lang.html.new"
            or die "can't open index file for output: $!";
        print {$pages{$key}{$lang}{source_index}{fh}} $template->page( 'suite_index', \%content );
-       print {$pages{$key}{$lang}{source_index}{fh}} $template->trailer( 'index', $lang, \@LANGUAGES );
        close $pages{$key}{$lang}{source_index}{fh} or
            warn "can't close index file $wwwdir/source/$key/index.$lang.html.new: $!";
        rename( "$wwwdir/source/$key/index.$lang.html.new",
index ebd65471b33dd2af1c8beb61565e02c76cd4e969..4caf0b0444089302c5567f93b6c6d6cf22fde7ec 100755 (executable)
@@ -120,7 +120,6 @@ $content{quotemeta} = sub { return quotemeta($_[0]) };
 $content{string2id} = sub { return &Packages::CGI::string2id(@_) };
 
 print TAGLST $template->page( 'tag_index', \%content );
-print TAGLST $template->trailer();
 close TAGLST or warn "Couldn't close tag list: $!";
 
 rename( "$wwwdir/debtags.en.html.new",
index 72117d6b18e40c5a4c4c52d6ceb1230c9264c8e1..80ea8a24afea67b6fd7f9260296010538e0b0ddd 100755 (executable)
 #!/usr/bin/perl -T
-# $Id: search_packages.pl 91 2006-02-10 22:18:31Z jeroen $
-# dispatcher.pl -- CGI interface for packages.debian.org
-#
-# Copyright (C) 2004-2006 Frank Lichtenheld
-#
-# use is allowed under the terms of the GNU Public License (GPL)                              
-# see http://www.fsf.org/copyleft/gpl.html for a copy of the license
+# Simple Wrapper for Packages::Dispatcher;
 
 use strict;
 use warnings;
 
 use lib '../lib';
-use CGI;
-use POSIX;
-use File::Basename;
-use URI::Escape;
-use HTML::Entities;
-use Template;
-use DB_File;
-use Benchmark ':hireswallclock';
-use I18N::AcceptLanguage;
-use Locale::gettext;
-
-use Deb::Versions;
-use Packages::Config qw( $DBDIR $ROOT $TEMPLATEDIR $CACHEDIR
-                        @SUITES @SECTIONS @ARCHIVES @ARCHITECTURES @PRIORITIES
-                        @LANGUAGES @DDTP_LANGUAGES $LOCALES );
-use Packages::CGI qw( :DEFAULT error get_all_messages );
-use Packages::DB;
-use Packages::Search qw( :all );
-use Packages::Template ();
-use Packages::Sections;
-use Packages::I18N::Locale;
-
-use Packages::DoSearch;
-use Packages::DoSearchContents;
-use Packages::DoShow;
-use Packages::DoIndex;
-use Packages::DoNewPkg;
-use Packages::DoDownload;
-use Packages::DoFilelist;
-
-&Packages::CGI::reset;
-$Packages::Search::too_many_hits = 0;
-
-# clean up env
-$ENV{PATH} = "/bin:/usr/bin";
-delete $ENV{'LANGUAGE'};
-delete $ENV{'LANG'};
-delete $ENV{'LC_ALL'};
-delete $ENV{'LC_MESSAGES'};
-
-# Read in all the variables set by the form
-my $input;
-if ($ARGV[0] && ($ARGV[0] eq 'php')) {
-       $input = new CGI(\*STDIN);
-} else {
-       $input = new CGI;
-}
-my $cgi_error = $input->cgi_error;
-if ($cgi_error) {
-    fatal_error( "Error parsing the request", $cgi_error );
-}
-
-
-my $pet0 = new Benchmark;
-my $tet0 = new Benchmark;
-my $debug = DEBUG && $input->param("debug");
-$debug = 0 if !defined($debug) || $debug !~ /^\d+$/o;
-$Packages::CGI::debug = $debug;
-
-my $homedir = dirname($ENV{SCRIPT_FILENAME}).'/../';
-&Packages::Config::init( $homedir );
-&Packages::DB::init();
-
-my $acc = I18N::AcceptLanguage->new();
-my %all_langs = map { $_ => 1 } (@LANGUAGES, @DDTP_LANGUAGES);
-my @all_langs = sort keys %all_langs;
-my $http_lang = $acc->accepts( $input->http("Accept-Language"),
-                              \@all_langs ) || 'en';
-debug( "LANGUAGES=@all_langs header=".
-       ($input->http("Accept-Language")||'').
-       " http_lang=$http_lang", 2 ) if DEBUG;
-bindtextdomain ( 'pdo', $LOCALES );
-textdomain( 'pdo' );
-
-# backwards compatibility stuff
-debug( "SCRIPT_URL=$ENV{SCRIPT_URL} SCRIPT_URI=$ENV{SCRIPT_URI}" ) if DEBUG;
-
-if ($ENV{SCRIPT_URL} =~ m|^/cgi-bin/search_|) {
-    error( "You reached this site over an old URL. ".
-          "Depending on the exact parameters your search might work or not." );
-    # contents search changed a lot
-    if ($ENV{SCRIPT_URL} =~ m|^/cgi-bin/search_contents|) {
-       $input->param('keywords',$input->param('word')) if $input->param('word');
-       $input->param('searchon','contents');
-       for ($input->param('searchmode')) {
-           /^searchfiles/ && do {
-               $input->param('mode','filename');
-               last;
-           };
-           /^filelist/ && do {
-               $ENV{PATH_INFO} = '/'.join('/',($input->param('version')||'stable',
-                                               $input->param('keywords'),
-                                               $input->param('arch')||'i386',
-                                               'filelist' ));
-               $input->delete('searchon','version','keywords','arch');
-               last;
-           };
-       }
-    }
-}
-if ($ENV{is_reportbug}) {
-    $input->param('exact', 1);
-    debug( "reportbug detected, set paramater exact to '1'" ) if DEBUG;
-}
-
-my $what_to_do = 'show';
-my $source = 0;
-if (my $path = $input->path_info() || $input->param('PATH_INFO')) {
-    my @components = grep { $_ } map { lc $_ } split /\/+/, $path;
-
-    debug( "PATH_INFO=$path components=@components", 3) if DEBUG;
-
-    push @components, 'index' if @components && $path =~ m,/$,;
-
-    my %LANGUAGES = map { $_ => 1 } @LANGUAGES;
-    if (@components > 0 and $LANGUAGES{$components[0]}) {
-       $input->param( 'lang', shift(@components) );
-    }
-    if (@components > 0 and $components[0] eq 'source') {
-       shift @components;
-       $input->param( 'source', 1 );
-    }
-    if (@components > 0 and $components[0] eq 'search') {
-       shift @components;
-       $what_to_do = 'search';
-       # Done
-       fatal_error( _g( "search doesn't take any more path elements" ) )
-           if @components;
-    } elsif (@components == 0) {
-       fatal_error( _g( "We're supposed to display the homepage here, instead of getting dispatch.pl" ) );
-    } elsif (@components == 1) {
-       $what_to_do = 'search';
-    } else {
-
-       for ($components[-1]) {
-           /^(index|allpackages|newpkg|changelog|copyright|download|filelist)$/ && do {
-               pop @components;
-               $what_to_do = $1;
-               last;
-           };
-       }
-
-       my %SUITES = map { $_ => 1 } @SUITES;
-       my %SUITES_ALIAS = ( sarge => 'oldstable',
-                            etch => 'stable',
-                            lenny => 'testing',
-                            sid => 'unstable', );
-       my %SECTIONS = map { $_ => 1 } @SECTIONS;
-       my %ARCHIVES = map { $_ => 1 } @ARCHIVES;
-       my %ARCHITECTURES = map { $_ => 1 } (@ARCHITECTURES, 'all', 'any');
-       my %PRIORITIES = map { $_ => 1 } @PRIORITIES;
-       my %params_set;
-       sub set_param_once {
-           my ($cgi, $params_set, $key, $val) = @_;
-           debug("set_param_once key=$key val=$val",4) if DEBUG;
-           if ($params_set->{$key}++) {
-               fatal_error( sprintf( _g( "%s set more than once in path" ), $key ) );
-           } else {
-               $cgi->param( $key, $val );
-           }
-       }
-
-       my (@pkg, $need_pkg);
-       foreach (reverse @components) {
-           $need_pkg = !@pkg
-               && ($what_to_do !~ /^(index|allpackages|newpkg)$/);
-           debug("need_pkg=$need_pkg component=$_",4) if DEBUG;
-           if (!$need_pkg && $SUITES{$_}) {
-               set_param_once( $input, \%params_set, 'suite', $_);
-           } elsif (!$need_pkg && (my $s = $SUITES_ALIAS{$_})) {
-               set_param_once( $input, \%params_set, 'suite', $s);
-           } elsif (!$need_pkg && $SECTIONS{$_}) {
-               set_param_once( $input, \%params_set, 'section', $_);
-           } elsif (!$need_pkg && $ARCHIVES{$_}) {
-               set_param_once( $input, \%params_set, 'archive', $_);
-           } elsif (!$need_pkg && $sections_descs{$_}) {
-               set_param_once( $input, \%params_set, 'subsection', $_);
-           } elsif (!$need_pkg && ($_ eq 'non-us')) { # non-US hack
-               set_param_once( $input, \%params_set, 'subsection', 'non-US');
-           } elsif (!$need_pkg && ($_ eq 'source')) {
-               set_param_once( $input, \%params_set, 'source', 1);
-           } elsif ($ARCHITECTURES{$_}) {
-               set_param_once( $input, \%params_set, 'arch', $_)
-                   unless $_ eq 'any';
-           } elsif ($PRIORITIES{$_}) {
-               set_param_once( $input, \%params_set, 'priority', $_);
-           } else {
-               push @pkg, $_;
-           }
-       }
-       @components = @pkg;
-
-       if (@components > 1) {
-           fatal_error( sprintf( _g( "two or more packages specified (%s)" ), "@components" ) );
-       }
-    } # else if (@components == 1)
-    
-    if (@components) {
-       $input->param( 'keywords', $components[0] );
-       $input->param( 'package', $components[0] );
-    }
-}
-
-my ( $pkg, @suites, @sections, @subsections, @archives, @archs );
-
-my %params_def = ( keywords => { default => undef,
-                                array => '\s+',
-                                match => '^([-+\@\w\/.:]+)$',
-                            },
-                  package => { default => undef,
-                               match => '^([\w.+-]+)$',
-                               var => \$pkg },
-                  suite => { default => 'default', match => '^([\w-]+)$',
-                             array => ',', var => \@suites,
-                             replace => { all => \@SUITES,
-                                          default => \@SUITES } },
-                  archive => { default => ($what_to_do eq 'search') ?
-                                   'all' : 'default',
-                                   match => '^([\w-]+)$',
-                                   array => ',', var => \@archives,
-                                   replace => { all => \@ARCHIVES,
-                                                default => \@ARCHIVES} },
-                  exact => { default => 0, match => '^(\w+)$',  },
-                  lang => { default => $http_lang, match => '^(\w+)$',  },
-                  source => { default => 0, match => '^(\d+)$',  },
-                  debug => { default => 0, match => '^(\d+)$',  },
-                  searchon => { default => 'names', match => '^(\w+)$', },
-                  section => { default => 'all', match => '^([\w-]+)$',
-                               alias => 'release', array => ',',
-                               var => \@sections,
-                               replace => { all => \@SECTIONS } },
-                  subsection => { default => 'default', match => '^([\w-]+)$',
-                                  array => ',', var => \@subsections,
-                                  replace => { default => [] } },
-                  priority => { default => 'default', match => '^([\w-]+)$',
-                                array => ',',
-                                replace => { default => [] } },
-                  arch => { default => 'any', match => '^([\w-]+)$',
-                            array => ',', var => \@archs, replace =>
-                            { any => \@ARCHITECTURES } },
-                  format => { default => 'html', match => '^([\w.]+)$',  },
-                  mode => { default => undef, match => '^(\w+)$',  },
-                  sort_by => { default => 'file', match => '^(\w+)$', },
-                  );
-my %opts;
-my %params = Packages::CGI::parse_params( $input, \%params_def, \%opts );
-Packages::CGI::init_url( $input, \%params, \%opts );
-
-my $locale = get_locale($opts{lang});
-my $charset = get_charset($opts{lang});
-setlocale ( LC_ALL, $locale )
-    or do { debug( "couldn't set locale $locale, using default" ) if DEBUG;
-           setlocale( LC_ALL, get_locale() )
-               or do {
-                   debug( "couldn't set default locale either" ) if DEBUG;
-                   setlocale( LC_ALL, "C" );
-               };
-       };
-debug( "locale=$locale charset=$charset", 2 ) if DEBUG;
-
-$opts{h_suites} = { map { $_ => 1 } @suites };
-$opts{h_sections} = { map { $_ => 1 } @sections };
-$opts{h_archives} = { map { $_ => 1 } @archives };
-$opts{h_archs} = { map { $_ => 1 } @archs };
-
-if ((($opts{searchon} eq 'names') && $opts{source}) ||
-    ($opts{searchon} eq 'sourcenames')) {
-    $opts{source} = 1;
-    $opts{searchon} = 'names',
-    $opts{searchon_form} = 'sourcenames';
-} else {
-    $opts{searchon_form} = $opts{searchon};
-}
-if ($opts{searchon} eq 'contents' or $opts{searchon} eq 'filenames') {
-    $what_to_do = 'search_contents';
-}
-
-my $pet1 = new Benchmark;
-my $petd = timediff($pet1, $pet0);
-debug( "Parameter evaluation took ".timestr($petd) ) if DEBUG;
-
-my $template = new Packages::Template( $TEMPLATEDIR, $opts{format}, { lang => $opts{lang}, charset => $charset, debug => ( DEBUG ? $opts{debug} : 0 ) }, ( $CACHEDIR ? { COMPILE_DIR => $CACHEDIR } : {} ) );
-
-unless (-e "$TEMPLATEDIR/$opts{format}/${what_to_do}.tmpl") {
-    fatal_error( "requested format not available for this document",
-                "406 requested format not available");
-}
-
-my (%html_header, %page_content);
-unless (@Packages::CGI::fatal_errors) {
-    no strict 'refs';
-    &{"do_$what_to_do"}( \%params, \%opts, \%html_header,
-                        \%page_content );
-}
-
-$page_content{opts} = \%opts;
-$page_content{params} = \%params;
-
-$page_content{make_search_url} = sub { return &Packages::CGI::make_search_url(@_) };
-$page_content{make_url} = sub { return &Packages::CGI::make_url(@_) };
-# needed to work around the limitations of the the FILTER syntax
-$page_content{html_encode} = sub { return HTML::Entities::encode_entities(@_,'<>&"') };
-$page_content{uri_escape} = sub { return URI::Escape::uri_escape(@_) };
-$page_content{quotemeta} = sub { return quotemeta($_[0]) };
-$page_content{string2id} = sub { return &Packages::CGI::string2id(@_) };
-
-unless (@Packages::CGI::fatal_errors) {
-    print $input->header(-charset => $charset, -type => get_mime($opts{format}) );
-    #use Data::Dumper;
-    #print '<pre>'.Dumper(\%ENV, \%html_header, \%page_content, get_all_messages()).'</pre>';
-    print $template->page( $what_to_do, { %page_content, %{ get_all_messages() } } );
-    my $tet1 = new Benchmark;
-    my $tetd = timediff($tet1, $tet0);
-    print $template->trailer( undef, undef, undef, $tetd );
-} elsif ($Packages::CGI::http_code && $Packages::CGI::http_code !~ /^2\d\d/) {
-    print $input->header( -charset => $charset, -status => $Packages::CGI::http_code );
-} else {
-    # We currently have only an error page in html
-    # so no format support here
-    print $input->header( -charset => $charset );
-    print $template->error_page( get_all_messages() );
-    print $template->trailer();;
-}
+use Packages::Dispatcher;
 
+&Packages::Dispatcher::do_dispatch();
 
 # vim: ts=8 sw=4
diff --git a/lib/Packages/Dispatcher.pm b/lib/Packages/Dispatcher.pm
new file mode 100755 (executable)
index 0000000..3dcab38
--- /dev/null
@@ -0,0 +1,352 @@
+#!/usr/bin/perl -T
+# Packages::Dispatcher -- CGI interface for packages.debian.org
+#
+# Copyright (C) 2004-2007 Frank Lichtenheld
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 1 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program; if not, write to the Free Software
+#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+package Packages::Dispatcher;
+
+use strict;
+use warnings;
+
+use CGI;
+use POSIX;
+use File::Basename;
+use URI::Escape;
+use HTML::Entities;
+use Template;
+use DB_File;
+use Benchmark ':hireswallclock';
+use I18N::AcceptLanguage;
+use Locale::gettext;
+
+use Deb::Versions;
+use Packages::Config qw( $DBDIR $ROOT $TEMPLATEDIR $CACHEDIR
+                        @SUITES @SECTIONS @ARCHIVES @ARCHITECTURES @PRIORITIES
+                        @LANGUAGES @DDTP_LANGUAGES $LOCALES );
+use Packages::CGI qw( :DEFAULT error get_all_messages );
+use Packages::DB;
+use Packages::Search qw( :all );
+use Packages::Template ();
+use Packages::Sections;
+use Packages::I18N::Locale;
+
+use Packages::DoSearch;
+use Packages::DoSearchContents;
+use Packages::DoShow;
+use Packages::DoIndex;
+use Packages::DoNewPkg;
+use Packages::DoDownload;
+use Packages::DoFilelist;
+
+
+sub do_dispatch {
+
+    &Packages::CGI::reset;
+    $Packages::Search::too_many_hits = 0;
+
+    # clean up env
+    $ENV{PATH} = "/bin:/usr/bin";
+    delete $ENV{'LANGUAGE'};
+    delete $ENV{'LANG'};
+    delete $ENV{'LC_ALL'};
+    delete $ENV{'LC_MESSAGES'};
+
+    # Read in all the variables set by the form
+    my $input;
+    if ($ARGV[0] && ($ARGV[0] eq 'php')) {
+       $input = new CGI(\*STDIN);
+    } else {
+       $input = new CGI;
+    }
+    my $cgi_error = $input->cgi_error;
+    if ($cgi_error) {
+       fatal_error( "Error parsing the request", $cgi_error );
+    }
+
+    my $pet0 = new Benchmark;
+    my $tet0 = new Benchmark;
+    my $debug = DEBUG && $input->param("debug");
+    $debug = 0 if !defined($debug) || $debug !~ /^\d+$/o;
+    $Packages::CGI::debug = $debug;
+
+    my $homedir = dirname($ENV{SCRIPT_FILENAME}).'/../';
+    &Packages::Config::init( $homedir );
+    &Packages::DB::init();
+
+    my $acc = I18N::AcceptLanguage->new();
+    my %all_langs = map { $_ => 1 } (@LANGUAGES, @DDTP_LANGUAGES);
+    my @all_langs = sort keys %all_langs;
+    my $http_lang = $acc->accepts( $input->http("Accept-Language"),
+                                  \@all_langs ) || 'en';
+    debug( "LANGUAGES=@all_langs header=".
+          ($input->http("Accept-Language")||'').
+          " http_lang=$http_lang", 2 ) if DEBUG;
+    bindtextdomain ( 'pdo', $LOCALES );
+    textdomain( 'pdo' );
+
+    # backwards compatibility stuff
+    debug( "SCRIPT_URL=$ENV{SCRIPT_URL} SCRIPT_URI=$ENV{SCRIPT_URI}" ) if DEBUG;
+
+    if ($ENV{SCRIPT_URL} =~ m|^/cgi-bin/search_|) {
+       error( "You reached this site over an old URL. ".
+              "Depending on the exact parameters your search might work or not." );
+       # contents search changed a lot
+       if ($ENV{SCRIPT_URL} =~ m|^/cgi-bin/search_contents|) {
+           $input->param('keywords',$input->param('word')) if $input->param('word');
+           $input->param('searchon','contents');
+           for ($input->param('searchmode')) {
+               /^searchfiles/ && do {
+                   $input->param('mode','filename');
+                   last;
+               };
+               /^filelist/ && do {
+                   $ENV{PATH_INFO} = '/'.join('/',($input->param('version')||'stable',
+                                                   $input->param('keywords'),
+                                                   $input->param('arch')||'i386',
+                                                   'filelist' ));
+                   $input->delete('searchon','version','keywords','arch');
+                   last;
+               };
+           }
+       }
+    }
+    if ($ENV{is_reportbug}) {
+       $input->param('exact', 1);
+       debug( "reportbug detected, set paramater exact to '1'" ) if DEBUG;
+    }
+
+    my $what_to_do = 'show';
+    my $source = 0;
+    if (my $path = $input->path_info() || $input->param('PATH_INFO')) {
+       my @components = grep { $_ } map { lc $_ } split /\/+/, $path;
+
+       debug( "PATH_INFO=$path components=@components", 3) if DEBUG;
+
+       push @components, 'index' if @components && $path =~ m,/$,;
+
+       my %LANGUAGES = map { $_ => 1 } @all_langs;
+       if (@components > 0 and $LANGUAGES{$components[0]}
+           and !$input->param('lang')) {
+           $input->param( 'lang', shift(@components) );
+       }
+       if (@components > 0 and $components[0] eq 'source') {
+           shift @components;
+           $input->param( 'source', 1 );
+       }
+       if (@components > 0 and $components[0] eq 'search') {
+           shift @components;
+           $what_to_do = 'search';
+           # Done
+           fatal_error( _g( "search doesn't take any more path elements" ) )
+               if @components;
+       } elsif (@components == 0) {
+           fatal_error( _g( "We're supposed to display the homepage here, instead of getting dispatch.pl" ) );
+       } elsif (@components == 1) {
+           $what_to_do = 'search';
+       } else {
+
+           for ($components[-1]) {
+               /^(index|allpackages|newpkg|changelog|copyright|download|filelist)$/ && do {
+                   pop @components;
+                   $what_to_do = $1;
+                   last;
+               };
+           }
+
+           my %SUITES = map { $_ => 1 } @SUITES;
+           my %SUITES_ALIAS = ( sarge => 'oldstable',
+                                etch => 'stable',
+                                lenny => 'testing',
+                                sid => 'unstable', );
+           my %SECTIONS = map { $_ => 1 } @SECTIONS;
+           my %ARCHIVES = map { $_ => 1 } @ARCHIVES;
+           my %ARCHITECTURES = map { $_ => 1 } (@ARCHITECTURES, 'all', 'any');
+           my %PRIORITIES = map { $_ => 1 } @PRIORITIES;
+           my %params_set;
+           sub set_param_once {
+               my ($cgi, $params_set, $key, $val) = @_;
+               debug("set_param_once key=$key val=$val",4) if DEBUG;
+               if ($params_set->{$key}++) {
+                   fatal_error( sprintf( _g( "%s set more than once in path" ), $key ) );
+               } else {
+                   $cgi->param( $key, $val );
+               }
+           }
+
+           my (@pkg, $need_pkg);
+           foreach (reverse @components) {
+               $need_pkg = !@pkg
+                   && ($what_to_do !~ /^(index|allpackages|newpkg)$/);
+               debug("need_pkg=$need_pkg component=$_",4) if DEBUG;
+               if (!$need_pkg && $SUITES{$_}) {
+                   set_param_once( $input, \%params_set, 'suite', $_);
+               } elsif (!$need_pkg && (my $s = $SUITES_ALIAS{$_})) {
+                   set_param_once( $input, \%params_set, 'suite', $s);
+               } elsif (!$need_pkg && $SECTIONS{$_}) {
+                   set_param_once( $input, \%params_set, 'section', $_);
+               } elsif (!$need_pkg && $ARCHIVES{$_}) {
+                   set_param_once( $input, \%params_set, 'archive', $_);
+               } elsif (!$need_pkg && $sections_descs{$_}) {
+                   set_param_once( $input, \%params_set, 'subsection', $_);
+               } elsif (!$need_pkg && ($_ eq 'non-us')) { # non-US hack
+                   set_param_once( $input, \%params_set, 'subsection', 'non-US');
+               } elsif (!$need_pkg && ($_ eq 'source')) {
+                   set_param_once( $input, \%params_set, 'source', 1);
+               } elsif ($ARCHITECTURES{$_}) {
+                   set_param_once( $input, \%params_set, 'arch', $_)
+                       unless $_ eq 'any';
+               } elsif ($PRIORITIES{$_}) {
+                   set_param_once( $input, \%params_set, 'priority', $_);
+               } else {
+                   push @pkg, $_;
+               }
+           }
+           @components = @pkg;
+
+           if (@components > 1) {
+               fatal_error( sprintf( _g( "two or more packages specified (%s)" ), "@components" ) );
+           }
+       } # else if (@components == 1)
+
+       if (@components) {
+           $input->param( 'keywords', $components[0] );
+           $input->param( 'package', $components[0] );
+       }
+    }
+
+    my ( $pkg, @suites, @sections, @subsections, @archives, @archs );
+
+    my %params_def = ( keywords => { default => undef,
+                                    array => '\s+',
+                                    match => '^([-+\@\w\/.:]+)$',
+                                },
+                      package => { default => undef,
+                                   match => '^([\w.+-]+)$',
+                                   var => \$pkg },
+                      suite => { default => 'default', match => '^([\w-]+)$',
+                                 array => ',', var => \@suites,
+                                 replace => { all => \@SUITES,
+                                              default => \@SUITES } },
+                      archive => { default => ($what_to_do eq 'search') ?
+                                       'all' : 'default',
+                                       match => '^([\w-]+)$',
+                                       array => ',', var => \@archives,
+                                       replace => { all => \@ARCHIVES,
+                                                    default => \@ARCHIVES} },
+                      exact => { default => 0, match => '^(\w+)$',  },
+                      lang => { default => $http_lang, match => '^(\w+)$',  },
+                      source => { default => 0, match => '^(\d+)$',  },
+                      debug => { default => 0, match => '^(\d+)$',  },
+                      searchon => { default => 'names', match => '^(\w+)$', },
+                      section => { default => 'all', match => '^([\w-]+)$',
+                                   alias => 'release', array => ',',
+                                   var => \@sections,
+                                   replace => { all => \@SECTIONS } },
+                      subsection => { default => 'default', match => '^([\w-]+)$',
+                                      array => ',', var => \@subsections,
+                                      replace => { default => [] } },
+                      priority => { default => 'default', match => '^([\w-]+)$',
+                                    array => ',',
+                                    replace => { default => [] } },
+                      arch => { default => 'any', match => '^([\w-]+)$',
+                                array => ',', var => \@archs, replace =>
+                                { any => \@ARCHITECTURES } },
+                      format => { default => 'html', match => '^([\w.]+)$',  },
+                  mode => { default => undef, match => '^(\w+)$',  },
+                  sort_by => { default => 'file', match => '^(\w+)$', },
+                  );
+    my %opts;
+    my %params = Packages::CGI::parse_params( $input, \%params_def, \%opts );
+Packages::CGI::init_url( $input, \%params, \%opts );
+
+    my $locale = get_locale($opts{lang});
+    my $charset = get_charset($opts{lang});
+    setlocale ( LC_ALL, $locale )
+       or do { debug( "couldn't set locale $locale, using default" ) if DEBUG;
+               setlocale( LC_ALL, get_locale() )
+                   or do {
+                       debug( "couldn't set default locale either" ) if DEBUG;
+                       setlocale( LC_ALL, "C" );
+                   };
+           };
+    debug( "locale=$locale charset=$charset", 2 ) if DEBUG;
+
+    $opts{h_suites} = { map { $_ => 1 } @suites };
+    $opts{h_sections} = { map { $_ => 1 } @sections };
+    $opts{h_archives} = { map { $_ => 1 } @archives };
+    $opts{h_archs} = { map { $_ => 1 } @archs };
+
+    if ((($opts{searchon} eq 'names') && $opts{source}) ||
+       ($opts{searchon} eq 'sourcenames')) {
+       $opts{source} = 1;
+       $opts{searchon} = 'names',
+       $opts{searchon_form} = 'sourcenames';
+    } else {
+       $opts{searchon_form} = $opts{searchon};
+    }
+    if ($opts{searchon} eq 'contents' or $opts{searchon} eq 'filenames') {
+       $what_to_do = 'search_contents';
+    }
+
+    my $pet1 = new Benchmark;
+    my $petd = timediff($pet1, $pet0);
+    debug( "Parameter evaluation took ".timestr($petd) ) if DEBUG;
+
+    my $template = new Packages::Template( $TEMPLATEDIR, $opts{format},
+                                          { lang => $opts{lang}, charset => $charset,
+                                            debug => ( DEBUG ? $opts{debug} : 0 ) },
+                                          ( $CACHEDIR ? { COMPILE_DIR => $CACHEDIR } : {} ) );
+
+    unless (-e "$TEMPLATEDIR/$opts{format}/${what_to_do}.tmpl") {
+       fatal_error( "requested format not available for this document",
+                    "406 requested format not available");
+    }
+
+    my (%page_content);
+    unless (@Packages::CGI::fatal_errors) {
+       no strict 'refs';
+       &{"do_$what_to_do"}( \%params, \%opts, \%page_content );
+    }
+
+    $page_content{opts} = \%opts;
+    $page_content{params} = \%params;
+
+    $page_content{make_search_url} = sub { return &Packages::CGI::make_search_url(@_) };
+    $page_content{make_url} = sub { return &Packages::CGI::make_url(@_) };
+    # needed to work around the limitations of the the FILTER syntax
+    $page_content{html_encode} = sub { return HTML::Entities::encode_entities(@_,'<>&"') };
+    $page_content{uri_escape} = sub { return URI::Escape::uri_escape(@_) };
+    $page_content{quotemeta} = sub { return quotemeta($_[0]) };
+    $page_content{string2id} = sub { return &Packages::CGI::string2id(@_) };
+
+    unless (@Packages::CGI::fatal_errors) {
+       print $input->header(-charset => $charset, -type => get_mime($opts{format}) );
+       #use Data::Dumper;
+       #print '<pre>'.Dumper(\%ENV, \%page_content, get_all_messages()).'</pre>';
+       print $template->page( $what_to_do, { %page_content, %{ get_all_messages() } } );
+    } elsif ($Packages::CGI::http_code && $Packages::CGI::http_code !~ /^2\d\d/) {
+       print $input->header( -charset => $charset, -status => $Packages::CGI::http_code );
+    } else {
+       # We currently have only an error page in html
+       # so no format support here
+       print $input->header( -charset => $charset );
+       print $template->error_page( get_all_messages() );
+    }
+}
+
+1;
+# vim: ts=8 sw=4
index bd7f8e1660bb5d68b6a0d0233e6c34ffcecdc6fb..7c59272085c3db58e923c24562ae5be720c3b128 100644 (file)
@@ -21,7 +21,7 @@ our @EXPORT = qw( do_download );
 
 
 sub do_download {
-    my ($params, $opts, $html_header, $page_content) = @_;
+    my ($params, $opts, $page_content) = @_;
 
     if ($params->{errors}{package}) {
        fatal_error( _g( "package not valid or not specified" ) );
index 97e9f013bea2db584800accdc1c87bbfde3c41ca..c8061905add7ef5f6a806b5d815ec3d3b4387a89 100644 (file)
@@ -24,7 +24,7 @@ our @ISA = qw( Exporter );
 our @EXPORT = qw( do_filelist );
 
 sub do_filelist {
-    my ($params, $opts, $html_header, $page_content) = @_;
+    my ($params, $opts, $page_content) = @_;
 
     if ($params->{errors}{package}) {
        fatal_error( _g( "package not valid or not specified" ) );
index 239f3301a7af582f8faf1478483224fdb63548d8..8f96fdf8b20ef6f79a4353480bfca06c3ebc3f9d 100644 (file)
@@ -25,7 +25,7 @@ my %encoding = (
                'txt.gz' => 'x-gzip',
                );
 sub send_file {
-    my ($file, $params, $opts, $html_header) = @_;
+    my ($file, $params, $opts) = @_;
 
     if ($params->{errors}{suite}) {
        fatal_error( _g( "suite not valid or not specified" ) );
index 362c4260dd5cb66e122f531e405368f0e1ed6729..c9e0ca23f009f79615048c7d1a4519230667e2e7 100644 (file)
@@ -19,7 +19,7 @@ use Packages::DB;
 use Packages::Config qw( $TOPDIR @SECTIONS $ROOT );
 
 sub do_newpkg {
-    my ($params, $opts, $html_header, $page_content) = @_;
+    my ($params, $opts, $page_content) = @_;
 
     if ($params->{errors}{suite}) {
        fatal_error( _g( "suite not valid or not specified" ) );
index d395a310334b787775aa078162bb739b928a8d1c..5f91d2463adb3fd2addbae713e43dc3c9ed3466c 100644 (file)
@@ -19,7 +19,7 @@ use Packages::DB;
 use Packages::Config qw( $DBDIR @SUITES @ARCHIVES $ROOT );
 
 sub do_search {
-    my ($params, $opts, $html_header, $page_content) = @_;
+    my ($params, $opts, $page_content) = @_;
 
     $Params::Search::too_many_hits = 0;
 
index 101c10cc975e90f8b93f3790d811c08119e53013..29b79770d44ef4407430f7a3e2aa5f3c3ef09a78 100644 (file)
@@ -19,7 +19,7 @@ use Packages::DB;
 use Packages::Config qw( $DBDIR @SUITES @ARCHIVES @ARCHITECTURES $ROOT );
 
 sub do_search_contents {
-    my ($params, $opts, $html_header, $page_content) = @_;
+    my ($params, $opts, $page_content) = @_;
 
     if ($params->{errors}{keywords}) {
        fatal_error( _g( "keyword not valid or missing" ) );
index e47ec6ba791a7d0d8bf3ebd92a8a1d1bf78f6222..1d21462878d4dbcf0e2a21f8e9d16c48000bcab8 100644 (file)
@@ -24,7 +24,7 @@ our @ISA = qw( Exporter );
 our @EXPORT = qw( do_show );
 
 sub do_show {
-    my ($params, $opts, $html_header, $page_contents) = @_;
+    my ($params, $opts, $page_contents) = @_;
 
     if ($params->{errors}{package}) {
        fatal_error( _g( "package not valid or not specified" ) );
@@ -175,6 +175,7 @@ sub do_show {
                        my $trans_desc = $desctrans{$desc_md5};
                        if ($trans_desc) {
                            my %trans_desc = split /\000|\001/, $trans_desc;
+                           $contents{used_langs} = ['en', sort keys %trans_desc];
                            debug( "TRANSLATIONS: ".join(" ",keys %trans_desc), 2)
                                if DEBUG;
                            while (my ($l, $d) = each %trans_desc) {
index 7d85f46ba1cd53b1c3315bfc32525df0d89775c6..554f2ce0e4c8551248ad625a9d0224190c1fff01 100644 (file)
@@ -38,6 +38,7 @@ sub new {
        %$options,
     } ) or fatal_error( sprintf( _g( "Initialization of Template Engine failed: %s" ), $Template::ERROR ) );
     $self->{format} = $format;
+    $self->{vars} = $vars;
 
     return $self;
 }
@@ -56,6 +57,10 @@ sub page {
 
     #use Data::Dumper;
     #die Dumper($self, $action, $page_content);
+    $page_content->{used_langs} ||= [ 'en' ];
+    $page_content->{langs} = languages( $page_content->{lang}
+                                       || $self->{vars}{lang} || 'en',
+                                       @{$page_content->{used_langs}} );
 
     my $txt;
     $self->process("$self->{format}/$action.tmpl", $page_content, \$txt)
@@ -77,18 +82,6 @@ sub error_page {
     return $txt;
 }
 
-sub trailer {
-    my ($self, $NAME, $LANG, $USED_LANGS, $timediff) = @_;
-
-    my $langs = languages( $LANG, @$USED_LANGS );
-
-    my $txt;
-    $self->process("$self->{format}/foot.tmpl", { langs => $langs, name => $NAME, benchmark => $timediff ? timestr($timediff) : '' }, \$txt)
-       or die sprintf( "template error: %s", $self->error ); # too late for reporting on-line
-
-    return $txt;
-}
-
 sub languages {
     my ( $lang, @used_langs ) = @_;
     
index e08aff21b00be974e416b4f49615242f3cd84e25..27a4cf5b4733dff42d7cbd6e3595dfc62a5ffa41 100644 (file)
@@ -113,3 +113,5 @@ For example, in Firefox or Mozilla, you should hold the Shift key when you click
 <tr><th>SHA1 checksum</th>             <td><tt>[% sha1 || 'Not Available' %]</tt></td>
 <tr><th>SHA256 checksum</th>           <td><tt>[% sha256  || 'Not Available' %]</tt></td>
 </table>
+
+[%- PROCESS 'html/foot.tmpl' -%]
index 72c4fd49107757d31e34fd89ecd016d1e986237f..6c0cd8964885610ec64a17ff19399ae64f52131d 100644 (file)
@@ -2,3 +2,5 @@
    title_tag = 'Error'
    page_title = 'Error'
 -%]
+
+[%- PROCESS 'html/foot.tmpl' -%]
index c6b4dc6b893bd0288b4311e0a9a954dad77d2c08..493069863a1fafb13aad41ac1c3757ddbcece919 100644 (file)
@@ -12,7 +12,7 @@ Total page evaluation took [% benchmark %]<br>
 <p>This page is also available in the following languages:</p>
 <p class="navpara">
 [% FOREACH langs %]
-<a href="[% "$name?lang=$lang" %]" title="[% tooltip %]" hreflang="[% lang %]" lang="[% lang %]" rel="alternate">[% selfname %]
+<a href="[% "$page_name?lang=$lang" %]" title="[% tooltip %]" hreflang="[% lang %]" lang="[% lang %]" rel="alternate">[% selfname %]
 [%- IF transliteration %] ([% transliteration %])[% END %]</a>
 [% END %]
 </p>
index 9daa9a5d0542d4157efadfe865a6c7639b36ba3c..11cab5ceee6e2ed3dee2a745109df6f2b3b7ec7a 100644 (file)
@@ -43,3 +43,5 @@
 
   [% '</dl>' IF loop.last %]
 [% END %]
+
+[%- PROCESS 'html/foot.tmpl' -%]
index cfa6bd3288abe316bd5c409d9257033f95c5f198..016dcb5b2623d64168f1ac33fb96cd1061716dd0 100644 (file)
@@ -28,4 +28,6 @@
   [%- END -%]
 [% ', ' UNLESS loop.last %]
 [% END %]
-</p>
\ No newline at end of file
+</p>
+
+[%- PROCESS 'html/foot.tmpl' -%]
index bbb4cde6e93d408f05d5ed8ccdd35da2018a119f..9eafd1ee313428e0bf9a35575e982c3a0096b7f2 100644 (file)
@@ -123,3 +123,5 @@ Please consider using a longer keyword or more keywords.</p>
 [% END %]
 
 </div>
+
+[%- PROCESS 'html/foot.tmpl' -%]
index 77836fec87bea076604d16068923c42564b4d5b9..7cfc54fa77846bc1e6d7934a33cddf279a874dd3 100644 (file)
@@ -125,3 +125,5 @@ Please consider using a longer keyword or more keywords.</p>
 <p id="psearchnoresult">Sorry, your search gave no results</p>
 
 [% END %]
+
+[%- PROCESS 'html/foot.tmpl' -%]
index 0ef593e7bafd9bc51598bbe2d90ee15d9b4bb78f..c4b1e904f1bd7df684e1fffbf8a2f2a8f00a4fa7 100644 (file)
@@ -315,3 +315,4 @@ Do not install it on a normal Debian system.</p>
 
 <script type="text/javascript">init_tab_list("ptablist")</script>
 
+[%- PROCESS 'html/foot.tmpl' -%]
index 92b7d97a590f2dd1e456140edc9817a12b2c544f..465c6930ae0e125483a3a7e78b310457e4f10f2a 100644 (file)
@@ -39,3 +39,5 @@
        <a href="allpackages" title="List of all [% "source " IF source %]packages">All [% "source " IF source %]packages</a><br>
        (<a href="allpackages?format=txt.gz">compact compressed textlist</a>)
 </p>
+
+[%- PROCESS 'html/foot.tmpl' -%]
index df51e22483207f853f1c30437f83b17ac54884f7..1df4853cbfe0a82d3d275fd34bfe2c7961d44db6 100644 (file)
@@ -21,3 +21,5 @@
        [% END %]
 
 [% END %]
+
+[%- PROCESS 'html/foot.tmpl' -%]
diff --git a/templates/rfc822/foot.tmpl b/templates/rfc822/foot.tmpl
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/templates/rss/foot.tmpl b/templates/rss/foot.tmpl
deleted file mode 100644 (file)
index e69de29..0000000