orphans.pl 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # orphans.pl --- A module for oddmuse to show all orphaned pages on the wiki
  2. # Copyright (C) 2004 Jorgen Schaefer <forcer@forcix.cx>
  3. # Author: Jorgen Schaefer <forcer@forcix.cx>
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. # This module will show ALL orphaned pages, even whole orphaned
  17. # subgraphs on this wiki.
  18. use strict;
  19. use v5.10;
  20. AddModuleDescription('orphans.pl', 'Orphans Extension');
  21. our (%Action, $RCName, $HomePage);
  22. # What is interesting to us?
  23. my @orphan_entrypoints = ($HomePage, $RCName);
  24. $Action{orphans} = \&DoOrphans;
  25. sub DoOrphans {
  26. if (GetParam('raw', 0)) {
  27. print GetHttpHeader('text/plain');
  28. PrintOrphans(GetOrphans());
  29. } else {
  30. print GetHeader('', QuoteHtml(T('Orphan List')), '');
  31. PrintOrphans(GetOrphans());
  32. PrintFooter();
  33. }
  34. }
  35. sub PrintOrphans {
  36. my @orphans = @_;
  37. if (GetParam('raw', 0)) {
  38. foreach my $page (@orphans) {
  39. print "$page\n";
  40. }
  41. } else {
  42. map { PrintPage($_); } @orphans;
  43. }
  44. }
  45. sub GetOrphans {
  46. my @allpages = AllPagesList();
  47. # GetFullLinkList results depend on wether we are raw or not...
  48. my $oldraw = GetParam('raw', 0);
  49. SetParam('raw', 1);
  50. my %links = %{GetFullLinkList()};
  51. SetParam('raw', $oldraw);
  52. my %alife;
  53. my @pagelist;
  54. my @orphans;
  55. @pagelist = @orphan_entrypoints;
  56. foreach my $page (@orphan_entrypoints) {
  57. $alife{$page} = 1;
  58. }
  59. while (@pagelist) {
  60. my $currpage = pop(@pagelist);
  61. foreach my $link (@{$links{$currpage}}) {
  62. $link =~ s/ /_/g;
  63. if (!$alife{$link}) {
  64. $alife{$link} = 1;
  65. push @pagelist, $link;
  66. }
  67. }
  68. }
  69. # Now return all the pages in @allpages that are not in %alife.
  70. foreach my $page (@allpages) {
  71. if (!$alife{$page}) {
  72. push(@orphans, $page);
  73. }
  74. }
  75. return @orphans;
  76. }