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.

Our Privacy Policy

tips:cleannotificationscheme

This is an old revision of the document!


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);

and change it to

//subscriber_addresslist($id); //replaced to clean notification scheme, more info at http://www.dokuwiki.org/tips:cleannotificationscheme
restricted_subscriber_addresslist($id,$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,$rev=''){
  global $conf;
  global $auth;
 
  if (!$conf['subscribers']) return '';
 
  $users = array();
  $emails = array();
  $mlist = array();
 
  if($rev) {
    // load the page mlist file content
    $file=metaFN($id,'.mlist');
    if (@file_exists($file)) {
      $mlist = file($file);
      foreach ($mlist as $who) {
        $who = rtrim($who);
        $users[$who] = true;
      }
    }
  }
  else { //rev not set
    // load 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);
          $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);
        $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 has been tested on dokuwiki2008-05-05, and nicely combines with the betteremailnotifications tip.

Comments - feedback

Please give comments / feedback!

tips/cleannotificationscheme.1225368669.txt.gz · Last modified: 2009-08-25 12:36 (external edit)