2006-05-02 08:15:31 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Provides a list of pages no other page links to.
|
|
|
|
package IkiWiki::Plugin::orphans;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2006-05-02 08:53:33 +02:00
|
|
|
use IkiWiki;
|
2006-05-02 08:15:31 +02:00
|
|
|
|
|
|
|
sub import { #{{{
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "preprocess", id => "orphans", call => \&preprocess);
|
2006-05-02 08:15:31 +02:00
|
|
|
} # }}}
|
|
|
|
|
|
|
|
sub preprocess (@) { #{{{
|
|
|
|
my %params=@_;
|
|
|
|
$params{pages}="*" unless defined $params{pages};
|
|
|
|
|
|
|
|
# Needs to update whenever a page is added or removed, so
|
|
|
|
# register a dependency.
|
2006-09-10 00:50:27 +02:00
|
|
|
add_depends($params{page}, $params{pages});
|
2006-05-02 08:15:31 +02:00
|
|
|
|
|
|
|
my %linkedto;
|
2006-09-10 00:50:27 +02:00
|
|
|
foreach my $p (keys %links) {
|
|
|
|
map { $linkedto{bestlink($p, $_)}=1 if length $_ }
|
|
|
|
@{$links{$p}};
|
2006-05-02 08:15:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
my @orphans;
|
2007-01-31 08:18:06 +01:00
|
|
|
my $discussion=gettext("discussion");
|
2006-09-10 00:50:27 +02:00
|
|
|
foreach my $page (keys %renderedfiles) {
|
2006-05-02 08:15:31 +02:00
|
|
|
next if $linkedto{$page};
|
2007-02-06 22:17:25 +01:00
|
|
|
next unless pagespec_match($page, $params{pages}, $params{page});
|
2006-05-02 08:15:31 +02:00
|
|
|
# If the page has a link to some other page, it's
|
|
|
|
# indirectly linked to a page via that page's backlinks.
|
2006-06-25 09:21:53 +02:00
|
|
|
next if grep {
|
|
|
|
length $_ &&
|
2007-01-31 08:18:06 +01:00
|
|
|
($_ !~ /\/\Q$discussion\E$/i || ! $config{discussion}) &&
|
2006-09-10 00:50:27 +02:00
|
|
|
bestlink($page, $_) !~ /^($page|)$/
|
|
|
|
} @{$links{$page}};
|
2006-05-02 08:15:31 +02:00
|
|
|
push @orphans, $page;
|
|
|
|
}
|
|
|
|
|
2006-12-29 05:38:40 +01:00
|
|
|
return gettext("All pages are linked to by other pages.") unless @orphans;
|
2006-09-10 00:50:27 +02:00
|
|
|
return "<ul>\n".join("\n", map { "<li>".htmllink($params{page}, $params{destpage}, $_, 1)."</li>" } sort @orphans)."</ul>\n";
|
2006-05-02 08:15:31 +02:00
|
|
|
} # }}}
|
|
|
|
|
|
|
|
1
|