]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/orphans.pm
lockedit: Detect if no authentication plugins are enabled, and die with an error...
[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 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}, "*", deptype("links"));
30         
31         my @orphans=pagespec_match_list($params{page}, $params{pages},
32                 # update when orphans are added/removed
33                 deptype => deptype("presence"),
34                 filter => sub {
35                         my $page=shift;
37                         # Filter out pages that other pages link to.
38                         return 1 if IkiWiki::backlink_pages($page);
40                         # Toplevel index is assumed to never be orphaned.
41                         return 1 if $page eq 'index';
43                         # If the page has a link to some other page, it's
44                         # indirectly linked via that page's backlinks.
45                         return 1 if grep {
46                                 length $_ &&
47                                 ($_ !~ /\/\Q$config{discussionpage}\E$/i || ! $config{discussion}) &&
48                                 bestlink($page, $_) !~ /^(\Q$page\E|)$/ 
49                         } @{$links{$page}};
50                         
51                         return 0;
52                 },
53         );
54         
55         return gettext("All pages have other pages linking to them.") unless @orphans;
56         return "<ul>\n".
57                 join("\n",
58                         map {
59                                 "<li>".
60                                 htmllink($params{page}, $params{destpage}, $_,
61                                          noimageinline => 1).
62                                 "</li>"
63                         } sort @orphans).
64                 "</ul>\n";
65 }
67 1