]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/pagecount.pm
Merge branch 'master' of ssh://git.ikiwiki.info/srv/git/ikiwiki.info
[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                         section => "widget",
19                 },
20 }
21
22 sub preprocess (@) {
23         my %params=@_;
24         my $pages=defined $params{pages} ? $params{pages} : "*";
25         
26         # Just get a list of all the pages, and count the items in it.
27         # Use a presence dependency to only update when pages are added
28         # or removed.
29
30         if ($pages eq '*') {
31                 # optimisation to avoid needing to try matching every page
32                 add_depends($params{page}, $pages, deptype("presence"));
33                 return scalar keys %pagesources;
34         }
35
36         return scalar pagespec_match_list($params{page}, $pages,
37                 deptype => deptype("presence"));
38 }
39
40 1