]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/orphans.pm
* Split off an IkiWiki.pm out of ikiwiki and have all the other modules use
[ikiwiki.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;
4
5 use warnings;
6 use strict;
7 use IkiWiki;
8
9 sub import { #{{{
10         IkiWiki::register_plugin("preprocess", "orphans", \&preprocess);
11 } # }}}
12
13 sub preprocess (@) { #{{{
14         my %params=@_;
15         $params{pages}="*" unless defined $params{pages};
16         
17         # Needs to update whenever a page is added or removed, so
18         # register a dependency.
19         IkiWiki::add_depends($params{page}, $params{pages});
20         
21         my %linkedto;
22         foreach my $p (keys %IkiWiki::links) {
23                 map { $linkedto{IkiWiki::bestlink($p, $_)}=1 if length $_ }
24                         @{$IkiWiki::links{$p}};
25         }
26         
27         my @orphans;
28         foreach my $page (keys %IkiWiki::renderedfiles) {
29                 next if $linkedto{$page};
30                 next unless IkiWiki::globlist_match($page, $params{pages});
31                 # If the page has a link to some other page, it's
32                 # indirectly linked to a page via that page's backlinks.
33                 next if grep { length $_ && $_ !~/\/Discussion$/i && IkiWiki::bestlink($page, $_) ne $page } @{$IkiWiki::links{$page}};
34                 push @orphans, $page;
35         }
36         
37         return "All pages are linked to by other pages." unless @orphans;
38         return "<ul>\n".join("\n", map { "<li>".IkiWiki::htmllink($params{page}, $_, 1)."</li>" } sort @orphans)."</ul>\n";
39 } # }}}
40
41 1