[dokuwiki] Namespace notifications (patch)

Hi list,


The attached patch is a first attempt to add namespace notifications
to DokuWiki. Currently DokuWiki is able to send an email to inform a
user who has subscribed to a page changes when the page is modified.
The patch introduces the same behavior for namespaces: a user can
subscribe to a namespace and be notified when any page contained in
the namespace is modified.

It uses .mlist files stored in the meta directory for each namespace
and adds two new actions: subscribens, unsubscribens which are small
variant of the already existing subscribe and unsubscribe actions. A
new button is displayed to allow namespace changes (un)subscription.

I've been playing with the patch for a few weeks now, and it works
for me, but your mileage may vary. More tests are needed, so feel
free to comment, modify or suggest changes.

-- 
  bug

New patches:

[Namespace notifications
Guy Brand <gb@xxxxxxxxxxxxxxxxx>**20080222225003] {
hunk ./inc/actions.php 50
+    //check if user is asking to (un)subscribe a namespace
+    if($ACT == 'subscribens' || $ACT == 'unsubscribens')
+      $ACT = act_subscriptionns($ACT);
+
hunk ./inc/actions.php 176
-                                             'resendpwd',))){
+                                             
'resendpwd','subscribens','unsubscribens',))){
hunk ./inc/actions.php 185
-                          'draftdel',)) && substr($act,0,7) != 'export_' ) {
+                          'draftdel','subscribens','unsubscribens',)) && 
substr($act,0,7) != 'export_' ) {
hunk ./inc/actions.php 424
- * Handle 'subscribe', 'unsubscribe'
+ * Handle page 'subscribe', 'unsubscribe'
hunk ./inc/actions.php 450
+    } else {
+      msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1);
+    }
+  }
+
+  return 'show';
+}
+
+/**
+ * Handle namespace 'subscribe', 'unsubscribe'
+ *
+ */
+function act_subscriptionns($act){
+  global $ID;
+  global $INFO;
+  global $lang;
+
+  if(!getNS($ID)) {
+    $file = metaFN(getNS($ID),'.mlist');
+  } else {
+    $file = metaFN(getNS($ID),'/.mlist');
+  }
+
+  if ($act=='subscribens' && !$INFO['subscribedns']){
+    if ($INFO['userinfo']['mail']){
+      if (io_saveFile($file,$_SERVER['REMOTE_USER']."\n",true)) {
+        $INFO['subscribedns'] = true;
+        msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1);
+      } else {
+        msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1);
+      }
+    } else {
+      msg($lang['subscribe_noaddress']);
+    }
+  } elseif ($act=='unsubscribens' && $INFO['subscribedns']){
+    if (io_deleteFromFile($file,$_SERVER['REMOTE_USER']."\n")) {
+      $INFO['subscribedns'] = false;
+      msg(sprintf($lang[$act.'_success'], $INFO['userinfo']['name'], $ID),1);
hunk ./inc/common.php 111
-    $info['userinfo']   = $USERINFO;
-    $info['perm']       = auth_quickaclcheck($ID);
-    $info['subscribed'] = is_subscribed($ID,$_SERVER['REMOTE_USER']);
-    $info['client']     = $_SERVER['REMOTE_USER'];
+    $info['userinfo']     = $USERINFO;
+    $info['perm']         = auth_quickaclcheck($ID);
+    $info['subscribed']   = is_subscribed($ID,$_SERVER['REMOTE_USER'],false);
+    $info['subscribedns'] = is_subscribed($ID,$_SERVER['REMOTE_USER'],true);
+    $info['client']       = $_SERVER['REMOTE_USER'];
hunk ./inc/common.php 1072
- * Let us know if a user is tracking a page
+ * Let us know if a user is tracking a page or a namespace
hunk ./inc/common.php 1076
-function is_subscribed($id,$uid){
-  $file=metaFN($id,'.mlist');
+function is_subscribed($id,$uid,$ns=false){
+  if(!$ns) {
+    $file=metaFN($id,'.mlist');
+  } else {
+    if(!getNS($id)) {
+      $file = metaFN(getNS($id),'.mlist');
+    } else {
+      $file = metaFN(getNS($id),'/.mlist');
+    }
+  }
hunk ./inc/common.php 1095
+
hunk ./inc/common.php 1110
+  // load the page mlist file content
hunk ./inc/common.php 1116
+  if(count($mlist) > 0) {
+    foreach ($mlist as $who) {
+      $who = rtrim($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) {
+          if (empty($emails)) {
+            $emails = $info['mail'];
+          } else {
+            $emails = "$emails,".$info['mail'];
+          }
+        }
+      }
+    }
+  }
+
+  // load also the namespace mlist file content
+  if(!getNS($id)) {
+    $nsfile = metaFN(getNS($id),'.mlist');
+  } else {
+    $nsfile = metaFN(getNS($id),'/.mlist');
+  }
+  if (@file_exists($nsfile)) {
+    $mlist = file($nsfile);
+  }
hunk ./inc/lang/en/lang.php 42
-$lang['btn_subscribe']   = 'Subscribe Changes';
-$lang['btn_unsubscribe'] = 'Unsubscribe Changes';
+$lang['btn_subscribe']   = 'Subscribe Page Changes';
+$lang['btn_unsubscribe'] = 'Unsubscribe Page Changes';
+$lang['btn_subscribens']   = 'Subscribe Namespace Changes';
+$lang['btn_unsubscribens'] = 'Unsubscribe Namespace Changes';
hunk ./inc/template.php 520
+          }
+          if($INFO['subscribedns']){
+            print html_btn('unsubscribens',$ID,'',array('do' => 
'unsubscribens',));
+          } else {
+            print html_btn('subscribens',$ID,'',array('do' => 'subscribens',));
}

Context:

[popularity plugin: record PCRE infos
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080220213222] 
[updated year in copyright notice
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080220201711] 
[add gidnumber to LDAP auth userdata FS#1338
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080219165659] 
[popularity plugin added
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080219165223
 
 This new default plugin allows to send feedback to the DokuWiki developers. An
 introduction is available at
 http://www.splitbrain.org/blog/2008-02/17-gathering_dokuwiki_usage_data
] 
[Finnish language update
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080217172914] 
[fix for plugin manager breaking multibyte chars
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080215214857] 
[do case insensitive search word highlighting in page FS#1297
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080215180239] 
[fix highlighting of search engine referer keywords for recent highlight change
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080215175816] 
[better highlighting for phrase searches FS#1193
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080215174653
 
 This patch makes the highlighting of phrases in search snippets and on
 the pages itself much better.
 
 Now a regexp gets passed to the ?s= parameter. I ask everybody to test
 this feature throughly especially for the handling of malicious inputs
 and the use of non-latin characters.
] 
[Use auth backend to verify password on profile update FS#1328
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080215154316] 
[fix for resetting timelimit in fetch.php FS#1243
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080215152132] 
[Make session reference file check overridable for auth backends
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080215121716] 
[invalidate all user session cache when userdatabase is changed FS#1085
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080215114923
 
 A reference file is now stored in data/cache/sessionpurge and is used to
 check if user sessions are still valid.
 
 To accomondate for slow auth backends DokuWiki caches user info for
 a certain time in the user session.
] 
[redirect to root namespace in mediamanager when namespace was deleted FS#1286
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080215105251] 
[correctly encode namespace in mediapopup URL FS#1319
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080215094453] 
[fix line endings for meta data editing in media manager FS#1324
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080215091527] 
[add title attribute on page title FS#1330
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080215090454] 
[LDAP backend: try to rebind with current user for getUserData() FS#1053
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080215085556] 
[fix for earlier phpok & htmlok path
Chris Smith <chris@xxxxxxxxxxxxx>**20080214113350] 
[French strings update
Guy Brand <gb@xxxxxxxxxxxxxxxxx>**20080213214113] 
[make sure not supported profile fields are not accepted FS#1329
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080213214505] 
[check modMail capability correctly FS#1329
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080213213322] 
[Hungarian update
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080213204325] 
[filter usernames case-insensitive in user manager
Gabriel Birke <Gabriel.Birke@xxxxxxxxx>**20080213194342] 
[Importoldchangelog: Added metadata support
'Simon Coffey <spc03@xxxxxxxxxxxx>'**20080213145734
 Added function savePerPageMetadata() to populate creator and contributor fields
 of metadata array from old-style changes.log.
] 
[Rationalise Parser PHP & HTML syntax mode handling to renderer only.
Chris Smith <chris@xxxxxxxxxxxxx>**20080213024941
 This patch corrects the problems with the previously (reversed) patch 
 "remove htmlok and phpok tests from Doku_Handler".
 
 The handler will now write php, phpblock, html & htmlblock instructions
 and let the renderer decide how these instructions should be processed.
 
 The xhtml renderer will follow the "phpok" and "htmlok" config settings.
 If these settings are turned off the any instructions will be rendered as 
 code with php or html syntax highlighting (as appropriate).
 
] 
[Have aclcheck use auth_isadmin
Guy Brand <gb@xxxxxxxxxxxxxxxxx>**20080212213222] 
[Hungarian update
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080209092859] 
[make sure $ID is set correct when rendering metadata
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080208212733] 
[removed security token requirement for login
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080208200733
 This was discussed a while ago on the mailing list. We want to work cross-site
 logins keep working.
] 
[TAG develsnap 2008-02-01
Andreas Gohr <andi@xxxxxxxxxxxxxx>**20080201000001] 
Patch bundle hash:
46b8b54e43014654af297f467832bdf42c00a8a9

Other related posts: