2006-05-02 04:34:33 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki::Plugin::pagecount;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2006-05-02 04:34:33 +02:00
|
|
|
|
2008-12-17 21:22:16 +01: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);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-05-02 04:34:33 +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 04:34:33 +02:00
|
|
|
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
|
|
|
|
2009-04-23 22:35:56 +02:00
|
|
|
my @pages=keys %pagesources;
|
|
|
|
@pages=pagespec_match_list(\@pages, $params{pages}, location => $params{page})
|
|
|
|
if $params{pages} ne "*"; # optimisation;
|
2009-04-23 21:45:30 +02:00
|
|
|
return $#pages+1;
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-05-02 04:34:33 +02:00
|
|
|
|
|
|
|
1
|