summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/orphans.pm
blob: d981670e78d22d5f85a86429cdcda9bc60f78d44 (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 3.00;
  7. sub import {
  8. hook(type => "getsetup", id => "orphans", call => \&getsetup);
  9. hook(type => "preprocess", id => "orphans", call => \&preprocess);
  10. }
  11. sub getsetup () {
  12. return
  13. plugin => {
  14. safe => 1,
  15. rebuild => undef,
  16. },
  17. }
  18. sub preprocess (@) {
  19. my %params=@_;
  20. $params{pages}="*" unless defined $params{pages};
  21. # Needs to update whenever a page is changed, added, or removed,
  22. # in order to see the link changes.
  23. add_depends($params{page}, $params{pages});
  24. my @orphans;
  25. foreach my $page (pagespec_match_list(
  26. [ grep { ! IkiWiki::backlink_pages($_) && $_ ne 'index' }
  27. keys %pagesources ],
  28. $params{pages}, location => $params{page})) {
  29. # If the page has a link to some other page, it's
  30. # indirectly linked to a page via that page's backlinks.
  31. next if grep {
  32. length $_ &&
  33. ($_ !~ /\/\Q$config{discussionpage}\E$/i || ! $config{discussion}) &&
  34. bestlink($page, $_) !~ /^(\Q$page\E|)$/
  35. } @{$links{$page}};
  36. push @orphans, $page;
  37. }
  38. return gettext("All pages have other pages linking to them.") unless @orphans;
  39. return "<ul>\n".
  40. join("\n",
  41. map {
  42. "<li>".
  43. htmllink($params{page}, $params{destpage}, $_,
  44. noimageinline => 1).
  45. "</li>"
  46. } sort @orphans).
  47. "</ul>\n";
  48. }
  49. 1