[Home]WikiPatches/RecentVisitorsFeature

UseModWiki | WikiPatches | RecentChanges | Preferences

There is a patch for UseMod which implements a RecentVisitors feature. Whenever you request a page, this will add your user name to the list and expire all entries older than a certain time. Such a thing has been Implemented on the EmacsWiki:RecentChanges. Click on the [Recent Visitors] link at the top of the page.

Currently (2001-10-16) only visitors during the last five minutes are kept. The timespan is so short because I felt a long timespan such as 5 hours was meaningless and even something like 1 hour was similar to logging -- an invasion of privacy. If you have no username set, you will be kept as "Anonymous" in the list. Telling the various anonymous users appart via their IP has not been implemented, also due to privacy considerations.

If you are interested, send me mail. I am still unsure whether this is useful at all. Some slash sites have a similar feature: They tell you "There are 2 members and 5 guests online" or something like that.

The patch has been working fine for the last weeks. I don't know how it will act under stress -- the list of recent visitors is kept in a file which is not locked when reading and writing. I figured that corruptions errors should be self-correcting, everything else is a bug. And locking would introduce a performance problem.

Patch contact information: MeatBall:AlexSchroeder

Feedback

I think that the only reason I wanted this is because I wanted to know wether anybody was actually reading the pages. Most of the time there will be one "Anonymous" entry and myself as recent visitors. That turned out to be boring so I practically never use the link. Thus, I think this patch is worthless. -- MeatBall:AlexSchroeder

Patch

*** /home/alex/src/usemod092/wiki.pl	Sun Apr 22 02:44:10 2001
--- /home/alex/WWW/emacswiki/cgi-bin/wiki-visitors.pl	Fri Mar 15 19:51:18 2002
***************
*** 45,58 ****
    $UrlProtocols $UrlPattern $ImageExtensions $RFCPattern $ISBNPattern
    $FS $FS1 $FS2 $FS3 $CookieName $SiteBase $StyleSheet $NotFoundPg
    $FooterNote $EditNote $MaxPost $NewText $NotifyDefault $HttpCharset
!   $UserGotoBar);
  # Note: $NotifyDefault is kept because it was a config variable in 0.90
  # Other global variables:
  use vars qw(%Page %Section %Text %InterSite %SaveUrl %SaveNumUrl
    %KeptRevisions %UserCookie %SetCookie %UserData %IndexHash %Translate
    %LinkIndex $InterSiteInit $SaveUrlIndex $SaveNumUrlIndex $MainPage
    $OpenPageName @KeptList @IndexList $IndexInit
!   $q $Now $UserID $TimeZoneOffset $ScriptName $BrowseCode $OtherCode);
  
  # == Configuration =====================================================
  $DataDir     = "/tmp/mywikidb"; # Main wiki directory
--- 45,59 ----
    $UrlProtocols $UrlPattern $ImageExtensions $RFCPattern $ISBNPattern
    $FS $FS1 $FS2 $FS3 $CookieName $SiteBase $StyleSheet $NotFoundPg
    $FooterNote $EditNote $MaxPost $NewText $NotifyDefault $HttpCharset
!   $UserGotoBar $VisitorTime $VisitorFile);
  # Note: $NotifyDefault is kept because it was a config variable in 0.90
  # Other global variables:
  use vars qw(%Page %Section %Text %InterSite %SaveUrl %SaveNumUrl
    %KeptRevisions %UserCookie %SetCookie %UserData %IndexHash %Translate
    %LinkIndex $InterSiteInit $SaveUrlIndex $SaveNumUrlIndex $MainPage
    $OpenPageName @KeptList @IndexList $IndexInit
!   $q $Now $UserID $TimeZoneOffset $ScriptName $BrowseCode $OtherCode
!   %RecentVisitors);
  
  # == Configuration =====================================================
  $DataDir     = "/tmp/mywikidb"; # Main wiki directory
***************
*** 84,89 ****
--- 85,91 ----
  $NewText     = "";              # New page text ("" for default message)
  $HttpCharset = "";              # Charset for pages, like "iso-8859-2"
  $UserGotoBar = "";              # HTML added to end of goto bar
+ $VisitorTime = 30 * 60;          # Timespan to remember visitors (seconds or 0)
  
  # Major options:
  $UseSubpage  = 1;       # 1 = use subpages,       0 = do not use subpages
***************
*** 142,147 ****
--- 144,150 ----
  $RcFile      = "$DataDir/rclog";    # New RecentChanges logfile
  $RcOldFile   = "$DataDir/oldrclog"; # Old RecentChanges logfile
  $IndexFile   = "$DataDir/pageidx";  # List of all pages
+ $VisitorFile = "$DataDir/visitors"; # List of recent visitors
  
  # The "main" program, called at the end of this script file.
  sub DoWikiRequest {
***************
*** 355,360 ****
--- 358,364 ----
      &BrowsePage($HomePage);
      return 1;
    }
+   &AddUserToRecentVisitors();
    $id = &GetParam('keywords', '');
    if ($id) {                    # Just script?PageName
      if ($FreeLinks && (!-f &GetPageFile($id))) {
***************
*** 2475,2480 ****
--- 2479,2486 ----
        &DoEditPrefs();  # Also creates new ID
      } elsif ($action eq "version") {
        &DoShowVersion();
+     } elsif ($action eq "visitors") {
+       &DoShowVisitors();
      } else {
        # Later improve error reporting
        &ReportError(Ts('Invalid action parameter %s', $action));
***************
*** 4036,4041 ****
--- 4042,4102 ----
    print "<p>UseModWiki version 0.92<p>\n";
    print &GetCommonFooter();
  }
+ 
+ # ==== Maintaining a list of recent visitors ====
+ sub ReadRecentVisitors {
+   my ($status, $data) = &ReadFile($VisitorFile);
+   if (!$status) {
+     return;
+   }
+   %RecentVisitors = ();
+   foreach (split(/\n/,$data)) {
+     my ($name, $time) = split /:/;
+     $RecentVisitors{$name} = $time;
+   }
+ }
+ 
+ sub WriteRecentVisitors {
+   my $data = "";
+   my $limit = time() - $VisitorTime;
+   foreach my $name (keys %RecentVisitors) {
+     my $time = $RecentVisitors{$name};
+     if ($time >= $limit) {
+       $data .= "$name:$time\n";
+     }
+   }
+   &WriteStringToFile($VisitorFile, $data);
+ }
+ 
+ sub UpdateRecentVisitors {
+   my ($name) = @_;
+   &ReadRecentVisitors();
+   $RecentVisitors{$name} = time;
+   &WriteRecentVisitors();
+ }
+ 
+ sub AddUserToRecentVisitors {
+   &UpdateRecentVisitors(&GetParam("username", ""));
+ }
+ 
+ sub DoShowVisitors {
+   print &GetHeader("", "Recent Visitors", "");
+   &ReadRecentVisitors();
+   print "<p><ul>";
+   foreach my $name (sort (keys %RecentVisitors)) {
+     my $time = $RecentVisitors{$name};
+     print "<li>";
+     if (!$name) {
+       print "Anonymous";
+     } else {
+       print &GetPageLink($name);
+     }
+     print ", ", time - $time, " seconds ago</li>";
+   }
+   print "</ul>";
+   print &GetCommonFooter();
+ }
+ 
  #END_OF_OTHER_CODE
  
  &DoWikiRequest()  if ($RunCGI && ($_ ne 'nocgi'));   # Do everything.

Diff finished at Fri Mar 15 19:54:10

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited February 8, 2014 6:20 pm by MarkusLude (diff)
Search: