[Home]WikiPatches/SubscribePage

UseModWiki | WikiPatches | RecentChanges | Preferences

This small patch makes it possible for interested parties to add their email address to the /Mail sub-page of a given page. Then, when the page is modified, an email notification is sent to the addresses in the /Mail page. This certainly wouldn't scale to a public wiki, but is rather handy in a small internal team wiki. It makes it quite easy to set up ad-hoc collaborations on a given page.

The patch can be applied as follows:

In the subroutine DoPost add the following line in this context:

  $user = &GetParam("username", "");
  # If the person doing editing chooses, send out email notification
  if ($EmailNotify) {
    &EmailNotify($id, $user) if &GetParam("do_email_notify", "") eq 'on';
  }

  &SubscriberNotify($id,$user);   # ADD THIS LINE

  if (&GetParam("recent_edit", "") eq 'on') {
    $isEdit = 1;
  }

Then, towards the end of the wiki.pl file add the following two routines:


sub GetPageText {
    my ($fname) = @_;
    my (%MyPage) =  ();
    my (%MySection) = ();
    my (%MyText) = ();
    my ($retText) = "";

    if (-f $fname) {
	my ($data) = &ReadFileOrDie($fname);
	%MyPage = split(/$FS1/,$data,-1);
	%MySection = split(/$FS2/,$MyPage{'text_default'},-1);
	%MyText = split(/$FS3/,$MySection{'data'},-1);
	$retText = $MyText{'text'};
    }
    return $retText;
}

sub SubscriberNotify {
  local $/ = "\n";   # don't slurp whole files in this sub.

  return if (&GetParam("recent_edit","") eq 'on');

  my ($id, $user) = @_;

  my @subscribers;

  my ($mailFile) = &GetPageFile("$id/Mail");

  if (-r $mailFile) {
      my ($pageText) = &GetPageText($mailFile);
      @subscribers = grep /^[ \t]*[^ \t]*\@[^ \t]*[ \t]*$/, split(/[ \t\n]/,$pageText);

      if ($#subscribers >= 0) {
	  my $toAddress = join(",",@subscribers);

	  my $home_url = $q->url();
	  my $page_url = $home_url . "?$id";
	  my $editors_summary = $q->param("summary");
	  if (($editors_summary eq "*") or ($editors_summary eq "")){
	      $editors_summary = "";
	  }
	  else {
	      $editors_summary = "\n Summary: $editors_summary";
	  }
	  my $content = <<"END_MAIL_CONTENT";

 The $SiteName page $id at
   $page_url
 has been changed by $user to revision $Page{revision}. 

 $editors_summary

  To remove yourself from this list, edit ${page_url}/Mail 
END_MAIL_CONTENT
	  my $subject = "The $id page at $SiteName has been changed.";
	  # I'm setting the "reply-to" field to be the same as the "to:" field
	  # which seems appropriate for a mailing list, especially since the
	  # $EmailFrom string needn't be a real email address.
	  &SendEmail($toAddress, $EmailFrom, "", $subject, $content);
     }
  }
}

Just before the #END_OF_OTHER_CODE comment near the end of the file.


Q: added in latest version?:

This feature gives the same functionality in the core code when it says "Send mail notification that ... has been changed" when we editing?, does it overlap with the same functionality at latest version? --JuanmaMP

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited March 14, 2008 7:29 pm by JuanmaMP (diff)
Search: