]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/orphans.pm
git: --getctime will now follow renames back to the original creation of a file.
[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 @orphans;
31         foreach my $page (pagespec_match_list(
32                         [ grep { ! IkiWiki::backlink_pages($_) && $_ ne 'index' }
33                                 keys %pagesources ],
34                         $params{pages}, location => $params{page})) {
35                 # If the page has a link to some other page, it's
36                 # indirectly linked to a page via that page's backlinks.
37                 next if grep { 
38                         length $_ &&
39                         ($_ !~ /\/\Q$config{discussionpage}\E$/i || ! $config{discussion}) &&
40                         bestlink($page, $_) !~ /^(\Q$page\E|)$/ 
41                 } @{$links{$page}};
42                 push @orphans, $page;
43         }
44         
45         return gettext("All pages have other pages linking to them.") unless @orphans;
46         return "<ul>\n".
47                 join("\n",
48                         map {
49                                 "<li>".
50                                 htmllink($params{page}, $params{destpage}, $_,
51                                          noimageinline => 1).
52                                 "</li>"
53                         } sort @orphans).
54                 "</ul>\n";
55 }
57 1