summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/orphans.pm
blob: 3a0150d53e4c52b08fe076bf276c1bb2e6e563dd (plain)
  1. #!/usr/bin/perl
  2. # Provides a list of pages no other page links to.
  3. package IkiWiki::Plugin::orphans;
  4. use warnings;
  5. use strict;
  6. use IkiWiki 2.00;
  7. sub import { #{{{
  8. hook(type => "preprocess", id => "orphans", call => \&preprocess);
  9. } # }}}
  10. sub preprocess (@) { #{{{
  11. my %params=@_;
  12. $params{pages}="*" unless defined $params{pages};
  13. # Needs to update whenever a page is added or removed, so
  14. # register a dependency.
  15. add_depends($params{page}, $params{pages});
  16. my %linkedto;
  17. foreach my $p (keys %links) {
  18. map { $linkedto{bestlink($p, $_)}=1 if length $_ }
  19. @{$links{$p}};
  20. }
  21. my @orphans;
  22. my $discussion=gettext("discussion");
  23. foreach my $page (keys %pagesources) {
  24. next if $linkedto{$page};
  25. next unless pagespec_match($page, $params{pages}, location => $params{page});
  26. # If the page has a link to some other page, it's
  27. # indirectly linked to a page via that page's backlinks.
  28. next if grep {
  29. length $_ &&
  30. ($_ !~ /\/\Q$discussion\E$/i || ! $config{discussion}) &&
  31. bestlink($page, $_) !~ /^($page|)$/
  32. } @{$links{$page}};
  33. push @orphans, $page;
  34. }
  35. return gettext("All pages are linked to by other pages.") unless @orphans;
  36. return "<ul>\n".
  37. join("\n",
  38. map {
  39. "<li>".
  40. htmllink($params{page}, $params{destpage}, $_,
  41. noimageinline => 1).
  42. "</li>"
  43. } sort @orphans).
  44. "</ul>\n";
  45. } # }}}
  46. 1