diff --git a/inc/actions.php b/inc/actions.php index 83500475ba9580b760ae646fe5dfb183d2499c2f..2ae366ce02c35880febbc581163f33f74a05519f 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -47,6 +47,10 @@ function act_dispatch(){ if($ACT == 'subscribe' || $ACT == 'unsubscribe') $ACT = act_subscription($ACT); + //check if user is asking to (un)subscribe a namespace + if($ACT == 'subscribens' || $ACT == 'unsubscribens') + $ACT = act_subscriptionns($ACT); + //check permissions $ACT = act_permcheck($ACT); @@ -169,7 +173,7 @@ function act_clean($act){ //disable all acl related commands if ACL is disabled if(!$conf['useacl'] && in_array($act,array('login','logout','register','admin', 'subscribe','unsubscribe','profile', - 'resendpwd',))){ + 'resendpwd','subscribens','unsubscribens',))){ msg('Command unavailable: '.htmlspecialchars($act),-1); return 'show'; } @@ -178,7 +182,7 @@ function act_clean($act){ 'preview','search','show','check','index','revisions', 'diff','recent','backlink','admin','subscribe', 'unsubscribe','profile','resendpwd','recover','wordblock', - 'draftdel',)) && substr($act,0,7) != 'export_' ) { + 'draftdel','subscribens','unsubscribens',)) && substr($act,0,7) != 'export_' ) { msg('Command unknown: '.htmlspecialchars($act),-1); return 'show'; } @@ -417,7 +421,7 @@ function act_export($act){ } /** - * Handle 'subscribe', 'unsubscribe' + * Handle page 'subscribe', 'unsubscribe' * * @author Steven Danz <steven-danz@kc.rr.com> * @todo localize @@ -451,4 +455,42 @@ function act_subscription($act){ 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); + } else { + msg(sprintf($lang[$act.'_error'], $INFO['userinfo']['name'], $ID),1); + } + } + + return 'show'; +} + //Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/common.php b/inc/common.php index ce32e42cb10fa17df118a01adf4d9c4641cacc30..7f550dbde95ad4da7cd07b1583caeba67fe4f2ab 100644 --- a/inc/common.php +++ b/inc/common.php @@ -108,10 +108,11 @@ function pageinfo(){ $info['rev'] = $REV; if($_SERVER['REMOTE_USER']){ - $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']; // set info about manager/admin status $info['isadmin'] = false; @@ -1071,12 +1072,20 @@ function obfuscate($email) { } /** - * Let us know if a user is tracking a page + * Let us know if a user is tracking a page or a namespace * * @author Andreas Gohr <andi@splitbrain.org> */ -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'); + } + } if (@file_exists($file)) { $mlist = file($file); $pos = array_search($uid."\n",$mlist); @@ -1100,6 +1109,7 @@ function subscriber_addresslist($id){ if (!$conf['subscribers']) return; + // load the page mlist file content $mlist = array(); $file=metaFN($id,'.mlist'); if (@file_exists($file)) { @@ -1123,6 +1133,33 @@ function subscriber_addresslist($id){ } } + // 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); + } + 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']; + } + } + } + } + } + return $emails; } diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php index c2fdaf5dba79d847f24a1c849d5c8aade32feb6e..d7ece398bd094e67a9eee9e6b1934502ed0916e1 100644 --- a/inc/lang/en/lang.php +++ b/inc/lang/en/lang.php @@ -39,8 +39,10 @@ $lang['btn_delete'] = 'Delete'; $lang['btn_back'] = 'Back'; $lang['btn_backlink'] = "Backlinks"; $lang['btn_backtomedia'] = 'Back to Mediafile Selection'; -$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'; $lang['btn_profile'] = 'Update Profile'; $lang['btn_reset'] = 'Reset'; $lang['btn_resendpwd'] = 'Send new password'; diff --git a/inc/lang/en/subscribermail.txt b/inc/lang/en/subscribermail.txt index bdb2f6c7d96b3b2759f73a5e22b0200165d19177..d7c7671c617987b404a4583fff4c70dcb28df905 100644 --- a/inc/lang/en/subscribermail.txt +++ b/inc/lang/en/subscribermail.txt @@ -7,10 +7,10 @@ Here are the changes: @DIFF@ -------------------------------------------------------- -To unsubscribe from this page log into the wiki at +To cancel the page notifications, log into the wiki at @DOKUWIKIURL@ then visit @NEWPAGE@ -and choose 'Unsubscribe Changes'. +and unsubscribe page and/or namespace changes. -- This mail was generated by DokuWiki at diff --git a/inc/template.php b/inc/template.php index b0cb56c5bfd83f4c09f7023656ffade0337a04bf..4f4ba9813f42e3f1c18640ed1208cb7e3931e267 100644 --- a/inc/template.php +++ b/inc/template.php @@ -518,6 +518,11 @@ function tpl_button($type){ } else { print html_btn('subscribe',$ID,'',array('do' => 'subscribe',)); } + if($INFO['subscribedns']){ + print html_btn('unsubscribens',$ID,'',array('do' => 'unsubscribens',)); + } else { + print html_btn('subscribens',$ID,'',array('do' => 'subscribens',)); + } return true; } }