2 # Provides a list of broken links.
3 package IkiWiki::Plugin::brokenlinks;
10 hook(type => "preprocess", id => "brokenlinks", call => \&preprocess);
13 sub preprocess (@) { #{{{
15 $params{pages}="*" unless defined $params{pages};
17 # Needs to update whenever a page is added or removed, so
18 # register a dependency.
19 add_depends($params{page}, $params{pages});
22 foreach my $page (keys %links) {
23 if (pagespec_match($page, $params{pages})) {
24 foreach my $link (@{$links{$page}}) {
25 next if $link =~ /.*\/discussion/i && $config{discussion};
26 my $bestlink=bestlink($page, $link);
27 next if length $bestlink;
29 htmllink($page, $params{destpage}, $link, 1).
31 htmllink($params{page}, $params{destpage}, $page, 1);
36 return gettext("There are no broken links!") unless @broken;
38 return "<ul>\n".join("\n", map { "<li>$_</li>" } grep { ! $seen{$_}++ } sort @broken)."</ul>\n";