* New pagestats plugin from Enrico, which can generate a table counting

the backlinks for each page, or a del.icio.us style cloud.
master
joey 2006-07-29 17:44:41 +00:00
parent 267f98e2e1
commit d76c73eb86
6 changed files with 102 additions and 3 deletions

View File

@ -0,0 +1,64 @@
#!/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
#
# By Enrico Zini.
package IkiWiki::Plugin::pagestats;
use warnings;
use strict;
use IkiWiki;
# Names of the HTML classes to use for the tag cloud
our @classes = ('smallestPC', 'smallPC', 'normalPC', 'bigPC', 'biggestPC' );
sub import { #{{{
IkiWiki::hook(type => "preprocess", id => "pagestats",
call => \&preprocess);
} # }}}
sub preprocess (@) { #{{{
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.
IkiWiki::add_depends($params{page}, $params{pages});
my %counts;
my $max = 0;
foreach my $page (%IkiWiki::links) {
if (IkiWiki::globlist_match($page, $params{pages})) {
my @bl = IkiWiki::backlinks($page);
$counts{$page} = scalar(@bl);
$max = $counts{$page} if $counts{$page} > $max;
}
}
if ($style eq 'table') {
return "<table class='pageStats'>\n".join("\n", map { "<tr><td>$_</td><td>".$counts{$_}."</td></tr>" }
sort { $counts{$b} <=> $counts{$a} } keys %counts)."\n</table>\n" ;
} else {
# 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)];
my $link = IkiWiki::abs2rel(IkiWiki::htmlpage($page), IkiWiki::dirname($params{page}));
$res .= sprintf("<span class='%s'><a href='%s'>%s</a></span>\n",
$class, $link, $page);
}
$res .= "</div>\n";
return $res;
}
} # }}}
1

View File

@ -108,3 +108,15 @@ td.changelog {
color: white !important;
background: #ff9900;
}
/* Tag cloud. */
.pagecloud {
float: right;
width: 30%;
text-align: center;
}
.smallestPC { font-size: 70%; }
.smallPC { font-size: 85%; }
.normalPC { font-size: 100%; }
.bigPC { font-size: 115%; }
.biggestPC { font-size: 130%; }

11
debian/changelog vendored
View File

@ -1,11 +1,18 @@
ikiwiki (1.12) UNRELEASED; urgency=low
ikiwiki (1.13) UNRELEASED; urgency=low
* New pagestats plugin from Enrico, which can generate a table counting
the backlinks for each page, or a del.icio.us style cloud.
-- Joey Hess <joeyh@debian.org> Sat, 29 Jul 2006 13:30:16 -0400
ikiwiki (1.12) unstable; urgency=low
* Add getopt hook type, this allows plugins to add new command-line options.
* Add --tagbase option to tag plugin.
* Add exclude option in setup files, works same as --exclude.
* Put categories in rss feeds for tagged items.
-- Joey Hess <joeyh@debian.org> Sat, 29 Jul 2006 02:58:23 -0400
-- Joey Hess <joeyh@debian.org> Sat, 29 Jul 2006 03:24:58 -0400
ikiwiki (1.11) unstable; urgency=low

View File

@ -0,0 +1,13 @@
This plugin can generate stats about how pages link to each other. It can
produce either a del.icio.us style cloud, or a table counting the number of
links to each page.
Here's how to use it to create a [[tag]] cloud:
\[[pagestats pages="tags/*"]]
And here's how to create a table of all the pages on the wiki:
\[[pagestats style="table"]]
This plugin is included in ikiwiki, but is not enabled by default.

View File

@ -17,3 +17,6 @@ One way to use these tags is to create a [[blog]] of pages that have a
particular set of tags. Or just look at the [[BackLinks]] to a tag page to
see all the pages that are tagged with it. [[Plugins]] can be written to do
anything else with tags that you might desire.
Once you have tags, you can use the [[plugins/pagestats]] plugin to
generate tag clouds.

View File

@ -6,7 +6,7 @@ Suggestions of ideas for plugins:
* a [[link_map]]
* [[sigs]] ?
* [[pageindexes]]
* Wiki stats, such as total number of links, most linked to pages
* Wiki stats, such as total number of links, most linked to pages (done)
* Support [[RecentChanges]] as a regular page containing a plugin that
updates each time there is a change, and statically builds the recent