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;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2006-05-02 08:15:31 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-08-03 23:20:21 +02:00
|
|
|
hook(type => "getsetup", id => "orphans", call => \&getsetup);
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "preprocess", id => "orphans", call => \&preprocess);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-05-02 08:15:31 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-08-03 23:20:21 +02:00
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => undef,
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-03 23:20:21 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub preprocess (@) {
|
2006-05-02 08:15:31 +02:00
|
|
|
my %params=@_;
|
|
|
|
$params{pages}="*" unless defined $params{pages};
|
|
|
|
|
2009-10-05 21:14:18 +02:00
|
|
|
# Needs to update whenever a link changes, on any page
|
|
|
|
# since any page could link to one of the pages we're
|
|
|
|
# considering as orphans.
|
|
|
|
add_depends($params{page}, "*", links => 1);
|
|
|
|
# Also needs to update whenever potential orphans are added or
|
|
|
|
# removed.
|
|
|
|
add_depends($params{page}, $params{pages}, presence => 1);
|
2006-05-02 08:15:31 +02:00
|
|
|
|
|
|
|
my @orphans;
|
2009-04-23 21:45:30 +02:00
|
|
|
foreach my $page (pagespec_match_list(
|
2009-08-14 06:51:52 +02:00
|
|
|
[ grep { ! IkiWiki::backlink_pages($_) && $_ ne 'index' }
|
2009-04-23 21:45:30 +02:00
|
|
|
keys %pagesources ],
|
|
|
|
$params{pages}, location => $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 $_ &&
|
2009-08-14 03:41:33 +02:00
|
|
|
($_ !~ /\/\Q$config{discussionpage}\E$/i || ! $config{discussion}) &&
|
2008-10-10 01:09:16 +02:00
|
|
|
bestlink($page, $_) !~ /^(\Q$page\E|)$/
|
2006-09-10 00:50:27 +02:00
|
|
|
} @{$links{$page}};
|
2006-05-02 08:15:31 +02:00
|
|
|
push @orphans, $page;
|
|
|
|
}
|
|
|
|
|
2009-07-23 12:01:54 +02:00
|
|
|
return gettext("All pages have other pages linking to them.") unless @orphans;
|
2007-02-20 04:05:47 +01:00
|
|
|
return "<ul>\n".
|
|
|
|
join("\n",
|
|
|
|
map {
|
|
|
|
"<li>".
|
|
|
|
htmllink($params{page}, $params{destpage}, $_,
|
|
|
|
noimageinline => 1).
|
|
|
|
"</li>"
|
|
|
|
} sort @orphans).
|
|
|
|
"</ul>\n";
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-05-02 08:15:31 +02:00
|
|
|
|
|
|
|
1
|