2006-05-02 04:34:33 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Provides a list of broken links.
|
|
|
|
package IkiWiki::Plugin::brokenlinks;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2006-05-02 08:53:33 +02:00
|
|
|
use IkiWiki;
|
2006-05-02 04:34:33 +02:00
|
|
|
|
|
|
|
sub import { #{{{
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "preprocess", id => "brokenlinks", call => \&preprocess);
|
2006-05-02 04:34:33 +02:00
|
|
|
} # }}}
|
|
|
|
|
|
|
|
sub preprocess (@) { #{{{
|
|
|
|
my %params=@_;
|
|
|
|
$params{pages}="*" unless defined $params{pages};
|
|
|
|
|
|
|
|
# Needs to update whenever a page is added or removed, so
|
|
|
|
# register a dependency.
|
2006-09-10 00:50:27 +02:00
|
|
|
add_depends($params{page}, $params{pages});
|
2006-05-02 04:34:33 +02:00
|
|
|
|
|
|
|
my @broken;
|
2006-09-10 00:50:27 +02:00
|
|
|
foreach my $page (keys %links) {
|
|
|
|
if (pagespec_match($page, $params{pages})) {
|
|
|
|
foreach my $link (@{$links{$page}}) {
|
|
|
|
next if $link =~ /.*\/discussion/i && $config{discussion};
|
|
|
|
my $bestlink=bestlink($page, $link);
|
2006-05-02 04:34:33 +02:00
|
|
|
next if length $bestlink;
|
|
|
|
push @broken,
|
2006-09-10 00:50:27 +02:00
|
|
|
htmllink($page, $params{destpage}, $link, 1).
|
2006-05-02 04:34:33 +02:00
|
|
|
" in ".
|
2006-09-10 00:50:27 +02:00
|
|
|
htmllink($params{page}, $params{destpage}, $page, 1);
|
2006-05-02 04:34:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "There are no broken links!" unless @broken;
|
2006-05-06 05:57:43 +02:00
|
|
|
my %seen;
|
|
|
|
return "<ul>\n".join("\n", map { "<li>$_</li>" } grep { ! $seen{$_}++ } sort @broken)."</ul>\n";
|
2006-05-02 04:34:33 +02:00
|
|
|
} # }}}
|
|
|
|
|
|
|
|
1
|