clear sandbox/test commit
[ikiwiki.git] / IkiWiki / Plugin / brokenlinks.pm
blob8ee734bf947b6137a2925bac3eeb69ebc965a9bd
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 3.00;
9 sub import {
10 hook(type => "getsetup", id => "brokenlinks", call => \&getsetup);
11 hook(type => "preprocess", id => "brokenlinks", call => \&preprocess);
14 sub getsetup {
15 return
16 plugin => {
17 safe => 1,
18 rebuild => undef,
22 sub preprocess (@) {
23 my %params=@_;
24 $params{pages}="*" unless defined $params{pages};
26 my @broken;
27 foreach my $link (keys %IkiWiki::brokenlinks) {
28 next if $link =~ /.*\/\Q$config{discussionpage}\E/i && $config{discussion};
30 my @pages=pagespec_match_list($params{page}, $params{pages},
31 list => $IkiWiki::brokenlinks{$link},
32 # needs to update when links on a page change
33 deptype => deptype("links")
35 next unless @pages;
37 my $page=$IkiWiki::brokenlinks{$link}->[0];
38 push @broken, sprintf(gettext("%s from %s"),
39 htmllink($page, $params{destpage}, $link, noimageinline => 1),
40 join(", ", map {
41 htmllink($params{page}, $params{destpage}, $_, noimageinline => 1)
42 } @pages)
46 return gettext("There are no broken links!") unless @broken;
47 return "<ul>\n"
48 .join("\n",
49 map {
50 "<li>$_</li>"
52 sort @broken)
53 ."</ul>\n";