2 # Provides a list of broken links.
3 package IkiWiki::Plugin::brokenlinks;
10 hook(type => "getsetup", id => "brokenlinks", call => \&getsetup);
11 hook(type => "preprocess", id => "brokenlinks", call => \&preprocess);
22 sub preprocess (@) { #{{{
24 $params{pages}="*" unless defined $params{pages};
26 # Needs to update whenever a page is added or removed, so
27 # register a dependency.
28 add_depends($params{page}, $params{pages});
31 foreach my $page (keys %links) {
32 if (pagespec_match($page, $params{pages}, location => $params{page})) {
33 my $discussion=gettext("discussion");
35 foreach my $link (@{$links{$page}}) {
38 next if $link =~ /.*\/\Q$discussion\E/i && $config{discussion};
39 my $bestlink=bestlink($page, $link);
40 next if length $bestlink;
41 push @{$broken{$link}}, $page;
47 foreach my $link (keys %broken) {
48 my $page=$broken{$link}->[0];
49 push @broken, sprintf(gettext("%s from %s"),
50 htmllink($page, $params{destpage}, $link, noimageinline => 1),
52 htmllink($params{page}, $params{destpage}, $_, noimageinline => 1)
53 } @{$broken{$link}}));
56 return gettext("There are no broken links!") unless %broken;