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);
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 my $discussion=gettext("Discussion");
32 foreach my $page (pagespec_match_list([keys %links],
33 $params{pages}, location => $params{page})) {
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;
46 foreach my $link (keys %broken) {
47 my $page=$broken{$link}->[0];
48 push @broken, sprintf(gettext("%s from %s"),
49 htmllink($page, $params{destpage}, $link, noimageinline => 1),
51 htmllink($params{page}, $params{destpage}, $_, noimageinline => 1)
52 } @{$broken{$link}}));
55 return gettext("There are no broken links!") unless %broken;