summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/orphans.pm
blob: 605e6e43ada79398afe07d1c7c07393612eeca6d (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 added or removed, so
  22. # register a dependency.
  23. add_depends($params{page}, $params{pages});
  24. my %linkedto;
  25. foreach my $p (keys %links) {
  26. map { $linkedto{bestlink($p, $_)}=1 if length $_ }
  27. @{$links{$p}};
  28. }
  29. my @orphans;
  30. my $discussion=gettext("discussion");
  31. foreach my $page (keys %pagesources) {
  32. next if $linkedto{$page} || $page eq 'index';
  33. next unless pagespec_match($page, $params{pages}, location => $params{page});
  34. # If the page has a link to some other page, it's
  35. # indirectly linked to a page via that page's backlinks.
  36. next if grep {
  37. length $_ &&
  38. ($_ !~ /\/\Q$discussion\E$/i || ! $config{discussion}) &&
  39. bestlink($page, $_) !~ /^(\Q$page\E|)$/
  40. } @{$links{$page}};
  41. push @orphans, $page;
  42. }
  43. return gettext("All pages are linked to by other pages.") unless @orphans;
  44. return "<ul>\n".
  45. join("\n",
  46. map {
  47. "<li>".
  48. htmllink($params{page}, $params{destpage}, $_,
  49. noimageinline => 1).
  50. "</li>"
  51. } sort @orphans).
  52. "</ul>\n";
  53. }
  54. 1