2 package IkiWiki::Plugin::progress;
8 my $percentage_pattern = qr/[0-9]+\%?/; # pattern to validate percentages
11 hook(type => "getsetup", id => "progress", call => \&getsetup);
12 hook(type => "preprocess", id => "progress", call => \&preprocess);
13 hook(type => "format", id => "progress", call => \&format);
29 if (defined $params{percent}) {
30 $fill = $params{percent};
31 ($fill) = $fill =~ m/($percentage_pattern)/; # fill is untainted now
33 if (! defined $fill || ! length $fill || $fill > 100 || $fill < 0) {
34 error(sprintf(gettext("illegal percent value %s"), $params{percent}));
38 elsif (defined $params{totalpages} and defined $params{donepages}) {
39 add_depends($params{page}, $params{totalpages});
40 add_depends($params{page}, $params{donepages});
42 my @pages=keys %pagesources;
45 foreach my $page (@pages) {
46 $totalcount++ if pagespec_match($page, $params{totalpages}, location => $params{page});
47 $donecount++ if pagespec_match($page, $params{donepages}, location => $params{page});
50 if ($totalcount == 0) {
54 my $number = $donecount/$totalcount*100;
55 $fill = sprintf("%u%%", $number);
59 error(gettext("need either `percent` or `totalpages` and `donepages` parameters"));
63 <div class="progress">
64 <div class="progress-done" style="width: $fill">$fill</div>
72 # If HTMLScrubber has removed the style attribute, then bring it back
74 $params{content} =~ s!<div class="progress-done">($percentage_pattern)</div>!<div class="progress-done" style="width: $1">$1</div>!g;
76 return $params{content};