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) {
|
2007-02-06 22:17:25 +01:00
|
|
|
if (pagespec_match($page, $params{pages}, $params{page})) {
|
2007-01-31 08:18:06 +01:00
|
|
|
my $discussion=gettext("discussion");
|
2006-09-10 00:50:27 +02:00
|
|
|
foreach my $link (@{$links{$page}}) {
|
2007-01-31 08:18:06 +01:00
|
|
|
next if $link =~ /.*\/\Q$discussion\E/i && $config{discussion};
|
2006-09-10 00:50:27 +02:00
|
|
|
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-10-09 00:12:12 +02:00
|
|
|
" from ".
|
2006-09-10 00:50:27 +02:00
|
|
|
htmllink($params{page}, $params{destpage}, $page, 1);
|
2006-05-02 04:34:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-29 05:38:40 +01:00
|
|
|
return gettext("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
|