diff options
Diffstat (limited to 'inc/Subscriptions')
-rw-r--r-- | inc/Subscriptions/BulkSubscriptionSender.php | 29 | ||||
-rw-r--r-- | inc/Subscriptions/MediaSubscriptionSender.php | 7 | ||||
-rw-r--r-- | inc/Subscriptions/PageSubscriptionSender.php | 6 | ||||
-rw-r--r-- | inc/Subscriptions/RegistrationSubscriptionSender.php | 1 | ||||
-rw-r--r-- | inc/Subscriptions/SubscriberManager.php | 40 | ||||
-rw-r--r-- | inc/Subscriptions/SubscriberRegexBuilder.php | 8 | ||||
-rw-r--r-- | inc/Subscriptions/SubscriptionSender.php | 4 |
7 files changed, 44 insertions, 51 deletions
diff --git a/inc/Subscriptions/BulkSubscriptionSender.php b/inc/Subscriptions/BulkSubscriptionSender.php index d0ae2bf1e..df6141007 100644 --- a/inc/Subscriptions/BulkSubscriptionSender.php +++ b/inc/Subscriptions/BulkSubscriptionSender.php @@ -1,16 +1,14 @@ <?php - namespace dokuwiki\Subscriptions; - use dokuwiki\ChangeLog\PageChangeLog; +use dokuwiki\Extension\AuthPlugin; use dokuwiki\Input\Input; -use DokuWiki_Auth_Plugin; +use Exception; class BulkSubscriptionSender extends SubscriptionSender { - /** * Send digest and list subscriptions * @@ -20,8 +18,8 @@ class BulkSubscriptionSender extends SubscriptionSender * This function is called form lib/exe/indexer.php * * @param string $page - * * @return int number of sent mails + * @throws Exception */ public function sendBulk($page) { @@ -30,7 +28,7 @@ class BulkSubscriptionSender extends SubscriptionSender return 0; } - /** @var DokuWiki_Auth_Plugin $auth */ + /** @var AuthPlugin $auth */ global $auth; global $conf; global $USERINFO; @@ -50,7 +48,7 @@ class BulkSubscriptionSender extends SubscriptionSender } foreach ($users as $user => $info) { - list($style, $lastupdate) = $info; + [$style, $lastupdate] = $info; $lastupdate = (int)$lastupdate; if ($lastupdate + $conf['subscribe_time'] > time()) { @@ -86,12 +84,13 @@ class BulkSubscriptionSender extends SubscriptionSender foreach ($changes as $rev) { $n = 0; $pagelog = new PageChangeLog($rev['id']); - while (!is_null($rev) && $rev['date'] >= $lastupdate && + while ( + !is_null($rev) && $rev['date'] >= $lastupdate && ($INPUT->server->str('REMOTE_USER') === $rev['user'] || $rev['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) ) { $revisions = $pagelog->getRevisions($n++, 1); - $rev = (count($revisions) > 0) ? $pagelog->getRevisionInfo($revisions[0]) : null; + $rev = ($revisions !== []) ? $pagelog->getRevisionInfo($revisions[0]) : null; } if (!is_null($rev) && $rev['date'] >= $lastupdate) { @@ -110,11 +109,9 @@ class BulkSubscriptionSender extends SubscriptionSender ); $count++; } - } else { - if ($style === 'list') { - $this->sendList($USERINFO['mail'], $change_ids, $target); - $count++; - } + } elseif ($style === 'list') { + $this->sendList($USERINFO['mail'], $change_ids, $target); + $count++; } // TODO: Handle duplicate subscriptions. @@ -199,7 +196,7 @@ class BulkSubscriptionSender extends SubscriptionSender $n = 0; do { $rev = $pagelog->getRevisions($n++, 1); - $rev = (count($rev) > 0) ? $rev[0] : null; + $rev = ($rev !== []) ? $rev[0] : null; } while (!is_null($rev) && $rev > $lastupdate); // TODO I'm not happy with the following line and passing $this->mailer around. Not sure how to solve it better @@ -227,7 +224,7 @@ class BulkSubscriptionSender extends SubscriptionSender */ protected function sendList($subscriber_mail, $ids, $ns_id) { - if (count($ids) === 0) { + if ($ids === []) { return false; } diff --git a/inc/Subscriptions/MediaSubscriptionSender.php b/inc/Subscriptions/MediaSubscriptionSender.php index 1757c2b1c..84497c071 100644 --- a/inc/Subscriptions/MediaSubscriptionSender.php +++ b/inc/Subscriptions/MediaSubscriptionSender.php @@ -1,12 +1,9 @@ <?php - namespace dokuwiki\Subscriptions; - class MediaSubscriptionSender extends SubscriptionSender { - /** * Send the diff for some media change * @@ -23,11 +20,11 @@ class MediaSubscriptionSender extends SubscriptionSender global $conf; $file = mediaFN($id); - list($mime, /* $ext */) = mimetype($id); + [$mime, /* ext */] = mimetype($id); $trep = [ 'MIME' => $mime, - 'MEDIA' => ml($id, $current_rev?('rev='.$current_rev):'', true, '&', true), + 'MEDIA' => ml($id, $current_rev ? ('rev=' . $current_rev) : '', true, '&', true), 'SIZE' => filesize_h(filesize($file)), ]; diff --git a/inc/Subscriptions/PageSubscriptionSender.php b/inc/Subscriptions/PageSubscriptionSender.php index e5577c1af..dbdc454ac 100644 --- a/inc/Subscriptions/PageSubscriptionSender.php +++ b/inc/Subscriptions/PageSubscriptionSender.php @@ -1,16 +1,13 @@ <?php - namespace dokuwiki\Subscriptions; - use Diff; use InlineDiffFormatter; use UnifiedDiffFormatter; class PageSubscriptionSender extends SubscriptionSender { - /** * Send the diff for some page change * @@ -30,7 +27,7 @@ class PageSubscriptionSender extends SubscriptionSender // prepare replacements (keys not set in hrep will be taken from trep) $trep = [ 'PAGE' => $id, - 'NEWPAGE' => wl($id, $current_rev?('rev='.$current_rev):'', true, '&'), + 'NEWPAGE' => wl($id, $current_rev ? ('rev=' . $current_rev) : '', true, '&'), 'SUMMARY' => $summary, 'SUBSCRIBE' => wl($id, ['do' => 'subscribe'], true, '&'), ]; @@ -84,5 +81,4 @@ class PageSubscriptionSender extends SubscriptionSender $headers ); } - } diff --git a/inc/Subscriptions/RegistrationSubscriptionSender.php b/inc/Subscriptions/RegistrationSubscriptionSender.php index bd4887599..34cfc8907 100644 --- a/inc/Subscriptions/RegistrationSubscriptionSender.php +++ b/inc/Subscriptions/RegistrationSubscriptionSender.php @@ -4,7 +4,6 @@ namespace dokuwiki\Subscriptions; class RegistrationSubscriptionSender extends SubscriptionSender { - /** * Send a notify mail on new registration * diff --git a/inc/Subscriptions/SubscriberManager.php b/inc/Subscriptions/SubscriberManager.php index 44a9b4a26..484daaa51 100644 --- a/inc/Subscriptions/SubscriberManager.php +++ b/inc/Subscriptions/SubscriberManager.php @@ -2,13 +2,12 @@ namespace dokuwiki\Subscriptions; +use dokuwiki\Extension\AuthPlugin; use dokuwiki\Input\Input; -use DokuWiki_Auth_Plugin; use Exception; class SubscriberManager { - /** * Check if subscription system is enabled * @@ -71,12 +70,13 @@ class SubscriberManager * 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 $id The target object’s (namespace or page) id * @param string|array $user * @param string|array $style * @param string|array $data * * @return bool + * @throws Exception */ public function remove($id, $user = null, $style = null, $data = null) { @@ -101,12 +101,13 @@ class SubscriberManager * and user is in effect. Else it contains an array of arrays with the fields * “target”, “style”, and optionally “data”. * - * @author Adrian Lang <lang@cosmocode.de> - * - * @param string $id Page ID, defaults to global $ID + * @param string $id Page ID, defaults to global $ID * @param string $user User, defaults to $_SERVER['REMOTE_USER'] * * @return array|false + * @throws Exception + * + * @author Adrian Lang <lang@cosmocode.de> */ public function userSubscription($id = '', $user = '') { @@ -130,7 +131,7 @@ class SubscriberManager } $subs = $this->subscribers($id, $user); - if (!count($subs)) { + if ($subs === []) { return false; } @@ -152,14 +153,16 @@ class SubscriberManager * This function searches all relevant subscription files for a page or * namespace. * - * @author Adrian Lang <lang@cosmocode.de> - * - * @param string $page The target object’s (namespace or page) id + * @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 + * @throws Exception + * + * @author Adrian Lang <lang@cosmocode.de> + * */ public function subscribers($page, $user = null, $style = null, $data = null) { @@ -216,17 +219,18 @@ class SubscriberManager * * Aggregates all email addresses of user who have subscribed the given page with 'every' style * - * @author Adrian Lang <lang@cosmocode.de> - * @author Steven Danz <steven-danz@kc.rr.com> - * - * @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 the entries: * - $id (the page id), * - $self (whether the author should be notified, * - $addresslist (current email address list) * - $replacements (array of additional string substitutions, @KEY@ to be replaced by value) + * @throws Exception + * + * @author Adrian Lang <lang@cosmocode.de> + * @author Steven Danz <steven-danz@kc.rr.com> + * + * @todo move the whole functionality into this class, trigger SUBSCRIPTION_NOTIFY_ADDRESSLIST instead, + * use an array for the addresses within it */ public function notifyAddresses(&$data) { @@ -234,7 +238,7 @@ class SubscriberManager return; } - /** @var DokuWiki_Auth_Plugin $auth */ + /** @var AuthPlugin $auth */ global $auth; global $conf; /** @var \Input $INPUT */ @@ -247,7 +251,7 @@ class SubscriberManager $subscriptions = $this->subscribers($id, null, 'every'); $result = []; - foreach ($subscriptions as $target => $users) { + foreach ($subscriptions as $users) { foreach ($users as $user => $info) { $userinfo = $auth->getUserData($user); if ($userinfo === false) { diff --git a/inc/Subscriptions/SubscriberRegexBuilder.php b/inc/Subscriptions/SubscriberRegexBuilder.php index 959702aac..6c8fd7e6b 100644 --- a/inc/Subscriptions/SubscriberRegexBuilder.php +++ b/inc/Subscriptions/SubscriberRegexBuilder.php @@ -6,7 +6,6 @@ use Exception; class SubscriberRegexBuilder { - /** * Construct a regular expression for parsing a subscription definition line * @@ -36,13 +35,14 @@ class SubscriberRegexBuilder // quote $user = array_map('preg_quote_cb', $user); + $style = array_map('preg_quote_cb', $style); $data = array_map('preg_quote_cb', $data); // join - $user = join('|', $user); - $style = join('|', $style); - $data = join('|', $data); + $user = implode('|', $user); + $style = implode('|', $style); + $data = implode('|', $data); // any data at all? if ($user . $style . $data === '') { diff --git a/inc/Subscriptions/SubscriptionSender.php b/inc/Subscriptions/SubscriptionSender.php index afc05bfc0..4a4e31ea2 100644 --- a/inc/Subscriptions/SubscriptionSender.php +++ b/inc/Subscriptions/SubscriptionSender.php @@ -10,7 +10,7 @@ abstract class SubscriptionSender public function __construct(Mailer $mailer = null) { - if ($mailer === null) { + if (!$mailer instanceof \Mailer) { $mailer = new Mailer(); } $this->mailer = $mailer; @@ -29,7 +29,7 @@ abstract class SubscriptionSender static $listid = null; if (is_null($listid)) { $server = parse_url(DOKU_URL, PHP_URL_HOST); - $listid = join('.', array_reverse(explode('/', DOKU_BASE))) . $server; + $listid = implode('.', array_reverse(explode('/', DOKU_BASE))) . $server; $listid = urlencode($listid); $listid = strtolower(trim($listid, '.')); } |