Skip to content

Commit

Permalink
🤖 Automatic code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
annda authored and github-actions[bot] committed Oct 10, 2024
1 parent 687bfce commit 92c202a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 70 deletions.
73 changes: 37 additions & 36 deletions action.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
use dokuwiki\Form\Form;
use dokuwiki\ChangeLog\PageChangeLog;
use dokuwiki\plugin\sqlite\SQLiteDB;

/**
Expand All @@ -9,16 +14,16 @@
* @author Szymon Olewniczak <dokuwiki@cosmocode.de>
*/

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');
Expand All @@ -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',
Expand All @@ -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;
Expand All @@ -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');
Expand All @@ -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')) {
Expand All @@ -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;

Expand Down Expand Up @@ -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));
}
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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)
Expand Down Expand Up @@ -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'];
Expand All @@ -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');
Expand All @@ -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;
Expand All @@ -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');
Expand All @@ -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');
Expand Down
7 changes: 4 additions & 3 deletions admin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use dokuwiki\Extension\AdminPlugin;
use dokuwiki\Form\Form;
use dokuwiki\Form\InputElement;
use dokuwiki\plugin\sqlite\SQLiteDB;
Expand All @@ -11,7 +12,7 @@
* @author Szymon Olewniczak <dokuwiki@cosmocode.de>
*/

class admin_plugin_watchcycle extends DokuWiki_Admin_Plugin
class admin_plugin_watchcycle extends AdminPlugin
{
/**
* @return int sort number in admin menu
Expand Down Expand Up @@ -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 '<h1>' . $this->getLang('menu') . '</h1>';

Expand All @@ -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'));
Expand Down
26 changes: 12 additions & 14 deletions helper.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

use dokuwiki\Extension\Plugin;

/**
* DokuWiki Plugin struct (Helper Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Szymon Olewniczak <dokuwiki@cosmocode.de>
*/

class helper_plugin_watchcycle extends DokuWiki_Plugin
class helper_plugin_watchcycle extends Plugin
{
public const MAINTAINERS_RAW = 0;
public const MAINTAINERS_FLAT = 1;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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'];
}
Expand Down Expand Up @@ -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 = '<a href="' . wl($page, '', true) . '">' . $page . '</a>';
$html = sprintf($this->getLang('mail body'), $link);
Expand All @@ -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']);
}
Expand All @@ -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
Expand Down
16 changes: 1 addition & 15 deletions helper/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -78,7 +64,7 @@ public function getAll(array $headers = [])
$where[] = 'uptodate=0';
}

if (count($where) > 0) {
if ($where !== []) {
$q .= ' WHERE ';
$q .= implode(' AND ', $where);
}
Expand Down
Loading

0 comments on commit 92c202a

Please sign in to comment.