X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FWwwStream.pm;h=01f7b31ba186001723d21dcbe2d3291e5f4383bc;hb=21f5b7a8bcd942b19475c1c0c265f39dfdf93608;hp=fdab4da3bab2dabf7e71005afe860963177e363e;hpb=add1c663d1048d76b3d608e81f8e653f79b8f9f5;p=public-inbox.git diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm index fdab4da3..01f7b31b 100644 --- a/lib/PublicInbox/WwwStream.pm +++ b/lib/PublicInbox/WwwStream.pm @@ -7,11 +7,17 @@ use strict; use warnings; use PublicInbox::Hval qw(ascii_html); use URI; -use constant PI_URL => 'https://public-inbox.org/'; +our $TOR_URL = 'https://www.torproject.org/'; +our $TOR2WEB_URL = 'https://www.tor2web.org/'; +our $CODE_URL = 'https://public-inbox.org/'; +our $PROJECT = 'public-inbox'; + +# noop for HTTP.pm (and any other PSGI servers) +sub close {} sub new { my ($class, $ctx, $cb) = @_; - bless { nr => 0, cb => $cb, ctx => $ctx }, $class; + bless { nr => 0, cb => $cb || *close, ctx => $ctx }, $class; } sub response { @@ -27,13 +33,16 @@ sub _html_top ($) { my $desc = ascii_html($obj->description); my $title = $ctx->{-title_html} || $desc; my $upfx = $ctx->{-upfx} || ''; + my $help = $upfx.'_/text/help'; my $atom = $ctx->{-atom} || $upfx.'new.atom'; my $tip = $ctx->{-html_tip} || ''; - my $top = "$desc (Atom feed)"; + my $top = "$desc"; + my $links = "help / ". + "Atom feed"; if ($obj->search) { my $q_val = $ctx->{-q_value_html}; if (defined $q_val && $q_val ne '') { - $q_val = qq(\nvalue="$q_val" ); + $q_val = qq(\nvalue="$q_val"); } else { $q_val = ''; } @@ -41,12 +50,13 @@ sub _html_top ($) { my $extra = $ctx->{-extra_form_html} || ''; my $action = $upfx eq '' ? './' : $upfx; $top = qq{
} } else { - $top = '' . $top . ''; + $top = '
' . $top . "\n" . $links . ''; } "
'.join("\n", - '- ' . $desc, + + my @nntp = map { qq($_) } @{$obj->nntp_url}; + if (@nntp) { + $urls .= "\n\n"; + $urls .= @nntp == 1 ? 'Newsgroup' : 'Newsgroups are'; + $urls .= ' available over NNTP:'; + $urls .= "\n\t" . join("\n\t", @nntp) . "\n"; + } + if ($urls =~ m!\b[^:]+://\w+\.onion/!) { + $urls .= "\n note: .onion URLs require Tor: "; + $urls .= qq[$TOR_URL]; + if ($TOR2WEB_URL) { + $urls .= "\n or Tor2web: "; + $urls .= qq[$TOR2WEB_URL]; + } + } + my $url = PublicInbox::Hval::prurl($ctx->{env}, $CODE_URL); + ''.join("\n\n", + $desc, $urls, - 'Archived served using code from public-inbox:', - qq(\tgit clone $url public-inbox), + 'AGPL code for this site: '. + qq(git clone $url $PROJECT) ).''; } +# callback for HTTP.pm (and any other PSGI servers) sub getline { my ($self) = @_; my $nr = $self->{nr}++; return _html_top($self) if $nr == 0; - if (my $mid = $self->{cb}) { # middle - $mid = $mid->($nr, $self->{ctx}) and return $mid; + if (my $middle = $self->{cb}) { + $middle = $middle->($nr, $self->{ctx}) and return $middle; } delete $self->{cb} ? _html_end($self) : undef; } -sub close {} - 1;