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;
|
2007-04-27 04:55:52 +02:00
|
|
|
use IkiWiki 2.00;
|
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-04-27 04:55:52 +02:00
|
|
|
if (pagespec_match($page, $params{pages}, location => $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;
|
2007-11-08 21:03:57 +01:00
|
|
|
push @broken, sprintf(gettext("%s from %s"),
|
|
|
|
htmllink($page, $params{destpage}, $link, noimageinline => 1),
|
|
|
|
htmllink($params{page}, $params{destpage}, $page, noimageinline => 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
|