1 package Packages::HTML;
11 use Packages::CGI qw(make_url make_search_url);
12 use Packages::Search qw( read_entry_simple );
13 use Packages::Config qw( :all );
16 use Packages::I18N::Locale;
17 use Packages::I18N::Languages;
18 use Packages::I18N::LanguageNames;
19 #use Generated::Strings qw( gettext dgettext );
21 our @ISA = qw( Exporter );
22 our @EXPORT = qw( header title trailer file_changed time_stamp
23 read_md5_hash write_md5_hash simple_menu
24 ds_begin ds_item ds_end title marker pdesc ptags
25 pdeplegend pkg_list pmoreinfo print_deps print_src_deps );
27 our $CHANGELOG_URL = '/changelogs';
30 my ( $root, $url, $src, $alt, %attr ) = @_;
33 foreach my $a ( keys %attr ) {
34 push @attr, "$a=\"$attr{$a}\"";
37 return "<a href=\"$root$url\"><img src=\"$root$src\" alt=\"$alt\" @attr></a>";
42 foreach my $entry (@_) {
43 $str .= "[ $entry->[0] <a title=\"$entry->[1]\" href=\"$entry->[2]\">$entry->[3]</a> ]\n";
49 return "<h1>$_[0]</h1>\n";
53 return "[<strong class=\"pmarker\">$_[0]</strong>]";
57 my ( $short_desc, $long_desc ) = @_;
60 $str .= "<div id=\"pdesc\">\n";
61 $str .= "<h2>$short_desc</h2>\n";
63 $str .= "<p>$long_desc\n";
64 $str .= "</div> <!-- end pdesc -->\n";
70 my ( $package, @tags ) = @_;
73 $str .= "<div id=\"ptags\">\n<p>";
74 $str .= "<a href=\"http://debtags.alioth.debian.org/cgi-bin/edit.cgi?pkg=".uri_escape($package)."\">Tags</a>:\n";
75 foreach my $tag (@tags) {
76 $str .= "<a href=\"http://debtags.alioth.debian.org/cgi-bin/index.cgi?tags=".uri_escape($tag)."\">$tag</a>\n";
78 $str .= "</p>\n</div> <!-- end ptags -->\n";
84 my $str = "<table id=\"pdeplegend\" summary=\"legend\"><tr>\n";
86 foreach my $entry (@_) {
87 $str .= "<td><img src=\"$ROOT/Pics/$entry->[0].gif\" alt=\"[$entry->[0]]\" width=\"16\" height=\"16\">= $entry->[1]</td>";
90 $str .= "\n</tr></table>\n";
95 my ( $packages, $opts, $pkgs, $lang ) = @_;
96 my $suite = $opts->{suite}[0];
99 foreach my $p ( sort @$pkgs ) {
101 # we don't deal with virtual packages here because for the
102 # current uses of this function this isn't needed
103 my $short_desc = (read_entry_simple( $packages, $p, $opts->{h_archives}, $suite))->[-1];
106 $str .= "<dt><a href=\"".make_url($p,'',{source=>undef})."\">$p</a></dt>\n".
107 "\t<dd>$short_desc</dd>\n";
109 $str .= "<dt>$p</dt>\n\t<dd>"._g("Not available")."</dd>\n";
113 $str = "<dl>$str</dl>\n";
122 my $name = $info{name} or return;
123 my $env = $info{env} or return;
124 my $opts = $info{opts} or return;
125 my $page = $info{data} or return;
126 my $is_source = $info{is_source};
127 my $suite = $opts->{suite}[0];
129 my $str = "<div id=\"pmoreinfo\">";
130 $str .= sprintf( "<h2>"._g( "More Information on %s" )."</h2>",
133 if ($info{bugreports}) {
134 my $bug_url = $is_source ? $SRC_BUG_URL : $BUG_URL;
135 $str .= "<p>\n".sprintf( _g( "Check for <a href=\"%s\">Bug Reports</a> about %s." )."<br>\n",
136 $bug_url.$name, $name );
139 my $source = $page->get_src( 'package' );
140 my $source_version = $page->get_src( 'version' );
141 my $src_dir = $page->get_src('directory');
142 if ($info{sourcedownload}) {
143 my $files = $page->get_src( 'files' );
144 $str .= _g( "Source Package:" );
145 $str .= " <a href=\"".make_url($source,'',{source=>'source'})."\">$source</a>, ".
146 _g( "Download" ).":\n";
148 unless (defined($files) and @$files) {
149 $str .= _g( "Not found" );
152 my ($src_file_md5, $src_file_size, $src_file_name) = split /\s/o, $_;
154 (my $server = lc $page->get_newest('archive')) =~ s/-//go;
155 $str .= sprintf("<a href=\"%s/$src_dir/$src_file_name\">[",
156 $env->{$server}||$env->{us});
157 if ($src_file_name =~ /dsc$/) {
160 $str .= $src_file_name;
165 # $package_page .= sprintf( _g( " (These sources are for version %s)\n" ), $src_version )
166 # if ($src_version ne $version) && !$src_version_given_in_control;
169 if ($info{changesandcopy}) {
171 (my $src_basename = $source_version) =~ s,^\d+:,,; # strip epoche
172 $src_basename = "${source}_$src_basename";
173 $src_dir =~ s,pool/updates,pool,o;
174 $src_dir =~ s,pool/non-US,pool,o;
175 $str .= "<br>".sprintf( _g( 'View the <a href="%s">Debian changelog</a>' ),
176 "$CHANGELOG_URL/$src_dir/$src_basename/changelog" )."<br>\n";
177 my $copyright_url = "$CHANGELOG_URL/$src_dir/$src_basename/";
178 $copyright_url .= ( $is_source ? 'copyright' : "$name.copyright" );
180 $str .= sprintf( _g( 'View the <a href="%s">copyright file</a>' ),
181 $copyright_url )."</p>";
185 if ($info{maintainers}) {
186 my $uploaders = $page->get_src( 'uploaders' );
187 if ($uploaders && @$uploaders) {
188 foreach (@$uploaders) {
189 $_->[0] = encode_entities( $_->[0], '&<>' );
191 my ($maint_name, $maint_mail) = @{shift @$uploaders};
192 unless (@$uploaders) {
193 $str .= "<p>\n".sprintf( _g( "%s is responsible for this Debian package." ).
195 "<a href=\"mailto:$maint_mail\">$maint_name</a>"
198 my $up_str = "<a href=\"mailto:$maint_mail\">$maint_name</a>";
200 foreach (@$uploaders) {
201 push @uploaders_str, "<a href=\"mailto:$_->[1]\">$_->[0]</a>";
203 my $last_up = pop @uploaders_str;
204 $up_str .= ", ".join ", ", @uploaders_str if @uploaders_str;
205 $up_str .= sprintf( _g( " and %s are responsible for this Debian package." ), $last_up );
206 $str .= "<p>\n$up_str ";
210 $str .= sprintf( _g( "See the <a href=\"%s\">developer information for %s</a>." )."</p>", $QA_URL.$source, $name ) if $source;
214 my $encodedname = uri_escape( $name );
215 my $search_url = $is_source ? "$ROOT/source" : $ROOT;
216 $str .= "<p>".sprintf( _g( "Search for <a href=\"%s\">other versions of %s</a>" ),
217 "$search_url/$encodedname", $name )."</p>\n";
220 $str .= "</div> <!-- end pmoreinfo -->\n";
225 my ( $suite, $name, $info, $desc ) = @_;
226 my ($link, $post_link) = ('', '');
228 $link = "<a href=\"".make_url($name,'',{suite=>$suite,source=>undef})."\">";
237 $desc = "</dt><dd>$desc</dd>";
242 return "$link$name$post_link$info$desc";
245 sub provides_string {
246 my ($suite, $entry, $also) = @_;
247 my %tmp = map { $_ => 1 } split /\s/, $entry;
248 my @provided_by = keys %tmp; # weed out duplicates
249 my $short_desc = $also ? _g("also a virtual package provided by ")
250 : _g("virtual package provided by ");
251 if (@provided_by < 10) {
252 $short_desc .= join( ', ',map { "<a href=\"".make_url($_,'',{suite=>$suite,source=>undef})."\">$_</a>" } @provided_by);
254 $short_desc .= sprintf( _g("%s packages"), scalar(@provided_by));
260 my ( $packages, $opts, $pkg, $relations, $type) = @_;
261 my %dep_type = ('depends' => 'dep', 'recommends' => 'rec',
262 'suggests' => 'sug', 'build-depends' => 'adep',
263 'build-depends-indep' => 'idep' );
264 my $res = "<ul class=\"ul$dep_type{$type}\">\n";
266 my $suite = $opts->{suite}[0];
269 # debug( "print_deps called:\n".Dumper( $pkg, $relations, \$type ), 3 ) if DEBUG;
271 foreach my $rel (@$relations) {
272 my $is_old_pkgs = $rel->[0];
282 $res .= "</dl></li>\n<li>";
284 $res .= "<dl><dt><img class=\"hidecss\" src=\"$ROOT/Pics/$dep_type{$type}.gif\" alt=\"[$dep_type{$type}]\"> ";
287 foreach my $rel_alt ( @$rel ) {
288 next unless ref($rel_alt);
289 my ( $p_name, $pkg_version, $arch_neg,
290 $arch_str, $subsection, $available ) = @$rel_alt;
292 if ($arch_str ||= '') {
294 $arch_str = " ["._g("not")." $arch_str]";
296 $arch_str = " [$arch_str]";
299 $pkg_version = "($pkg_version)" if $pkg_version ||= '';
303 my $entry = $entries{$p_name} ||
304 read_entry_simple( $packages, $p_name, $opts->{h_archives}, $suite);
305 my $short_desc = $entry->[-1];
306 my $arch = $entry->[3];
307 my $archive = $entry->[1];
308 my $p_suite = $entry->[2];
310 if ( $is_old_pkgs ) {
311 push @res_pkgs, dep_item( $p_suite,
312 $p_name, "$pkg_version$arch_str" );
313 } elsif (defined $entry->[1]) {
314 $entries{$p_name} ||= $entry;
315 $short_desc = encode_entities( $short_desc, "<>&\"" );
316 $short_desc .= "<br>".provides_string( $p_suite,
319 if defined $entry->[0];
320 push @res_pkgs, dep_item( $p_suite,
321 $p_name, "$pkg_version$arch_str", $short_desc );
322 } elsif (defined $entry->[0]) {
323 $short_desc = provides_string( $p_suite,
325 #FIXME: we don't handle virtual packages from
326 # the fallback suite correctly here
327 push @res_pkgs, dep_item( $suite,
328 $p_name, "$pkg_version$arch_str", $short_desc );
330 } elsif ( $is_old_pkgs ) {
331 push @res_pkgs, dep_item( undef, $p_name, "$pkg_version$arch_str" );
333 my $short_desc = _g( "Package not available" );
334 push @res_pkgs, dep_item( undef, $p_name, "$pkg_version$arch_str", $short_desc );
339 $res .= "\n".join( "<dt>"._g( "or" )." ", @res_pkgs )."\n";
342 $res .= "</dl></li>\n";
350 my $ds_begin = '<dl>';
351 my $ds_item_desc = '<dt>';
352 my $ds_item = ':</dt><dd>';
353 my $ds_item_end = '</dd>';
354 my $ds_end = '</dl>';
355 # my $ds_begin = '<table><tbody>';
356 # my $ds_item_desc = '<tr><td>';
357 # my $ds_item = '</td><td>';
358 # my $ds_item_end = '</td></tr>';
359 # my $ds_end = '</tbody></table>';
365 return "$ds_item_desc$_[0]$ds_item$_[1]$ds_item_end\n";
375 if (defined $params{desc}) {
376 $DESC_LINE = "<meta name=\"Description\" content=\"$params{desc}\">";
382 my $title_keywords = $params{title_keywords} || $params{title} || '';
383 my $title_tag = $params{title_tag} || $params{title} || '';
384 my $title_in_header = $params{page_title} || $params{title} || '';
385 my $page_title = $params{page_title} || $params{title} || '';
386 my $meta = $params{meta} || '';
388 my $search_in_header = '';
389 $params{print_search_field} ||= "";
390 if ($params{print_search_field} eq 'packages') {
391 my %values = %{$params{search_field_values}};
392 my %checked_searchon = ( names => "",
396 $checked_searchon{$values{searchon}} = "checked=\"checked\"";
397 $checked_searchon{names} = "checked=\"checked\""
398 if $values{searchon} eq 'default';
399 $search_in_header = <<MENU;
400 <form method="GET" action="$SEARCH_URL">
401 <div id="hpacketsearch">
402 <input type="text" size="30" name="keywords" value="" id="kw">
403 <input type="submit" value="%s">
404 <span style="font-size: 60%%"><a href="$SEARCH_PAGE#search_packages">%s</a></span>
406 <div style="font-size: 80%%">%s
407 <input type="radio" name="searchon" value="names" id="onlynames" $checked_searchon{names}>
408 <label for="onlynames">%s</label>
409 <input type="radio" name="searchon" value="all" id="descs" $checked_searchon{all}>
410 <label for="descs">%s</label>
412 <input type="radio" name="searchon" value="sourcenames" id="src" $checked_searchon{sourcenames}>
413 <label for="src">%s</label>
414 <input type="radio" name="searchon" value="contents" id="conts" $checked_searchon{contents}>
415 <label for="conts">%s</label>
417 </div> <!-- end hpacketsearch -->
421 $search_in_header = sprintf( $search_in_header,
423 _g( 'Full options' ),
425 _g( 'Package Names' ),
426 _g( 'Descriptions' ),
427 _g( 'Source package names' ),
428 _g( 'Package contents' ));
429 # } elsif ($params{print_search_field} eq 'contents') {
430 # my %values = %{$params{search_field_values}};
431 # my %checked_searchmode = ( searchfiles => "",
432 # searchfilesanddirs => "",
435 # $checked_searchmode{$values{searchmode}} = "checked=\"checked\"";
436 # $search_in_header = <<MENU;
437 # <form method="GET" action="$CONTENTS_SEARCH_CGI">
438 # <div id="hpacketsearch">
439 # <input type="hidden" name="debug" value="$values{debug}" />
440 # <input type="hidden" name="version" value="$values{version}" />
441 # <input type="hidden" name="arch" value="$values{arch}" />
442 # <input type="hidden" name="case" value="$values{case}" />
443 # <input type="text" size="30" name="word" id="keyword" value="$values{keyword}">
444 # <input type="submit" value="Search">
445 # <span style="font-size: 60%"><a href="$SEARCH_PAGE#search_contents">Full options</a></span>
447 # <div style="font-size: 80%">Display:
448 # <input type=radio name="searchmode" value="searchfiles" id="searchfiles" $checked_searchmode{searchfiles}>
449 # <label for="searchfiles">files</label>
450 # <input type=radio name="searchmode" value="searchfilesanddirs" id="searchfilesanddirs" $checked_searchmode{searchfilesanddirs}>
451 # <label for="searchfilesanddirs">files & directories</label>
453 # <input type=radio name="searchmode" value="searchword" id="searchword" $checked_searchmode{searchword}>
454 # <label for="searchword">subword matching</label>
455 # <input type=radio name="searchmode" value="filelist" id="filelist" $checked_searchmode{filelist}>
456 # <label for="filelist">content list</label>
458 # </div> <!-- end hpacketsearch -->
464 my $keywords = $params{keywords} || '';
465 my $KEYWORDS_LINE = "<meta name=\"Keywords\" content=\"debian, $keywords $title_keywords\">";
467 my $LANG = $params{lang};
468 my $charset = get_charset($LANG);
470 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
473 <title>Debian -- $title_tag</title>
474 <link rev="made" href="mailto:$WEBMASTER_MAIL">
475 <meta http-equiv="Content-Type" content="text/html; charset=$charset">
476 <meta name="Author" content="Debian Webmaster, $WEBMASTER_MAIL">
480 <link href="$ROOT/debian.css" rel="stylesheet" type="text/css" media="all">
481 <link href="$ROOT/packages.css" rel="stylesheet" type="text/css" media="all">
485 <div id="upperheader">
487 <a href="$HOME/"><img src="$HOME/logos/openlogo-nd-50.png" alt="" /></a>
491 $txt .= img( "$HOME/", "", "Pics/debian.png", _g( "Debian Project" ),
492 width => 179, height => 61 );
495 </div> <!-- end logo -->
501 </div> <!-- end upperheader -->
505 $txt .= "<p class=\"hidecss\"><a href=\"\#inner\">" . _g("Skip Site Navigation")."</a></p>\n";
506 $txt .= "<div id=\"navbar\">\n<ul>".
507 "<li><a href=\"$HOME/intro/about\">"._g( "About Debian" )."</a></li>\n".
508 "<li><a href=\"$HOME/News/\">"._g( "News" )."</a></li>\n".
509 "<li><a href=\"$HOME/distrib/\">"._g( "Getting Debian" )."</a></li>\n".
510 "<li><a href=\"$HOME/support\">"._g( "Support" )."</a></li>\n".
511 "<li><a href=\"$HOME/devel/\">"._g( "Development" )."</a></li>\n".
512 "<li><a href=\"$HOME/sitemap\">"._g( "Site map" )."</a></li>\n".
513 "<li><a href=\"http://search.debian.org/\">"._g( "Search" )."</a></li>\n";
516 </div> <!-- end navbar -->
517 </div> <!-- end header -->
520 $txt .= <<BEGINCONTENT;
526 if ($params{print_title}) {
527 $txt .= "<h1>$page_title</h1>\n";
534 my ($ROOT, $NAME, $LANG, @USED_LANGS) = @_;
535 my $txt = "</div> <!-- end inner -->\n<div id=\"footer\">\n";
536 my $langs = languages( $NAME, $LANG, @USED_LANGS );
537 my $bl_class = $langs ? ' class="bordertop"' : "";
540 "\n<hr class=\"hidecss\">\n" .
542 sprintf( _g( "Back to: <a href=\"%s/\">Debian Project homepage</a> || <a href=\"%s/\">Packages search page</a>" ), $HOME, $ROOT ).
543 "</p>\n<hr class=\"hidecss\">\n".
544 "<div id=\"fineprint\" class=\"bordertop\"><p>".
545 sprintf( _g( "To report a problem with the web site, e-mail <a href=\"mailto:%s\">%s</a>. For other contact information, see the Debian <a href=\"%s/contact\">contact page</a>." ), $CONTACT_MAIL, $CONTACT_MAIL, $HOME).
547 "<p>". _g( "Last Modified: " ). gmtime().
549 sprintf( _g( "Copyright © 1997-2005 <a href=\"http://www.spi-inc.org\">SPI</a>; See <a href=\"%s/license\">license terms</a>." ), "$HOME/" )."<br>\n".
550 _g( "Debian is a registered trademark of Software in the Public Interest, Inc." ).
551 "</div> <!-- end fineprint -->\n".
552 "</div> <!-- end footer -->\n".
553 "</div> <!-- end outer -->\n".
554 "</body>\n</html>\n";
560 my ( $name, $lang, @used_langs ) = @_;
565 $str .= "<hr class=\"hidecss\">\n";
566 $str .= "<!--UdmComment-->\n<p>\n";
567 $str .= _g( "This page is also available in the following languages:\n" );
568 $str .= "</p><p class=\"navpara\">\n";
570 my @printed_langs = ();
571 foreach (@used_langs) {
572 next if $_ eq $lang; # Never print the current language
573 unless (get_selfname($_)) { warn "missing language $_"; next } #DEBUG
574 push @printed_langs, $_;
576 return "" unless scalar @printed_langs;
577 # Sort on uppercase to work with languages which use lowercase initial
579 foreach my $cur_lang (sort langcmp @printed_langs) {
580 my $tooltip = dgettext( "langs", get_language_name($cur_lang) );
581 $str .= "<a href=\"$name.$cur_lang.html\" title=\"$tooltip\" hreflang=\"$cur_lang\" lang=\"$cur_lang\" rel=\"alternate\">".get_selfname($cur_lang);
582 $str .= " (".get_transliteration($cur_lang).")" if defined get_transliteration($cur_lang);
585 $str .= "\n</p><p>\n";
586 $str .= sprintf( _g( "How to set <a href=\"%s\">the default document language</a>" ), $CN_HELP_URL )."</p>";
587 $str .= "\n<!--/UdmComment-->\n";