X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/ef7bddbc3693d7abf227100a9a9bc21d186dfada..276f0cf57861418fae5b4db8446d3d1098130cdf:/IkiWiki/Plugin/pagestats.pm diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm index 47638210a..ac0a463e3 100644 --- a/IkiWiki/Plugin/pagestats.pm +++ b/IkiWiki/Plugin/pagestats.pm @@ -27,14 +27,34 @@ sub getsetup () { plugin => { safe => 1, rebuild => undef, + section => "widget", }, } +sub linktext ($%) { + # Return the text of the link to a tag, depending on option linktext. + my ($page, %params) = @_; + if (exists $params{show} && + exists $pagestate{$page} && + exists $pagestate{$page}{meta}{$params{show}}) { + return $pagestate{$page}{meta}{$params{show}}; + } + else { + return undef; + } +} + sub preprocess (@) { my %params=@_; $params{pages}="*" unless defined $params{pages}; my $style = ($params{style} or 'cloud'); - + + # Backwards compatibility + if (defined $params{show} && $params{show} =~ m/^\d+$/) { + $params{limit} = $params{show}; + delete $params{show}; + } + my %counts; my $max = 0; foreach my $page (pagespec_match_list($params{page}, $params{pages}, @@ -63,11 +83,21 @@ sub preprocess (@) { $max = $counts{$page} if $counts{$page} > $max; } + if (exists $params{limit}) { + my $i=0; + my %show; + foreach my $key (sort { $counts{$b} <=> $counts{$a} } keys %counts) { + last if ++$i > $params{limit}; + $show{$key}=$counts{$key}; + } + %counts=%show; + } + if ($style eq 'table') { - return "\n". + return "
\n". join("\n", map { "" } sort { $counts{$b} <=> $counts{$a} } keys %counts). @@ -76,16 +106,31 @@ sub preprocess (@) { else { # In case of misspelling, default to a page cloud - my $res = "
\n"; + my $res; + if ($style eq 'list') { + $res = "\n"; + } + else { + $res .= "
\n"; } - $res .= "\n"; return $res; }
". - htmllink($params{page}, $params{destpage}, $_, noimageinline => 1). + htmllink($params{page}, $params{destpage}, $_, noimageinline => 1, linktext => linktext($_, %params)). "".$counts{$_}."