From 2240ea1f316156f3cb4475ea23a16246c999b6f0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 12:00:37 +0200 Subject: first start at refactoring the subscription system BROKEN This introduces a class for nicer wrapping and easier testing. Some functions were changed to provide nicer APIs (no throwing around of unescaped regexps) and to simplify things (hopefully). The refactoring isn't completed yet, so this will break the subscription system. The goal is to move as much subscription related stuff to this class as possible. Currently there is some code in lib/exe/indexer.php and maybe elsewhere (common.php?). Additionally everything should be covered by tests. A few tests are included here already. --- inc/load.php | 1 + inc/subscription.php | 724 ++++++++++++++++++++++++++------------------------- 2 files changed, 376 insertions(+), 349 deletions(-) (limited to 'inc') diff --git a/inc/load.php b/inc/load.php index b676518e7..bd6d39814 100644 --- a/inc/load.php +++ b/inc/load.php @@ -81,6 +81,7 @@ function load_autoload($name){ 'Mailer' => DOKU_INC.'inc/Mailer.class.php', 'RemoteAPI' => DOKU_INC.'inc/remote.php', 'RemoteAPICore' => DOKU_INC.'inc/RemoteAPICore.php', + 'Subscription' => DOKU_INC.'inc/subscription.php', 'DokuWiki_Action_Plugin' => DOKU_PLUGIN.'action.php', 'DokuWiki_Admin_Plugin' => DOKU_PLUGIN.'admin.php', diff --git a/inc/subscription.php b/inc/subscription.php index 1f1aedfa4..856836cd5 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -12,399 +12,425 @@ * - subscription_lock * - subscription_unlock * + * @fixme handle $conf['subscribers'] and disable actions + * * @author Adrian Lang + * @author Andreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) */ -/** - * Get the name of the metafile tracking subscriptions to target page or - * namespace - * - * @author Adrian Lang - * - * @param string $id The target page or namespace, specified by id; Namespaces - * are identified by appending a colon. - * @return string - */ -function subscription_filename($id) { - $meta_fname = '.mlist'; - if ((substr($id, -1, 1) === ':')) { - $meta_froot = getNS($id); - $meta_fname = '/' . $meta_fname; - } else { - $meta_froot = $id; +class Subscription { + + /** + * Return the subscription meta file for the given ID + * + * @author Adrian Lang + * + * @param string $id The target page or namespace, specified by id; Namespaces + * are identified by appending a colon. + * @return string + */ + protected function file($id) { + $meta_fname = '.mlist'; + if((substr($id, -1, 1) === ':')) { + $meta_froot = getNS($id); + $meta_fname = '/'.$meta_fname; + } else { + $meta_froot = $id; + } + return metaFN((string) $meta_froot, $meta_fname); } - return metaFN((string) $meta_froot, $meta_fname); -} -/** - * Lock subscription info for an ID - * - * @author Adrian Lang - * @param string $id The target page or namespace, specified by id; Namespaces - * are identified by appending a colon. - * @return string - */ -function subscription_lock_filename ($id){ - global $conf; - return $conf['lockdir'].'/_subscr_' . md5($id) . '.lock'; -} + /** + * Lock subscription info + * + * We don't use io_lock() her because we do not wait for the lock and use a larger stale time + * + * @author Adrian Lang + * @param string $id The target page or namespace, specified by id; Namespaces + * are identified by appending a colon. + * @return bool true, if you got a succesful lock + */ + protected function lock($id) { + global $conf; -/** - * Creates a lock file for writing subscription data - * - * @todo add lock time parameter to io_lock() and use this instead - * @param $id - * @return bool - */ -function subscription_lock($id) { - global $conf; - $lock = subscription_lock_filename($id); + $lock = $conf['lockdir'].'/_subscr_'.md5($id).'.lock'; - if (is_dir($lock) && time()-@filemtime($lock) > 60*5) { - // looks like a stale lock - remove it - @rmdir($lock); + if(is_dir($lock) && time() - @filemtime($lock) > 60 * 5) { + // looks like a stale lock - remove it + @rmdir($lock); + } + + // try creating the lock directory + if(!@mkdir($lock, $conf['dmode'])) { + return false; + } + + if($conf['dperm']) chmod($lock, $conf['dperm']); + return true; } - // try creating the lock directory - if (!@mkdir($lock,$conf['dmode'])) { - return false; + /** + * Unlock subscription info + * + * @author Adrian Lang + * @param string $id The target page or namespace, specified by id; Namespaces + * are identified by appending a colon. + * @return bool + */ + protected function unlock($id) { + global $conf; + $lock = $conf['lockdir'].'/_subscr_'.md5($id).'.lock'; + return @rmdir($lock); } - if($conf['dperm']) chmod($lock, $conf['dperm']); - return true; -} + /** + * Construct a regular expression for parsing a subscription definition line + * + * @author Andreas Gohr + * + * @param string|array $user + * @param string|array $style + * @param string|array $data + * @return string complete regexp including delimiters + * @throws Exception when no data is passed + */ + protected function buildregex($user = null, $style = null, $data = null) { + // always work with arrays + $user = (array) $user; + $style = (array) $style; + $data = (array) $data; -/** - * Unlock subscription info for an ID - * - * @author Adrian Lang - * @param string $id The target page or namespace, specified by id; Namespaces - * are identified by appending a colon. - * @return bool - */ -function subscription_unlock($id) { - $lockf = subscription_lock_filename($id); - return @rmdir($lockf); -} + // clean + $user = array_filter(array_map('trim', $user)); + $style = array_filter(array_map('trim', $style)); + $data = array_filter(array_map('trim', $data)); -/** - * Set subscription information - * - * Allows to set subscription information for permanent storage in meta files. - * Subscriptions consist of a target object, a subscribing user, a subscribe - * style and optional data. - * A subscription may be deleted by specifying an empty subscribe style. - * Only one subscription per target and user is allowed. - * The function returns false on error, otherwise true. Note that no error is - * returned if a subscription should be deleted but the user is not subscribed - * and the subscription meta file exists. - * - * @author Adrian Lang - * - * @param string $user The subscriber or unsubscriber - * @param string $page The target object (page or namespace), specified by - * id; Namespaces are identified by a trailing colon. - * @param string $style The subscribe style; DokuWiki currently implements - * “every”, “digest”, and “list”. - * @param string $data An optional data blob - * @param bool $overwrite Whether an existing subscription may be overwritten - * @return bool - */ -function subscription_set($user, $page, $style, $data = null, - $overwrite = false) { - global $lang; - if (is_null($style)) { - // Delete subscription. - $file = subscription_filename($page); - if (!@file_exists($file)) { - msg(sprintf($lang['subscr_not_subscribed'], $user, - prettyprint_id($page)), -1); - return false; - } + // user names are encoded + $user = array_map('auth_nameencode', $user); - // io_deleteFromFile does not return false if no line matched. - return io_deleteFromFile($file, - subscription_regex(array('user' => auth_nameencode($user))), - true); - } + // quote + $user = array_map('preg_quote_cb', $user); + $style = array_map('preg_quote_cb', $style); + $data = array_map('preg_quote_cb', $data); - // Delete subscription if one exists and $overwrite is true. If $overwrite - // is false, fail. - $subs = subscription_find($page, array('user' => $user)); - if (count($subs) > 0 && array_pop(array_keys($subs)) === $page) { - if (!$overwrite) { - msg(sprintf($lang['subscr_already_subscribed'], $user, - prettyprint_id($page)), -1); - return false; + // join + $user = join('|', $user); + $style = join('|', $style); + $data = join('|', $data); + + // any data at all? + if($user.$style.$data === '') throw new Exception('no data passed'); + + // replace empty values, set which ones are optional + $sopt = ''; + $dopt = ''; + if($user === '') { + $user = '\S+'; } - // Fail if deletion failed, else continue. - if (!subscription_set($user, $page, null)) { - return false; + if($style === '') { + $style = '\S+'; + $sopt = '?'; + } + if($data === '') { + $data = '\S+'; + $dopt = '?'; } - } - $file = subscription_filename($page); - $content = auth_nameencode($user) . ' ' . $style; - if (!is_null($data)) { - $content .= ' ' . $data; + // assemble + return "/^($user)(?:\\s+($style))$sopt(?:\\s+($data))$dopt$/"; } - return io_saveFile($file, $content . "\n", true); -} -/** - * Recursively search for matching subscriptions - * - * This function searches all relevant subscription files for a page or - * namespace. - * - * @author Adrian Lang - * @see function subscription_regex for $pre documentation - * - * @param string $page The target object’s (namespace or page) id - * @param array $pre A hash of predefined values - * @return array - */ -function subscription_find($page, $pre) { - // Construct list of files which may contain relevant subscriptions. - $filenames = array(':' => subscription_filename(':')); - do { - $filenames[$page] = subscription_filename($page); - $page = getNS(rtrim($page, ':')) . ':'; - } while ($page !== ':'); - - // Handle files. - $matches = array(); - foreach ($filenames as $cur_page => $filename) { - if (!@file_exists($filename)) { - continue; - } - $subscriptions = file($filename); - foreach ($subscriptions as $subscription) { - if (strpos($subscription, ' ') === false) { - // This is an old subscription file. - $subscription = trim($subscription) . " every\n"; - } + /** + * Recursively search for matching subscriptions + * + * This function searches all relevant subscription files for a page or + * namespace. + * + * @author Adrian Lang + * + * @param string $page The target object’s (namespace or page) id + * @param string|array $user + * @param string|array $style + * @param string|array $data + * @return array + */ + public function subscribers($page, $user = null, $style = null, $data = null) { + // Construct list of files which may contain relevant subscriptions. + $files = array(':' => $this->file(':')); + do { + $files[$page] = $this->file($page); + $page = getNS(rtrim($page, ':')).':'; + } while($page !== ':'); - list($user, $rest) = explode(' ', $subscription, 2); - $subscription = rawurldecode($user) . " " . $rest; + $re = $this->buildregex($user, $style, $data); - if (preg_match(subscription_regex($pre), $subscription, - $line_matches) === 0) { - continue; - } - $match = array_slice($line_matches, 1); - if (!isset($matches[$cur_page])) { - $matches[$cur_page] = array(); + // Handle files. + $result = array(); + foreach($files as $target => $file) { + if(!@file_exists($file)) continue; + + $lines = file($file); + foreach($lines as $line) { + // fix old style subscription files + if(strpos($line, ' ') === false) $line = trim($line)." every\n"; + + // check for matching entries + if(!preg_match($re, $line, $m)) continue; + + $u = rawurldecode($m[1]); // decode the user name + if(!isset($result[$target])) $result[$target] = array(); + $result[$target][$u] = array($m[2], $m[3]); // add to result } - $matches[$cur_page][] = $match; } + return array_reverse($result); } - return array_reverse($matches); -} -/** - * Get data for $INFO['subscribed'] - * - * $INFO['subscribed'] is either false if no subscription for the current page - * and user is in effect. Else it contains an array of arrays with the fields - * “target”, “style”, and optionally “data”. - * - * @author Adrian Lang - */ -function get_info_subscribed() { - global $ID; - global $conf; - if (!$conf['subscribers']) { - return false; - } + /** + * Adds a new subscription for the given page or namespace + * + * This will automatically overwrite any existent subscription for the given user on this + * *exact* page or namespace. It will *not* modify any subscription that may exist in higher namespaces. + * + * @param string $id The target page or namespace, specified by id; Namespaces + * are identified by appending a colon. + * @param string $user + * @param string $style + * @param string $data + * @throws Exception when user or style is empty + * @return bool + */ + public function add($id, $user, $style, $data = '') { + // delete any existing subscription + $this->remove($id, $user); - $subs = subscription_find($ID, array('user' => $_SERVER['REMOTE_USER'])); - if (count($subs) === 0) { - return false; - } + $user = auth_nameencode(trim($user)); + $style = trim($style); + $data = trim($data); - $_ret = array(); - foreach ($subs as $target => $subs_data) { - $new = array('target' => $target, - 'style' => $subs_data[0][0]); - if (count($subs_data[0]) > 1) { - $new['data'] = $subs_data[0][1]; - } - $_ret[] = $new; + if(!$user) throw new Exception('no subscription user given'); + if(!$style) throw new Exception('no subscription style given'); + + $line = "$user $style"; + if($data) $line .= " $data"; + $line .= "\n"; + + $file = $this->file($id); + + return io_saveFile($file, $line, true); } - return $_ret; -} + /** + * Removes a subscription for the given page or namespace + * + * This removes all subscriptions matching the given criteria on the given page or + * namespace. It will *not* modify any subscriptions that may exist in higher + * namespaces. + * + * @param string $id The target object’s (namespace or page) id + * @param string|array $user + * @param string|array $style + * @param string|array $data + * @return bool + */ + public function remove($id, $user = null, $style = null, $data = null) { + $file = $this->file($id); + if(!file_exists($file)) return true; -/** - * Construct a regular expression parsing a subscription definition line - * - * @author Adrian Lang - * - * @param array $pre A hash of predefined values; “user”, “style”, and - * “data” may be set to limit the results to - * subscriptions matching these parameters. If - * “escaped” is true, these fields are inserted into the - * regular expression without escaping. - * - * @return string complete regexp including delimiters - */ -function subscription_regex($pre = array()) { - if (!isset($pre['escaped']) || $pre['escaped'] === false) { - $pre = array_map('preg_quote_cb', $pre); + $re = $this->buildregex($user, $style, $data); + return io_deleteFromFile($file, $re, true); } - foreach (array('user', 'style', 'data') as $key) { - if (!isset($pre[$key])) { - $pre[$key] = '(\S+)'; + + /** + * Get data for $INFO['subscribed'] + * + * $INFO['subscribed'] is either false if no subscription for the current page + * and user is in effect. Else it contains an array of arrays with the fields + * “target”, “style”, and optionally “data”. + * + * @param string $id Page ID, defaults to global $ID + * @param string $user User, defaults to $_SERVER['REMOTE_USER'] + * @return array + * @author Adrian Lang + */ + function user_subscription($id='', $user='') { + global $ID; + global $conf; + if(!$conf['subscribers']) return false; + + if(!$id) $id = $ID; + if(!$user) $user = $_SERVER['REMOTE_USER']; + + + $subs = $this->subscribers($id, $user); + if(!count($subs)) return false; + + $result = array(); + foreach($subs as $target => $data) { + $result[] = array( + 'target' => $target, + 'style' => $data[$user][0], + 'data' => $data[$user][1] + ); } + + return $result; } - return '/^' . $pre['user'] . '(?: ' . $pre['style'] . - '(?: ' . $pre['data'] . ')?)?$/'; -} -/** - * Return a string with the email addresses of all the - * users subscribed to a page - * - * This is the default action for COMMON_NOTIFY_ADDRESSLIST. - * - * @author Steven Danz - * @author Adrian Lang - * - * @todo this does NOT return a string but uses a reference to write back, either fix function or docs - * @param array $data Containing $id (the page id), $self (whether the author - * should be notified, $addresslist (current email address - * list) - * @return string - */ -function subscription_addresslist(&$data){ - global $conf; - /** @var auth_basic $auth */ - global $auth; + /** + * Return a string with the email addresses of all the + * users subscribed to a page + * + * This is the default action for COMMON_NOTIFY_ADDRESSLIST. + * + * @author Steven Danz + * @author Adrian Lang + * + * @todo this does NOT return a string but uses a reference to write back, either fix function or docs + * @param array $data Containing $id (the page id), $self (whether the author + * should be notified, $addresslist (current email address + * list) + * @return string + */ + function subscription_addresslist(&$data) { + global $conf; + /** @var auth_basic $auth */ + global $auth; - $id = $data['id']; - $self = $data['self']; - $addresslist = $data['addresslist']; + $id = $data['id']; + $self = $data['self']; + $addresslist = $data['addresslist']; - if (!$conf['subscribers'] || $auth === null) { - return ''; - } - $pres = array('style' => 'every', 'escaped' => true); - if (!$self && isset($_SERVER['REMOTE_USER'])) { - $pres['user'] = '((?!' . preg_quote_cb($_SERVER['REMOTE_USER']) . - '(?: |$))\S+)'; - } - $subs = subscription_find($id, $pres); - $emails = array(); - foreach ($subs as $by_targets) { - foreach ($by_targets as $sub) { - $info = $auth->getUserData($sub[0]); - if ($info === false) continue; - $level = auth_aclcheck($id, $sub[0], $info['grps']); - if ($level >= AUTH_READ) { - if (strcasecmp($info['mail'], $conf['notify']) != 0) { - $emails[$sub[0]] = $info['mail']; + if(!$conf['subscribers'] || $auth === null) { + return ''; + } + $pres = array('style' => 'every', 'escaped' => true); + if(!$self && isset($_SERVER['REMOTE_USER'])) { + $pres['user'] = '((?!'.preg_quote_cb($_SERVER['REMOTE_USER']). + '(?: |$))\S+)'; + } + $subs = subscription_find($id, $pres); + $emails = array(); + foreach($subs as $by_targets) { + foreach($by_targets as $sub) { + $info = $auth->getUserData($sub[0]); + if($info === false) continue; + $level = auth_aclcheck($id, $sub[0], $info['grps']); + if($level >= AUTH_READ) { + if(strcasecmp($info['mail'], $conf['notify']) != 0) { + $emails[$sub[0]] = $info['mail']; + } } } } + $data['addresslist'] = trim($addresslist.','.implode(',', $emails), ','); } - $data['addresslist'] = trim($addresslist . ',' . implode(',', $emails), ','); -} -/** - * Send a digest mail - * - * Sends a digest mail showing a bunch of changes. - * - * @author Adrian Lang - * - * @param string $subscriber_mail The target mail address - * @param array $id The ID - * @param int $lastupdate Time of the last notification - */ -function subscription_send_digest($subscriber_mail, $id, $lastupdate) { - $n = 0; - do { - $rev = getRevisions($id, $n++, 1); - $rev = (count($rev) > 0) ? $rev[0] : null; - } while (!is_null($rev) && $rev > $lastupdate); - - $replaces = array('NEWPAGE' => wl($id, '', true, '&'), - 'SUBSCRIBE' => wl($id, array('do' => 'subscribe'), true, '&')); - if (!is_null($rev)) { - $subject = 'changed'; - $replaces['OLDPAGE'] = wl($id, "rev=$rev", true, '&'); - $df = new Diff(explode("\n", rawWiki($id, $rev)), - explode("\n", rawWiki($id))); - $dformat = new UnifiedDiffFormatter(); - $replaces['DIFF'] = $dformat->format($df); - } else { - $subject = 'newpage'; - $replaces['OLDPAGE'] = 'none'; - $replaces['DIFF'] = rawWiki($id); + /** + * Send a digest mail + * + * Sends a digest mail showing a bunch of changes. + * + * @author Adrian Lang + * + * @param string $subscriber_mail The target mail address + * @param array $id The ID + * @param int $lastupdate Time of the last notification + */ + function subscription_send_digest($subscriber_mail, $id, $lastupdate) { + $n = 0; + do { + $rev = getRevisions($id, $n++, 1); + $rev = (count($rev) > 0) ? $rev[0] : null; + } while(!is_null($rev) && $rev > $lastupdate); + + $replaces = array( + 'NEWPAGE' => wl($id, '', true, '&'), + 'SUBSCRIBE' => wl($id, array('do' => 'subscribe'), true, '&') + ); + if(!is_null($rev)) { + $subject = 'changed'; + $replaces['OLDPAGE'] = wl($id, "rev=$rev", true, '&'); + $df = new Diff(explode("\n", rawWiki($id, $rev)), + explode("\n", rawWiki($id))); + $dformat = new UnifiedDiffFormatter(); + $replaces['DIFF'] = $dformat->format($df); + } else { + $subject = 'newpage'; + $replaces['OLDPAGE'] = 'none'; + $replaces['DIFF'] = rawWiki($id); + } + subscription_send( + $subscriber_mail, $replaces, $subject, $id, + 'subscr_digest' + ); } - subscription_send($subscriber_mail, $replaces, $subject, $id, - 'subscr_digest'); -} -/** - * Send a list mail - * - * Sends a list mail showing a list of changed pages. - * - * @author Adrian Lang - * - * @param string $subscriber_mail The target mail address - * @param array $ids Array of ids - * @param string $ns_id The id of the namespace - */ -function subscription_send_list($subscriber_mail, $ids, $ns_id) { - if (count($ids) === 0) return; - global $conf; - $list = ''; - foreach ($ids as $id) { - $list .= '* ' . wl($id, array(), true) . NL; + /** + * Send a list mail + * + * Sends a list mail showing a list of changed pages. + * + * @author Adrian Lang + * + * @param string $subscriber_mail The target mail address + * @param array $ids Array of ids + * @param string $ns_id The id of the namespace + */ + function subscription_send_list($subscriber_mail, $ids, $ns_id) { + if(count($ids) === 0) return; + global $conf; + $list = ''; + foreach($ids as $id) { + $list .= '* '.wl($id, array(), true).NL; + } + subscription_send( + $subscriber_mail, + array( + 'DIFF' => rtrim($list), + 'SUBSCRIBE' => wl( + $ns_id.$conf['start'], + array('do' => 'subscribe'), + true, '&' + ) + ), + 'subscribe_list', + prettyprint_id($ns_id), + 'subscr_list' + ); } - subscription_send($subscriber_mail, - array('DIFF' => rtrim($list), - 'SUBSCRIBE' => wl($ns_id . $conf['start'], - array('do' => 'subscribe'), - true, '&')), - 'subscribe_list', - prettyprint_id($ns_id), - 'subscr_list'); -} -/** - * Helper function for sending a mail - * - * @author Adrian Lang - * - * @param string $subscriber_mail The target mail address - * @param array $replaces Predefined parameters used to parse the - * template - * @param string $subject The lang id of the mail subject (without the - * prefix “mail_”) - * @param string $id The page or namespace id - * @param string $template The name of the mail template - * @return bool - */ -function subscription_send($subscriber_mail, $replaces, $subject, $id, $template) { - global $lang; - - $text = rawLocale($template); - $trep = array_merge($replaces, array('PAGE' => $id)); - - $subject = $lang['mail_' . $subject] . ' ' . $id; - $mail = new Mailer(); - $mail->bcc($subscriber_mail); - $mail->subject($subject); - $mail->setBody($text,$trep); - $mail->setHeader( - 'List-Unsubscribe', - '<'.wl($id,array('do'=>'subscribe'),true,'&').'>', - false - ); - return $mail->send(); -} + /** + * Helper function for sending a mail + * + * @author Adrian Lang + * + * @param string $subscriber_mail The target mail address + * @param array $replaces Predefined parameters used to parse the + * template + * @param string $subject The lang id of the mail subject (without the + * prefix “mail_”) + * @param string $id The page or namespace id + * @param string $template The name of the mail template + * @return bool + */ + function subscription_send($subscriber_mail, $replaces, $subject, $id, $template) { + global $lang; + + $text = rawLocale($template); + $trep = array_merge($replaces, array('PAGE' => $id)); + + $subject = $lang['mail_'.$subject].' '.$id; + $mail = new Mailer(); + $mail->bcc($subscriber_mail); + $mail->subject($subject); + $mail->setBody($text, $trep); + $mail->setHeader( + 'List-Unsubscribe', + '<'.wl($id, array('do'=> 'subscribe'), true, '&').'>', + false + ); + return $mail->send(); + } + +} \ No newline at end of file -- cgit v1.2.3 From e920a0a10c3027700e61166a6f8d4ea29a9ff102 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 14:00:53 +0200 Subject: handle empty changelog in getRecentsSince() --- inc/changelog.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc') diff --git a/inc/changelog.php b/inc/changelog.php index 24583b341..7ca7c62e9 100644 --- a/inc/changelog.php +++ b/inc/changelog.php @@ -254,6 +254,7 @@ function getRecentsSince($from,$to=null,$ns='',$flags=0){ } else { $lines = @file($conf['changelog']); } + if(!$lines) return $recent; // we start searching at the end of the list $lines = array_reverse($lines); -- cgit v1.2.3 From adec979fd5453cf213b776d7dceaaaac4eb05713 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 15:07:03 +0200 Subject: more subscription refactoring BROKEN now the actual sending of bulk messages (digest, list) is reimplemented and partially tested. Still not complete --- inc/common.php | 4 +- inc/subscription.php | 191 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 149 insertions(+), 46 deletions(-) (limited to 'inc') diff --git a/inc/common.php b/inc/common.php index ac7e744d8..29940d8a6 100644 --- a/inc/common.php +++ b/inc/common.php @@ -107,9 +107,11 @@ function pageinfo() { $info['isadmin'] = false; $info['ismanager'] = false; if(isset($_SERVER['REMOTE_USER'])) { + $sub = new Subscription(); + $info['userinfo'] = $USERINFO; $info['perm'] = auth_quickaclcheck($ID); - $info['subscribed'] = get_info_subscribed(); + $info['subscribed'] = $sub->user_subscription(); $info['client'] = $_SERVER['REMOTE_USER']; if($info['perm'] == AUTH_ADMIN) { diff --git a/inc/subscription.php b/inc/subscription.php index 856836cd5..804776ced 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -253,24 +253,23 @@ class Subscription { * @return array * @author Adrian Lang */ - function user_subscription($id='', $user='') { + function user_subscription($id = '', $user = '') { global $ID; global $conf; if(!$conf['subscribers']) return false; - if(!$id) $id = $ID; + if(!$id) $id = $ID; if(!$user) $user = $_SERVER['REMOTE_USER']; - $subs = $this->subscribers($id, $user); if(!count($subs)) return false; $result = array(); - foreach($subs as $target => $data) { + foreach($subs as $target => $info) { $result[] = array( 'target' => $target, - 'style' => $data[$user][0], - 'data' => $data[$user][1] + 'style' => $info[$user][0], + 'data' => $info[$user][1] ); } @@ -278,52 +277,100 @@ class Subscription { } /** - * Return a string with the email addresses of all the - * users subscribed to a page + * Send digest and list subscriptions * - * This is the default action for COMMON_NOTIFY_ADDRESSLIST. + * This sends mails to all subscribers that have a subscription for namespaces above + * the given page if the needed $conf['subscribe_time'] has passed already. * - * @author Steven Danz - * @author Adrian Lang + * This function is called form lib/exe/indexer.php * - * @todo this does NOT return a string but uses a reference to write back, either fix function or docs - * @param array $data Containing $id (the page id), $self (whether the author - * should be notified, $addresslist (current email address - * list) - * @return string + * @param string $page + * @return int number of sent mails */ - function subscription_addresslist(&$data) { - global $conf; + public function send_bulk($page) { /** @var auth_basic $auth */ global $auth; + global $conf; + global $USERINFO; + $count = 0; - $id = $data['id']; - $self = $data['self']; - $addresslist = $data['addresslist']; + $subscriptions = $this->subscribers($page, null, array('digest', 'list')); - if(!$conf['subscribers'] || $auth === null) { - return ''; - } - $pres = array('style' => 'every', 'escaped' => true); - if(!$self && isset($_SERVER['REMOTE_USER'])) { - $pres['user'] = '((?!'.preg_quote_cb($_SERVER['REMOTE_USER']). - '(?: |$))\S+)'; - } - $subs = subscription_find($id, $pres); - $emails = array(); - foreach($subs as $by_targets) { - foreach($by_targets as $sub) { - $info = $auth->getUserData($sub[0]); - if($info === false) continue; - $level = auth_aclcheck($id, $sub[0], $info['grps']); - if($level >= AUTH_READ) { - if(strcasecmp($info['mail'], $conf['notify']) != 0) { - $emails[$sub[0]] = $info['mail']; + // remember current user info + $olduinfo = $USERINFO; + $olduser = $_SERVER['REMOTE_USER']; + + foreach($subscriptions as $target => $users) { + if(!$this->lock($target)) continue; + + foreach($users as $user => $info) { + list($style, $lastupdate) = $info; + + $lastupdate = (int) $lastupdate; + if($lastupdate + $conf['subscribe_time'] > time()) { + // Less than the configured time period passed since last + // update. + continue; + } + + // Work as the user to make sure ACLs apply correctly + $USERINFO = $auth->getUserData($user); + $_SERVER['REMOTE_USER'] = $user; + if($USERINFO === false) continue; + if(!$USERINFO['mail']) continue; + + if(substr($target, -1, 1) === ':') { + // subscription target is a namespace, get all changes within + $changes = getRecentsSince($lastupdate, null, getNS($target)); + } else { + // single page subscription, check ACL ourselves + if(auth_quickaclcheck($target) < AUTH_READ) continue; + $meta = p_get_metadata($target); + $changes = array($meta['last_change']); + } + + // Filter out pages only changed in small and own edits + $change_ids = array(); + foreach($changes as $rev) { + $n = 0; + while(!is_null($rev) && $rev['date'] >= $lastupdate && + ($_SERVER['REMOTE_USER'] === $rev['user'] || + $rev['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT)) { + $rev = getRevisions($rev['id'], $n++, 1); + $rev = (count($rev) > 0) ? $rev[0] : null; + } + + if(!is_null($rev) && $rev['date'] >= $lastupdate) { + // Some change was not a minor one and not by myself + $change_ids[] = $rev['id']; } } + + // send it + if($style === 'digest') { + foreach($change_ids as $change_id) { + $this->send_digest( + $USERINFO['mail'], $change_id, + $lastupdate + ); + $count++; + } + } elseif($style === 'list') { + $this->send_list($USERINFO['mail'], $change_ids, $target); + $count++; + } + // TODO: Handle duplicate subscriptions. + + // Update notification time. + $this->add($target, $user, $style, time()); } + $this->unlock($target); } - $data['addresslist'] = trim($addresslist.','.implode(',', $emails), ','); + + // restore current user info + $USERINFO = $olduinfo; + $_SERVER['REMOTE_USER'] = $olduser; + return $count; } /** @@ -337,7 +384,7 @@ class Subscription { * @param array $id The ID * @param int $lastupdate Time of the last notification */ - function subscription_send_digest($subscriber_mail, $id, $lastupdate) { + protected function send_digest($subscriber_mail, $id, $lastupdate) { $n = 0; do { $rev = getRevisions($id, $n++, 1); @@ -360,7 +407,7 @@ class Subscription { $replaces['OLDPAGE'] = 'none'; $replaces['DIFF'] = rawWiki($id); } - subscription_send( + $this->send( $subscriber_mail, $replaces, $subject, $id, 'subscr_digest' ); @@ -377,14 +424,14 @@ class Subscription { * @param array $ids Array of ids * @param string $ns_id The id of the namespace */ - function subscription_send_list($subscriber_mail, $ids, $ns_id) { + protected function send_list($subscriber_mail, $ids, $ns_id) { if(count($ids) === 0) return; global $conf; $list = ''; foreach($ids as $id) { $list .= '* '.wl($id, array(), true).NL; } - subscription_send( + $this->send( $subscriber_mail, array( 'DIFF' => rtrim($list), @@ -414,7 +461,7 @@ class Subscription { * @param string $template The name of the mail template * @return bool */ - function subscription_send($subscriber_mail, $replaces, $subject, $id, $template) { + protected function send($subscriber_mail, $replaces, $subject, $id, $template) { global $lang; $text = rawLocale($template); @@ -433,4 +480,58 @@ class Subscription { return $mail->send(); } + + + // FIXME no refactoring below, yet + + /** + * Return a string with the email addresses of all the + * users subscribed to a page + * + * This is the default action for COMMON_NOTIFY_ADDRESSLIST. + * + * @author Steven Danz + * @author Adrian Lang + * + * @todo this does NOT return a string but uses a reference to write back, either fix function or docs + * @param array $data Containing $id (the page id), $self (whether the author + * should be notified, $addresslist (current email address + * list) + * @return string + */ + function subscription_addresslist(&$data) { + global $conf; + /** @var auth_basic $auth */ + global $auth; + + $id = $data['id']; + $self = $data['self']; + $addresslist = $data['addresslist']; + + if(!$conf['subscribers'] || $auth === null) { + return ''; + } + $pres = array('style' => 'every', 'escaped' => true); + if(!$self && isset($_SERVER['REMOTE_USER'])) { + $pres['user'] = '((?!'.preg_quote_cb($_SERVER['REMOTE_USER']). + '(?: |$))\S+)'; + } + $subs = subscription_find($id, $pres); + $emails = array(); + foreach($subs as $by_targets) { + foreach($by_targets as $sub) { + $info = $auth->getUserData($sub[0]); + if($info === false) continue; + $level = auth_aclcheck($id, $sub[0], $info['grps']); + if($level >= AUTH_READ) { + if(strcasecmp($info['mail'], $conf['notify']) != 0) { + $emails[$sub[0]] = $info['mail']; + } + } + } + } + $data['addresslist'] = trim($addresslist.','.implode(',', $emails), ','); + } + + } \ No newline at end of file -- cgit v1.2.3 From 835242b0f53a72a555ad30543a1677108ce210af Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 17:17:34 +0200 Subject: subscription system should work now again This readds the last part of the subscription system: the normal "every" subscriptions. --- inc/common.php | 2 +- inc/subscription.php | 57 ++++++++++++++++++++++------------------------------ 2 files changed, 25 insertions(+), 34 deletions(-) (limited to 'inc') diff --git a/inc/common.php b/inc/common.php index 29940d8a6..3cfeb3092 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1122,7 +1122,7 @@ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = $data = array('id' => $id, 'addresslist' => '', 'self' => false); trigger_event( 'COMMON_NOTIFY_ADDRESSLIST', $data, - 'subscription_addresslist' + array(new Subscription(), 'notifyaddresses') ); $bcc = $data['addresslist']; if(empty($bcc)) return false; diff --git a/inc/subscription.php b/inc/subscription.php index 804776ced..9b02225f9 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -12,7 +12,7 @@ * - subscription_lock * - subscription_unlock * - * @fixme handle $conf['subscribers'] and disable actions + * @fixme handle $conf['subscribers'] and disable actions and $auth == null * * @author Adrian Lang * @author Andreas Gohr @@ -480,26 +480,23 @@ class Subscription { return $mail->send(); } - - - // FIXME no refactoring below, yet - /** - * Return a string with the email addresses of all the - * users subscribed to a page + * Default callback for COMMON_NOTIFY_ADDRESSLIST * - * This is the default action for COMMON_NOTIFY_ADDRESSLIST. + * Aggregates all email addresses of user who have subscribed the given page with 'every' style * * @author Steven Danz * @author Adrian Lang * - * @todo this does NOT return a string but uses a reference to write back, either fix function or docs - * @param array $data Containing $id (the page id), $self (whether the author - * should be notified, $addresslist (current email address - * list) + * @todo move the whole functionality into this class, trigger SUBSCRIPTION_NOTIFY_ADDRESSLIST instead, + * use an array for the addresses within it + * + * @param array &$data Containing $id (the page id), $self (whether the author + * should be notified, $addresslist (current email address + * list) * @return string */ - function subscription_addresslist(&$data) { + public function notifyaddresses(&$data) { global $conf; /** @var auth_basic $auth */ global $auth; @@ -508,30 +505,24 @@ class Subscription { $self = $data['self']; $addresslist = $data['addresslist']; - if(!$conf['subscribers'] || $auth === null) { - return ''; - } - $pres = array('style' => 'every', 'escaped' => true); - if(!$self && isset($_SERVER['REMOTE_USER'])) { - $pres['user'] = '((?!'.preg_quote_cb($_SERVER['REMOTE_USER']). - '(?: |$))\S+)'; - } - $subs = subscription_find($id, $pres); - $emails = array(); - foreach($subs as $by_targets) { - foreach($by_targets as $sub) { - $info = $auth->getUserData($sub[0]); - if($info === false) continue; - $level = auth_aclcheck($id, $sub[0], $info['grps']); + $subscriptions = $this->subscribers($id, null, 'every'); + + $result = array(); + foreach($subscriptions as $target => $users) { + foreach($users as $user => $info) { + $userinfo = $auth->getUserData($user); + if($userinfo === false) continue; + if(!$userinfo['mail']) continue; + if(!$self && $user == $_SERVER['REMOTE_USER']) continue; //skip our own changes + + $level = auth_aclcheck($id, $user, $userinfo['grps']); if($level >= AUTH_READ) { - if(strcasecmp($info['mail'], $conf['notify']) != 0) { - $emails[$sub[0]] = $info['mail']; + if(strcasecmp($userinfo['mail'], $conf['notify']) != 0) { //skip user who get notified elsewhere + $result[$user] = $userinfo['mail']; } } } } - $data['addresslist'] = trim($addresslist.','.implode(',', $emails), ','); + $data['addresslist'] = trim($addresslist.','.implode(',', $result), ','); } - - } \ No newline at end of file -- cgit v1.2.3 From 84c1127cc070777c8cbcf488f5422bc4b71470a8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 17:30:01 +0200 Subject: correctly check if subscriptions are enabled --- inc/common.php | 2 +- inc/subscription.php | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'inc') diff --git a/inc/common.php b/inc/common.php index 3cfeb3092..b4a57b154 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1117,7 +1117,7 @@ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = $to = $conf['notify']; $bcc = ''; } elseif($who == 'subscribers') { - if(!$conf['subscribers']) return false; //subscribers enabled? + if(!actionOK('subscribe')) return false; //subscribers enabled? if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $minor) return false; //skip minors $data = array('id' => $id, 'addresslist' => '', 'self' => false); trigger_event( diff --git a/inc/subscription.php b/inc/subscription.php index 9b02225f9..742f5b1a0 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -21,6 +21,15 @@ class Subscription { + /** + * Check if subscription system is enabled + * + * @return bool + */ + public function isenabled() { + return actionOK('subscribe'); + } + /** * Return the subscription meta file for the given ID * @@ -156,6 +165,8 @@ class Subscription { * @return array */ public function subscribers($page, $user = null, $style = null, $data = null) { + if(!$this->isenabled()) return array(); + // Construct list of files which may contain relevant subscriptions. $files = array(':' => $this->file(':')); do { @@ -201,6 +212,8 @@ class Subscription { * @return bool */ public function add($id, $user, $style, $data = '') { + if(!$this->isenabled()) return false; + // delete any existing subscription $this->remove($id, $user); @@ -234,6 +247,8 @@ class Subscription { * @return bool */ public function remove($id, $user = null, $style = null, $data = null) { + if(!$this->isenabled()) return false; + $file = $this->file($id); if(!file_exists($file)) return true; @@ -254,10 +269,9 @@ class Subscription { * @author Adrian Lang */ function user_subscription($id = '', $user = '') { - global $ID; - global $conf; - if(!$conf['subscribers']) return false; + if(!$this->isenabled()) return false; + global $ID; if(!$id) $id = $ID; if(!$user) $user = $_SERVER['REMOTE_USER']; @@ -288,6 +302,8 @@ class Subscription { * @return int number of sent mails */ public function send_bulk($page) { + if(!$this->isenabled()) return 0; + /** @var auth_basic $auth */ global $auth; global $conf; @@ -497,9 +513,11 @@ class Subscription { * @return string */ public function notifyaddresses(&$data) { - global $conf; + if(!$this->isenabled()) return false; + /** @var auth_basic $auth */ global $auth; + global $conf; $id = $data['id']; $self = $data['self']; -- cgit v1.2.3 From a0519fdaeb59bd96d9071681a68c2dc1b646fc68 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 17:47:47 +0200 Subject: fixed subscription management now adding and removing subscriptions works again --- inc/actions.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'inc') diff --git a/inc/actions.php b/inc/actions.php index 62b0e1800..721492bd4 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -700,21 +700,28 @@ function act_subscription($act){ $target = $params['target']; $style = $params['style']; - $data = $params['data']; $action = $params['action']; // Perform action. - if (!subscription_set($_SERVER['REMOTE_USER'], $target, $style, $data)) { + $sub = new Subscription(); + if($action == 'unsubscribe'){ + $ok = $sub->remove($target, $_SERVER['REMOTE_USER'], $style); + }else{ + $ok = $sub->add($target, $_SERVER['REMOTE_USER'], $style); + } + + if($ok) { + msg(sprintf($lang["subscr_{$action}_success"], hsc($INFO['userinfo']['name']), + prettyprint_id($target)), 1); + act_redirect($ID, $act); + } else { throw new Exception(sprintf($lang["subscr_{$action}_error"], hsc($INFO['userinfo']['name']), prettyprint_id($target))); } - msg(sprintf($lang["subscr_{$action}_success"], hsc($INFO['userinfo']['name']), - prettyprint_id($target)), 1); - act_redirect($ID, $act); // Assure that we have valid data if act_redirect somehow fails. - $INFO['subscribed'] = get_info_subscribed(); + $INFO['subscribed'] = $sub->user_subscription(); return 'show'; } -- cgit v1.2.3 From 02308d17ed15cd633ba1fd5cab11994c42065121 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 18:01:30 +0200 Subject: initialize new subscriptions with current time We don't want to create a bunch of mails whenever a namespace is subscribed. Only changes *after* the subscription should be considered. This patch adds the timestamp to "every" style subscriptions as well, though this data is ignored. --- inc/subscription.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc') diff --git a/inc/subscription.php b/inc/subscription.php index 742f5b1a0..800329cb5 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -223,6 +223,7 @@ class Subscription { if(!$user) throw new Exception('no subscription user given'); if(!$style) throw new Exception('no subscription style given'); + if(!$data) $data = time(); //always add current time for new subscriptions $line = "$user $style"; if($data) $line .= " $data"; -- cgit v1.2.3 From f036cff4fde59f0265f6123f6faf92cb8ba8bb26 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 12 Aug 2012 18:07:20 +0200 Subject: minor cleanup --- inc/subscription.php | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'inc') diff --git a/inc/subscription.php b/inc/subscription.php index 800329cb5..74f4e4d03 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -1,24 +1,11 @@ * @author Andreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) */ - class Subscription { /** @@ -511,10 +498,9 @@ class Subscription { * @param array &$data Containing $id (the page id), $self (whether the author * should be notified, $addresslist (current email address * list) - * @return string */ public function notifyaddresses(&$data) { - if(!$this->isenabled()) return false; + if(!$this->isenabled()) return; /** @var auth_basic $auth */ global $auth; -- cgit v1.2.3 From 2ed38036a53a489d2fcadc46ce601f8c876fca31 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 21 Sep 2012 11:53:17 +0200 Subject: consolidate more notification code in subscription class This is untested and probably broken currently --- inc/auth.php | 11 +--- inc/common.php | 45 +++------------ inc/subscription.php | 159 +++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 126 insertions(+), 89 deletions(-) (limited to 'inc') diff --git a/inc/auth.php b/inc/auth.php index cedfdee36..3fb937613 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -778,23 +778,18 @@ function register() { return false; } - // create substitutions for use in notification email - $substitutions = array( - 'NEWUSER' => $_POST['login'], - 'NEWNAME' => $_POST['fullname'], - 'NEWEMAIL' => $_POST['email'], - ); + $subscription = new Subscription(); if(!$conf['autopasswd']) { msg($lang['regsuccess2'], 1); - notify('', 'register', '', $_POST['login'], false, $substitutions); + $subscription->send_register($_POST['login'], $_POST['fullname'], $_POST['email']); return true; } // autogenerated password? then send him the password if(auth_sendPassword($_POST['login'], $pass)) { msg($lang['regsuccess'], 1); - notify('', 'register', '', $_POST['login'], false, $substitutions); + $subscription->send_register($_POST['login'], $_POST['fullname'], $_POST['email']); return true; } else { msg($lang['regmailfail'], -1); diff --git a/inc/common.php b/inc/common.php index b4a57b154..d17061a1b 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1113,9 +1113,8 @@ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = // decide if there is something to do, eg. whom to mail if($who == 'admin') { if(empty($conf['notify'])) return false; //notify enabled? - $text = rawLocale('mailtext'); - $to = $conf['notify']; - $bcc = ''; + $tpl = 'mailtext'; + $to = $conf['notify']; } elseif($who == 'subscribers') { if(!actionOK('subscribe')) return false; //subscribers enabled? if($conf['useacl'] && $_SERVER['REMOTE_USER'] && $minor) return false; //skip minors @@ -1124,57 +1123,29 @@ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = 'COMMON_NOTIFY_ADDRESSLIST', $data, array(new Subscription(), 'notifyaddresses') ); - $bcc = $data['addresslist']; - if(empty($bcc)) return false; - $to = ''; - $text = rawLocale('subscr_single'); + $to = $data['addresslist']; + if(empty($to)) return false; + $tpl = 'subscr_single'; } elseif($who == 'register') { if(empty($conf['registernotify'])) return false; $text = rawLocale('registermail'); $to = $conf['registernotify']; - $bcc = ''; } else { return false; //just to be safe } - // prepare replacements (keys not set in hrep will be taken from trep) - $trep = array( - 'NEWPAGE' => wl($id, '', true, '&'), - 'PAGE' => $id, - 'SUMMARY' => $summary - ); - $trep = array_merge($trep, $replace); - $hrep = array(); - // prepare content if($who == 'register') { $subject = $lang['mail_new_user'].' '.$summary; - } elseif($rev) { - $subject = $lang['mail_changed'].' '.$id; - $trep['OLDPAGE'] = wl($id, "rev=$rev", true, '&'); - $df = new Diff(explode("\n", rawWiki($id, $rev)), - explode("\n", rawWiki($id))); - $dformat = new UnifiedDiffFormatter(); - $tdiff = $dformat->format($df); - - $DIFF_INLINESTYLES = true; - $dformat = new InlineDiffFormatter(); - $hdiff = $dformat->format($df); - $hdiff = ''.$hdiff.'
'; - $DIFF_INLINESTYLES = false; } else { - $subject = $lang['mail_newpage'].' '.$id; - $trep['OLDPAGE'] = '---'; - $tdiff = rawWiki($id); - $hdiff = nl2br(hsc($tdiff)); + $subscription = new Subscription(); + return $subscription->send_diff($to, $tpl, $id, $rev, $summary); } - $trep['DIFF'] = $tdiff; - $hrep['DIFF'] = $hdiff; + // send mail $mail = new Mailer(); $mail->to($to); - $mail->bcc($bcc); $mail->subject($subject); $mail->setBody($text, $trep, $hrep); if($who == 'subscribers') { diff --git a/inc/subscription.php b/inc/subscription.php index 74f4e4d03..4757b216c 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -377,16 +377,90 @@ class Subscription { return $count; } + /** + * Send the diff for some page change + * + * @param string $subscriber_mail The target mail address + * @param string $template Mail template, should be 'subscr_digest' or 'subscr_single' + * @param string $id Page for which the notification is + * @param int|null $rev Old revision if any + * @param string $summary Change summary if any + * @return bool true if successfully sent + */ + public function send_diff($subscriber_mail, $template, $id, $rev = null, $summary = '') { + global $DIFF_INLINESTYLES; + + // prepare replacements (keys not set in hrep will be taken from trep) + $trep = array( + 'PAGE' => $id, + 'NEWPAGE' => wl($id, '', true, '&'), + 'SUMMARY' => $summary, + 'SUBSCRIBE' => wl($id, array('do' => 'subscribe'), true, '&') + ); + $hrep = array(); + + if($rev) { + $subject = 'changed'; + $trep['OLDPAGE'] = wl($id, "rev=$rev", true, '&'); + $df = new Diff(explode("\n", rawWiki($id, $rev)), + explode("\n", rawWiki($id))); + $dformat = new UnifiedDiffFormatter(); + $tdiff = $dformat->format($df); + + $DIFF_INLINESTYLES = true; + $dformat = new InlineDiffFormatter(); + $hdiff = $dformat->format($df); + $hdiff = ''.$hdiff.'
'; + $DIFF_INLINESTYLES = false; + + } else { + $subject = 'newpage'; + $trep['OLDPAGE'] = '---'; + $tdiff = rawWiki($id); + $hdiff = nl2br(hsc($tdiff)); + } + + $trep['DIFF'] = $tdiff; + $hrep['DIFF'] = $hdiff; + + return $this->send( + $subscriber_mail, $subject, $id, + $template, $trep, $hrep + ); + } + + public function send_register($login, $fullname, $email) { + global $conf; + global $ID; + if(empty($conf['registernotify'])) return false; + + $trep = array( + 'NEWUSER' => $login, + 'NEWNAME' => $fullname, + 'NEWEMAIL' => $email, + ); + + return $this->send( + $conf['registernotify'], + 'new_user', + $ID, + 'registermail', + $trep + ); + } + /** * Send a digest mail * - * Sends a digest mail showing a bunch of changes. + * Sends a digest mail showing a bunch of changes of a single page. Basically the same as send_diff() + * but determines the last known revision first * * @author Adrian Lang * * @param string $subscriber_mail The target mail address * @param array $id The ID * @param int $lastupdate Time of the last notification + * @return bool */ protected function send_digest($subscriber_mail, $id, $lastupdate) { $n = 0; @@ -395,25 +469,10 @@ class Subscription { $rev = (count($rev) > 0) ? $rev[0] : null; } while(!is_null($rev) && $rev > $lastupdate); - $replaces = array( - 'NEWPAGE' => wl($id, '', true, '&'), - 'SUBSCRIBE' => wl($id, array('do' => 'subscribe'), true, '&') - ); - if(!is_null($rev)) { - $subject = 'changed'; - $replaces['OLDPAGE'] = wl($id, "rev=$rev", true, '&'); - $df = new Diff(explode("\n", rawWiki($id, $rev)), - explode("\n", rawWiki($id))); - $dformat = new UnifiedDiffFormatter(); - $replaces['DIFF'] = $dformat->format($df); - } else { - $subject = 'newpage'; - $replaces['OLDPAGE'] = 'none'; - $replaces['DIFF'] = rawWiki($id); - } - $this->send( - $subscriber_mail, $replaces, $subject, $id, - 'subscr_digest' + return $this->send_diff( + $subscriber_mail, + 'subscr_digest', + $id, $rev ); } @@ -427,27 +486,35 @@ class Subscription { * @param string $subscriber_mail The target mail address * @param array $ids Array of ids * @param string $ns_id The id of the namespace + * @return bool */ protected function send_list($subscriber_mail, $ids, $ns_id) { if(count($ids) === 0) return; - global $conf; - $list = ''; + + $tlist = ''; + $hlist = '
    '; foreach($ids as $id) { - $list .= '* '.wl($id, array(), true).NL; + $link = wl($id, array(), true); + $tlist .= '* '.$link.NL; + $hlist .= '
  • '.hsc($id).'
  • '.NL; } - $this->send( + $hlist = '
'; + + $id = prettyprint_id($ns_id); + $trep = array( + 'DIFF' => rtrim($tlist), + 'PAGE' => $id, + 'SUBSCRIBE' => wl($id, array('do' => 'subscribe'), true, '&') + ); + $hrep = array( + 'DIFF' => $hlist + ); + + return $this->send( $subscriber_mail, - array( - 'DIFF' => rtrim($list), - 'SUBSCRIBE' => wl( - $ns_id.$conf['start'], - array('do' => 'subscribe'), - true, '&' - ) - ), 'subscribe_list', - prettyprint_id($ns_id), - 'subscr_list' + + 'subscr_list', $trep, $hrep ); } @@ -457,30 +524,34 @@ class Subscription { * @author Adrian Lang * * @param string $subscriber_mail The target mail address - * @param array $replaces Predefined parameters used to parse the - * template * @param string $subject The lang id of the mail subject (without the * prefix “mail_”) * @param string $id The page or namespace id * @param string $template The name of the mail template + * @param array $trep Predefined parameters used to parse the + * template (in text format) + * @param array $hrep Predefined parameters used to parse the + * template (in HTML format), null to default to $trep * @return bool */ - protected function send($subscriber_mail, $replaces, $subject, $id, $template) { + protected function send($subscriber_mail, $subject, $id, $template, $trep, $hrep = null) { global $lang; $text = rawLocale($template); - $trep = array_merge($replaces, array('PAGE' => $id)); + $trep = array_merge( + $trep, array( + + ) + ); $subject = $lang['mail_'.$subject].' '.$id; $mail = new Mailer(); $mail->bcc($subscriber_mail); $mail->subject($subject); - $mail->setBody($text, $trep); - $mail->setHeader( - 'List-Unsubscribe', - '<'.wl($id, array('do'=> 'subscribe'), true, '&').'>', - false - ); + $mail->setBody($text, $trep, $hrep); + if(isset($trep['SUBSCRIBE'])){ + $mail->setHeader('List-Unsubscribe', '<'.$trep['SUBSCRIBE'].'>', false); + } return $mail->send(); } -- cgit v1.2.3 From 10b5c32d6486ab0884deda109b1e5947f7ec7662 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 30 Nov 2012 12:35:46 +0100 Subject: fixed merge error in inc/auth.php merged the wrong change here --- inc/auth.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'inc') diff --git a/inc/auth.php b/inc/auth.php index 54d2cd50a..9c458338d 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -782,21 +782,21 @@ function register() { // create substitutions for use in notification email $substitutions = array( - 'NEWUSER' => $_POST['login'], - 'NEWNAME' => $_POST['fullname'], - 'NEWEMAIL' => $_POST['email'], + 'NEWUSER' => $login, + 'NEWNAME' => $fullname, + 'NEWEMAIL' => $email, ); if(!$conf['autopasswd']) { msg($lang['regsuccess2'], 1); - notify('', 'register', '', $_POST['login'], false, $substitutions); + notify('', 'register', '', $login, false, $substitutions); return true; } // autogenerated password? then send him the password if(auth_sendPassword($login, $pass)) { msg($lang['regsuccess'], 1); - notify('', 'register', '', $_POST['login'], false, $substitutions); + notify('', 'register', '', $login, false, $substitutions); return true; } else { msg($lang['regmailfail'], -1); -- cgit v1.2.3 From 790b77202079261b11d425e0c814608d626eea70 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 30 Nov 2012 13:09:15 +0100 Subject: moved registration notification to subscription class --- inc/auth.php | 14 +++++--------- inc/common.php | 27 ++------------------------- inc/subscription.php | 29 ++++++++++++++++------------- 3 files changed, 23 insertions(+), 47 deletions(-) (limited to 'inc') diff --git a/inc/auth.php b/inc/auth.php index 9c458338d..29a46b37e 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -780,23 +780,19 @@ function register() { return false; } - // create substitutions for use in notification email - $substitutions = array( - 'NEWUSER' => $login, - 'NEWNAME' => $fullname, - 'NEWEMAIL' => $email, - ); + // send notification about the new user + $subscription = new Subscription(); + $subscription->send_register($login, $fullname, $email); + // are we done? if(!$conf['autopasswd']) { msg($lang['regsuccess2'], 1); - notify('', 'register', '', $login, false, $substitutions); return true; } - // autogenerated password? then send him the password + // autogenerated password? then send password to user if(auth_sendPassword($login, $pass)) { msg($lang['regsuccess'], 1); - notify('', 'register', '', $login, false, $substitutions); return true; } else { msg($lang['regmailfail'], -1); diff --git a/inc/common.php b/inc/common.php index d17061a1b..20e0af389 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1126,36 +1126,13 @@ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = $to = $data['addresslist']; if(empty($to)) return false; $tpl = 'subscr_single'; - } elseif($who == 'register') { - if(empty($conf['registernotify'])) return false; - $text = rawLocale('registermail'); - $to = $conf['registernotify']; } else { return false; //just to be safe } // prepare content - if($who == 'register') { - $subject = $lang['mail_new_user'].' '.$summary; - } else { - $subscription = new Subscription(); - return $subscription->send_diff($to, $tpl, $id, $rev, $summary); - } - - - // send mail - $mail = new Mailer(); - $mail->to($to); - $mail->subject($subject); - $mail->setBody($text, $trep, $hrep); - if($who == 'subscribers') { - $mail->setHeader( - 'List-Unsubscribe', - '<'.wl($id, array('do'=> 'subscribe'), true, '&').'>', - false - ); - } - return $mail->send(); + $subscription = new Subscription(); + return $subscription->send_diff($to, $tpl, $id, $rev, $summary); } /** diff --git a/inc/subscription.php b/inc/subscription.php index 4757b216c..bfbd95244 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -429,9 +429,18 @@ class Subscription { ); } + /** + * Send a notify mail on new registration + * + * @author Andreas Gohr + * + * @param string $login login name of the new user + * @param string $fullname full name of the new user + * @param string $email email address of the new user + * @return bool true if a mail was sent + */ public function send_register($login, $fullname, $email) { global $conf; - global $ID; if(empty($conf['registernotify'])) return false; $trep = array( @@ -443,7 +452,7 @@ class Subscription { return $this->send( $conf['registernotify'], 'new_user', - $ID, + $login, 'registermail', $trep ); @@ -486,10 +495,10 @@ class Subscription { * @param string $subscriber_mail The target mail address * @param array $ids Array of ids * @param string $ns_id The id of the namespace - * @return bool + * @return bool true if a mail was sent */ protected function send_list($subscriber_mail, $ids, $ns_id) { - if(count($ids) === 0) return; + if(count($ids) === 0) return false; $tlist = ''; $hlist = '
    '; @@ -526,7 +535,7 @@ class Subscription { * @param string $subscriber_mail The target mail address * @param string $subject The lang id of the mail subject (without the * prefix “mail_”) - * @param string $id The page or namespace id + * @param string $context The context of this mail, eg. page or namespace id * @param string $template The name of the mail template * @param array $trep Predefined parameters used to parse the * template (in text format) @@ -534,17 +543,11 @@ class Subscription { * template (in HTML format), null to default to $trep * @return bool */ - protected function send($subscriber_mail, $subject, $id, $template, $trep, $hrep = null) { + protected function send($subscriber_mail, $subject, $context, $template, $trep, $hrep = null) { global $lang; $text = rawLocale($template); - $trep = array_merge( - $trep, array( - - ) - ); - - $subject = $lang['mail_'.$subject].' '.$id; + $subject = $lang['mail_'.$subject].' '.$context; $mail = new Mailer(); $mail->bcc($subscriber_mail); $mail->subject($subject); -- cgit v1.2.3 From e13e01da48b642dcdf3efe6864f0fc2bb5094455 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 7 Dec 2012 10:35:27 +0100 Subject: added compatibility function --- inc/subscription.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'inc') diff --git a/inc/subscription.php b/inc/subscription.php index bfbd95244..df6f1af32 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -604,4 +604,19 @@ class Subscription { } $data['addresslist'] = trim($addresslist.','.implode(',', $result), ','); } +} + +/** + * Compatibility wrapper around Subscription:notifyaddresses + * + * for plugins emitting COMMON_NOTIFY_ADDRESSLIST themselves and relying on on this to + * be the default handler + * + * @param array $data event data for + * + * @deprecated 2012-12-07 + */ +function subscription_addresslist(&$data){ + $sub = new Subscription(); + $sub->notifyaddresses($data); } \ No newline at end of file -- cgit v1.2.3 From b34cf753be6c2c3fc67eac58738acc74a1c1785a Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 7 Dec 2012 10:35:49 +0100 Subject: some reformatting --- inc/subscription.php | 78 ++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'inc') diff --git a/inc/subscription.php b/inc/subscription.php index df6f1af32..44248a39d 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -93,27 +93,27 @@ class Subscription { */ protected function buildregex($user = null, $style = null, $data = null) { // always work with arrays - $user = (array) $user; + $user = (array) $user; $style = (array) $style; - $data = (array) $data; + $data = (array) $data; // clean - $user = array_filter(array_map('trim', $user)); + $user = array_filter(array_map('trim', $user)); $style = array_filter(array_map('trim', $style)); - $data = array_filter(array_map('trim', $data)); + $data = array_filter(array_map('trim', $data)); // user names are encoded $user = array_map('auth_nameencode', $user); // quote - $user = array_map('preg_quote_cb', $user); + $user = array_map('preg_quote_cb', $user); $style = array_map('preg_quote_cb', $style); - $data = array_map('preg_quote_cb', $data); + $data = array_map('preg_quote_cb', $data); // join - $user = join('|', $user); + $user = join('|', $user); $style = join('|', $style); - $data = join('|', $data); + $data = join('|', $data); // any data at all? if($user.$style.$data === '') throw new Exception('no data passed'); @@ -126,7 +126,7 @@ class Subscription { } if($style === '') { $style = '\S+'; - $sopt = '?'; + $sopt = '?'; } if($data === '') { $data = '\S+'; @@ -158,7 +158,7 @@ class Subscription { $files = array(':' => $this->file(':')); do { $files[$page] = $this->file($page); - $page = getNS(rtrim($page, ':')).':'; + $page = getNS(rtrim($page, ':')).':'; } while($page !== ':'); $re = $this->buildregex($user, $style, $data); @@ -204,9 +204,9 @@ class Subscription { // delete any existing subscription $this->remove($id, $user); - $user = auth_nameencode(trim($user)); + $user = auth_nameencode(trim($user)); $style = trim($style); - $data = trim($data); + $data = trim($data); if(!$user) throw new Exception('no subscription user given'); if(!$style) throw new Exception('no subscription style given'); @@ -270,8 +270,8 @@ class Subscription { foreach($subs as $target => $info) { $result[] = array( 'target' => $target, - 'style' => $info[$user][0], - 'data' => $info[$user][1] + 'style' => $info[$user][0], + 'data' => $info[$user][1] ); } @@ -302,7 +302,7 @@ class Subscription { // remember current user info $olduinfo = $USERINFO; - $olduser = $_SERVER['REMOTE_USER']; + $olduser = $_SERVER['REMOTE_USER']; foreach($subscriptions as $target => $users) { if(!$this->lock($target)) continue; @@ -318,7 +318,7 @@ class Subscription { } // Work as the user to make sure ACLs apply correctly - $USERINFO = $auth->getUserData($user); + $USERINFO = $auth->getUserData($user); $_SERVER['REMOTE_USER'] = $user; if($USERINFO === false) continue; if(!$USERINFO['mail']) continue; @@ -329,7 +329,7 @@ class Subscription { } else { // single page subscription, check ACL ourselves if(auth_quickaclcheck($target) < AUTH_READ) continue; - $meta = p_get_metadata($target); + $meta = p_get_metadata($target); $changes = array($meta['last_change']); } @@ -372,7 +372,7 @@ class Subscription { } // restore current user info - $USERINFO = $olduinfo; + $USERINFO = $olduinfo; $_SERVER['REMOTE_USER'] = $olduser; return $count; } @@ -392,32 +392,32 @@ class Subscription { // prepare replacements (keys not set in hrep will be taken from trep) $trep = array( - 'PAGE' => $id, - 'NEWPAGE' => wl($id, '', true, '&'), - 'SUMMARY' => $summary, + 'PAGE' => $id, + 'NEWPAGE' => wl($id, '', true, '&'), + 'SUMMARY' => $summary, 'SUBSCRIBE' => wl($id, array('do' => 'subscribe'), true, '&') ); $hrep = array(); if($rev) { - $subject = 'changed'; + $subject = 'changed'; $trep['OLDPAGE'] = wl($id, "rev=$rev", true, '&'); - $df = new Diff(explode("\n", rawWiki($id, $rev)), - explode("\n", rawWiki($id))); - $dformat = new UnifiedDiffFormatter(); - $tdiff = $dformat->format($df); + $df = new Diff(explode("\n", rawWiki($id, $rev)), + explode("\n", rawWiki($id))); + $dformat = new UnifiedDiffFormatter(); + $tdiff = $dformat->format($df); $DIFF_INLINESTYLES = true; - $dformat = new InlineDiffFormatter(); - $hdiff = $dformat->format($df); - $hdiff = ''.$hdiff.'
    '; + $dformat = new InlineDiffFormatter(); + $hdiff = $dformat->format($df); + $hdiff = ''.$hdiff.'
    '; $DIFF_INLINESTYLES = false; } else { - $subject = 'newpage'; + $subject = 'newpage'; $trep['OLDPAGE'] = '---'; - $tdiff = rawWiki($id); - $hdiff = nl2br(hsc($tdiff)); + $tdiff = rawWiki($id); + $hdiff = nl2br(hsc($tdiff)); } $trep['DIFF'] = $tdiff; @@ -444,8 +444,8 @@ class Subscription { if(empty($conf['registernotify'])) return false; $trep = array( - 'NEWUSER' => $login, - 'NEWNAME' => $fullname, + 'NEWUSER' => $login, + 'NEWNAME' => $fullname, 'NEWEMAIL' => $email, ); @@ -548,11 +548,11 @@ class Subscription { $text = rawLocale($template); $subject = $lang['mail_'.$subject].' '.$context; - $mail = new Mailer(); + $mail = new Mailer(); $mail->bcc($subscriber_mail); $mail->subject($subject); $mail->setBody($text, $trep, $hrep); - if(isset($trep['SUBSCRIBE'])){ + if(isset($trep['SUBSCRIBE'])) { $mail->setHeader('List-Unsubscribe', '<'.$trep['SUBSCRIBE'].'>', false); } return $mail->send(); @@ -580,8 +580,8 @@ class Subscription { global $auth; global $conf; - $id = $data['id']; - $self = $data['self']; + $id = $data['id']; + $self = $data['self']; $addresslist = $data['addresslist']; $subscriptions = $this->subscribers($id, null, 'every'); @@ -616,7 +616,7 @@ class Subscription { * * @deprecated 2012-12-07 */ -function subscription_addresslist(&$data){ +function subscription_addresslist(&$data) { $sub = new Subscription(); $sub->notifyaddresses($data); } \ No newline at end of file -- cgit v1.2.3 From 16c665d9fa1d3d1c5d82866a942ba8cb6db3a4ee Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 18 Jan 2013 10:41:26 +0100 Subject: removed data parameter in subscription_handle_post() now the data parameter, which really is a timestamp is only handled internally of the subscription class --- inc/actions.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'inc') diff --git a/inc/actions.php b/inc/actions.php index 911edf936..4083b0454 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -784,8 +784,7 @@ function subscription_handle_post(&$params) { $style = null; } - $data = in_array($style, array('list', 'digest')) ? time() : null; - $params = compact('target', 'style', 'data', 'action'); + $params = compact('target', 'style', 'action'); } //Setup VIM: ex: et ts=2 : -- cgit v1.2.3 From cfbb9916556595cd8987f6c79771883dde656185 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 18 Jan 2013 10:47:21 +0100 Subject: removed unused vars --- inc/common.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'inc') diff --git a/inc/common.php b/inc/common.php index 20e0af389..bc49e76b2 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1105,10 +1105,7 @@ function saveOldRevision($id) { * @author Andreas Gohr */ function notify($id, $who, $rev = '', $summary = '', $minor = false, $replace = array()) { - global $lang; global $conf; - global $INFO; - global $DIFF_INLINESTYLES; // decide if there is something to do, eg. whom to mail if($who == 'admin') { -- cgit v1.2.3 From edf986ad6271abac1f00055d3de4a9857cae1553 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 18 Jan 2013 10:49:41 +0100 Subject: comment adjusted --- inc/subscription.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/subscription.php b/inc/subscription.php index 44248a39d..92c1e8579 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -381,7 +381,7 @@ class Subscription { * Send the diff for some page change * * @param string $subscriber_mail The target mail address - * @param string $template Mail template, should be 'subscr_digest' or 'subscr_single' + * @param string $template Mail template ('subscr_digest', 'subscr_single', 'mailtext', ...) * @param string $id Page for which the notification is * @param int|null $rev Old revision if any * @param string $summary Change summary if any -- cgit v1.2.3 From 004e7e6efb2e8da1d76f3959667ca0dbf8b0aaf6 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 18 Jan 2013 10:52:26 +0100 Subject: simplified subscription->add() code a bit --- inc/subscription.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'inc') diff --git a/inc/subscription.php b/inc/subscription.php index 92c1e8579..e888ee27f 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -204,20 +204,16 @@ class Subscription { // delete any existing subscription $this->remove($id, $user); - $user = auth_nameencode(trim($user)); + $user = auth_nameencode(trim($user)); $style = trim($style); - $data = trim($data); + $data = trim($data); if(!$user) throw new Exception('no subscription user given'); if(!$style) throw new Exception('no subscription style given'); if(!$data) $data = time(); //always add current time for new subscriptions - $line = "$user $style"; - if($data) $line .= " $data"; - $line .= "\n"; - + $line = "$user $style $data\n"; $file = $this->file($id); - return io_saveFile($file, $line, true); } -- cgit v1.2.3 From 8b87bc02a80bd1436f031d46f2d1e167b815323a Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 18 Jan 2013 11:01:04 +0100 Subject: fixed lists in HTML mails --- inc/subscription.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/subscription.php b/inc/subscription.php index e888ee27f..fc26e42e8 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -503,7 +503,7 @@ class Subscription { $tlist .= '* '.$link.NL; $hlist .= '
  • '.hsc($id).'
  • '.NL; } - $hlist = '
'; + $hlist .= ''; $id = prettyprint_id($ns_id); $trep = array( -- cgit v1.2.3 From 903e04c3aaaad8e237d8e50434aed40692672a43 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 18 Jan 2013 11:07:46 +0100 Subject: correctly escape diffs in HTML mails --- inc/subscription.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'inc') diff --git a/inc/subscription.php b/inc/subscription.php index fc26e42e8..e4cabffed 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -398,17 +398,22 @@ class Subscription { if($rev) { $subject = 'changed'; $trep['OLDPAGE'] = wl($id, "rev=$rev", true, '&'); - $df = new Diff(explode("\n", rawWiki($id, $rev)), - explode("\n", rawWiki($id))); + + $old_content = rawWiki($id, $rev); + $new_content = rawWiki($id); + + $df = new Diff(explode("\n", $old_content), + explode("\n", $new_content)); $dformat = new UnifiedDiffFormatter(); $tdiff = $dformat->format($df); $DIFF_INLINESTYLES = true; + $df = new Diff(explode("\n", hsc($old_content)), + explode("\n", hsc($new_content))); $dformat = new InlineDiffFormatter(); $hdiff = $dformat->format($df); $hdiff = ''.$hdiff.'
'; $DIFF_INLINESTYLES = false; - } else { $subject = 'newpage'; $trep['OLDPAGE'] = '---'; -- cgit v1.2.3 From 29c964eb1ccaac4204b31ac7409bd91e93e9ed0c Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 18 Jan 2013 11:16:53 +0100 Subject: readded mailfromnobody to subscription sending this was lost because the subscription branch, branched before this change in master --- inc/subscription.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'inc') diff --git a/inc/subscription.php b/inc/subscription.php index e4cabffed..dfb3533fd 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -546,6 +546,7 @@ class Subscription { */ protected function send($subscriber_mail, $subject, $context, $template, $trep, $hrep = null) { global $lang; + global $conf; $text = rawLocale($template); $subject = $lang['mail_'.$subject].' '.$context; @@ -553,6 +554,7 @@ class Subscription { $mail->bcc($subscriber_mail); $mail->subject($subject); $mail->setBody($text, $trep, $hrep); + $mail->from($conf['mailfromnobody']); if(isset($trep['SUBSCRIBE'])) { $mail->setHeader('List-Unsubscribe', '<'.$trep['SUBSCRIBE'].'>', false); } -- cgit v1.2.3 From 368571d88a6155195d8d285c5facd569e8a5b385 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 25 Jan 2013 10:58:01 +0100 Subject: added missing context for list mails --- inc/subscription.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/subscription.php b/inc/subscription.php index dfb3533fd..6d62e4ced 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -523,7 +523,7 @@ class Subscription { return $this->send( $subscriber_mail, 'subscribe_list', - + $ns_id, 'subscr_list', $trep, $hrep ); } -- cgit v1.2.3 From 6cd7e49ba5bd41e3345b5cc4418f1e71476b3991 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 25 Jan 2013 10:58:15 +0100 Subject: only use mailfromnobody for bulk mails --- inc/subscription.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'inc') diff --git a/inc/subscription.php b/inc/subscription.php index 6d62e4ced..62cfd1509 100644 --- a/inc/subscription.php +++ b/inc/subscription.php @@ -554,7 +554,9 @@ class Subscription { $mail->bcc($subscriber_mail); $mail->subject($subject); $mail->setBody($text, $trep, $hrep); - $mail->from($conf['mailfromnobody']); + if(in_array($template, array('subscr_list', 'subscr_digest'))){ + $mail->from($conf['mailfromnobody']); + } if(isset($trep['SUBSCRIBE'])) { $mail->setHeader('List-Unsubscribe', '<'.$trep['SUBSCRIBE'].'>', false); } -- cgit v1.2.3 From c38b7fab9eeb9456aaf5fe8e4481c3b8569e5644 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 26 Jan 2013 11:17:01 +0100 Subject: link directly to subscription management in mails This was updated in the english translation a while ago, but was still missing in some translations --- inc/lang/ar/subscr_single.txt | 2 +- inc/lang/bg/subscr_single.txt | 2 +- inc/lang/da/subscr_single.txt | 2 +- inc/lang/de-informal/subscr_single.txt | 2 +- inc/lang/de/subscr_single.txt | 2 +- inc/lang/en/subscr_single.txt | 2 +- inc/lang/eo/subscr_single.txt | 2 +- inc/lang/he/subscr_single.txt | 2 +- inc/lang/ia/subscr_single.txt | 2 +- inc/lang/it/subscr_single.txt | 2 +- inc/lang/ko/subscr_single.txt | 2 +- inc/lang/la/subscr_digest.txt | 2 +- inc/lang/la/subscr_single.txt | 2 +- inc/lang/no/subscr_digest.txt | 2 +- inc/lang/no/subscr_list.txt | 2 +- inc/lang/no/subscr_single.txt | 2 +- inc/lang/pt/subscr_single.txt | 2 +- inc/lang/sq/subscr_single.txt | 2 +- 18 files changed, 18 insertions(+), 18 deletions(-) (limited to 'inc') diff --git a/inc/lang/ar/subscr_single.txt b/inc/lang/ar/subscr_single.txt index 5c62aeaeb..611688415 100644 --- a/inc/lang/ar/subscr_single.txt +++ b/inc/lang/ar/subscr_single.txt @@ -15,7 +15,7 @@ لإلغاء إشعارات الصفحة,لُج الويكي في @DOKUWIKIURL@ ثم زُر -@NEWPAGE@ +@SUBSCRIBE@ وألغ الاشتراك من تغييرات الصفحة و/أو النطاق. -- diff --git a/inc/lang/bg/subscr_single.txt b/inc/lang/bg/subscr_single.txt index 7b26f8e96..a74a21fb8 100644 --- a/inc/lang/bg/subscr_single.txt +++ b/inc/lang/bg/subscr_single.txt @@ -14,7 +14,7 @@ Нова версия: @NEWPAGE@ Ако желаете да прекратите уведомяването за страницата трябва да се впишете на адрес @DOKUWIKIURL@, да посетите -@NEWPAGE@ +@SUBSCRIBE@ и да прекратите абонамента за промени по страницата или именното пространство. -- diff --git a/inc/lang/da/subscr_single.txt b/inc/lang/da/subscr_single.txt index 64b14588c..cdc554513 100644 --- a/inc/lang/da/subscr_single.txt +++ b/inc/lang/da/subscr_single.txt @@ -15,7 +15,7 @@ Ny Revision: @NEWPAGE@ For at slå side notifikationer fra, skal du logge ind på @DOKUWIKIURL@ og besøge -@NEWPAGE@ +@SUBSCRIBE@ og slå abonnoment for side / navnerum ændringer fra. -- diff --git a/inc/lang/de-informal/subscr_single.txt b/inc/lang/de-informal/subscr_single.txt index 3c557bc17..6e3f58b9f 100644 --- a/inc/lang/de-informal/subscr_single.txt +++ b/inc/lang/de-informal/subscr_single.txt @@ -15,7 +15,7 @@ Neue Revision: @NEWPAGE@ Um das Abonnement für diese Seite aufzulösen, melde dich im Wiki an @DOKUWIKIURL@, besuche dann -@NEWPAGE@ +@SUBSCRIBE@ und klicke auf den Link 'Aboverwaltung'. -- diff --git a/inc/lang/de/subscr_single.txt b/inc/lang/de/subscr_single.txt index f3e1cd393..da9914e50 100644 --- a/inc/lang/de/subscr_single.txt +++ b/inc/lang/de/subscr_single.txt @@ -15,7 +15,7 @@ Neue Revision: @NEWPAGE@ Um das Abonnement für diese Seite aufzulösen, melden Sie sich im Wiki an @DOKUWIKIURL@, besuchen dann -@NEWPAGE@ +@SUBSCRIBE@ und klicken auf die Taste 'Aboverwaltung'. -- diff --git a/inc/lang/en/subscr_single.txt b/inc/lang/en/subscr_single.txt index 673c4c32a..0bc310e04 100644 --- a/inc/lang/en/subscr_single.txt +++ b/inc/lang/en/subscr_single.txt @@ -15,7 +15,7 @@ New Revision: @NEWPAGE@ To cancel the page notifications, log into the wiki at @DOKUWIKIURL@ then visit -@NEWPAGE@ +@SUBSCRIBE@ and unsubscribe page and/or namespace changes. -- diff --git a/inc/lang/eo/subscr_single.txt b/inc/lang/eo/subscr_single.txt index 431fd0251..e4847e8ab 100644 --- a/inc/lang/eo/subscr_single.txt +++ b/inc/lang/eo/subscr_single.txt @@ -15,7 +15,7 @@ Nova versio: @NEWPAGE@ Por nuligi la paĝinformojn, ensalutu la vikion ĉe @DOKUWIKIURL@, poste iru al -@NEWPAGE@ +@SUBSCRIBE@ kaj malabonu la paĝajn kaj/aŭ nomspacajn ŝanĝojn. -- diff --git a/inc/lang/he/subscr_single.txt b/inc/lang/he/subscr_single.txt index 123b186c8..78b551e2f 100644 --- a/inc/lang/he/subscr_single.txt +++ b/inc/lang/he/subscr_single.txt @@ -14,7 +14,7 @@ לביטול התרעות בנוגע לעמוד, יש להיכנס לאתר הוויקי בכתובת @DOKUWIKIURL@ ואז לבקר בדף -@NEWPAGE@ +@SUBSCRIBE@ ולבטל את המינוי לקבלת שינויים בדף ו/או במרחב השם. -- diff --git a/inc/lang/ia/subscr_single.txt b/inc/lang/ia/subscr_single.txt index 3d6ef7103..445df197c 100644 --- a/inc/lang/ia/subscr_single.txt +++ b/inc/lang/ia/subscr_single.txt @@ -15,7 +15,7 @@ Version nove: @NEWPAGE@ Pro cancellar le notificationes de paginas, aperi un session al wiki a @DOKUWIKIURL@ postea visita -@NEWPAGE@ +@SUBSCRIBE@ e cancella tu subscription al modificationes in paginas e/o spatios de nomines. -- diff --git a/inc/lang/it/subscr_single.txt b/inc/lang/it/subscr_single.txt index 8cde8ea0f..a8649a4ef 100644 --- a/inc/lang/it/subscr_single.txt +++ b/inc/lang/it/subscr_single.txt @@ -15,7 +15,7 @@ Nuova revisione: @NEWPAGE@ Per non ricevere più queste notifiche, collegati al wiki all'indirizzo @DOKUWIKIURL@ e poi visita -@NEWPAGE@ +@SUBSCRIBE@ e rimuovi la sottoscrizione alle modifiche della pagina o categoria. diff --git a/inc/lang/ko/subscr_single.txt b/inc/lang/ko/subscr_single.txt index 6bd1885e6..2679db393 100644 --- a/inc/lang/ko/subscr_single.txt +++ b/inc/lang/ko/subscr_single.txt @@ -14,7 +14,7 @@ 새 버전 : @NEWPAGE@ 이 문서의 알림을 취소하려면, @DOKUWIKIURL@에 로그인한 뒤 -@NEWPAGE@ 문서를 방문하여 문서나 이름공간의 구독을 취소하세요. +@SUBSCRIBE@ 문서를 방문하여 문서나 이름공간의 구독을 취소하세요. -- @DOKUWIKIURL@의 DokuWiki가 자동으로 만들어낸 메일입니다. \ No newline at end of file diff --git a/inc/lang/la/subscr_digest.txt b/inc/lang/la/subscr_digest.txt index 629213359..32d378a7e 100644 --- a/inc/lang/la/subscr_digest.txt +++ b/inc/lang/la/subscr_digest.txt @@ -12,7 +12,7 @@ Noua recensio: @NEWPAGE@ Ut paginae adnotationes deleas, in uicem ineas in @DOKUWIKIURL@, deinde uideas -@NEWPAGE@ +@SUBSCRIBE@ et paginarum generum optiones mutes. -- diff --git a/inc/lang/la/subscr_single.txt b/inc/lang/la/subscr_single.txt index 7839791ea..14285014c 100644 --- a/inc/lang/la/subscr_single.txt +++ b/inc/lang/la/subscr_single.txt @@ -15,7 +15,7 @@ Noua recensio: @NEWPAGE@ Ut paginae adnotationes deleas, in uicem ineas in @DOKUWIKIURL@, deinde uideas -@NEWPAGE@ +@SUBSCRIBE@ et paginarum et\aut generum optiones mutasa. -- diff --git a/inc/lang/no/subscr_digest.txt b/inc/lang/no/subscr_digest.txt index 6afd0cc5c..670d39d32 100644 --- a/inc/lang/no/subscr_digest.txt +++ b/inc/lang/no/subscr_digest.txt @@ -12,7 +12,7 @@ Ny versjon: @NEWPAGE@ For å avslutte varslingen, logg inn på @DOKUWIKIURL@ og gå til -@NEWPAGE@ +@SUBSCRIBE@ og avslutt abonnementet på endringer av siden eller i navnerommet. -- diff --git a/inc/lang/no/subscr_list.txt b/inc/lang/no/subscr_list.txt index 72cd307cb..860d88d2a 100644 --- a/inc/lang/no/subscr_list.txt +++ b/inc/lang/no/subscr_list.txt @@ -9,7 +9,7 @@ Her er endringene: For å avslutte varslinga, logg inn på @DOKUWIKIURL@ og gå til -@NEWPAGE@ +@SUBSCRIBE@ og avslutt abonnementet på endringer av sida eller i navnerommet. -- diff --git a/inc/lang/no/subscr_single.txt b/inc/lang/no/subscr_single.txt index 25296da58..b26b3a879 100644 --- a/inc/lang/no/subscr_single.txt +++ b/inc/lang/no/subscr_single.txt @@ -15,7 +15,7 @@ Ny versjon: @NEWPAGE@ For å avslutte varslingen, logg inn på @DOKUWIKIURL@, gå til -@NEWPAGE@ +@SUBSCRIBE@ og avslutt abonnementet på endringer av siden eller i navnerommet. -- diff --git a/inc/lang/pt/subscr_single.txt b/inc/lang/pt/subscr_single.txt index 1187b5911..469c6bfb1 100644 --- a/inc/lang/pt/subscr_single.txt +++ b/inc/lang/pt/subscr_single.txt @@ -15,7 +15,7 @@ Revisão Nova: @NEWPAGE@ Para cancelar as notificações de página, inicie sessão no wiki em @DOKUWIKIURL@, visite -@NEWPAGE@ +@SUBSCRIBE@ e des-subscreva às alterações de página e/ou espaço de nome. -- diff --git a/inc/lang/sq/subscr_single.txt b/inc/lang/sq/subscr_single.txt index 90520be4f..df28ee176 100644 --- a/inc/lang/sq/subscr_single.txt +++ b/inc/lang/sq/subscr_single.txt @@ -15,7 +15,7 @@ Rishikimi i ri: @NEWPAGE@ Për të fshirë lajmërimet e faqes, hyni në wiki tek @DOKUWIKIURL@ dhe pastaj vizitoni -@NEWPAGE@ +@SUBSCRIBE@ dhe fshini ndryshimet e faqes dhe/ose hapësirës së emrit. -- -- cgit v1.2.3