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);
use PublicInbox::Reply;
use PublicInbox::ViewDiff qw(flush_diff);
use PublicInbox::Eml;
+use POSIX qw(strftime);
use Time::Local qw(timegm);
use PublicInbox::Smsg qw(subject_normalized);
use PublicInbox::ContentHash qw(content_hash);
}
delete $ctx->{obuf};
eval { $$obuf .= html_footer($ctx, $eml) };
- html_oneshot($ctx, 200, $obuf);
+ html_oneshot($ctx, 200, $$obuf);
}
# public functions: (unstable)
# 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};
" <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%]";
# 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
$rv .= qq(<a\nhref="#R">reply</a>);
$rv .= $skel;
$rv .= '</pre>';
+ $rv .= $related // '';
$rv .= msg_reply($ctx, $hdr);
}
}
my @out;
- my $ibx = $ctx->{ibx};
- my $obfs_ibx = $ibx->{obfuscate} ? $ibx : undef;
-
+ my $obfs_ibx = $ctx->{ibx}->{obfuscate} ? $ctx->{ibx} : undef;
+ if (my $note = delete $ctx->{t_note}) {
+ push @out, $note; # "messages from ... to ..."
+ }
# sort by recency, this allows new posts to "bump" old topics...
foreach my $topic (sort { $b->[0] <=> $a->[0] } @$order) {
my ($ds, $n, $seen, $top_subj, @extra) = @$topic;
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
$next = $next ? "$next | " : ' | ';
$prev .= qq[ | <a\nhref="$latest">latest</a>];
}
- "<hr><pre>page: $next$prev</pre>";
+ ($next || $prev) ? "<hr><pre id=nav>page: $next$prev</pre>" : '';
}
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 $nr = scalar @$msgs;
- if ($nr < $lim && defined($after)) {
+ my $msgs = $ctx->{ibx}->over->recent($opts, $after, $before);
+ if (defined($after) && scalar(@$msgs) < $lim) {
$after = $before = undef;
- $msgs = $ibx->recent($opts);
- $nr = scalar @$msgs;
+ $msgs = $ctx->{ibx}->over->recent($opts);
}
- my $more = $nr == $lim;
+ my $more = scalar(@$msgs) == $lim;
my ($newest, $oldest);
- if ($nr) {
+ if (@$msgs) {
$newest = $msgs->[0]->{ts};
$oldest = $msgs->[-1]->{ts};
# if we only had $after, our SQL query in ->recent ordered
if ($newest < $oldest) {
($oldest, $newest) = ($newest, $oldest);
- $more = 0 if defined($after) && $after < $oldest;
+ $more = undef if defined($after) && $after < $oldest;
+ }
+ if (defined($after // $before)) {
+ my $n = strftime('%Y-%m-%d %H:%M:%S', gmtime($newest));
+ my $o = strftime('%Y-%m-%d %H:%M:%S', gmtime($oldest));
+ $ctx->{t_note} = <<EOM;
+ messages from $o to $n UTC, [<a href="#nav">more...</a>]
+EOM
+ my $s = ts2str($newest);
+ $ctx->{prev_page} = qq[<a\nhref="?t=$s-"\nrel=prev>] .
+ 'prev (newer)</a>';
}
}
if (defined($oldest) && $more) {
$ctx->{next_page} = qq[<a\nhref="?t=$s"\nrel=next>] .
'next (older)</a>';
}
- if (defined($newest) && (defined($before) || defined($after))) {
- my $s = ts2str($newest);
- $ctx->{prev_page} = qq[<a\nhref="?t=$s-"\nrel=prev>] .
- 'prev (newer)</a>';
- }
$msgs;
}
sub index_topics {
my ($ctx) = @_;
my $msgs = paginate_recent($ctx, 200); # 200 is our window
- if (@$msgs) {
- walk_thread(thread_results($ctx, $msgs), $ctx, \&acc_topic);
- }
- html_oneshot($ctx, dump_topics($ctx), \pagination_footer($ctx, '.'));
-
+ walk_thread(thread_results($ctx, $msgs), $ctx, \&acc_topic) if @$msgs;
+ html_oneshot($ctx, dump_topics($ctx), pagination_footer($ctx, '.'));
}
sub thread_adj_level {