[Home]WikiPatches/EditionsPerUser

UseModWiki | WikiPatches | RecentChanges | Preferences

Another indexing scheme to add to sub DoOtherRequest. Work in progress.

The Patch

sub DoUserMod {
  my (@dirs, @files, @pages, $dir, $file);
  my (%Data, $maxID);
  my ($status, $data, $fileData, $oldFileData);
  my ($firstTs, @firstTs, @firstUs);
  my (@full, @fullrc, @fullnewrc);
  my ($c, @unsorted, $dupla, $revs, $auth, %v, %t, @sorted);
  my ($i, $j, @i, @j);
  my $id;

  print &GetHeader('', T('Umod'), '');
  opendir(DIRLIST, $UserDir);
  @dirs = readdir(DIRLIST);
  closedir(DIRLIST);
  foreach $dir (@dirs) {
    next  if (substr($dir, 0, 1) eq '.');   # No ., .., or .dirs
    next  if (!-d "$UserDir/$dir");         # Top level directories only
    opendir(DIRLIST, "$UserDir/$dir");
    @files = readdir(DIRLIST);
    closedir(DIRLIST);
    foreach $file (@files) {
      $c++;
      if ($file =~ m/(\d+).db/) {  # Only numeric ID files
        $id = $1;
        $maxID = $id  if ($id > $maxID);
        %Data = ();
        ($status, $data) = &ReadFile("$UserDir/$dir/$file");
        if ($status) {
          %Data = split(/$FS1/, $data, -1);  # -1 keeps trailing null fields
          ($status, $fileData) = &ReadFile($RcFile);
          if ($status) {
            @fullnewrc = split(/\n/, $fileData);
          }
          ($status, $oldFileData) = &ReadFile($RcOldFile);
          if ($status) {
            @fullrc = split(/\n/, $oldFileData);
          }
          @full = (@fullrc, @fullnewrc);
          ($i, $j) =0;
          if (@full > 0) {  # Only false if no lines in file
            for ($i=0; $i <= $#full; $i++) {
              @firstUs = split(/$FS2/, $full[$i]);
              if ($Data{username} eq $firstUs[$#i-2] 
              and $Data{id} eq $firstUs[$#i]) {
                ++$j;
              }
            }
          }
          if ($Data{username}) {
            if (!$j) {$v{$c} = 0} else {$v{$c} = $j;}
            $t{$c} = $Data{username};
            $dupla = "$v{$c}|$t{$c}";
            push(@unsorted, $dupla);
          }
        }
      }
    }
  }
  @sorted = reverse sort { $a <=> $b } @unsorted; 
  print '<ol>';
  foreach $c (@sorted) {
    ($revs,$auth) = split(/\|/,$c);
    print '<li>' . &GetPageOrEditLink($auth) . ' ' . '['. $revs . ']';
  }
  print '</ol>';
  print &GetCommonFooter();
  return;
}
--JuanmaMP

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited December 17, 2009 7:48 pm by JuanmaMP (diff)
Search: