DokuWiki

It's better when it's simple

User Tools

Site Tools


Sidebar

Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community


Follow us on Facebook, Twitter and other social networks.

tips:cleannotificationscheme

Clean notification scheme

To make the notification system lighter (read: sending less notifications) I modified the notifications to be sent according to the following scheme:

  1. namespace subscribers get notified for new pages in the current namespace
  2. page subscribers get notified for major page modifications (they are likely subscribed to namespace as well)
  3. no one is notified for minor modifications

inc/common.php

2 small changes need to be brought to inc/common.php

1. find

subscriber_addresslist($id,false);

and change it to

//subscriber_addresslist($id,false); //replaced to clean notification scheme, more info at http://www.dokuwiki.org/tips:cleannotificationscheme
restricted_subscriber_addresslist($id,false,$rev);

2. add the following function (heavy copy-paste of existing code by Steven Danz), for instance before the function subscriber_addresslist($id) declaration.

/**
 * Return a string with the email addresses of all the
 * users subscribed to a page
 *
 * if $rev is set, the list of page subscribers is returned (for page  update notification)
 * if $rev is not set, the list of namespace subsribers is returned (for new page notification)
 *
 * @author Berteh <berteh@hotmail.com>
 * @info http://www.dokuwiki.org/tips:cleannotificationscheme
 */
function restricted_subscriber_addresslist($id,$self=true,$rev=''){
  global $conf;
  global $auth;
 
  if (!$conf['subscribers']) return '';
 
  $users = array();
  $emails = array();
  $mlist = array();
 
 if($rev) { //only direct page subscribers
  // load the page mlist file content
  $file=metaFN($id,'.mlist');
  if (@file_exists($file)) {
    $mlist = file($file);
    foreach ($mlist as $who) {
      $who = rtrim($who);
      if(!$self && $who == $_SERVER['REMOTE_USER']) continue;
      $users[$who] = true;
    }
  }
 }
 else { //rev not set - only namespace subscribers
  // load also the namespace mlist file content
  $ns = getNS($id);
  while ($ns) {
    $nsfile = metaFN($ns,'/.mlist');
    if (@file_exists($nsfile)) {
      $mlist = file($nsfile);
      foreach ($mlist as $who) {
        $who = rtrim($who);
        if(!$self && $who == $_SERVER['REMOTE_USER']) continue;
        $users[$who] = true;
      }
    }
    $ns = getNS($ns);
  }
  // root namespace
  $nsfile = metaFN('','.mlist');
  if (@file_exists($nsfile)) {
    $mlist = file($nsfile);
    foreach ($mlist as $who) {
      $who = rtrim($who);
      if(!$self && $who == $_SERVER['REMOTE_USER']) continue;
      $users[$who] = true;
    }
  }
 }
 if(!empty($users)) {
    foreach (array_keys($users) as $who) {
      $info = $auth->getUserData($who);
      if($info === false) continue;
      $level = auth_aclcheck($id,$who,$info['grps']);
      if ($level >= AUTH_READ) {
        if (strcasecmp($info['mail'],$conf['notify']) != 0) {
          $emails[] = $info['mail'];
        }
      }
    }
 }
 
 return implode(',',$emails);
}

This hack has been tested on dokuwiki-2009-02-14, and nicely combines with the betteremailnotifications tip. An older version was working on dokuwiki-2008-05-05.

Comments - feedback

Please give comments / feedback!

Any idea on how to implement this in Ponder Stibbons? I believe the changes to how subscriptions work has made this irrelevant :-(
Feel free to correct me if I'm wrong, I'd love to get this working!
absolutejamabsolutejam

2014-06-11 23:20
tips/cleannotificationscheme.txt · Last modified: 2014-06-11 23:25 by absolutejam