diff options
Diffstat (limited to 'inc/Extension')
-rw-r--r-- | inc/Extension/ActionPlugin.php | 5 | ||||
-rw-r--r-- | inc/Extension/AdminPlugin.php | 10 | ||||
-rw-r--r-- | inc/Extension/AuthPlugin.php | 22 | ||||
-rw-r--r-- | inc/Extension/CLIPlugin.php | 4 | ||||
-rw-r--r-- | inc/Extension/Event.php | 7 | ||||
-rw-r--r-- | inc/Extension/EventHandler.php | 10 | ||||
-rw-r--r-- | inc/Extension/PluginController.php | 54 | ||||
-rw-r--r-- | inc/Extension/PluginInterface.php | 3 | ||||
-rw-r--r-- | inc/Extension/PluginTrait.php | 28 | ||||
-rw-r--r-- | inc/Extension/RemotePlugin.php | 16 | ||||
-rw-r--r-- | inc/Extension/SyntaxPlugin.php | 7 |
11 files changed, 76 insertions, 90 deletions
diff --git a/inc/Extension/ActionPlugin.php b/inc/Extension/ActionPlugin.php index ed6d82038..7fbd6f7f2 100644 --- a/inc/Extension/ActionPlugin.php +++ b/inc/Extension/ActionPlugin.php @@ -12,11 +12,10 @@ namespace dokuwiki\Extension; */ abstract class ActionPlugin extends Plugin { - /** * Registers a callback function for a given event * - * @param \Doku_Event_Handler $controller + * @param EventHandler $controller */ - abstract public function register(\Doku_Event_Handler $controller); + abstract public function register(EventHandler $controller); } diff --git a/inc/Extension/AdminPlugin.php b/inc/Extension/AdminPlugin.php index 7900a1ec4..099a83623 100644 --- a/inc/Extension/AdminPlugin.php +++ b/inc/Extension/AdminPlugin.php @@ -12,7 +12,6 @@ namespace dokuwiki\Extension; */ abstract class AdminPlugin extends Plugin { - /** * Return the text that is displayed at the main admin menu * (Default localized language string 'menu' is returned, override this function for setting another name) @@ -78,13 +77,14 @@ abstract class AdminPlugin extends Plugin * * @return bool true if the current user may access this admin plugin */ - public function isAccessibleByCurrentUser() { + public function isAccessibleByCurrentUser() + { $data = []; $data['instance'] = $this; $data['hasAccess'] = false; $event = new Event('ADMINPLUGIN_ACCESS_CHECK', $data); - if($event->advise_before()) { + if ($event->advise_before()) { if ($this->forAdminOnly()) { $data['hasAccess'] = auth_isadmin(); } else { @@ -116,8 +116,6 @@ abstract class AdminPlugin extends Plugin */ public function getTOC() { - return array(); + return []; } - } - diff --git a/inc/Extension/AuthPlugin.php b/inc/Extension/AuthPlugin.php index 4b75fba95..4e889f90c 100644 --- a/inc/Extension/AuthPlugin.php +++ b/inc/Extension/AuthPlugin.php @@ -20,7 +20,7 @@ abstract class AuthPlugin extends Plugin * do. The things a backend can do need to be set to true * in the constructor. */ - protected $cando = array( + protected $cando = [ 'addUser' => false, // can Users be created? 'delUser' => false, // can Users be deleted? 'modLogin' => false, // can login names be changed? @@ -33,7 +33,7 @@ abstract class AuthPlugin extends Plugin 'getGroups' => false, // can a list of available groups be retrieved? 'external' => false, // does the module do external auth checking? 'logout' => true, // can the user logout again? (eg. not possible with HTTP auth) - ); + ]; /** * Constructor. @@ -90,7 +90,6 @@ abstract class AuthPlugin extends Plugin return ($this->cando['modPass'] || $this->cando['modName'] || $this->cando['modMail']); - break; case 'UserMod': // can at least anything be changed? return ($this->cando['modPass'] || @@ -99,7 +98,6 @@ abstract class AuthPlugin extends Plugin $this->cando['modLogin'] || $this->cando['modGroups'] || $this->cando['modMail']); - break; default: // print a helping message for developers if (!isset($this->cando[$cap])) { @@ -124,20 +122,20 @@ abstract class AuthPlugin extends Plugin */ public function triggerUserMod($type, $params) { - $validTypes = array( + $validTypes = [ 'create' => 'createUser', 'modify' => 'modifyUser', - 'delete' => 'deleteUsers', - ); + 'delete' => 'deleteUsers' + ]; if (empty($validTypes[$type])) { return false; } $result = false; - $eventdata = array('type' => $type, 'params' => $params, 'modification_result' => null); + $eventdata = ['type' => $type, 'params' => $params, 'modification_result' => null]; $evt = new Event('AUTH_USER_CHANGE', $eventdata); if ($evt->advise_before(true)) { - $result = call_user_func_array(array($this, $validTypes[$type]), $evt->data['params']); + $result = call_user_func_array([$this, $validTypes[$type]], $evt->data['params']); $evt->data['modification_result'] = $result; } $evt->advise_after(); @@ -323,7 +321,7 @@ abstract class AuthPlugin extends Plugin * @param array $filter array of field/pattern pairs, empty array for no filter * @return int */ - public function getUserCount($filter = array()) + public function getUserCount($filter = []) { msg("authorisation method does not provide user counts", -1); return 0; @@ -343,7 +341,7 @@ abstract class AuthPlugin extends Plugin public function retrieveUsers($start = 0, $limit = 0, $filter = null) { msg("authorisation method does not support mass retrieval of user data", -1); - return array(); + return []; } /** @@ -374,7 +372,7 @@ abstract class AuthPlugin extends Plugin public function retrieveGroups($start = 0, $limit = 0) { msg("authorisation method does not support group list retrieval", -1); - return array(); + return []; } /** diff --git a/inc/Extension/CLIPlugin.php b/inc/Extension/CLIPlugin.php index 8637ccf8c..e06e87d2c 100644 --- a/inc/Extension/CLIPlugin.php +++ b/inc/Extension/CLIPlugin.php @@ -2,12 +2,14 @@ namespace dokuwiki\Extension; +use splitbrain\phpcli\CLI; + /** * CLI plugin prototype * * Provides DokuWiki plugin functionality on top of php-cli */ -abstract class CLIPlugin extends \splitbrain\phpcli\CLI implements PluginInterface +abstract class CLIPlugin extends CLI implements PluginInterface { use PluginTrait; } diff --git a/inc/Extension/Event.php b/inc/Extension/Event.php index cc38f0f36..12c9753b8 100644 --- a/inc/Extension/Event.php +++ b/inc/Extension/Event.php @@ -1,4 +1,5 @@ <?php + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps namespace dokuwiki\Extension; @@ -13,13 +14,13 @@ class Event /** @var string READONLY event name, objects must register against this name to see the event */ public $name = ''; /** @var mixed|null READWRITE data relevant to the event, no standardised format, refer to event docs */ - public $data = null; + public $data; /** * @var mixed|null READWRITE the results of the event action, only relevant in "_AFTER" advise * event handlers may modify this if they are preventing the default action * to provide the after event handlers with event results */ - public $result = null; + public $result; /** @var bool READONLY if true, event handlers can prevent the events default action */ public $canPreventDefault = true; @@ -193,7 +194,7 @@ class Event * by default this is the return value of the default action however * it can be set or modified by event handler hooks */ - static public function createAndTrigger($name, &$data, $action = null, $canPreventDefault = true) + public static function createAndTrigger($name, &$data, $action = null, $canPreventDefault = true) { $evt = new Event($name, $data); return $evt->trigger($action, $canPreventDefault); diff --git a/inc/Extension/EventHandler.php b/inc/Extension/EventHandler.php index 33ae5e123..cc537d3c3 100644 --- a/inc/Extension/EventHandler.php +++ b/inc/Extension/EventHandler.php @@ -1,4 +1,5 @@ <?php + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps namespace dokuwiki\Extension; @@ -8,11 +9,10 @@ namespace dokuwiki\Extension; */ class EventHandler { - // public properties: none // private properties - protected $hooks = array(); // array of events and their registered handlers + protected $hooks = []; // array of events and their registered handlers /** * event_handler @@ -31,7 +31,7 @@ class EventHandler foreach ($pluginlist as $plugin_name) { $plugin = plugin_load('action', $plugin_name); - if ($plugin !== null) $plugin->register($this); + if ($plugin instanceof PluginInterface) $plugin->register($this); } } @@ -51,7 +51,7 @@ class EventHandler { $seq = (int)$seq; $doSort = !isset($this->hooks[$event . '_' . $advise][$seq]); - $this->hooks[$event . '_' . $advise][$seq][] = array($obj, $method, $param); + $this->hooks[$event . '_' . $advise][$seq][] = [$obj, $method, $param]; if ($doSort) { ksort($this->hooks[$event . '_' . $advise]); @@ -72,7 +72,7 @@ class EventHandler if (!empty($this->hooks[$evt_name])) { foreach ($this->hooks[$evt_name] as $sequenced_hooks) { foreach ($sequenced_hooks as $hook) { - list($obj, $method, $param) = $hook; + [$obj, $method, $param] = $hook; if ($obj === null) { $method($event, $param); diff --git a/inc/Extension/PluginController.php b/inc/Extension/PluginController.php index d53ea853e..dcdf29cd2 100644 --- a/inc/Extension/PluginController.php +++ b/inc/Extension/PluginController.php @@ -13,7 +13,7 @@ use dokuwiki\ErrorHandler; class PluginController { /** @var array the types of plugins DokuWiki supports */ - const PLUGIN_TYPES = ['auth', 'admin', 'syntax', 'action', 'renderer', 'helper', 'remote', 'cli']; + public const PLUGIN_TYPES = ['auth', 'admin', 'syntax', 'action', 'renderer', 'helper', 'remote', 'cli']; protected $listByType = []; /** @var array all installed plugins and their enabled state [plugin=>enabled] */ @@ -83,7 +83,7 @@ class PluginController //we keep all loaded plugins available in global scope for reuse global $DOKU_PLUGINS; - list($plugin, /* $component */) = $this->splitName($name); + [$plugin, /* component */ ] = $this->splitName($name); // check if disabled if (!$disabled && !$this->isEnabled($plugin)) { @@ -96,8 +96,7 @@ class PluginController //plugin already loaded? if (!empty($DOKU_PLUGINS[$type][$name])) { if ($new || !$DOKU_PLUGINS[$type][$name]->isSingleton()) { - - return class_exists($class, true) ? new $class : null; + return class_exists($class, true) ? new $class() : null; } return $DOKU_PLUGINS[$type][$name]; @@ -115,21 +114,19 @@ class PluginController hsc( $inf['base'] ) - ), -1 + ), + -1 ); } elseif (preg_match('/^' . DOKU_PLUGIN_NAME_REGEX . '$/', $plugin) !== 1) { - msg( - sprintf( - "Plugin name '%s' is not a valid plugin name, only the characters a-z ". - "and 0-9 are allowed. " . - 'Maybe the plugin has been installed in the wrong directory?', hsc($plugin) - ), -1 - ); + msg(sprintf( + 'Plugin name \'%s\' is not a valid plugin name, only the characters a-z and 0-9 are allowed. ' . + 'Maybe the plugin has been installed in the wrong directory?', + hsc($plugin) + ), -1); } return null; } - $DOKU_PLUGINS[$type][$name] = new $class; - + $DOKU_PLUGINS[$type][$name] = new $class(); } catch (\Throwable $e) { ErrorHandler::showExceptionMsg($e, sprintf('Failed to load plugin %s', $plugin)); return null; @@ -204,14 +201,13 @@ class PluginController protected function populateMasterList() { if ($dh = @opendir(DOKU_PLUGIN)) { - $all_plugins = array(); + $all_plugins = []; while (false !== ($plugin = readdir($dh))) { if ($plugin[0] === '.') continue; // skip hidden entries if (is_file(DOKU_PLUGIN . $plugin)) continue; // skip files, we're only interested in directories if (array_key_exists($plugin, $this->masterList) && $this->masterList[$plugin] == 0) { $all_plugins[$plugin] = 0; - } elseif (array_key_exists($plugin, $this->masterList) && $this->masterList[$plugin] == 1) { $all_plugins[$plugin] = 1; } else { @@ -234,7 +230,7 @@ class PluginController */ protected function checkRequire($files) { - $plugins = array(); + $plugins = []; foreach ($files as $file) { if (file_exists($file)) { include_once($file); @@ -297,7 +293,7 @@ class PluginController //gives us the ones we need to check and save $diffed_ones = array_diff_key($local_default, $this->pluginCascade['default']); //The ones which we are sure of (list of 0s not in default) - $sure_plugins = array_filter($diffed_ones, array($this, 'negate')); + $sure_plugins = array_filter($diffed_ones, [$this, 'negate']); //the ones in need of diff $conflicts = array_diff_key($local_default, $diffed_ones); //The final list @@ -311,20 +307,18 @@ class PluginController protected function loadConfig() { global $config_cascade; - foreach (array('default', 'protected') as $type) { + foreach (['default', 'protected'] as $type) { if (array_key_exists($type, $config_cascade['plugins'])) { $this->pluginCascade[$type] = $this->checkRequire($config_cascade['plugins'][$type]); } } $local = $config_cascade['plugins']['local']; $this->lastLocalConfigFile = array_pop($local); - $this->pluginCascade['local'] = $this->checkRequire(array($this->lastLocalConfigFile)); - if (is_array($local)) { - $this->pluginCascade['default'] = array_merge( - $this->pluginCascade['default'], - $this->checkRequire($local) - ); - } + $this->pluginCascade['local'] = $this->checkRequire([$this->lastLocalConfigFile]); + $this->pluginCascade['default'] = array_merge( + $this->pluginCascade['default'], + $this->checkRequire($local) + ); $this->masterList = array_merge( $this->pluginCascade['default'], $this->pluginCascade['local'], @@ -344,11 +338,10 @@ class PluginController { $master_list = $enabled ? array_keys(array_filter($this->masterList)) - : array_keys(array_filter($this->masterList, array($this, 'negate'))); - $plugins = array(); + : array_keys(array_filter($this->masterList, [$this, 'negate'])); + $plugins = []; foreach ($master_list as $plugin) { - if (file_exists(DOKU_PLUGIN . "$plugin/$type.php")) { $plugins[] = $plugin; continue; @@ -366,7 +359,6 @@ class PluginController closedir($dp); } } - }//foreach return $plugins; @@ -386,7 +378,7 @@ class PluginController return sexplode('_', $name, 2, ''); } - return array($name, ''); + return [$name, '']; } /** diff --git a/inc/Extension/PluginInterface.php b/inc/Extension/PluginInterface.php index f2dbe8626..b5ded25ee 100644 --- a/inc/Extension/PluginInterface.php +++ b/inc/Extension/PluginInterface.php @@ -157,6 +157,3 @@ interface PluginInterface */ public function isSingleton(); } - - - diff --git a/inc/Extension/PluginTrait.php b/inc/Extension/PluginTrait.php index 7f399df1a..96c25aeb7 100644 --- a/inc/Extension/PluginTrait.php +++ b/inc/Extension/PluginTrait.php @@ -7,11 +7,10 @@ namespace dokuwiki\Extension; */ trait PluginTrait { - protected $localised = false; // set to true by setupLocale() after loading language dependent strings - protected $lang = array(); // array to hold language dependent strings, best accessed via ->getLang() + protected $lang = []; // array to hold language dependent strings, best accessed via ->getLang() protected $configloaded = false; // set to true by loadConfig() after loading plugin configuration variables - protected $conf = array(); // array to hold plugin settings, best accessed via ->getConf() + protected $conf = []; // array to hold plugin settings, best accessed via ->getConf() /** * @see PluginInterface::getInfo() @@ -25,12 +24,13 @@ trait PluginTrait msg( 'getInfo() not implemented in ' . get_class($this) . ' and ' . $info . ' not found.<br />' . 'Verify you\'re running the latest version of the plugin. If the problem persists, send a ' . - 'bug report to the author of the ' . $parts[2] . ' plugin.', -1 + 'bug report to the author of the ' . $parts[2] . ' plugin.', + -1 ); - return array( + return [ 'date' => '0000-00-00', - 'name' => $parts[2] . ' plugin', - ); + 'name' => $parts[2] . ' plugin' + ]; } /** @@ -58,7 +58,7 @@ trait PluginTrait */ public function getPluginType() { - list($t) = explode('_', get_class($this), 2); + [$t] = explode('_', get_class($this), 2); return $t; } @@ -67,7 +67,7 @@ trait PluginTrait */ public function getPluginName() { - list(/* $t */, /* $p */, $n) = sexplode('_', get_class($this), 4, ''); + [/* t */, /* p */, $n] = sexplode('_', get_class($this), 4, ''); return $n; } @@ -76,7 +76,7 @@ trait PluginTrait */ public function getPluginComponent() { - list(/* $t */, /* $p */, /* $n */, $c) = sexplode('_', get_class($this), 4, ''); + [/* t */, /* p */, /* n */, $c] = sexplode('_', get_class($this), 4, ''); return $c; } @@ -90,7 +90,7 @@ trait PluginTrait { if (!$this->localised) $this->setupLocale(); - return (isset($this->lang[$id]) ? $this->lang[$id] : ''); + return ($this->lang[$id] ?? ''); } /** @@ -129,7 +129,7 @@ trait PluginTrait global $conf, $config_cascade; // definitely don't invoke "global $lang" $path = DOKU_PLUGIN . $this->getPluginName() . '/lang/'; - $lang = array(); + $lang = []; // don't include once, in case several plugin components require the same language file @include($path . 'en/lang.php'); @@ -201,7 +201,7 @@ trait PluginTrait { $path = DOKU_PLUGIN . $this->getPluginName() . '/conf/'; - $conf = array(); + $conf = []; if (file_exists($path . 'default.php')) { include($path . 'default.php'); @@ -221,7 +221,7 @@ trait PluginTrait if (!$email) return $name; $email = obfuscate($email); if (!$name) $name = $email; - $class = "class='" . ($class ? $class : 'mail') . "'"; + $class = "class='" . ($class ?: 'mail') . "'"; return "<a href='mailto:$email' $class title='$email' $more>$name</a>"; } diff --git a/inc/Extension/RemotePlugin.php b/inc/Extension/RemotePlugin.php index 33bca980a..985aa91c9 100644 --- a/inc/Extension/RemotePlugin.php +++ b/inc/Extension/RemotePlugin.php @@ -13,8 +13,7 @@ use ReflectionMethod; */ abstract class RemotePlugin extends Plugin { - - private $api; + private Api $api; /** * Constructor @@ -35,7 +34,7 @@ abstract class RemotePlugin extends Plugin */ public function _getMethods() { - $result = array(); + $result = []; $reflection = new \ReflectionClass($this); foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { @@ -52,17 +51,17 @@ abstract class RemotePlugin extends Plugin // strip asterisks $doc = $method->getDocComment(); $doc = preg_replace( - array('/^[ \t]*\/\*+[ \t]*/m', '/[ \t]*\*+[ \t]*/m', '/\*+\/\s*$/m', '/\s*\/\s*$/m'), - array('', '', '', ''), + ['/^[ \t]*\/\*+[ \t]*/m', '/[ \t]*\*+[ \t]*/m', '/\*+\/\s*$/m', '/\s*\/\s*$/m'], + ['', '', '', ''], $doc ); // prepare data - $data = array(); + $data = []; $data['name'] = $method_name; $data['public'] = 0; $data['doc'] = $doc; - $data['args'] = array(); + $data['args'] = []; // get parameter type from doc block type hint foreach ($method->getParameters() as $parameter) { @@ -104,7 +103,7 @@ abstract class RemotePlugin extends Plugin if ($t === 'boolean') { return 'bool'; } - if (in_array($t, array('array', 'string', 'int', 'double', 'bool', 'null', 'date', 'file'))) { + if (in_array($t, ['array', 'string', 'int', 'double', 'bool', 'null', 'date', 'file'])) { return $t; } } @@ -118,5 +117,4 @@ abstract class RemotePlugin extends Plugin { return $this->api; } - } diff --git a/inc/Extension/SyntaxPlugin.php b/inc/Extension/SyntaxPlugin.php index ea8f51b4d..d590b04e4 100644 --- a/inc/Extension/SyntaxPlugin.php +++ b/inc/Extension/SyntaxPlugin.php @@ -2,6 +2,7 @@ namespace dokuwiki\Extension; +use dokuwiki\Parsing\ParserMode\Plugin; use Doku_Handler; use Doku_Renderer; @@ -14,7 +15,7 @@ use Doku_Renderer; * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Andreas Gohr <andi@splitbrain.org> */ -abstract class SyntaxPlugin extends \dokuwiki\Parsing\ParserMode\Plugin +abstract class SyntaxPlugin extends Plugin { use PluginTrait; @@ -40,7 +41,7 @@ abstract class SyntaxPlugin extends \dokuwiki\Parsing\ParserMode\Plugin */ public function getAllowedTypes() { - return array(); + return []; } /** @@ -120,7 +121,7 @@ abstract class SyntaxPlugin extends \dokuwiki\Parsing\ParserMode\Plugin $this->allowedModes = array_merge($this->allowedModes, $PARSER_MODES[$mt]); } - $idx = array_search(substr(get_class($this), 7), (array)$this->allowedModes); + $idx = array_search(substr(get_class($this), 7), (array)$this->allowedModes, true); if ($idx !== false) { unset($this->allowedModes[$idx]); } |