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);
35 $params{pages}="*" unless defined $params{pages};
36 my $style = ($params{style} or 'cloud');
40 foreach my $page (pagespec_match_list($params{page}, $params{pages},
41 # update when a displayed page is added/removed
42 deptype => deptype("presence"))) {
45 my @backlinks = IkiWiki::backlink_pages($page);
47 if (exists $params{among}) {
48 # only consider backlinks from the amoung pages
49 @backlinks = pagespec_match_list(
50 $params{page}, $params{among},
51 # update whenever links on those pages change
52 deptype => deptype("links"),
57 # update when any page with links changes,
58 # in case the links point to our displayed pages
59 add_depends($params{page}, "*", deptype("links"));
62 $counts{$page} = scalar(@backlinks);
63 $max = $counts{$page} if $counts{$page} > $max;
66 if ($style eq 'table') {
67 return "<table class='pageStats'>\n".
70 htmllink($params{page}, $params{destpage}, $_, noimageinline => 1).
71 "</td><td>".$counts{$_}."</td></tr>"
73 sort { $counts{$b} <=> $counts{$a} } keys %counts).
77 # In case of misspelling, default to a page cloud
79 my $res = "<div class='pagecloud'>\n";
80 foreach my $page (sort keys %counts) {
81 next unless $counts{$page} > 0;
83 my $class = $classes[$counts{$page} * scalar(@classes) / ($max + 1)];
84 $res .= "<span class=\"$class\">".
85 htmllink($params{page}, $params{destpage}, $page).