3 # Produce page statistics in various forms.
6 # cloud: produces statistics in the form of a del.icio.us-style tag cloud
8 # table: produces a table with the number of backlinks for each page
11 package IkiWiki::Plugin::pagestats;
17 # Names of the HTML classes to use for the tag cloud
18 our @classes = ('smallestPC', 'smallPC', 'normalPC', 'bigPC', 'biggestPC' );
21 hook(type => "getsetup", id => "pagestats", call => \&getsetup);
22 hook(type => "preprocess", id => "pagestats", call => \&preprocess);
25 sub getsetup () { #{{{
33 sub preprocess (@) { #{{{
35 $params{pages}="*" unless defined $params{pages};
36 my $style = ($params{style} or 'cloud');
38 # Needs to update whenever a page is added or removed, so
39 # register a dependency.
40 add_depends($params{page}, $params{pages});
44 foreach my $page (keys %links) {
45 if (pagespec_match($page, $params{pages}, location => $params{page})) {
47 $counts{$page} = scalar(IkiWiki::backlinks($page));
48 $max = $counts{$page} if $counts{$page} > $max;
52 if ($style eq 'table') {
53 return "<table class='pageStats'>\n".
56 htmllink($params{page}, $params{destpage}, $_, noimageinline => 1).
57 "</td><td>".$counts{$_}."</td></tr>"
59 sort { $counts{$b} <=> $counts{$a} } keys %counts).
63 # In case of misspelling, default to a page cloud
65 my $res = "<div class='pagecloud'>\n";
66 foreach my $page (sort keys %counts) {
67 my $class = $classes[$counts{$page} * scalar(@classes) / ($max + 1)];
68 $res .= "<span class=\"$class\">".
69 htmllink($params{page}, $params{destpage}, $page).