]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/orphans.pm
Allow the openid plugin to be loaded but disabled, for its side-effect of defining...
[git.ikiwiki.info.git] / IkiWiki / Plugin / orphans.pm
1 #!/usr/bin/perl
2 # Provides a list of pages no other page links to.
3 package IkiWiki::Plugin::orphans;
5 use warnings;
6 use strict;
7 use IkiWiki 3.00;
9 sub import {
10         hook(type => "getsetup", id => "orphans", call => \&getsetup);
11         hook(type => "preprocess", id => "orphans", 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         # Needs to update whenever a page is added or removed, so
27         # register a dependency.
28         add_depends($params{page}, $params{pages});
29         
30         my %linkedto;
31         foreach my $p (keys %links) {
32                 map { $linkedto{bestlink($p, $_)}=1 if length $_ }
33                         @{$links{$p}};
34         }
35         
36         my @orphans;
37         my $discussion=lc(gettext("Discussion"));
38         foreach my $page (pagespec_match_list(
39                         [ grep { ! $linkedto{$_} && $_ ne 'index' }
40                                 keys %pagesources ],
41                         $params{pages}, location => $params{page})) {
42                 # If the page has a link to some other page, it's
43                 # indirectly linked to a page via that page's backlinks.
44                 next if grep { 
45                         length $_ &&
46                         ($_ !~ /\/\Q$discussion\E$/i || ! $config{discussion}) &&
47                         bestlink($page, $_) !~ /^(\Q$page\E|)$/ 
48                 } @{$links{$page}};
49                 push @orphans, $page;
50         }
51         
52         return gettext("All pages are linked to by other pages.") unless @orphans;
53         return "<ul>\n".
54                 join("\n",
55                         map {
56                                 "<li>".
57                                 htmllink($params{page}, $params{destpage}, $_,
58                                          noimageinline => 1).
59                                 "</li>"
60                         } sort @orphans).
61                 "</ul>\n";
62 }
64 1