-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 $type=shift;
- my $content=shift;
-
- if (exists $hooks{htmlize}{$type}) {
- $content=$hooks{htmlize}{$type}{call}->($content);
- }
- else {
- error("htmlization of $type not supported");
- }
-
- run_hooks(sanitize => sub {
- $content=shift->($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;
+our %brokenlinks;
+my $links_calculated=0;
+
+sub calculate_links () {
+ return if $links_calculated;
+ %backlinks=%brokenlinks=();
+ foreach my $page (keys %links) {
+ foreach my $link (@{$links{$page}}) {
+ my $bestlink=bestlink($page, $link);
+ if (length $bestlink) {
+ $backlinks{$bestlink}{$page}=1
+ if $bestlink ne $page;
+ }
+ else {
+ push @{$brokenlinks{$link}}, $page;
+ }