]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/brokenlinks.pm
Merge remote-tracking branch 'smcv/ready/map'
[git.ikiwiki.info.git] / IkiWiki / Plugin / brokenlinks.pm
1 #!/usr/bin/perl
2 # Provides a list of broken links.
3 package IkiWiki::Plugin::brokenlinks;
5 use warnings;
6 use strict;
7 use IkiWiki 3.00;
9 sub import {
10         hook(type => "getsetup", id => "brokenlinks", call => \&getsetup);
11         hook(type => "preprocess", id => "brokenlinks", call => \&preprocess);
12 }
14 sub getsetup {
15         return
16                 plugin => {
17                         safe => 1,
18                         rebuild => undef,
19                 },
20 }
22 sub preprocess (@) {
23         my %params=@_;
24         $params{pages}="*" unless defined $params{pages};
25         
26         my @broken;
27         foreach my $link (keys %IkiWiki::brokenlinks) {
28                 next if $link =~ /.*\/\Q$config{discussionpage}\E/i && $config{discussion};
30                 my @pages=pagespec_match_list($params{page}, $params{pages},
31                         list => $IkiWiki::brokenlinks{$link},
32                         # needs to update when links on a page change
33                         deptype => deptype("links")
34                 );
35                 next unless @pages;
37                 my $page=$IkiWiki::brokenlinks{$link}->[0];
38                 push @broken, sprintf(gettext("%s from %s"),
39                         htmllink($page, $params{destpage}, $link, noimageinline => 1),
40                         join(", ", map {
41                                 htmllink($params{page}, $params{destpage}, $_,  noimageinline => 1)
42                         } @pages)
43                 );
44         }
45         
46         return gettext("There are no broken links!") unless @broken;
47         return "<ul>\n"
48                 .join("\n",
49                         map {
50                                 "<li>$_</li>"
51                         }
52                         sort @broken)
53                 ."</ul>\n";
54 }
56 1