]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/orphans.pm
Merge branch 'master' into dependency-types
[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 3.00;
8
9 sub import {
10         hook(type => "getsetup", id => "orphans", call => \&getsetup);
11         hook(type => "preprocess", id => "orphans", call => \&preprocess);
12 }
13
14 sub getsetup () {
15         return 
16                 plugin => {
17                         safe => 1,
18                         rebuild => undef,
19                 },
20 }
21
22 sub preprocess (@) {
23         my %params=@_;
24         $params{pages}="*" unless defined $params{pages};
25         
26         # Needs to update whenever a link changes, on any page
27         # since any page could link to one of the pages we're
28         # considering as orphans.
29         add_depends($params{page}, "*", links => 1);
30         # Also needs to update whenever potential orphans are added or
31         # removed.
32         add_depends($params{page}, $params{pages}, presence => 1);
33         
34         my @orphans;
35         foreach my $page (pagespec_match_list(
36                         [ grep { ! IkiWiki::backlink_pages($_) && $_ ne 'index' }
37                                 keys %pagesources ],
38                         $params{pages}, location => $params{page})) {
39                 # If the page has a link to some other page, it's
40                 # indirectly linked to a page via that page's backlinks.
41                 next if grep { 
42                         length $_ &&
43                         ($_ !~ /\/\Q$config{discussionpage}\E$/i || ! $config{discussion}) &&
44                         bestlink($page, $_) !~ /^(\Q$page\E|)$/ 
45                 } @{$links{$page}};
46                 push @orphans, $page;
47         }
48         
49         return gettext("All pages have other pages linking to them.") unless @orphans;
50         return "<ul>\n".
51                 join("\n",
52                         map {
53                                 "<li>".
54                                 htmllink($params{page}, $params{destpage}, $_,
55                                          noimageinline => 1).
56                                 "</li>"
57                         } sort @orphans).
58                 "</ul>\n";
59 }
60
61 1