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};
|
|
|
|
|
2009-08-14 07:11:53 +02:00
|
|
|
my @broken;
|
|
|
|
foreach my $link (keys %IkiWiki::brokenlinks) {
|
|
|
|
next if $link =~ /.*\/\Q$config{discussionpage}\E/i && $config{discussion};
|
|
|
|
|
2009-10-09 19:35:11 +02:00
|
|
|
my @pages=pagespec_match_list($params{page}, $params{pages},
|
|
|
|
list => $IkiWiki::brokenlinks{$link},
|
|
|
|
# needs to update when links on a page change
|
|
|
|
deptype => deptype("links")
|
|
|
|
);
|
2009-08-14 07:11:53 +02:00
|
|
|
next unless @pages;
|
2007-11-17 22:16:34 +01:00
|
|
|
|
2009-08-14 07:11:53 +02:00
|
|
|
my $page=$IkiWiki::brokenlinks{$link}->[0];
|
2007-11-17 22:16:34 +01:00
|
|
|
push @broken, sprintf(gettext("%s from %s"),
|
|
|
|
htmllink($page, $params{destpage}, $link, noimageinline => 1),
|
|
|
|
join(", ", map {
|
|
|
|
htmllink($params{page}, $params{destpage}, $_, noimageinline => 1)
|
2015-06-09 10:47:40 +02:00
|
|
|
} sort @pages)
|
2009-08-14 07:11:53 +02:00
|
|
|
);
|
2007-11-17 22:16:34 +01:00
|
|
|
}
|
2006-05-02 04:34:33 +02:00
|
|
|
|
2009-08-14 07:11:53 +02:00
|
|
|
return gettext("There are no broken links!") unless @broken;
|
2007-11-17 22:16:34 +01:00
|
|
|
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
|