]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/orphans.pm
setup file ordering
[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                         section => "widget",
20                 },
21 }
23 sub preprocess (@) {
24         my %params=@_;
25         $params{pages}="*" unless defined $params{pages};
26         
27         # Needs to update whenever a link changes, on any page
28         # since any page could link to one of the pages we're
29         # considering as orphans.
30         add_depends($params{page}, "*", deptype("links"));
31         
32         my @orphans=pagespec_match_list($params{page}, $params{pages},
33                 # update when orphans are added/removed
34                 deptype => deptype("presence"),
35                 filter => sub {
36                         my $page=shift;
38                         # Filter out pages that other pages link to.
39                         return 1 if IkiWiki::backlink_pages($page);
41                         # Toplevel index is assumed to never be orphaned.
42                         return 1 if $page eq 'index';
44                         # If the page has a link to some other page, it's
45                         # indirectly linked via that page's backlinks.
46                         return 1 if grep {
47                                 length $_ &&
48                                 ($_ !~ /\/\Q$config{discussionpage}\E$/i || ! $config{discussion}) &&
49                                 bestlink($page, $_) !~ /^(\Q$page\E|)$/ 
50                         } @{$links{$page}};
51                         
52                         return 0;
53                 },
54         );
55         
56         return gettext("All pages have other pages linking to them.") unless @orphans;
57         return "<ul>\n".
58                 join("\n",
59                         map {
60                                 "<li>".
61                                 htmllink($params{page}, $params{destpage}, $_,
62                                          noimageinline => 1).
63                                 "</li>"
64                         } sort @orphans).
65                 "</ul>\n";
66 }
68 1