]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/pagestats.pm
Merge remote-tracking branch 'smcv/ready/limit'
[git.ikiwiki.info.git] / IkiWiki / Plugin / pagestats.pm
index 1c0b46830163da3872a0e4b62f0db4960ca3605c..460a5969a60e6924af3f637db2c3760e8883e7ae 100644 (file)
@@ -35,7 +35,13 @@ 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},
@@ -64,18 +70,18 @@ sub preprocess (@) {
                $max = $counts{$page} if $counts{$page} > $max;
        }
 
-       if (exists $params{show}) {
+       if (exists $params{limit}) {
                my $i=0;
                my %show;
                foreach my $key (sort { $counts{$b} <=> $counts{$a} } keys %counts) {
-                       last if ++$i > $params{show};
+                       last if ++$i > $params{limit};
                        $show{$key}=$counts{$key};
                }
                %counts=%show;
        }
 
        if ($style eq 'table') {
-               return "<table class='pageStats'>\n".
+               return "<table class='".(exists $params{class} ? $params{class} : "pageStats")."'>\n".
                        join("\n", map {
                                "<tr><td>".
                                htmllink($params{page}, $params{destpage}, $_, noimageinline => 1).
@@ -87,16 +93,31 @@ sub preprocess (@) {
        else {
                # In case of misspelling, default to a page cloud
 
-               my $res = "<div class='pagecloud'>\n";
+               my $res;
+               if ($style eq 'list') {
+                       $res = "<ul class='".(exists $params{class} ? $params{class} : "list")."'>\n";
+               }
+               else {
+                       $res = "<div class='".(exists $params{class} ? $params{class} : "pagecloud")."'>\n";
+               }
                foreach my $page (sort keys %counts) {
                        next unless $counts{$page} > 0;
 
                        my $class = $classes[$counts{$page} * scalar(@classes) / ($max + 1)];
+                       
+                       $res.="<li>" if $style eq 'list';
                        $res .= "<span class=\"$class\">".
                                htmllink($params{page}, $params{destpage}, $page).
                                "</span>\n";
+                       $res.="</li>" if $style eq 'list';
+
+               }
+               if ($style eq 'list') {
+                       $res .= "</ul>\n";
+               }
+               else {
+                       $res .= "</div>\n";
                }
-               $res .= "</div>\n";
 
                return $res;
        }