orphans.pl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program; if not, write to the Free Software
  14. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. # 02111-1307, USA.
  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. }