From 57cf47ec49dee9f919460840ae94074ff807b695 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 16 Aug 2015 02:17:14 +0000 Subject: www: /t/$MESSAGE_ID.html for threads This should bring up nearly the entire thread a given Message-ID is linked to. --- lib/PublicInbox/WWW.pm | 51 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'lib/PublicInbox/WWW.pm') diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 32cc0b27..52e51c43 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -49,9 +49,15 @@ sub run { } elsif ($path_info =~ m!$LISTNAME_RE/f/(\S+)\.html\z!o) { invalid_list_mid(\%ctx, $1, $2) || get_full_html(\%ctx, $cgi); + # thread display + } elsif ($path_info =~ m!$LISTNAME_RE/t/(\S+)\.html\z!o) { + invalid_list_mid(\%ctx, $1, $2) || get_thread(\%ctx, $cgi); + # convenience redirects, order matters - } elsif ($path_info =~ m!$LISTNAME_RE/(?:m|f)/(\S+)\z!o) { - invalid_list_mid(\%ctx, $1, $2) || redirect_mid(\%ctx, $cgi); + } elsif ($path_info =~ m!$LISTNAME_RE/(m|f|t)/(\S+)\z!o) { + my $pfx = $2; + invalid_list_mid(\%ctx, $1, $3) || + redirect_mid(\%ctx, $cgi, $2); } else { r404(); @@ -170,9 +176,7 @@ sub get_mid_html { return r404() unless $x; require PublicInbox::View; - my $mid_href = PublicInbox::Hval::ascii_html( - uri_escape_utf8($ctx->{mid})); - my $pfx = "../f/$mid_href.html"; + my $pfx = msg_pfx($ctx); my $foot = footer($ctx); require Email::MIME; my $mime = Email::MIME->new($x); @@ -195,6 +199,18 @@ sub get_full_html { [ PublicInbox::View->msg_html($mime, undef, $foot, $srch)] ]; } +# /$LISTNAME/t/$MESSAGE_ID.html +sub get_thread { + my ($ctx, $cgi) = @_; + my $srch = searcher($ctx) or return need_search($ctx); + require PublicInbox::View; + my $foot = footer($ctx); + my $body = PublicInbox::View->thread_html($ctx, $foot, $srch) or + return r404(); + [ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ], + [ $body ] ]; +} + sub self_url { my ($cgi) = @_; ref($cgi) eq 'CGI' ? $cgi->self_url : $cgi->uri->as_string; @@ -206,10 +222,13 @@ sub redirect_list_index { } sub redirect_mid { - my ($ctx, $cgi) = @_; + my ($ctx, $cgi, $pfx) = @_; my $url = self_url($cgi); - $url =~ s!/f/!/m/!; - do_redirect($url . '.html'); + my $anchor = ''; + if (lc($pfx) eq 't') { + $anchor = '#u'; # is used to highlight in View.pm + } + do_redirect($url . ".html$anchor"); } sub do_redirect { @@ -295,4 +314,20 @@ sub searcher { }; } +sub need_search { + my ($ctx) = @_; + my $msg = <Search not available for this +public-inbox
Search is not available for this public-inbox
+Return to index
+EOF + [ 501, [ 'Content-Type' => 'text/html; charset=UTF-8' ], [ $msg ] ]; +} + +sub msg_pfx { + my ($ctx) = @_; + my $href = PublicInbox::Hval::ascii_html(uri_escape_utf8($ctx->{mid})); + "../f/$href.html"; +} + 1; -- cgit v1.2.3-24-ge0c7