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,
|
2010-02-12 12:35:52 +01:00
|
|
|
section => "widget",
|
2008-08-03 23:20:21 +02:00
|
|
|
},
|
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=@_;
|
2009-10-09 00:41:08 +02:00
|
|
|
my $pages=defined $params{pages} ? $params{pages} : "*";
|
2006-05-02 04:34:33 +02:00
|
|
|
|
2009-10-09 00:41:08 +02:00
|
|
|
# Just get a list of all the pages, and count the items in it.
|
|
|
|
# Use a presence dependency to only update when pages are added
|
|
|
|
# or removed.
|
|
|
|
|
|
|
|
if ($pages eq '*') {
|
|
|
|
# optimisation to avoid needing to try matching every page
|
|
|
|
add_depends($params{page}, $pages, deptype("presence"));
|
|
|
|
return scalar keys %pagesources;
|
2009-06-06 00:04:39 +02:00
|
|
|
}
|
2009-10-09 00:41:08 +02:00
|
|
|
|
2009-10-09 05:51:06 +02:00
|
|
|
return scalar pagespec_match_list($params{page}, $pages,
|
2009-10-09 00:41:08 +02:00
|
|
|
deptype => deptype("presence"));
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-05-02 04:34:33 +02:00
|
|
|
|
|
|
|
1
|