2006-07-29 19:44:41 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# Produce page statistics in various forms.
|
|
|
|
#
|
|
|
|
# Currently supported:
|
|
|
|
# cloud: produces statistics in the form of a del.icio.us-style tag cloud
|
|
|
|
# (default)
|
|
|
|
# table: produces a table with the number of backlinks for each page
|
|
|
|
#
|
2006-08-19 07:05:02 +02:00
|
|
|
# by Enrico Zini
|
2006-07-29 19:44:41 +02:00
|
|
|
package IkiWiki::Plugin::pagestats;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2007-04-27 04:55:52 +02:00
|
|
|
use IkiWiki 2.00;
|
2006-07-29 19:44:41 +02:00
|
|
|
|
|
|
|
# Names of the HTML classes to use for the tag cloud
|
|
|
|
our @classes = ('smallestPC', 'smallPC', 'normalPC', 'bigPC', 'biggestPC' );
|
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-08-03 23:20:21 +02:00
|
|
|
hook(type => "getsetup", id => "pagestats", call => \&getsetup);
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "preprocess", id => "pagestats", call => \&preprocess);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-07-29 19:44:41 +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,
|
|
|
|
},
|
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-07-29 19:44:41 +02:00
|
|
|
my %params=@_;
|
|
|
|
$params{pages}="*" unless defined $params{pages};
|
|
|
|
my $style = ($params{style} or 'cloud');
|
|
|
|
|
|
|
|
# Needs to update whenever a page is added or removed, so
|
|
|
|
# register a dependency.
|
2006-09-10 00:50:27 +02:00
|
|
|
add_depends($params{page}, $params{pages});
|
2006-07-29 19:44:41 +02:00
|
|
|
|
|
|
|
my %counts;
|
|
|
|
my $max = 0;
|
2006-09-10 00:50:27 +02:00
|
|
|
foreach my $page (keys %links) {
|
2007-04-27 04:55:52 +02:00
|
|
|
if (pagespec_match($page, $params{pages}, location => $params{page})) {
|
2007-01-31 08:13:51 +01:00
|
|
|
use IkiWiki::Render;
|
2007-05-12 21:17:41 +02:00
|
|
|
$counts{$page} = scalar(IkiWiki::backlinks($page));
|
2006-07-29 19:44:41 +02:00
|
|
|
$max = $counts{$page} if $counts{$page} > $max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($style eq 'table') {
|
2006-07-29 22:14:07 +02:00
|
|
|
return "<table class='pageStats'>\n".
|
|
|
|
join("\n", map {
|
|
|
|
"<tr><td>".
|
2007-02-20 04:05:47 +01:00
|
|
|
htmllink($params{page}, $params{destpage}, $_, noimageinline => 1).
|
2006-07-29 22:14:07 +02:00
|
|
|
"</td><td>".$counts{$_}."</td></tr>"
|
|
|
|
}
|
|
|
|
sort { $counts{$b} <=> $counts{$a} } keys %counts).
|
|
|
|
"\n</table>\n" ;
|
2007-05-12 21:28:03 +02:00
|
|
|
}
|
|
|
|
else {
|
2006-07-29 19:44:41 +02:00
|
|
|
# In case of misspelling, default to a page cloud
|
|
|
|
|
|
|
|
my $res = "<div class='pagecloud'>\n";
|
|
|
|
foreach my $page (sort keys %counts) {
|
|
|
|
my $class = $classes[$counts{$page} * scalar(@classes) / ($max + 1)];
|
2006-07-29 22:07:48 +02:00
|
|
|
$res .= "<span class=\"$class\">".
|
2006-09-10 00:50:27 +02:00
|
|
|
htmllink($params{page}, $params{destpage}, $page).
|
2006-07-29 22:07:48 +02:00
|
|
|
"</span>\n";
|
2006-07-29 19:44:41 +02:00
|
|
|
}
|
|
|
|
$res .= "</div>\n";
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-07-29 19:44:41 +02:00
|
|
|
|
|
|
|
1
|