diff --git a/action.php b/action.php index 5a80c2d..41c9509 100644 --- a/action.php +++ b/action.php @@ -1,5 +1,10 @@ */ -class action_plugin_watchcycle extends DokuWiki_Action_Plugin +class action_plugin_watchcycle extends ActionPlugin { /** * Registers a callback function for a given event * - * @param Doku_Event_Handler $controller DokuWiki's event controller object + * @param EventHandler $controller DokuWiki's event controller object * * @return void */ - public function register(Doku_Event_Handler $controller) + public function register(EventHandler $controller) { $controller->register_hook('PARSER_METADATA_RENDER', 'AFTER', $this, 'handleParserMetadataRender'); @@ -41,13 +46,13 @@ public function register(Doku_Event_Handler $controller) /** * Register a new toolbar button * - * @param Doku_Event $event event object by reference + * @param Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * * @return void */ - public function handleToolbarDefine(Doku_Event $event, $param) + public function handleToolbarDefine(Event $event, $param) { $event->data[] = [ 'type' => 'plugin_watchcycle', @@ -59,10 +64,10 @@ public function handleToolbarDefine(Doku_Event $event, $param) /** * Add a checkbox to the search form to allow limiting the search to maintained pages only * - * @param Doku_Event $event + * @param Event $event * @param $param */ - public function addFilterToSearchForm(Doku_Event $event, $param) + public function addFilterToSearchForm(Event $event, $param) { /* @var \dokuwiki\Form\Form $searchForm */ $searchForm = $event->data; @@ -74,15 +79,15 @@ public function addFilterToSearchForm(Doku_Event $event, $param) /** * Handles the FORM_QUICKSEARCH_OUTPUT event * - * @param Doku_Event $event event object by reference + * @param Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * * @return void */ - public function handleFormQuicksearchOutput(Doku_Event $event, $param) + public function handleFormQuicksearchOutput(Event $event, $param) { - /** @var \dokuwiki\Form\Form $qsearchForm */ + /** @var Form $qsearchForm */ $qsearchForm = $event->data; if ($this->getConf('default_maintained_only')) { $qsearchForm->setHiddenField('watchcycle_only', '1'); @@ -92,10 +97,10 @@ public function handleFormQuicksearchOutput(Doku_Event $event, $param) /** * Filter the search results to show only maintained pages, if watchcycle_only is true in $INPUT * - * @param Doku_Event $event + * @param Event $event * @param $param */ - public function filterSearchResults(Doku_Event $event, $param) + public function filterSearchResults(Event $event, $param) { global $INPUT; if (!$INPUT->bool('watchcycle_only')) { @@ -110,13 +115,13 @@ public function filterSearchResults(Doku_Event $event, $param) /** * [Custom event handler which performs action] * - * @param Doku_Event $event event object by reference + * @param Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * * @return void */ - public function handleParserMetadataRender(Doku_Event $event, $param) + public function handleParserMetadataRender(Event $event, $param) { global $ID; @@ -169,10 +174,8 @@ public function handleParserMetadataRender(Doku_Event $event, $param) $toupdate['uptodate'] = (int)$uptodate; } - if (count($toupdate) > 0) { - $set = implode(',', array_map(function ($v) { - return "$v=?"; - }, array_keys($toupdate))); + if ($toupdate !== []) { + $set = implode(',', array_map(static fn($v) => "$v=?", array_keys($toupdate))); $toupdate[] = $page; $sqlite->query("UPDATE watchcycle SET $set WHERE page=?", array_values($toupdate)); } @@ -187,10 +190,10 @@ public function handleParserMetadataRender(Doku_Event $event, $param) /** * Returns JSON with filtered users and groups * - * @param Doku_Event $event + * @param Event $event * @param string $param */ - public function handleAjaxGet(Doku_Event $event, $param) + public function handleAjaxGet(Event $event, $param) { if ($event->data != 'plugin_watchcycle_get') return; $event->preventDefault(); @@ -216,10 +219,10 @@ public function handleAjaxGet(Doku_Event $event, $param) /** * JSON result of validation of maintainers definition * - * @param Doku_Event $event + * @param Event $event * @param $param */ - public function handleAjaxValidate(Doku_Event $event, $param) + public function handleAjaxValidate(Event $event, $param) { if ($event->data != 'plugin_watchcycle_validate') return; $event->preventDefault(); @@ -256,9 +259,7 @@ protected function fetchUsersAndGroups() $users = []; $foundUsers = $auth->retrieveUsers(0, 50, ['user' => $term]); if (!empty($foundUsers)) { - $users = array_map(function ($name, $user) use ($term) { - return ['label' => $user['name'] . " ($name)", 'value' => $name]; - }, array_keys($foundUsers), $foundUsers); + $users = array_map(static fn($name, $user) => ['label' => $user['name'] . " ($name)", 'value' => $name], array_keys($foundUsers), $foundUsers); } $groups = []; @@ -276,7 +277,7 @@ protected function fetchUsersAndGroups() $groups = array_filter( array_map(function ($grp) use ($term) { // filter groups - if (strpos($grp, $term) !== false) { + if (strpos($grp, (string) $term) !== false) { return ['label' => '@' . $grp, 'value' => '@' . $grp]; } }, $foundGroups) @@ -305,12 +306,12 @@ protected function getLastMaintainerRev($meta, $maintainer, &$rev) return $changes; } else { $page = $meta['current']['last_change']['id']; - $changelog = new PageChangelog($page); + $changelog = new PageChangeLog($page); $first = 0; $num = 100; while (count($revs = $changelog->getRevisions($first, $num)) > 0) { foreach ($revs as $rev) { - $changes += 1; + ++$changes; $revInfo = $changelog->getRevisionInfo($rev); if ($helper->isMaintainer($revInfo['user'], $maintainer)) { $rev = $revInfo['date']; @@ -328,13 +329,13 @@ protected function getLastMaintainerRev($meta, $maintainer, &$rev) /** * clean the cache every 24 hours * - * @param Doku_Event $event event object by reference + * @param Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * * @return void */ - public function handleParserCacheUse(Doku_Event $event, $param) + public function handleParserCacheUse(Event $event, $param) { /* @var \helper_plugin_watchcycle $helper */ $helper = plugin_load('helper', 'watchcycle'); @@ -347,13 +348,13 @@ public function handleParserCacheUse(Doku_Event $event, $param) /** * Check if the page has to be changed * - * @param Doku_Event $event event object by reference + * @param Event $event event object by reference * @param mixed $param [the parameters passed as fifth argument to register_hook() when this * handler was registered] * * @return void */ - public function handlePagesaveBefore(Doku_Event $event, $param) + public function handlePagesaveBefore(Event $event, $param) { if ($event->data['contentChanged']) { return; @@ -369,10 +370,10 @@ public function handlePagesaveBefore(Doku_Event $event, $param) /** * called for event SEARCH_RESULT_PAGELOOKUP * - * @param Doku_Event $event + * @param Event $event * @param $param */ - public function addIconToPageLookupResult(Doku_Event $event, $param) + public function addIconToPageLookupResult(Event $event, $param) { /* @var \helper_plugin_watchcycle $helper */ $helper = plugin_load('helper', 'watchcycle'); @@ -386,10 +387,10 @@ public function addIconToPageLookupResult(Doku_Event $event, $param) /** * called for event SEARCH_RESULT_FULLPAGE * - * @param Doku_Event $event + * @param Event $event * @param $param */ - public function addIconToFullPageResult(Doku_Event $event, $param) + public function addIconToFullPageResult(Event $event, $param) { /* @var \helper_plugin_watchcycle $helper */ $helper = plugin_load('helper', 'watchcycle'); diff --git a/admin.php b/admin.php index f81855c..2cb7c47 100644 --- a/admin.php +++ b/admin.php @@ -1,5 +1,6 @@ */ -class admin_plugin_watchcycle extends DokuWiki_Admin_Plugin +class admin_plugin_watchcycle extends AdminPlugin { /** * @return int sort number in admin menu @@ -48,8 +49,7 @@ public function html() /** @var \helper_plugin_watchcycle_db $dbHelper */ $dbHelper = plugin_load('helper', 'watchcycle_db'); - /** @var SQLiteDB */ - $sqlite = $dbHelper->getDB(); + $dbHelper->getDB(); echo '

' . $this->getLang('menu') . '

'; @@ -58,6 +58,7 @@ public function html() $form = new Form(); $filter_input = new InputElement('text', 'filter'); $filter_input->attr('placeholder', $this->getLang('search page')); + $form->addElement($filter_input); $form->addButton('', $this->getLang('btn filter')); diff --git a/helper.php b/helper.php index 56ff147..3ad50d8 100644 --- a/helper.php +++ b/helper.php @@ -1,13 +1,14 @@ */ - -class helper_plugin_watchcycle extends DokuWiki_Plugin +class helper_plugin_watchcycle extends Plugin { public const MAINTAINERS_RAW = 0; public const MAINTAINERS_FLAT = 1; @@ -94,13 +95,11 @@ public function validateMaintainerString($def) $item = trim($item); if (strpos($item, '@') !== false) { // check if group exists - if (empty($auth->retrieveUsers(0, 1, array('grps' => ltrim($item, '@'))))) { - return false; - } - } else { - if ($auth->getUserData($item) === false) { + if (empty($auth->retrieveUsers(0, 1, ['grps' => ltrim($item, '@')]))) { return false; } + } elseif ($auth->getUserData($item) === false) { + return false; } } return true; @@ -147,7 +146,7 @@ public function getMaintainerMails($def) { /* @var \dokuwiki\Extension\AuthPlugin $auth */ global $auth; - $auth = $auth ?? auth_setup(); + $auth ??= auth_setup(); if (!$auth) return []; $data = $this->getMaintainers($def); @@ -156,7 +155,7 @@ public function getMaintainerMails($def) if (is_array($info)) { $mails[] = $info['mail']; } elseif ($name[0] === '@' && $auth->canDo('getUsers')) { - $members = $auth->retrieveUsers(0, 0, array('grps' => ltrim($name, '@'))); + $members = $auth->retrieveUsers(0, 0, ['grps' => ltrim($name, '@')]); foreach ($members as $user) { $mails[] = $user['mail']; } @@ -217,6 +216,7 @@ protected function sendMail($mail, $page) $mailer = new Mailer(); $mailer->to($mail); $mailer->subject($this->getLang('mail subject')); + $text = sprintf($this->getLang('mail body'), $page); $link = '' . $page . ''; $html = sprintf($this->getLang('mail body'), $link); @@ -238,9 +238,7 @@ protected function flattenMaintainers($all) return $all; } - $users = array_map(function ($user) { - return $user['name']; - }, $all['users']); + $users = array_map(static fn($user) => $user['name'], $all['users']); return array_merge($users, $all['groups']); } @@ -261,9 +259,9 @@ protected function expandMaintainers($all) global $auth; if ($auth === null) return []; - $members = array(); + $members = []; foreach ($all['groups'] as $group) { - $members = array_merge($members, $auth->retrieveUsers(0, 0, array('grps' => ltrim($group, '@')))); + $members = array_merge($members, $auth->retrieveUsers(0, 0, ['grps' => ltrim($group, '@')])); } // merge eliminates any duplicates since we use string keys diff --git a/helper/db.php b/helper/db.php index 27655ca..b1691fb 100644 --- a/helper/db.php +++ b/helper/db.php @@ -42,20 +42,6 @@ protected function init() */ public function getDB($throw = true) { - if (!$this->sqlite instanceof SQLiteDB) { - if (!class_exists(SQLiteDB::class)) { - if ($throw || defined('DOKU_UNITTEST')) throw new Exception('no sqlite'); - return null; - } - - try { - $this->init(); - } catch (\Exception $exception) { - ErrorHandler::logException($exception); - if ($throw) throw $exception; - return null; - } - } return $this->sqlite; } @@ -78,7 +64,7 @@ public function getAll(array $headers = []) $where[] = 'uptodate=0'; } - if (count($where) > 0) { + if ($where !== []) { $q .= ' WHERE '; $q .= implode(' AND ', $where); } diff --git a/syntax.php b/syntax.php index 9b26319..1179660 100644 --- a/syntax.php +++ b/syntax.php @@ -65,7 +65,7 @@ public function handle($match, $state, $pos, Doku_Handler $handler) $match = substr($match, strlen('~~WATCHCYCLE:'), strlen($match) - 2); - list($maintainer, $cycle) = array_map('trim', explode(':', $match)); + [$maintainer, $cycle] = array_map('trim', explode(':', $match)); /* @var \helper_plugin_watchcycle $helper */ $helper = plugin_load('helper', 'watchcycle'); @@ -187,7 +187,7 @@ protected function getMaintainerHtml($def) $helper = plugin_load('helper', 'watchcycle'); $all = $helper->getMaintainers($def); - $flat = array(); + $flat = []; foreach ($all as $name => $info) { if (is_array($info)) { $flat[] = $this->email($info['mail'], $info['name']);