push @repo_objs, $repo if $repo;
}
if (scalar @repo_objs) {
+ require Scalar::Util;
+ for (@repo_objs) {
+ push @{$_->{-ibxs}}, $ibxish;
+ Scalar::Util::weaken($_->{-ibxs}->[-1]);
+ }
$ibxish->{-repo_objs} = \@repo_objs;
} else {
delete $ibxish->{coderepo};
$url .= '/' if $url !~ m!/\z!;
return $url .= $self->{name} . '/';
}
- # called from a non-PSGI environment (e.g. NNTP/POP3):
+ # called from a non-PSGI environment or cross-inbox environment
+ # where multiple inboxes can have different domains
my $url = $self->{url} // return undef;
$url = $url->[0] // return undef;
# expand protocol-relative URLs to HTTPS if we're
use PublicInbox::View;
use PublicInbox::Eml;
use Text::Wrap qw(wrap);
-use PublicInbox::Hval qw(ascii_html to_filename);
+use PublicInbox::Hval qw(ascii_html to_filename prurl);
my $hl = eval {
require PublicInbox::HlMod;
PublicInbox::HlMod->new;
}
}
+sub ibx_url_for {
+ my ($ctx) = @_;
+ $ctx->{ibx} and return; # just fall back to $upfx
+ $ctx->{git} or return; # /$CODEREPO/$OID/s/ to (eidx|ibx)
+ if (my $ALL = $ctx->{www}->{pi_cfg}->ALL) {
+ $ALL->base_url // $ALL->base_url($ctx->{env});
+ } elsif (my $ibxs = $ctx->{git}->{-ibxs}) {
+ for my $ibx (@$ibxs) {
+ if ($ibx->isrch) {
+ return defined($ibx->{url}) ?
+ prurl($ctx->{env}, $ibx->{url}) :
+ "../../../$ibx->{name}/";
+ }
+ }
+ } else {
+ undef;
+ }
+}
+
sub cmt_finalize {
my ($ctx) = @_;
$ctx->{-linkify} //= PublicInbox::Linkify->new;
$q = wrap('', '', $q);
my $rows = ($q =~ tr/\n/\n/) + 1;
$q = ascii_html($q);
+ my $ibx_url = ibx_url_for($ctx);
+ my $alt = $ibx_url ? ' '.ascii_html($ibx_url) : '';
+ $ibx_url = ascii_html($ibx_url) if defined $ibx_url;
+ $ibx_url //= $upfx;
print $zfh <<EOM;
-<hr><form action=$upfx
+<hr><form action="$ibx_url"
id=related><pre>find related emails, including ancestors/descendants/conflicts
<textarea name=q cols=${\PublicInbox::View::COLS} rows=$rows>$q</textarea>
-<input type=submit value=search
-/>\t(<a href=${upfx}_/text/help/>help</a>)</pre></form>
+<input type=submit value="search$alt"
+/>\t(<a href="${ibx_url}_/text/help/">help</a>)</pre></form>
EOM
}
}
$k = substr($k, length('coderepo.'), -length('.dir'));
$code_repos->{$k} //= $pi_cfg->fill_code_repo($k);
}
+
+ # associate inboxes and extindices with coderepos for search:
+ for my $k (grep(/\Apublicinbox\.(?:.+)\.coderepo\z/, keys %$pi_cfg)) {
+ $k = substr($k, length('publicinbox.'), -length('.coderepo'));
+ my $ibx = $pi_cfg->lookup_name($k) // next;
+ $pi_cfg->repo_objs($ibx);
+ push @{$self->{-strong}}, $ibx; # strengthen {-ibxs} weakref
+ }
+ for my $k (grep(/\Aextindex\.(?:.+)\.coderepo\z/, keys %$pi_cfg)) {
+ $k = substr($k, length('extindex.'), -length('.coderepo'));
+ my $eidx = $pi_cfg->lookup_ei($k) // next;
+ $pi_cfg->repo_objs($eidx);
+ push @{$self->{-strong}}, $eidx; # strengthen {-ibxs} weakref
+ }
while (my ($nick, $repo) = each %$code_repos) {
$self->{"\0$nick"} = $repo;
}