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;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2006-05-02 04:34:33 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-08-03 22:40:12 +02:00
|
|
|
hook(type => "getsetup", id => "brokenlinks", call => \&getsetup);
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "preprocess", id => "brokenlinks", call => \&preprocess);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-05-02 04:34:33 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup {
|
2008-08-03 22:40:12 +02:00
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => undef,
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-03 22:40:12 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub preprocess (@) {
|
2006-05-02 04:34:33 +02:00
|
|
|
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;
|
2009-04-23 21:45:30 +02:00
|
|
|
foreach my $page (pagespec_match_list([keys %links],
|
|
|
|
$params{pages}, location => $params{page})) {
|
2009-06-04 19:20:52 +02:00
|
|
|
my $discussion=gettext("Discussion");
|
2009-04-23 21:45:30 +02:00
|
|
|
my %seen;
|
|
|
|
foreach my $link (@{$links{$page}}) {
|
|
|
|
next if $seen{$link};
|
|
|
|
$seen{$link}=1;
|
|
|
|
next if $link =~ /.*\/\Q$discussion\E/i && $config{discussion};
|
|
|
|
my $bestlink=bestlink($page, $link);
|
|
|
|
next if length $bestlink;
|
|
|
|
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";
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-05-02 04:34:33 +02:00
|
|
|
|
|
|
|
1
|