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
|
|
|
|
2007-11-17 22:16:34 +01: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-17 22:16:34 +01:00
|
|
|
push @{$broken{$link}}, $page;
|
2006-05-02 04:34:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-17 22:16:34 +01:00
|
|
|
|
|
|
|
my @broken;
|
|
|
|
foreach my $link (keys %broken) {
|
|
|
|
my $page=$broken{$link}->[0];
|
|
|
|
push @broken, sprintf(gettext("%s from %s"),
|
|
|
|
htmllink($page, $params{destpage}, $link, noimageinline => 1),
|
|
|
|
join(", ", map {
|
|
|
|
htmllink($params{page}, $params{destpage}, $_, noimageinline => 1)
|
|
|
|
} @{$broken{$link}}));
|
|
|
|
}
|
2006-05-02 04:34:33 +02:00
|
|
|
|
2007-11-17 22:16:34 +01:00
|
|
|
return gettext("There are no broken links!") unless %broken;
|
|
|
|
return "<ul>\n"
|
|
|
|
.join("\n",
|
|
|
|
map {
|
|
|
|
"<li>$_</li>"
|
|
|
|
}
|
|
|
|
sort @broken)
|
|
|
|
."</ul>\n";
|
2006-05-02 04:34:33 +02:00
|
|
|
} # }}}
|
|
|
|
|
|
|
|
1
|