]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/pagecount.pm
8d36f057eb0820a62c9704988d66fde75ccf6c4b
[ikiwiki.git] / IkiWiki / Plugin / pagecount.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::pagecount;
3
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
7
8 sub import {
9         hook(type => "getsetup", id => "pagecount", call => \&getsetup);
10         hook(type => "preprocess", id => "pagecount", call => \&preprocess);
11 }
12
13 sub getsetup () {
14         return 
15                 plugin => {
16                         safe => 1,
17                         rebuild => undef,
18                 },
19 }
20
21 sub preprocess (@) {
22         my %params=@_;
23         my $pages=defined $params{pages} ? $params{pages} : "*";
24         
25         # Just get a list of all the pages, and count the items in it.
26         # Use a presence dependency to only update when pages are added
27         # or removed.
28
29         if ($pages eq '*') {
30                 # optimisation to avoid needing to try matching every page
31                 add_depends($params{page}, $pages, deptype("presence"));
32                 return scalar keys %pagesources;
33         }
34
35         return scalar pagespec_match_list($params{page}, $pages,
36                 deptype => deptype("presence"));
37 }
38
39 1