aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagecount.pm
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-05-02 02:34:33 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-05-02 02:34:33 +0000
commit54d5308cd83c67e7e9c32450c776ef0dac63549f (patch)
tree0352882349bca8952a59fd322099470b7952e0c8 /IkiWiki/Plugin/pagecount.pm
parent457d6bbbbfbb0474749a0d68e959613c86facf72 (diff)
downloadikiwiki-54d5308cd83c67e7e9c32450c776ef0dac63549f.tar
ikiwiki-54d5308cd83c67e7e9c32450c776ef0dac63549f.tar.gz
* Added plugin system, currently only supporting for PreProcessorDirectives.
* Added a pagecount plugin, enabled by default. * Support PreProcessorDirectives with no parameters, ie "[[pagecount ]]". * Fixed/optimised backlinks code, to avoid rebuilding pages to update backlinks when the backlinks hadn't really changed. * Moved inline page support, rss generation etc into the inline plugin, enabled by default. * Added brokenlinks plugin, not enabled by default, but rather handy. * Fix several broken links in the doc wiki.
Diffstat (limited to 'IkiWiki/Plugin/pagecount.pm')
-rw-r--r--IkiWiki/Plugin/pagecount.pm29
1 files changed, 29 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm
new file mode 100644
index 000000000..865ab4c39
--- /dev/null
+++ b/IkiWiki/Plugin/pagecount.pm
@@ -0,0 +1,29 @@
+#!/usr/bin/perl
+# Provides [[pagecount ]] to count the number of pages.
+package IkiWiki::Plugin::pagecount;
+
+use warnings;
+use strict;
+
+sub import { #{{{
+ IkiWiki::register_plugin("preprocess", "pagecount", \&preprocess);
+} # }}}
+
+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.
+ IkiWiki::add_depends($params{page}, $params{pages});
+
+ my @pages=keys %IkiWiki::pagesources;
+ return $#pages+1 if $params{pages} eq "*"; # optimisation
+ my $count=0;
+ foreach my $page (@pages) {
+ $count++ if IkiWiki::globlist_match($page, $params{pages});
+ }
+ return $count;
+} # }}}
+
+1