2006-05-02 04:34:33 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki::Plugin::pagecount;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2007-04-27 04:55:52 +02:00
|
|
|
use IkiWiki 2.00;
|
2006-05-02 04:34:33 +02:00
|
|
|
|
|
|
|
sub import { #{{{
|
2008-08-03 23:20:21 +02:00
|
|
|
hook(type => "getsetup", id => "pagecount", call => \&getsetup);
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "preprocess", id => "pagecount", call => \&preprocess);
|
2006-05-02 04:34:33 +02:00
|
|
|
} # }}}
|
|
|
|
|
2008-08-03 23:20:21 +02:00
|
|
|
sub getsetup () { #{{{
|
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => undef,
|
|
|
|
},
|
|
|
|
} #}}}
|
|
|
|
|
2006-05-02 04:34:33 +02:00
|
|
|
sub preprocess (@) { #{{{
|
|
|
|
my %params=@_;
|
|
|
|
$params{pages}="*" unless defined $params{pages};
|
|
|
|
|
|
|
|
# Needs to update count 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 04:34:33 +02:00
|
|
|
|
2006-09-10 00:50:27 +02:00
|
|
|
my @pages=keys %pagesources;
|
2006-05-02 04:34:33 +02:00
|
|
|
return $#pages+1 if $params{pages} eq "*"; # optimisation
|
|
|
|
my $count=0;
|
|
|
|
foreach my $page (@pages) {
|
2007-04-27 04:55:52 +02:00
|
|
|
$count++ if pagespec_match($page, $params{pages}, location => $params{page});
|
2006-05-02 04:34:33 +02:00
|
|
|
}
|
|
|
|
return $count;
|
|
|
|
} # }}}
|
|
|
|
|
|
|
|
1
|