This patch adds byte counts to each of the pages listed in the index. It's a little funky in that it caches the sizes in a symlink alongside each db file. --
SteveFink
--- wiki.pl.5 Mon Nov 18 18:13:24 2002
+++ wiki.pl.6 Mon Nov 18 18:22:16 2002
@@ -1853,6 +1853,29 @@
return $PageDir . "/" . &GetPageDirectory($id) . "/$id.db";
}
+sub CachePageSize {
+ my ($fname, $size) = @_;
+ unlink($fname);
+ symlink($size, $fname);
+}
+
+sub GetPageSize {
+ my ($id) = @_;
+ my $fname = GetPageFile($id) . ".size";
+ if (-l $fname) {
+ return readlink($fname);
+ } else {
+ local %Page;
+ local %Text;
+ local %Section;
+ OpenPage($id);
+ OpenDefaultText();
+ my $size = length($Text{'text'});
+ CachePageSize($fname, $size);
+ return $size;
+ }
+}
+
sub OpenPage {
my ($id) = @_;
my ($fname, $data);
@@ -1922,6 +1945,7 @@
$Page{'ts'} = $Now; # Updated every edit
&CreatePageDir($PageDir, $OpenPageName);
&WriteStringToFile($file, join($FS1, %Page));
+ &CachePageSize("$file.size", length($Text{'text'}));
}
sub SaveSection {
@@ -2361,6 +2385,11 @@
}
sub GenerateAllPagesList {
+ my (%options) = @_;
+ my $need_sizes = $options{'sizes'}
+ || defined($options{'minsize'})
+ || defined($options{'maxsize'});
+
my (@pages, @dirs, $id, $dir, @pageFiles, @subpageFiles, $subId);
@pages = ();
@@ -2406,14 +2435,51 @@
}
}
}
- return sort(@pages);
+
+ return sort(@pages) unless $need_sizes;
+
+ # Compute the sizes of all the pages
+ @pages = sort(@pages);
+ my @sizes;
+ push(@sizes, GetPageSize($_)) foreach (@pages);
+
+ if (defined($options{'minsize'})) {
+ my (@newpages, @newsizes);
+ for (0..$#pages) {
+ next if $sizes[$_] < $options{'minsize'};
+ push @newpages, $pages[$_];
+ push @newsizes, $sizes[$_];
+ }
+ @pages = @newpages;
+ @sizes = @newsizes;
+ }
+
+ if (defined($options{'maxsize'})) {
+ my (@newpages, @newsizes);
+ for (0..$#pages) {
+ next if $sizes[$_] > $options{'maxsize'};
+ push @newpages, $pages[$_];
+ push @newsizes, $sizes[$_];
+ }
+ @pages = @newpages;
+ @sizes = @newsizes;
+ }
+
+ return @pages if ! $options{'sizes'};
+ return (\@pages, \@sizes);
}
sub AllPagesList {
+ my (%options) = @_;
+
my ($rawIndex, $refresh, $status);
- if (!$UseIndex) {
- return &GenerateAllPagesList();
+ my $need_sizes = $options{'sizes'}
+ || defined($options{'minsize'})
+ || defined($options{'maxsize'});
+
+ if (!$UseIndex || $need_sizes) {
+ return &GenerateAllPagesList(%options);
}
$refresh = &GetParam("refresh", 0);
if ($IndexInit && !$refresh) {
@@ -2569,7 +2635,9 @@
} elsif ($action eq "unlock") {
&DoUnlock();
} elsif ($action eq "index") {
- &DoIndex();
+ &DoIndex(sizes => &GetParam("sizes", 0),
+ minsize => &GetParam("minsize", undef),
+ maxsize => &GetParam("maxsize", undef));
} elsif ($action eq "links") {
&DoLinks();
} elsif ($action eq "maintain") {
@@ -3023,9 +3091,10 @@
}
sub DoIndex {
+ my (%options) = @_;
print &GetHeader('', T('Index of all pages'), '');
print '<br>';
- &PrintPageList(&AllPagesList());
+ &PrintPageList(&AllPagesList(%options));
print &GetCommonFooter();
}
@@ -3154,13 +3223,29 @@
}
sub PrintPageList {
+ my ($pages, $sizes);
+ if (ref($_[0])) {
+ ($pages, $sizes) = @_;
+ } else {
+ $pages = \@_;
+ }
+
my $pagename;
- print "<h2>", Ts('%s pages found:', ($#_ + 1)), "</h2>\n";
- foreach $pagename (@_) {
+ print "<h2>", Ts('%s pages found:', (0+@$pages)), "</h2>\n";
+ print "<table>\n" if $sizes;
+ foreach $pagename (@$pages) {
+ print "<tr><td align=left>" if $sizes;
print ".... " if ($pagename =~ m|/|);
- print &GetPageLink($pagename), "<br>\n";
+ print &GetPageLink($pagename);
+ if ($sizes) {
+ print "</td><td align=right>";
+ print shift(@$sizes), " bytes";
+ print "</td></tr>\n";
+ }
+ print "<br>\n" unless $sizes;
}
+ print "</table>\n" if $sizes;
}
sub DoLinks {