hook(type => "formbuilder_setup", id => "po", call => \&formbuilder_setup, last => 1);
hook(type => "formbuilder", id => "po", call => \&formbuilder);
+ $origsubs{'bestlink'}=\&IkiWiki::bestlink;
+ inject(name => "IkiWiki::bestlink", call => \&mybestlink);
$origsubs{'beautify_urlpath'}=\&IkiWiki::beautify_urlpath;
inject(name => "IkiWiki::beautify_urlpath", call => \&mybeautify_urlpath);
$origsubs{'targetpage'}=\&IkiWiki::targetpage;
inject(name => "IkiWiki::urlto", call => \&myurlto);
$origsubs{'cgiurl'}=\&IkiWiki::cgiurl;
inject(name => "IkiWiki::cgiurl", call => \&mycgiurl);
+ $origsubs{'rootpage'}=\&IkiWiki::rootpage;
+ inject(name => "IkiWiki::rootpage", call => \&myrootpage);
}
warn(gettext('po_link_to=negotiated requires usedirs to be enabled, falling back to po_link_to=default'));
$config{po_link_to}='default';
}
- unless ($config{po_link_to} eq 'default') {
- $origsubs{'bestlink'}=\&IkiWiki::bestlink;
- inject(name => "IkiWiki::bestlink", call => \&mybestlink);
- }
push @{$config{wiki_file_prune_regexps}}, qr/\.pot$/;
# `----
# Implement po_link_to 'current' and 'negotiated' settings.
-# Not injected otherwise.
sub mybestlink ($$) {
my $page=shift;
my $link=shift;
+ return $origsubs{'bestlink'}->($page, $link)
+ if $config{po_link_to} eq "default";
+
my $res=$origsubs{'bestlink'}->(masterpage($page), $link);
+ my @caller = caller(1);
if (length $res
&& istranslatable($res)
- && istranslation($page)) {
+ && istranslation($page)
+ && !(exists $caller[3] && defined $caller[3]
+ && ($caller[3] eq "IkiWiki::PageSpec::match_link"))) {
return $res . "." . lang($page);
}
return $res;
return $origsubs{'cgiurl'}->(%params);
}
+sub myrootpage (@) {
+ my %params=@_;
+
+ my $rootpage;
+ if (exists $params{rootpage}) {
+ $rootpage=$origsubs{'bestlink'}->($params{page}, $params{rootpage});
+ if (!length $rootpage) {
+ $rootpage=$params{rootpage};
+ }
+ }
+ else {
+ $rootpage=masterpage($params{page});
+ }
+ return $rootpage;
+}
+
# ,----
# | Blackboxes for private data
# `----