Skip to content
Snippets Groups Projects
Commit 52b0dd67 authored by Guy Brand's avatar Guy Brand
Browse files

Add namespace changes mail notifications

This patch lets DokuWiki send mail notifications when any page inside
a namespace gets modified. Two actions are introduced: subscribens and
unsubscribens and two new buttons also appear in the bundled template.

darcs-hash:20080227155024-19e2d-8ce5bd66f4e870db31d6b438516599f294365ce1.gz
parent f342ae92
No related branches found
No related tags found
No related merge requests found
......@@ -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 :
......@@ -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;
}
......
......@@ -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';
......
......@@ -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
......
......@@ -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;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment