]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/brokenlinks.pm
* Fix another destpage issue in the inline directive. Closes: #385512
[git.ikiwiki.info.git] / IkiWiki / Plugin / brokenlinks.pm
1 #!/usr/bin/perl
2 # Provides a list of broken links.
3 package IkiWiki::Plugin::brokenlinks;
5 use warnings;
6 use strict;
7 use IkiWiki;
9 sub import { #{{{
10         IkiWiki::hook(type => "preprocess", id => "brokenlinks",
11                 call => \&preprocess);
12 } # }}}
14 sub preprocess (@) { #{{{
15         my %params=@_;
16         $params{pages}="*" unless defined $params{pages};
17         
18         # Needs to update whenever a page is added or removed, so
19         # register a dependency.
20         IkiWiki::add_depends($params{page}, $params{pages});
21         
22         my @broken;
23         foreach my $page (keys %IkiWiki::links) {
24                 if (IkiWiki::pagespec_match($page, $params{pages})) {
25                         foreach my $link (@{$IkiWiki::links{$page}}) {
26                                 next if $link =~ /.*\/discussion/i && $IkiWiki::config{discussion};
27                                 my $bestlink=IkiWiki::bestlink($page, $link);
28                                 next if length $bestlink;
29                                 push @broken,
30                                         IkiWiki::htmllink($page, $params{destpage}, $link, 1).
31                                         " in ".
32                                         IkiWiki::htmllink($params{page}, $params{destpage}, $page, 1);
33                         }
34                 }
35         }
36         
37         return "There are no broken links!" unless @broken;
38         my %seen;
39         return "<ul>\n".join("\n", map { "<li>$_</li>" } grep { ! $seen{$_}++ } sort @broken)."</ul>\n";
40 } # }}}
42 1