-sub linkify ($$$) { #{{{
- my $lpage=shift; # the page containing the links
- my $page=shift; # the page the link will end up on (different for inline)
- my $content=shift;
-
- $content =~ s{(\\?)$config{wiki_link_regexp}}{
- $2 ? ( $1 ? "[[$2|$3]]" : htmllink($lpage, $page, titlepage($3), 0, 0, pagetitle($2)))
- : ( $1 ? "[[$3]]" : htmllink($lpage, $page, titlepage($3)))
- }eg;
-
- return $content;
-} #}}}
-
-sub htmlize ($$$) { #{{{
- my $page=shift;
- my $type=shift;
- my $content=shift;
-
- if (exists $hooks{htmlize}{$type}) {
- $content=$hooks{htmlize}{$type}{call}->(
- page => $page,
- content => $content,
- );
- }
- else {
- error("htmlization of $type not supported");
- }
-
- run_hooks(sanitize => sub {
- $content=shift->(
- page => $page,
- content => $content,
- );
- });
-
- return $content;
-} #}}}
-
-sub backlinks ($) { #{{{
- my $page=shift;
-
- my @links;
- foreach my $p (keys %links) {
- next if bestlink($page, $p) eq $page;
- if (grep { length $_ && bestlink($p, $_) eq $page } @{$links{$p}}) {
- my $href=abs2rel(htmlpage($p), dirname($page));
-
- # Trim common dir prefixes from both pages.
- my $p_trimmed=$p;
- my $page_trimmed=$page;
- my $dir;
- 1 while (($dir)=$page_trimmed=~m!^([^/]+/)!) &&
- defined $dir &&
- $p_trimmed=~s/^\Q$dir\E// &&
- $page_trimmed=~s/^\Q$dir\E//;
-
- push @links, { url => $href, page => pagetitle($p_trimmed) };
+my %backlinks;
+my $backlinks_calculated=0;
+
+sub calculate_backlinks () {
+ return if $backlinks_calculated;
+ %backlinks=();
+ foreach my $page (keys %links) {
+ foreach my $link (@{$links{$page}}) {
+ my $bestlink=bestlink($page, $link);
+ if (length $bestlink && $bestlink ne $page) {
+ $backlinks{$bestlink}{$page}=1;
+ }