]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
treewide: ditch inbox->recent method
[public-inbox.git] / lib / PublicInbox / View.pm
index c28505f111424fdd03fe5aa8175deb5ce4c575ba..466ec6cfdad1c0677211878498d0db288e170247 100644 (file)
@@ -7,6 +7,7 @@ package PublicInbox::View;
 use strict;
 use v5.10.1;
 use List::Util qw(max);
+use Text::Wrap qw(wrap); # stdlib, we need Perl 5.6+ for $huge
 use PublicInbox::MsgTime qw(msg_datestamp);
 use PublicInbox::Hval qw(ascii_html obfuscate_addrs prurl mid_href
                        ts2str fmt_ts);
@@ -63,7 +64,7 @@ sub no_over_html ($) {
        }
        delete $ctx->{obuf};
        eval { $$obuf .= html_footer($ctx, $eml) };
-       html_oneshot($ctx, 200, $obuf);
+       html_oneshot($ctx, 200, $$obuf);
 }
 
 # public functions: (unstable)
@@ -246,6 +247,7 @@ sub eml_entry {
 
        # scan through all parts, looking for displayable text
        $ctx->{mhref} = $mhref;
+       $ctx->{end_id} = "e$id";
        $ctx->{obuf} = \$rv;
        $eml->each_part(\&add_text_body, $ctx, 1);
        delete $ctx->{obuf};
@@ -256,6 +258,9 @@ sub eml_entry {
                " <a\nhref=\"${mhref}raw\">raw</a>" .
                " <a\nhref=\"${mhref}#R\">reply</a>";
 
+       delete($ctx->{-qry}) and
+               $rv .= qq[ <a\nhref="${mhref}#related">related</a>];
+
        my $hr;
        if (defined(my $pct = $smsg->{pct})) { # used by SearchView.pm
                $rv .= "\t[relevance $pct%]";
@@ -820,15 +825,39 @@ sub _parent_headers {
 # returns a string buffer
 sub html_footer {
        my ($ctx, $hdr) = @_;
-       my $ibx = $ctx->{ibx};
        my $upfx = '../';
        my $skel;
        my $rv = '<pre>';
-       if ($ibx->over) {
+       my $related;
+       my $qry = delete $ctx->{-qry};
+       if ($qry && $ctx->{ibx}->isrch) {
+               my $q = ''; # search for either ancestor or descendent patches
+               for (@{$qry->{dfpre}}, @{$qry->{dfpost}}) {
+                       chop if length > 7; # include 1 abbrev "older" patches
+                       $q .= "dfblob:$_ ";
+               }
+               chop $q; # omit trailing SP
+               local $Text::Wrap::columns = COLS;
+               local $Text::Wrap::huge = 'overflow';
+               $q = wrap('', '', $q);
+               my $rows = ($q =~ tr/\n/\n/) + 1;
+               $q = ascii_html($q);
+               $related = <<EOM;
+<form id=related
+action=$upfx
+><pre>find likely ancestor, descendant, or conflicting patches for <a
+href=#t>this message</a>:
+<textarea name=q cols=${\COLS} rows=$rows>$q</textarea>
+<input type=submit value=search
+/>\t(<a href=${upfx}_/text/help/>help</a>)</pre></form>
+EOM
+       }
+       if ($ctx->{ibx}->over) {
                my $t = ts2str($ctx->{-t_max});
                my $t_fmt = fmt_ts($ctx->{-t_max});
-               $skel .= <<EOF;
-       other threads:[<a
+               my $fallback = $related ? "\t" : "<a id=related>\t</a>";
+               $skel = <<EOF;
+${fallback}other threads:[<a
 href="$upfx?t=$t">~$t_fmt UTC</a>|<a
 href="$upfx">newest</a>]
 EOF
@@ -869,6 +898,7 @@ EOF
        $rv .= qq(<a\nhref="#R">reply</a>);
        $rv .= $skel;
        $rv .= '</pre>';
+       $rv .= $related // '';
        $rv .= msg_reply($ctx, $hdr);
 }
 
@@ -1158,9 +1188,9 @@ sub dump_topics {
 
                my $s = "<a\nhref=\"$href/T/$anchor\">$top_subj</a>\n" .
                        " $ds UTC $n\n";
-               for (my $i = 0; $i < scalar(@extra); $i += 2) {
-                       my $level = $extra[$i];
-                       my $subj = $extra[$i + 1]; # already normalized
+               while (@extra) {
+                       my $level = shift @extra;
+                       my $subj = shift @extra; # already normalized
                        $mid = delete $seen->{$subj};
                        my @subj = split(/ /, $subj);
                        my @next_prev = @subj; # full copy
@@ -1192,7 +1222,7 @@ sub pagination_footer ($$) {
                $next = $next ? "$next | " : '             | ';
                $prev .= qq[ | <a\nhref="$latest">latest</a>];
        }
-       ($next || $prev) ? \"<hr><pre>page: $next$prev</pre>" : \'';
+       ($next || $prev) ? "<hr><pre>page: $next$prev</pre>" : '';
 }
 
 sub paginate_recent ($$) {
@@ -1207,12 +1237,11 @@ sub paginate_recent ($$) {
        $t =~ s/\A([0-9]{8,14})-// and $after = str2ts($1);
        $t =~ /\A([0-9]{8,14})\z/ and $before = str2ts($1);
 
-       my $ibx = $ctx->{ibx};
-       my $msgs = $ibx->recent($opts, $after, $before);
+       my $msgs = $ctx->{ibx}->over->recent($opts, $after, $before);
        my $nr = scalar @$msgs;
        if ($nr < $lim && defined($after)) {
                $after = $before = undef;
-               $msgs = $ibx->recent($opts);
+               $msgs = $ctx->{ibx}->over->recent($opts);
                $nr = scalar @$msgs;
        }
        my $more = $nr == $lim;