[Home]WikiPatches/IndexWithSortableSizes

UseModWiki | WikiPatches | RecentChanges | Preferences

Incremental patch on top of /IndexWithSizes. Allows sorting by either size or page name, in forward or reverse order. Also removes the parameter processing from the big switch statement, since that doesn't seem to be the standard place to do it. If I weren't lazy, I would fix /IndexWithSizes to never do it in the first place. -- SteveFink
--- wiki.pl.6	Mon Nov 18 18:22:16 2002
+++ wiki.pl.7	Mon Nov 18 18:55:34 2002
@@ -2388,7 +2388,8 @@
   my (%options) = @_;
   my $need_sizes = $options{'sizes'}
     || defined($options{'minsize'})
-    || defined($options{'maxsize'});
+    || defined($options{'maxsize'})
+    || defined($options{'sizesort'});
 
   my (@pages, @dirs, $id, $dir, @pageFiles, @subpageFiles, $subId);
 
@@ -2439,7 +2440,6 @@
   return sort(@pages) unless $need_sizes;
 
   # Compute the sizes of all the pages
-  @pages = sort(@pages);
   my @sizes;
   push(@sizes, GetPageSize($_)) foreach (@pages);
 
@@ -2465,6 +2465,17 @@
     @sizes = @newsizes;
   }
 
+  my @order;
+  if ($options{'sizesort'}) {
+    @order = sort { $sizes[$a] <=> $sizes[$b] } 0..$#pages;
+    @order = reverse @order if $options{'sizesort'} == -1;
+  } else {
+    @order = sort { $pages[$a] cmp $pages[$b] } 0..$#pages;
+    @order = reverse @order if $options{'pagesort'} == -1;
+  }
+  @pages = @pages[@order];
+  @sizes = @sizes[@order];
+
   return @pages if ! $options{'sizes'};
   return (\@pages, \@sizes);
 }
@@ -2476,7 +2487,8 @@
 
   my $need_sizes = $options{'sizes'}
     || defined($options{'minsize'})
-    || defined($options{'maxsize'});
+    || defined($options{'maxsize'})
+    || defined($options{'sizesort'});
 
   if (!$UseIndex || $need_sizes) {
     return &GenerateAllPagesList(%options);
@@ -2635,9 +2647,7 @@
     } elsif ($action eq "unlock") {
       &DoUnlock();
     } elsif ($action eq "index") {
-      &DoIndex(sizes => &GetParam("sizes", 0),
-	       minsize => &GetParam("minsize", undef),
-	       maxsize => &GetParam("maxsize", undef));
+      &DoIndex();
     } elsif ($action eq "links") {
       &DoLinks();
     } elsif ($action eq "maintain") {
@@ -3091,7 +3101,11 @@
 }
 
 sub DoIndex {
-  my (%options) = @_;
+  my %options = (sizes => &GetParam("sizes", 0),
+		 minsize => &GetParam("minsize", undef),
+		 maxsize => &GetParam("maxsize", undef),
+		 sizesort => &GetParam("sizesort", undef),
+		 pagesort => &GetParam("pagesort", undef));
   print &GetHeader('', T('Index of all pages'), '');
   print '<br>';
   &PrintPageList(&AllPagesList(%options));
@@ -3233,7 +3247,21 @@
   my $pagename;
 
   print "<h2>", Ts('%s pages found:', (0+@$pages)), "</h2>\n";
-  print "<table>\n" if $sizes;
+  if ($sizes) {
+    print "<table>\n";
+    my $query = $ENV{'QUERY_STRING'};
+    my $new_size_sort_dir = -($q->param('sizesort') || -1);
+    my $new_page_sort_dir = -($q->param('pagesort') || -1);
+    $query =~ s/[&;]sizesort=[\-\+\d]+//;
+    $query =~ s/[&;]pagesort=[\-\+\d]+//;
+    print "<tr><th align=left><font size=+2>",
+          ScriptLink("$query&pagesort=$new_page_sort_dir", "Page"),
+	  "</font></th>";
+    print "<th><font size=+2>",
+          ScriptLink("$query&sizesort=$new_size_sort_dir", "Size"),
+	  "</font></th></tr>\n";
+  }
+
   foreach $pagename (@$pages) {
     print "<tr><td align=left>" if $sizes;
     print ".... "  if ($pagename =~ m|/|);

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited July 12, 2023 12:01 am by MarkusLude (diff)
Search: