From d76c73eb8634f3181bd246d747ae42443d4b6d31 Mon Sep 17 00:00:00 2001 From: joey Date: Sat, 29 Jul 2006 17:44:41 +0000 Subject: [PATCH] * New pagestats plugin from Enrico, which can generate a table counting the backlinks for each page, or a del.icio.us style cloud. --- IkiWiki/Plugin/pagestats.pm | 64 +++++++++++++++++++++++++++++++++++++ basewiki/style.css | 12 +++++++ debian/changelog | 11 +++++-- doc/plugins/pagestats.mdwn | 13 ++++++++ doc/tags.mdwn | 3 ++ doc/todo/plugin.mdwn | 2 +- 6 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 IkiWiki/Plugin/pagestats.pm create mode 100644 doc/plugins/pagestats.mdwn diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm new file mode 100644 index 000000000..34fd11715 --- /dev/null +++ b/IkiWiki/Plugin/pagestats.pm @@ -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 "\n".join("\n", map { "" } + sort { $counts{$b} <=> $counts{$a} } keys %counts)."\n
$_".$counts{$_}."
\n" ; + } else { + # In case of misspelling, default to a page cloud + + my $res = "
\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("%s\n", + $class, $link, $page); + + } + $res .= "
\n"; + + return $res; + } +} # }}} + +1 diff --git a/basewiki/style.css b/basewiki/style.css index f96e11ab0..ebc912553 100644 --- a/basewiki/style.css +++ b/basewiki/style.css @@ -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%; } diff --git a/debian/changelog b/debian/changelog index 015c16ff1..c50f52eae 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 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 Sat, 29 Jul 2006 02:58:23 -0400 + -- Joey Hess Sat, 29 Jul 2006 03:24:58 -0400 ikiwiki (1.11) unstable; urgency=low diff --git a/doc/plugins/pagestats.mdwn b/doc/plugins/pagestats.mdwn new file mode 100644 index 000000000..41c853b16 --- /dev/null +++ b/doc/plugins/pagestats.mdwn @@ -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. diff --git a/doc/tags.mdwn b/doc/tags.mdwn index 36753a5b4..8d3a85cef 100644 --- a/doc/tags.mdwn +++ b/doc/tags.mdwn @@ -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. diff --git a/doc/todo/plugin.mdwn b/doc/todo/plugin.mdwn index 7f427ec96..0f37d6190 100644 --- a/doc/todo/plugin.mdwn +++ b/doc/todo/plugin.mdwn @@ -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 -- 2.39.5