aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/plugins/config/core
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plugins/config/core')
-rw-r--r--lib/plugins/config/core/ConfigParser.php33
-rw-r--r--lib/plugins/config/core/Configuration.php85
-rw-r--r--lib/plugins/config/core/Loader.php74
-rw-r--r--lib/plugins/config/core/Setting/Setting.php118
-rw-r--r--lib/plugins/config/core/Setting/SettingArray.php40
-rw-r--r--lib/plugins/config/core/Setting/SettingAuthtype.php20
-rw-r--r--lib/plugins/config/core/Setting/SettingCompression.php13
-rw-r--r--lib/plugins/config/core/Setting/SettingDirchoice.php19
-rw-r--r--lib/plugins/config/core/Setting/SettingDisableactions.php11
-rw-r--r--lib/plugins/config/core/Setting/SettingEmail.php26
-rw-r--r--lib/plugins/config/core/Setting/SettingFieldset.php8
-rw-r--r--lib/plugins/config/core/Setting/SettingHidden.php3
-rw-r--r--lib/plugins/config/core/Setting/SettingImConvert.php13
-rw-r--r--lib/plugins/config/core/Setting/SettingLicense.php11
-rw-r--r--lib/plugins/config/core/Setting/SettingMulticheckbox.php87
-rw-r--r--lib/plugins/config/core/Setting/SettingMultichoice.php33
-rw-r--r--lib/plugins/config/core/Setting/SettingNoClass.php3
-rw-r--r--lib/plugins/config/core/Setting/SettingNoDefault.php3
-rw-r--r--lib/plugins/config/core/Setting/SettingNoKnownClass.php3
-rw-r--r--lib/plugins/config/core/Setting/SettingNumeric.php25
-rw-r--r--lib/plugins/config/core/Setting/SettingNumericopt.php12
-rw-r--r--lib/plugins/config/core/Setting/SettingOnoff.php33
-rw-r--r--lib/plugins/config/core/Setting/SettingPassword.php18
-rw-r--r--lib/plugins/config/core/Setting/SettingRegex.php11
-rw-r--r--lib/plugins/config/core/Setting/SettingRenderer.php24
-rw-r--r--lib/plugins/config/core/Setting/SettingSavedir.php13
-rw-r--r--lib/plugins/config/core/Setting/SettingSepchar.php9
-rw-r--r--lib/plugins/config/core/Setting/SettingString.php18
-rw-r--r--lib/plugins/config/core/Setting/SettingUndefined.php25
-rw-r--r--lib/plugins/config/core/Writer.php62
30 files changed, 470 insertions, 383 deletions
diff --git a/lib/plugins/config/core/ConfigParser.php b/lib/plugins/config/core/ConfigParser.php
index fd9ff2ec6..aae44d983 100644
--- a/lib/plugins/config/core/ConfigParser.php
+++ b/lib/plugins/config/core/ConfigParser.php
@@ -10,7 +10,8 @@ namespace dokuwiki\plugin\config\core;
*
* @author Chris Smith <chris@jalakai.co.uk>
*/
-class ConfigParser {
+class ConfigParser
+{
/** @var string variable to parse from the file */
protected $varname = 'conf';
/** @var string the key to mark sub arrays */
@@ -24,36 +25,38 @@ class ConfigParser {
* @param string $file
* @return array
*/
- public function parse($file) {
- if(!file_exists($file)) return array();
+ public function parse($file)
+ {
+ if (!file_exists($file)) return [];
- $config = array();
+ $config = [];
$contents = @php_strip_whitespace($file);
// fallback to simply including the file #3271
- if($contents === null) {
+ if ($contents === null) {
$conf = [];
include $file;
return $conf;
}
$pattern = '/\$' . $this->varname . '\[[\'"]([^=]+)[\'"]\] ?= ?(.*?);(?=[^;]*(?:\$' . $this->varname . '|$))/s';
- $matches = array();
+ $matches = [];
preg_match_all($pattern, $contents, $matches, PREG_SET_ORDER);
+ $counter = count($matches);
- for($i = 0; $i < count($matches); $i++) {
+ for ($i = 0; $i < $counter; $i++) {
$value = $matches[$i][2];
// merge multi-dimensional array indices using the keymarker
$key = preg_replace('/.\]\[./', $this->keymarker, $matches[$i][1]);
// handle arrays
- if(preg_match('/^array ?\((.*)\)/', $value, $match)) {
+ if (preg_match('/^array ?\((.*)\)/', $value, $match)) {
$arr = explode(',', $match[1]);
// remove quotes from quoted strings & unescape escaped data
$len = count($arr);
- for($j = 0; $j < $len; $j++) {
+ for ($j = 0; $j < $len; $j++) {
$arr[$j] = trim($arr[$j]);
$arr[$j] = $this->readValue($arr[$j]);
}
@@ -75,17 +78,18 @@ class ConfigParser {
* @param string $value
* @return bool|string
*/
- protected function readValue($value) {
+ protected function readValue($value)
+ {
$removequotes_pattern = '/^(\'|")(.*)(?<!\\\\)\1$/s';
- $unescape_pairs = array(
+ $unescape_pairs = [
'\\\\' => '\\',
'\\\'' => '\'',
'\\"' => '"'
- );
+ ];
- if($value == 'true') {
+ if ($value == 'true') {
$value = true;
- } elseif($value == 'false') {
+ } elseif ($value == 'false') {
$value = false;
} else {
// remove quotes from quoted strings & unescape escaped data
@@ -94,5 +98,4 @@ class ConfigParser {
}
return $value;
}
-
}
diff --git a/lib/plugins/config/core/Configuration.php b/lib/plugins/config/core/Configuration.php
index c58645c5b..d2c63e3d4 100644
--- a/lib/plugins/config/core/Configuration.php
+++ b/lib/plugins/config/core/Configuration.php
@@ -15,14 +15,14 @@ use dokuwiki\plugin\config\core\Setting\SettingUndefined;
* @author Ben Coburn <btcoburn@silicodon.net>
* @author Andreas Gohr <andi@splitbrain.org>
*/
-class Configuration {
-
- const KEYMARKER = '____';
+class Configuration
+{
+ public const KEYMARKER = '____';
/** @var Setting[] metadata as array of Settings objects */
- protected $settings = array();
+ protected $settings = [];
/** @var Setting[] undefined and problematic settings */
- protected $undefined = array();
+ protected $undefined = [];
/** @var array all metadata */
protected $metadata;
@@ -44,7 +44,8 @@ class Configuration {
/**
* ConfigSettings constructor.
*/
- public function __construct() {
+ public function __construct()
+ {
$this->loader = new Loader(new ConfigParser());
$this->writer = new Writer();
@@ -61,7 +62,8 @@ class Configuration {
*
* @return Setting[]
*/
- public function getSettings() {
+ public function getSettings()
+ {
return $this->settings;
}
@@ -70,7 +72,8 @@ class Configuration {
*
* @return Setting[]
*/
- public function getUndefined() {
+ public function getUndefined()
+ {
return $this->undefined;
}
@@ -79,7 +82,8 @@ class Configuration {
*
* @return bool
*/
- public function hasChanged() {
+ public function hasChanged()
+ {
return $this->changed;
}
@@ -88,7 +92,8 @@ class Configuration {
*
* @return bool
*/
- public function isLocked() {
+ public function isLocked()
+ {
return $this->writer->isLocked();
}
@@ -98,15 +103,16 @@ class Configuration {
* @param array $input as posted
* @return bool true if all updates went through, false on errors
*/
- public function updateSettings($input) {
+ public function updateSettings($input)
+ {
$ok = true;
- foreach($this->settings as $key => $obj) {
- $value = isset($input[$key]) ? $input[$key] : null;
- if($obj->update($value)) {
+ foreach ($this->settings as $key => $obj) {
+ $value = $input[$key] ?? null;
+ if ($obj->update($value)) {
$this->changed = true;
}
- if($obj->hasError()) $ok = false;
+ if ($obj->hasError()) $ok = false;
}
return $ok;
@@ -120,7 +126,8 @@ class Configuration {
*
* @throws \Exception
*/
- public function save() {
+ public function save()
+ {
// only save the undefined settings that have not been handled in settings
$undefined = array_diff_key($this->undefined, $this->settings);
$this->writer->save(array_merge($this->settings, $undefined));
@@ -131,7 +138,8 @@ class Configuration {
*
* @throws \Exception
*/
- public function touch() {
+ public function touch()
+ {
$this->writer->touch();
}
@@ -140,32 +148,34 @@ class Configuration {
*
* @return array
*/
- public function getLangs() {
+ public function getLangs()
+ {
return $this->loader->loadLangs();
}
/**
* Initalizes the $settings and $undefined properties
*/
- protected function initSettings() {
- $keys = array_merge(
- array_keys($this->metadata),
- array_keys($this->default),
- array_keys($this->local),
- array_keys($this->protected)
- );
+ protected function initSettings()
+ {
+ $keys = [
+ ...array_keys($this->metadata),
+ ...array_keys($this->default),
+ ...array_keys($this->local),
+ ...array_keys($this->protected)
+ ];
$keys = array_unique($keys);
- foreach($keys as $key) {
+ foreach ($keys as $key) {
$obj = $this->instantiateClass($key);
- if($obj->shouldHaveDefault() && !isset($this->default[$key])) {
+ if ($obj->shouldHaveDefault() && !isset($this->default[$key])) {
$this->undefined[$key] = new SettingNoDefault($key);
}
- $d = isset($this->default[$key]) ? $this->default[$key] : null;
- $l = isset($this->local[$key]) ? $this->local[$key] : null;
- $p = isset($this->protected[$key]) ? $this->protected[$key] : null;
+ $d = $this->default[$key] ?? null;
+ $l = $this->local[$key] ?? null;
+ $p = $this->protected[$key] ?? null;
$obj->initialize($d, $l, $p);
}
@@ -179,8 +189,9 @@ class Configuration {
* @param string $key
* @return Setting
*/
- protected function instantiateClass($key) {
- if(isset($this->metadata[$key])) {
+ protected function instantiateClass($key)
+ {
+ if (isset($this->metadata[$key])) {
$param = $this->metadata[$key];
$class = $this->determineClassName(array_shift($param), $key); // first param is class
$obj = new $class($key, $param);
@@ -199,14 +210,15 @@ class Configuration {
* @param string $key the settings key
* @return string
*/
- protected function determineClassName($class, $key) {
+ protected function determineClassName($class, $key)
+ {
// try namespaced class first
- if(is_string($class)) {
+ if (is_string($class)) {
$modern = str_replace('_', '', ucwords($class, '_'));
$modern = '\\dokuwiki\\plugin\\config\\core\\Setting\\Setting' . $modern;
- if($modern && class_exists($modern)) return $modern;
+ if ($modern && class_exists($modern)) return $modern;
// try class as given
- if(class_exists($class)) return $class;
+ if (class_exists($class)) return $class;
// class wasn't found add to errors
$this->undefined[$key] = new SettingNoKnownClass($key);
} else {
@@ -215,5 +227,4 @@ class Configuration {
}
return '\\dokuwiki\\plugin\\config\\core\\Setting\\Setting';
}
-
}
diff --git a/lib/plugins/config/core/Loader.php b/lib/plugins/config/core/Loader.php
index e4d7b50af..c9dbec95d 100644
--- a/lib/plugins/config/core/Loader.php
+++ b/lib/plugins/config/core/Loader.php
@@ -10,7 +10,8 @@ use dokuwiki\Extension\Event;
* Loads configuration meta data and settings from the various files. Honors the
* configuration cascade and installed plugins.
*/
-class Loader {
+class Loader
+{
/** @var ConfigParser */
protected $parser;
@@ -24,7 +25,8 @@ class Loader {
* @param ConfigParser $parser
* @triggers PLUGIN_CONFIG_PLUGINLIST
*/
- public function __construct(ConfigParser $parser) {
+ public function __construct(ConfigParser $parser)
+ {
global $conf;
$this->parser = $parser;
$this->plugins = plugin_list();
@@ -40,13 +42,14 @@ class Loader {
*
* @return array
*/
- public function loadMeta() {
+ public function loadMeta()
+ {
// load main file
- $meta = array();
+ $meta = [];
include DOKU_PLUGIN . 'config/settings/config.metadata.php';
// plugins
- foreach($this->plugins as $plugin) {
+ foreach ($this->plugins as $plugin) {
$meta = array_merge(
$meta,
$this->loadExtensionMeta(
@@ -81,7 +84,7 @@ class Loader {
{
// initialize array
- $conf = array();
+ $conf = [];
// plugins
foreach ($this->plugins as $plugin) {
@@ -120,11 +123,12 @@ class Loader {
*
* @return array
*/
- public function loadLangs() {
- $lang = array();
+ public function loadLangs()
+ {
+ $lang = [];
// plugins
- foreach($this->plugins as $plugin) {
+ foreach ($this->plugins as $plugin) {
$lang = array_merge(
$lang,
$this->loadExtensionLang(
@@ -153,7 +157,8 @@ class Loader {
*
* @return array
*/
- public function loadLocal() {
+ public function loadLocal()
+ {
global $config_cascade;
return $this->loadConfigs($config_cascade['main']['local']);
}
@@ -163,7 +168,8 @@ class Loader {
*
* @return array
*/
- public function loadProtected() {
+ public function loadProtected()
+ {
global $config_cascade;
return $this->loadConfigs($config_cascade['main']['protected']);
}
@@ -174,9 +180,10 @@ class Loader {
* @param string[] $files paths to config php's
* @return array
*/
- protected function loadConfigs($files) {
- $conf = array();
- foreach($files as $file) {
+ protected function loadConfigs($files)
+ {
+ $conf = [];
+ foreach ($files as $file) {
$conf = array_merge($conf, $this->parser->parse($file));
}
return $conf;
@@ -192,20 +199,21 @@ class Loader {
* @param string $extname name of the extension
* @return array
*/
- protected function loadExtensionMeta($file, $type, $extname) {
- if(!file_exists($file)) return array();
+ protected function loadExtensionMeta($file, $type, $extname)
+ {
+ if (!file_exists($file)) return [];
$prefix = $type . Configuration::KEYMARKER . $extname . Configuration::KEYMARKER;
// include file
- $meta = array();
+ $meta = [];
include $file;
- if(empty($meta)) return array();
+ if ($meta === []) return [];
// read data
- $data = array();
+ $data = [];
$data[$prefix . $type . '_settings_name'] = ['fieldset'];
- foreach($meta as $key => $value) {
- if($value[0] == 'fieldset') continue; //plugins only get one fieldset
+ foreach ($meta as $key => $value) {
+ if ($value[0] == 'fieldset') continue; //plugins only get one fieldset
$data[$prefix . $key] = $value;
}
@@ -222,17 +230,18 @@ class Loader {
* @param string $extname name of the extension
* @return array
*/
- protected function loadExtensionConf($file, $type, $extname) {
- if(!file_exists($file)) return array();
+ protected function loadExtensionConf($file, $type, $extname)
+ {
+ if (!file_exists($file)) return [];
$prefix = $type . Configuration::KEYMARKER . $extname . Configuration::KEYMARKER;
// parse file
$conf = $this->parser->parse($file);
- if(empty($conf)) return array();
+ if (empty($conf)) return [];
// read data
- $data = array();
- foreach($conf as $key => $value) {
+ $data = [];
+ foreach ($conf as $key => $value) {
$data[$prefix . $key] = $value;
}
@@ -247,23 +256,24 @@ class Loader {
* @param string $extname name of the extension
* @return array
*/
- protected function loadExtensionLang($dir, $type, $extname) {
+ protected function loadExtensionLang($dir, $type, $extname)
+ {
global $conf;
$ll = $conf['lang'];
$prefix = $type . Configuration::KEYMARKER . $extname . Configuration::KEYMARKER;
// include files
- $lang = array();
- if(file_exists($dir . 'lang/en/settings.php')) {
+ $lang = [];
+ if (file_exists($dir . 'lang/en/settings.php')) {
include $dir . 'lang/en/settings.php';
}
- if($ll != 'en' && file_exists($dir . 'lang/' . $ll . '/settings.php')) {
+ if ($ll != 'en' && file_exists($dir . 'lang/' . $ll . '/settings.php')) {
include $dir . 'lang/' . $ll . '/settings.php';
}
// set up correct keys
- $strings = array();
- foreach($lang as $key => $val) {
+ $strings = [];
+ foreach ($lang as $key => $val) {
$strings[$prefix . $key] = $val;
}
diff --git a/lib/plugins/config/core/Setting/Setting.php b/lib/plugins/config/core/Setting/Setting.php
index bbf048a85..cc22cf91a 100644
--- a/lib/plugins/config/core/Setting/Setting.php
+++ b/lib/plugins/config/core/Setting/Setting.php
@@ -7,24 +7,25 @@ use dokuwiki\plugin\config\core\Configuration;
/**
* Class Setting
*/
-class Setting {
+class Setting
+{
/** @var string unique identifier of this setting */
protected $key = '';
/** @var mixed the default value of this setting */
- protected $default = null;
+ protected $default;
/** @var mixed the local value of this setting */
- protected $local = null;
+ protected $local;
/** @var mixed the protected value of this setting */
- protected $protected = null;
+ protected $protected;
/** @var array valid alerts, images matching the alerts are in the plugin's images directory */
- static protected $validCautions = array('warning', 'danger', 'security');
+ protected static $validCautions = ['warning', 'danger', 'security'];
protected $pattern = '';
protected $error = false; // only used by those classes which error check
- protected $input = null; // only used by those classes which error check
- protected $caution = null; // used by any setting to provide an alert along with the setting
+ protected $input; // only used by those classes which error check
+ protected $caution; // used by any setting to provide an alert along with the setting
/**
* Constructor.
@@ -36,11 +37,12 @@ class Setting {
* @param string $key
* @param array|null $params array with metadata of setting
*/
- public function __construct($key, $params = null) {
+ public function __construct($key, $params = null)
+ {
$this->key = $key;
- if(is_array($params)) {
- foreach($params as $property => $value) {
+ if (is_array($params)) {
+ foreach ($params as $property => $value) {
$property = trim($property, '_'); // we don't use underscores anymore
$this->$property = $value;
}
@@ -57,7 +59,8 @@ class Setting {
* @param mixed $local local setting value
* @param mixed $protected protected setting value
*/
- public function initialize($default = null, $local = null, $protected = null) {
+ public function initialize($default = null, $local = null, $protected = null)
+ {
$this->default = $this->cleanValue($default);
$this->local = $this->cleanValue($local);
$this->protected = $this->cleanValue($protected);
@@ -71,16 +74,17 @@ class Setting {
* @param mixed $input the new value
* @return boolean true if changed, false otherwise
*/
- public function update($input) {
- if(is_null($input)) return false;
- if($this->isProtected()) return false;
+ public function update($input)
+ {
+ if (is_null($input)) return false;
+ if ($this->isProtected()) return false;
$input = $this->cleanValue($input);
$value = is_null($this->local) ? $this->default : $this->local;
- if($value == $input) return false;
+ if ($value == $input) return false;
// validate new value
- if($this->pattern && !preg_match($this->pattern, $input)) {
+ if ($this->pattern && !preg_match($this->pattern, $input)) {
$this->error = true;
$this->input = $input;
return false;
@@ -104,7 +108,8 @@ class Setting {
* @param mixed $value
* @return mixed
*/
- protected function cleanValue($value) {
+ protected function cleanValue($value)
+ {
return $value;
}
@@ -113,7 +118,8 @@ class Setting {
*
* @return bool
*/
- public function shouldHaveDefault() {
+ public function shouldHaveDefault()
+ {
return true;
}
@@ -122,7 +128,8 @@ class Setting {
*
* @return string
*/
- public function getKey() {
+ public function getKey()
+ {
return $this->key;
}
@@ -132,10 +139,11 @@ class Setting {
* @param bool $url link to dokuwiki.org manual?
* @return string
*/
- public function getPrettyKey($url = true) {
+ public function getPrettyKey($url = true)
+ {
$out = str_replace(Configuration::KEYMARKER, "»", $this->key);
- if($url && !strstr($out, '»')) {//provide no urls for plugins, etc.
- if($out == 'start') {
+ if ($url && !strstr($out, '»')) {//provide no urls for plugins, etc.
+ if ($out == 'start') {
// exception, because this config name is clashing with our actual start page
return '<a href="https://www.dokuwiki.org/config:startpage">' . $out . '</a>';
} else {
@@ -152,7 +160,8 @@ class Setting {
*
* @return string key
*/
- public function getArrayKey() {
+ public function getArrayKey()
+ {
return str_replace(Configuration::KEYMARKER, "']['", $this->key);
}
@@ -167,10 +176,11 @@ class Setting {
*
* @return string
*/
- public function getType() {
- if(substr($this->getKey(), 0, 10) == 'plugin' . Configuration::KEYMARKER) {
+ public function getType()
+ {
+ if (substr($this->getKey(), 0, 10) == 'plugin' . Configuration::KEYMARKER) {
return 'plugin';
- } else if(substr($this->getKey(), 0, 7) == 'tpl' . Configuration::KEYMARKER) {
+ } elseif (substr($this->getKey(), 0, 7) == 'tpl' . Configuration::KEYMARKER) {
return 'template';
} else {
return 'dokuwiki';
@@ -184,18 +194,17 @@ class Setting {
* @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting
* @return string[] with content array(string $label_html, string $input_html)
*/
- public function html(\admin_plugin_config $plugin, $echo = false) {
+ public function html(\admin_plugin_config $plugin, $echo = false)
+ {
$disable = '';
- if($this->isProtected()) {
+ if ($this->isProtected()) {
$value = $this->protected;
$disable = 'disabled="disabled"';
+ } elseif ($echo && $this->error) {
+ $value = $this->input;
} else {
- if($echo && $this->error) {
- $value = $this->input;
- } else {
- $value = is_null($this->local) ? $this->default : $this->local;
- }
+ $value = is_null($this->local) ? $this->default : $this->local;
}
$key = htmlspecialchars($this->key);
@@ -204,7 +213,7 @@ class Setting {
$label = '<label for="config___' . $key . '">' . $this->prompt($plugin) . '</label>';
$input = '<textarea rows="3" cols="40" id="config___' . $key .
'" name="config[' . $key . ']" class="edit" ' . $disable . '>' . $value . '</textarea>';
- return array($label, $input);
+ return [$label, $input];
}
/**
@@ -213,10 +222,11 @@ class Setting {
* @see out() to run when this returns true
* @return bool
*/
- public function shouldBeSaved() {
- if($this->isProtected()) return false;
- if($this->local === null) return false;
- if($this->default == $this->local) return false;
+ public function shouldBeSaved()
+ {
+ if ($this->isProtected()) return false;
+ if ($this->local === null) return false;
+ if ($this->default == $this->local) return false;
return true;
}
@@ -226,8 +236,9 @@ class Setting {
* @param string $string
* @return string
*/
- protected function escape($string) {
- $tr = array("\\" => '\\\\', "'" => '\\\'');
+ protected function escape($string)
+ {
+ $tr = ["\\" => '\\\\', "'" => '\\\''];
return "'" . strtr(cleanText($string), $tr) . "'";
}
@@ -239,11 +250,12 @@ class Setting {
* @param string $fmt save format
* @return string
*/
- public function out($var, $fmt = 'php') {
+ public function out($var, $fmt = 'php')
+ {
if ($fmt != 'php') return '';
if (is_array($this->local)) {
- $value = 'array(' . join(', ', array_map([$this, 'escape'], $this->local)) . ')';
+ $value = 'array(' . implode(', ', array_map([$this, 'escape'], $this->local)) . ')';
} else {
$value = $this->escape($this->local);
}
@@ -259,9 +271,10 @@ class Setting {
* @param \admin_plugin_config $plugin object of config plugin
* @return string text
*/
- public function prompt(\admin_plugin_config $plugin) {
+ public function prompt(\admin_plugin_config $plugin)
+ {
$prompt = $plugin->getLang($this->key);
- if(!$prompt) $prompt = htmlspecialchars(str_replace(array('____', '_'), ' ', $this->key));
+ if (!$prompt) $prompt = htmlspecialchars(str_replace(['____', '_'], ' ', $this->key));
return $prompt;
}
@@ -270,7 +283,8 @@ class Setting {
*
* @return bool
*/
- public function isProtected() {
+ public function isProtected()
+ {
return !is_null($this->protected);
}
@@ -279,7 +293,8 @@ class Setting {
*
* @return bool
*/
- public function isDefault() {
+ public function isDefault()
+ {
return !$this->isProtected() && is_null($this->local);
}
@@ -288,7 +303,8 @@ class Setting {
*
* @return bool
*/
- public function hasError() {
+ public function hasError()
+ {
return $this->error;
}
@@ -297,14 +313,14 @@ class Setting {
*
* @return false|string caution string, otherwise false for invalid caution
*/
- public function caution() {
- if(empty($this->caution)) return false;
- if(!in_array($this->caution, Setting::$validCautions)) {
+ public function caution()
+ {
+ if (empty($this->caution)) return false;
+ if (!in_array($this->caution, Setting::$validCautions)) {
throw new \RuntimeException(
'Invalid caution string (' . $this->caution . ') in metadata for setting "' . $this->key . '"'
);
}
return $this->caution;
}
-
}
diff --git a/lib/plugins/config/core/Setting/SettingArray.php b/lib/plugins/config/core/Setting/SettingArray.php
index 8dfda0dd6..bae9e87df 100644
--- a/lib/plugins/config/core/Setting/SettingArray.php
+++ b/lib/plugins/config/core/Setting/SettingArray.php
@@ -5,15 +5,16 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_array
*/
-class SettingArray extends Setting {
-
+class SettingArray extends Setting
+{
/**
* Create an array from a string
*
* @param string $string
* @return array
*/
- protected function fromString($string) {
+ protected function fromString($string)
+ {
$array = explode(',', $string);
$array = array_map('trim', $array);
$array = array_filter($array);
@@ -27,8 +28,9 @@ class SettingArray extends Setting {
* @param array $array
* @return string
*/
- protected function fromArray($array) {
- return join(', ', (array) $array);
+ protected function fromArray($array)
+ {
+ return implode(', ', (array) $array);
}
/**
@@ -38,17 +40,18 @@ class SettingArray extends Setting {
* @param string $input
* @return bool true if changed, false otherwise (incl. on error)
*/
- public function update($input) {
- if(is_null($input)) return false;
- if($this->isProtected()) return false;
+ public function update($input)
+ {
+ if (is_null($input)) return false;
+ if ($this->isProtected()) return false;
$input = $this->fromString($input);
$value = is_null($this->local) ? $this->default : $this->local;
- if($value == $input) return false;
+ if ($value == $input) return false;
- foreach($input as $item) {
- if($this->pattern && !preg_match($this->pattern, $item)) {
+ foreach ($input as $item) {
+ if ($this->pattern && !preg_match($this->pattern, $item)) {
$this->error = true;
$this->input = $input;
return false;
@@ -60,18 +63,17 @@ class SettingArray extends Setting {
}
/** @inheritdoc */
- public function html(\admin_plugin_config $plugin, $echo = false) {
+ public function html(\admin_plugin_config $plugin, $echo = false)
+ {
$disable = '';
- if($this->isProtected()) {
+ if ($this->isProtected()) {
$value = $this->protected;
$disable = 'disabled="disabled"';
+ } elseif ($echo && $this->error) {
+ $value = $this->input;
} else {
- if($echo && $this->error) {
- $value = $this->input;
- } else {
- $value = is_null($this->local) ? $this->default : $this->local;
- }
+ $value = is_null($this->local) ? $this->default : $this->local;
}
$key = htmlspecialchars($this->key);
@@ -80,6 +82,6 @@ class SettingArray extends Setting {
$label = '<label for="config___' . $key . '">' . $this->prompt($plugin) . '</label>';
$input = '<input id="config___' . $key . '" name="config[' . $key .
']" type="text" class="edit" value="' . $value . '" ' . $disable . '/>';
- return array($label, $input);
+ return [$label, $input];
}
}
diff --git a/lib/plugins/config/core/Setting/SettingAuthtype.php b/lib/plugins/config/core/Setting/SettingAuthtype.php
index 3a6df6fe5..1874db0a7 100644
--- a/lib/plugins/config/core/Setting/SettingAuthtype.php
+++ b/lib/plugins/config/core/Setting/SettingAuthtype.php
@@ -5,15 +5,16 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_authtype
*/
-class SettingAuthtype extends SettingMultichoice {
-
+class SettingAuthtype extends SettingMultichoice
+{
/** @inheritdoc */
- public function initialize($default = null, $local = null, $protected = null) {
+ public function initialize($default = null, $local = null, $protected = null)
+ {
/** @var $plugin_controller \dokuwiki\Extension\PluginController */
global $plugin_controller;
// retrieve auth types provided by plugins
- foreach($plugin_controller->getList('auth') as $plugin) {
+ foreach ($plugin_controller->getList('auth') as $plugin) {
$this->choices[] = $plugin;
}
@@ -21,27 +22,28 @@ class SettingAuthtype extends SettingMultichoice {
}
/** @inheritdoc */
- public function update($input) {
+ public function update($input)
+ {
/** @var $plugin_controller \dokuwiki\Extension\PluginController */
global $plugin_controller;
// is an update possible/requested?
$local = $this->local; // save this, parent::update() may change it
- if(!parent::update($input)) return false; // nothing changed or an error caught by parent
+ if (!parent::update($input)) return false; // nothing changed or an error caught by parent
$this->local = $local; // restore original, more error checking to come
// attempt to load the plugin
$auth_plugin = $plugin_controller->load('auth', $input);
// @TODO: throw an error in plugin controller instead of returning null
- if(is_null($auth_plugin)) {
+ if (is_null($auth_plugin)) {
$this->error = true;
msg('Cannot load Auth Plugin "' . $input . '"', -1);
return false;
}
// verify proper instantiation (is this really a plugin?) @TODO use instanceof? implement interface?
- if(is_object($auth_plugin) && !method_exists($auth_plugin, 'getPluginName')) {
+ if (is_object($auth_plugin) && !method_exists($auth_plugin, 'getPluginName')) {
$this->error = true;
msg('Cannot create Auth Plugin "' . $input . '"', -1);
return false;
@@ -49,7 +51,7 @@ class SettingAuthtype extends SettingMultichoice {
// did we change the auth type? logout
global $conf;
- if($conf['authtype'] != $input) {
+ if ($conf['authtype'] != $input) {
msg('Authentication system changed. Please re-login.');
auth_logoff();
}
diff --git a/lib/plugins/config/core/Setting/SettingCompression.php b/lib/plugins/config/core/Setting/SettingCompression.php
index f97d82801..f52405989 100644
--- a/lib/plugins/config/core/Setting/SettingCompression.php
+++ b/lib/plugins/config/core/Setting/SettingCompression.php
@@ -5,16 +5,17 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_compression
*/
-class SettingCompression extends SettingMultichoice {
-
- protected $choices = array('0'); // 0 = no compression, always supported
+class SettingCompression extends SettingMultichoice
+{
+ protected $choices = ['0']; // 0 = no compression, always supported
/** @inheritdoc */
- public function initialize($default = null, $local = null, $protected = null) {
+ public function initialize($default = null, $local = null, $protected = null)
+ {
// populate _choices with the compression methods supported by this php installation
- if(function_exists('gzopen')) $this->choices[] = 'gz';
- if(function_exists('bzopen')) $this->choices[] = 'bz2';
+ if (function_exists('gzopen')) $this->choices[] = 'gz';
+ if (function_exists('bzopen')) $this->choices[] = 'bz2';
parent::initialize($default, $local, $protected);
}
diff --git a/lib/plugins/config/core/Setting/SettingDirchoice.php b/lib/plugins/config/core/Setting/SettingDirchoice.php
index dfb27f5f4..a571149f0 100644
--- a/lib/plugins/config/core/Setting/SettingDirchoice.php
+++ b/lib/plugins/config/core/Setting/SettingDirchoice.php
@@ -5,23 +5,24 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_dirchoice
*/
-class SettingDirchoice extends SettingMultichoice {
-
+class SettingDirchoice extends SettingMultichoice
+{
protected $dir = '';
/** @inheritdoc */
- public function initialize($default = null, $local = null, $protected = null) {
+ public function initialize($default = null, $local = null, $protected = null)
+ {
// populate $this->_choices with a list of directories
- $list = array();
+ $list = [];
- if($dh = @opendir($this->dir)) {
- while(false !== ($entry = readdir($dh))) {
- if($entry == '.' || $entry == '..') continue;
- if($this->pattern && !preg_match($this->pattern, $entry)) continue;
+ if ($dh = @opendir($this->dir)) {
+ while (false !== ($entry = readdir($dh))) {
+ if ($entry == '.' || $entry == '..') continue;
+ if ($this->pattern && !preg_match($this->pattern, $entry)) continue;
$file = (is_link($this->dir . $entry)) ? readlink($this->dir . $entry) : $this->dir . $entry;
- if(is_dir($file)) $list[] = $entry;
+ if (is_dir($file)) $list[] = $entry;
}
closedir($dh);
}
diff --git a/lib/plugins/config/core/Setting/SettingDisableactions.php b/lib/plugins/config/core/Setting/SettingDisableactions.php
index 2553175bd..46427c457 100644
--- a/lib/plugins/config/core/Setting/SettingDisableactions.php
+++ b/lib/plugins/config/core/Setting/SettingDisableactions.php
@@ -5,17 +5,18 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_disableactions
*/
-class SettingDisableactions extends SettingMulticheckbox {
-
+class SettingDisableactions extends SettingMulticheckbox
+{
/** @inheritdoc */
- public function html(\admin_plugin_config $plugin, $echo = false) {
+ public function html(\admin_plugin_config $plugin, $echo = false)
+ {
global $lang;
// make some language adjustments (there must be a better way)
// transfer some DokuWiki language strings to the plugin
$plugin->addLang($this->key . '_revisions', $lang['btn_revs']);
- foreach($this->choices as $choice) {
- if(isset($lang['btn_' . $choice])) $plugin->addLang($this->key . '_' . $choice, $lang['btn_' . $choice]);
+ foreach ($this->choices as $choice) {
+ if (isset($lang['btn_' . $choice])) $plugin->addLang($this->key . '_' . $choice, $lang['btn_' . $choice]);
}
return parent::html($plugin, $echo);
diff --git a/lib/plugins/config/core/Setting/SettingEmail.php b/lib/plugins/config/core/Setting/SettingEmail.php
index 25a0c0e75..a1a2ab028 100644
--- a/lib/plugins/config/core/Setting/SettingEmail.php
+++ b/lib/plugins/config/core/Setting/SettingEmail.php
@@ -5,24 +5,26 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_email
*/
-class SettingEmail extends SettingString {
+class SettingEmail extends SettingString
+{
protected $multiple = false;
protected $placeholders = false;
/** @inheritdoc */
- public function update($input) {
- if(is_null($input)) return false;
- if($this->isProtected()) return false;
+ public function update($input)
+ {
+ if (is_null($input)) return false;
+ if ($this->isProtected()) return false;
$value = is_null($this->local) ? $this->default : $this->local;
- if($value == $input) return false;
- if($input === '') {
+ if ($value == $input) return false;
+ if ($input === '') {
$this->local = $input;
return true;
}
$mail = $input;
- if($this->placeholders) {
+ if ($this->placeholders) {
// replace variables with pseudo values
$mail = str_replace('@USER@', 'joe', $mail);
$mail = str_replace('@NAME@', 'Joe Schmoe', $mail);
@@ -30,22 +32,22 @@ class SettingEmail extends SettingString {
}
// multiple mail addresses?
- if($this->multiple) {
+ if ($this->multiple) {
$mails = array_filter(array_map('trim', explode(',', $mail)));
} else {
- $mails = array($mail);
+ $mails = [$mail];
}
// check them all
- foreach($mails as $mail) {
+ foreach ($mails as $mail) {
// only check the address part
- if(preg_match('#(.*?)<(.*?)>#', $mail, $matches)) {
+ if (preg_match('#(.*?)<(.*?)>#', $mail, $matches)) {
$addr = $matches[2];
} else {
$addr = $mail;
}
- if(!mail_isvalid($addr)) {
+ if (!mail_isvalid($addr)) {
$this->error = true;
$this->input = $input;
return false;
diff --git a/lib/plugins/config/core/Setting/SettingFieldset.php b/lib/plugins/config/core/Setting/SettingFieldset.php
index 4e8618967..3db2962cb 100644
--- a/lib/plugins/config/core/Setting/SettingFieldset.php
+++ b/lib/plugins/config/core/Setting/SettingFieldset.php
@@ -7,11 +7,11 @@ namespace dokuwiki\plugin\config\core\Setting;
*
* Used to start a new settings "display-group".
*/
-class SettingFieldset extends Setting {
-
+class SettingFieldset extends Setting
+{
/** @inheritdoc */
- public function shouldHaveDefault() {
+ public function shouldHaveDefault()
+ {
return false;
}
-
}
diff --git a/lib/plugins/config/core/Setting/SettingHidden.php b/lib/plugins/config/core/Setting/SettingHidden.php
index ca8a03eb9..11b800f84 100644
--- a/lib/plugins/config/core/Setting/SettingHidden.php
+++ b/lib/plugins/config/core/Setting/SettingHidden.php
@@ -5,6 +5,7 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_hidden
*/
-class SettingHidden extends Setting {
+class SettingHidden extends Setting
+{
// Used to explicitly ignore a setting in the configuration manager.
}
diff --git a/lib/plugins/config/core/Setting/SettingImConvert.php b/lib/plugins/config/core/Setting/SettingImConvert.php
index 8740d94c8..985372deb 100644
--- a/lib/plugins/config/core/Setting/SettingImConvert.php
+++ b/lib/plugins/config/core/Setting/SettingImConvert.php
@@ -5,18 +5,19 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_im_convert
*/
-class SettingImConvert extends SettingString {
-
+class SettingImConvert extends SettingString
+{
/** @inheritdoc */
- public function update($input) {
- if($this->isProtected()) return false;
+ public function update($input)
+ {
+ if ($this->isProtected()) return false;
$input = trim($input);
$value = is_null($this->local) ? $this->default : $this->local;
- if($value == $input) return false;
+ if ($value == $input) return false;
- if($input && !file_exists($input)) {
+ if ($input && !file_exists($input)) {
$this->error = true;
$this->input = $input;
return false;
diff --git a/lib/plugins/config/core/Setting/SettingLicense.php b/lib/plugins/config/core/Setting/SettingLicense.php
index 8dacf8e25..edd5a09e3 100644
--- a/lib/plugins/config/core/Setting/SettingLicense.php
+++ b/lib/plugins/config/core/Setting/SettingLicense.php
@@ -5,15 +5,16 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_license
*/
-class SettingLicense extends SettingMultichoice {
-
- protected $choices = array(''); // none choosen
+class SettingLicense extends SettingMultichoice
+{
+ protected $choices = ['']; // none choosen
/** @inheritdoc */
- public function initialize($default = null, $local = null, $protected = null) {
+ public function initialize($default = null, $local = null, $protected = null)
+ {
global $license;
- foreach($license as $key => $data) {
+ foreach ($license as $key => $data) {
$this->choices[] = $key;
$this->lang[$this->key . '_o_' . $key] = $data['name']; // stored in setting
}
diff --git a/lib/plugins/config/core/Setting/SettingMulticheckbox.php b/lib/plugins/config/core/Setting/SettingMulticheckbox.php
index df212cca0..954a51018 100644
--- a/lib/plugins/config/core/Setting/SettingMulticheckbox.php
+++ b/lib/plugins/config/core/Setting/SettingMulticheckbox.php
@@ -5,24 +5,25 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_multicheckbox
*/
-class SettingMulticheckbox extends SettingString {
-
- protected $choices = array();
- protected $combine = array();
+class SettingMulticheckbox extends SettingString
+{
+ protected $choices = [];
+ protected $combine = [];
protected $other = 'always';
/** @inheritdoc */
- public function update($input) {
- if($this->isProtected()) return false;
+ public function update($input)
+ {
+ if ($this->isProtected()) return false;
// split any combined values + convert from array to comma separated string
- $input = ($input) ? $input : array();
+ $input = $input ?: [];
$input = $this->array2str($input);
$value = is_null($this->local) ? $this->default : $this->local;
- if($value == $input) return false;
+ if ($value == $input) return false;
- if($this->pattern && !preg_match($this->pattern, $input)) {
+ if ($this->pattern && !preg_match($this->pattern, $input)) {
$this->error = true;
$this->input = $input;
return false;
@@ -33,19 +34,18 @@ class SettingMulticheckbox extends SettingString {
}
/** @inheritdoc */
- public function html(\admin_plugin_config $plugin, $echo = false) {
+ public function html(\admin_plugin_config $plugin, $echo = false)
+ {
$disable = '';
- if($this->isProtected()) {
+ if ($this->isProtected()) {
$value = $this->protected;
$disable = 'disabled="disabled"';
+ } elseif ($echo && $this->error) {
+ $value = $this->input;
} else {
- if($echo && $this->error) {
- $value = $this->input;
- } else {
- $value = is_null($this->local) ? $this->default : $this->local;
- }
+ $value = is_null($this->local) ? $this->default : $this->local;
}
$key = htmlspecialchars($this->key);
@@ -55,17 +55,16 @@ class SettingMulticheckbox extends SettingString {
$default = $this->str2array($this->default);
$input = '';
- foreach($this->choices as $choice) {
+ foreach ($this->choices as $choice) {
$idx = array_search($choice, $value);
$idx_default = array_search($choice, $default);
$checked = ($idx !== false) ? 'checked="checked"' : '';
// @todo ideally this would be handled using a second class of "default"
- $class = (($idx !== false) == (false !== $idx_default)) ? " selectiondefault" : "";
+ $class = (($idx !== false) === (false !== $idx_default)) ? " selectiondefault" : "";
- $prompt = ($plugin->getLang($this->key . '_' . $choice) ?
- $plugin->getLang($this->key . '_' . $choice) : htmlspecialchars($choice));
+ $prompt = ($plugin->getLang($this->key . '_' . $choice) ?: htmlspecialchars($choice));
$input .= '<div class="selection' . $class . '">' . "\n";
$input .= '<label for="config___' . $key . '_' . $choice . '">' . $prompt . "</label>\n";
@@ -74,20 +73,19 @@ class SettingMulticheckbox extends SettingString {
$input .= "</div>\n";
// remove this action from the disabledactions array
- if($idx !== false) unset($value[$idx]);
- if($idx_default !== false) unset($default[$idx_default]);
+ if ($idx !== false) unset($value[$idx]);
+ if ($idx_default !== false) unset($default[$idx_default]);
}
// handle any remaining values
- if($this->other != 'never') {
- $other = join(',', $value);
+ if ($this->other != 'never') {
+ $other = implode(',', $value);
// test equivalent to ($this->_other == 'always' || ($other && $this->_other == 'exists')
// use != 'exists' rather than == 'always' to ensure invalid values default to 'always'
- if($this->other != 'exists' || $other) {
-
+ if ($this->other != 'exists' || $other) {
$class = (
- (count($default) == count($value)) &&
- (count($value) == count(array_intersect($value, $default)))
+ (count($default) === count($value)) &&
+ (count($value) === count(array_intersect($value, $default)))
) ?
" selectiondefault" : "";
@@ -102,7 +100,7 @@ class SettingMulticheckbox extends SettingString {
}
}
$label = '<label>' . $this->prompt($plugin) . '</label>';
- return array($label, $input);
+ return [$label, $input];
}
/**
@@ -111,18 +109,19 @@ class SettingMulticheckbox extends SettingString {
* @param string $str
* @return array
*/
- protected function str2array($str) {
+ protected function str2array($str)
+ {
$array = explode(',', $str);
- if(!empty($this->combine)) {
- foreach($this->combine as $key => $combinators) {
- $idx = array();
- foreach($combinators as $val) {
- if(($idx[] = array_search($val, $array)) === false) break;
+ if (!empty($this->combine)) {
+ foreach ($this->combine as $key => $combinators) {
+ $idx = [];
+ foreach ($combinators as $val) {
+ if (($idx[] = array_search($val, $array)) === false) break;
}
- if(count($idx) && $idx[count($idx) - 1] !== false) {
- foreach($idx as $i) unset($array[$i]);
+ if (count($idx) && $idx[count($idx) - 1] !== false) {
+ foreach ($idx as $i) unset($array[$i]);
$array[] = $key;
}
}
@@ -137,27 +136,27 @@ class SettingMulticheckbox extends SettingString {
* @param array $input
* @return string
*/
- protected function array2str($input) {
+ protected function array2str($input)
+ {
// handle other
$other = trim($input['other']);
- $other = !empty($other) ? explode(',', str_replace(' ', '', $input['other'])) : array();
+ $other = empty($other) ? [] : explode(',', str_replace(' ', '', $input['other']));
unset($input['other']);
$array = array_unique(array_merge($input, $other));
// deconstruct any combinations
- if(!empty($this->combine)) {
- foreach($this->combine as $key => $combinators) {
-
+ if (!empty($this->combine)) {
+ foreach ($this->combine as $key => $combinators) {
$idx = array_search($key, $array);
- if($idx !== false) {
+ if ($idx !== false) {
unset($array[$idx]);
$array = array_merge($array, $combinators);
}
}
}
- return join(',', array_unique($array));
+ return implode(',', array_unique($array));
}
}
diff --git a/lib/plugins/config/core/Setting/SettingMultichoice.php b/lib/plugins/config/core/Setting/SettingMultichoice.php
index 3a50857e0..7d29a0e2b 100644
--- a/lib/plugins/config/core/Setting/SettingMultichoice.php
+++ b/lib/plugins/config/core/Setting/SettingMultichoice.php
@@ -5,16 +5,18 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_multichoice
*/
-class SettingMultichoice extends SettingString {
- protected $choices = array();
+class SettingMultichoice extends SettingString
+{
+ protected $choices = [];
public $lang; //some custom language strings are stored in setting
/** @inheritdoc */
- public function html(\admin_plugin_config $plugin, $echo = false) {
+ public function html(\admin_plugin_config $plugin, $echo = false)
+ {
$disable = '';
$nochoice = '';
- if($this->isProtected()) {
+ if ($this->isProtected()) {
$value = $this->protected;
$disable = ' disabled="disabled"';
} else {
@@ -22,11 +24,11 @@ class SettingMultichoice extends SettingString {
}
// ensure current value is included
- if(!in_array($value, $this->choices)) {
+ if (!in_array($value, $this->choices)) {
$this->choices[] = $value;
}
// disable if no other choices
- if(!$this->isProtected() && count($this->choices) <= 1) {
+ if (!$this->isProtected() && count($this->choices) <= 1) {
$disable = ' disabled="disabled"';
$nochoice = $plugin->getLang('nochoice');
}
@@ -37,13 +39,13 @@ class SettingMultichoice extends SettingString {
$input = "<div class=\"input\">\n";
$input .= '<select class="edit" id="config___' . $key . '" name="config[' . $key . ']"' . $disable . '>' . "\n";
- foreach($this->choices as $choice) {
+ foreach ($this->choices as $choice) {
$selected = ($value == $choice) ? ' selected="selected"' : '';
$option = $plugin->getLang($this->key . '_o_' . $choice);
- if(!$option && isset($this->lang[$this->key . '_o_' . $choice])) {
+ if (!$option && isset($this->lang[$this->key . '_o_' . $choice])) {
$option = $this->lang[$this->key . '_o_' . $choice];
}
- if(!$option) $option = $choice;
+ if (!$option) $option = $choice;
$choice = htmlspecialchars($choice);
$option = htmlspecialchars($option);
@@ -52,18 +54,19 @@ class SettingMultichoice extends SettingString {
$input .= "</select> $nochoice \n";
$input .= "</div>\n";
- return array($label, $input);
+ return [$label, $input];
}
/** @inheritdoc */
- public function update($input) {
- if(is_null($input)) return false;
- if($this->isProtected()) return false;
+ public function update($input)
+ {
+ if (is_null($input)) return false;
+ if ($this->isProtected()) return false;
$value = is_null($this->local) ? $this->default : $this->local;
- if($value == $input) return false;
+ if ($value == $input) return false;
- if(!in_array($input, $this->choices)) return false;
+ if (!in_array($input, $this->choices)) return false;
$this->local = $input;
return true;
diff --git a/lib/plugins/config/core/Setting/SettingNoClass.php b/lib/plugins/config/core/Setting/SettingNoClass.php
index 8efff216a..805ab11c9 100644
--- a/lib/plugins/config/core/Setting/SettingNoClass.php
+++ b/lib/plugins/config/core/Setting/SettingNoClass.php
@@ -7,6 +7,7 @@ namespace dokuwiki\plugin\config\core\Setting;
* A do-nothing class used to detect settings with a missing setting class.
* Used internaly to hide undefined settings, and generate the undefined settings list.
*/
-class SettingNoClass extends SettingUndefined {
+class SettingNoClass extends SettingUndefined
+{
protected $errorMessage = '_msg_setting_no_class';
}
diff --git a/lib/plugins/config/core/Setting/SettingNoDefault.php b/lib/plugins/config/core/Setting/SettingNoDefault.php
index 07b8412dd..2780be095 100644
--- a/lib/plugins/config/core/Setting/SettingNoDefault.php
+++ b/lib/plugins/config/core/Setting/SettingNoDefault.php
@@ -8,6 +8,7 @@ namespace dokuwiki\plugin\config\core\Setting;
* A do-nothing class used to detect settings with no default value.
* Used internaly to hide undefined settings, and generate the undefined settings list.
*/
-class SettingNoDefault extends SettingUndefined {
+class SettingNoDefault extends SettingUndefined
+{
protected $errorMessage = '_msg_setting_no_default';
}
diff --git a/lib/plugins/config/core/Setting/SettingNoKnownClass.php b/lib/plugins/config/core/Setting/SettingNoKnownClass.php
index 3c527e1ee..0d5c1c734 100644
--- a/lib/plugins/config/core/Setting/SettingNoKnownClass.php
+++ b/lib/plugins/config/core/Setting/SettingNoKnownClass.php
@@ -6,6 +6,7 @@ namespace dokuwiki\plugin\config\core\Setting;
* A do-nothing class used to detect settings with a missing setting class.
* Used internaly to hide undefined settings, and generate the undefined settings list.
*/
-class SettingNoKnownClass extends SettingUndefined {
+class SettingNoKnownClass extends SettingUndefined
+{
protected $errorMessage = '_msg_setting_no_known_class';
}
diff --git a/lib/plugins/config/core/Setting/SettingNumeric.php b/lib/plugins/config/core/Setting/SettingNumeric.php
index 8a6b17956..27ca1945c 100644
--- a/lib/plugins/config/core/Setting/SettingNumeric.php
+++ b/lib/plugins/config/core/Setting/SettingNumeric.php
@@ -5,22 +5,26 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_numeric
*/
-class SettingNumeric extends SettingString {
+class SettingNumeric extends SettingString
+{
// This allows for many PHP syntax errors...
// var $_pattern = '/^[-+\/*0-9 ]*$/';
// much more restrictive, but should eliminate syntax errors.
- protected $pattern = '/^[-+]? *[0-9]+ *(?:[-+*] *[0-9]+ *)*$/';
- protected $min = null;
- protected $max = null;
+ protected $pattern = '/^[-+]? *\d+ *(?:[-+*] *\d+ *)*$/';
+ protected $min;
+ protected $max;
/** @inheritdoc */
- public function update($input) {
+ public function update($input)
+ {
$local = $this->local;
$valid = parent::update($input);
- if($valid && !(is_null($this->min) && is_null($this->max))) {
+ if ($valid && !(is_null($this->min) && is_null($this->max))) {
$numeric_local = (int) eval('return ' . $this->local . ';');
- if((!is_null($this->min) && $numeric_local < $this->min) ||
- (!is_null($this->max) && $numeric_local > $this->max)) {
+ if (
+ (!is_null($this->min) && $numeric_local < $this->min) ||
+ (!is_null($this->max) && $numeric_local > $this->max)
+ ) {
$this->error = true;
$this->input = $input;
$this->local = $local;
@@ -31,8 +35,9 @@ class SettingNumeric extends SettingString {
}
/** @inheritdoc */
- public function out($var, $fmt = 'php') {
- if($fmt != 'php') return '';
+ public function out($var, $fmt = 'php')
+ {
+ if ($fmt != 'php') return '';
$local = $this->local === '' ? "''" : $this->local;
$out = '$' . $var . "['" . $this->getArrayKey() . "'] = " . $local . ";\n";
diff --git a/lib/plugins/config/core/Setting/SettingNumericopt.php b/lib/plugins/config/core/Setting/SettingNumericopt.php
index a486e187f..117e3920a 100644
--- a/lib/plugins/config/core/Setting/SettingNumericopt.php
+++ b/lib/plugins/config/core/Setting/SettingNumericopt.php
@@ -5,17 +5,19 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_numericopt
*/
-class SettingNumericopt extends SettingNumeric {
+class SettingNumericopt extends SettingNumeric
+{
// just allow an empty config
- protected $pattern = '/^(|[-]?[0-9]+(?:[-+*][0-9]+)*)$/';
+ protected $pattern = '/^(|[-]?\d+(?:[-+*]\d+)*)$/';
/**
* @inheritdoc
* Empty string is valid for numericopt
*/
- public function update($input) {
- if($input === '') {
- if($input == $this->local) return false;
+ public function update($input)
+ {
+ if ($input === '') {
+ if ($input == $this->local) return false;
$this->local = $input;
return true;
}
diff --git a/lib/plugins/config/core/Setting/SettingOnoff.php b/lib/plugins/config/core/Setting/SettingOnoff.php
index 780778b48..69a74aa9f 100644
--- a/lib/plugins/config/core/Setting/SettingOnoff.php
+++ b/lib/plugins/config/core/Setting/SettingOnoff.php
@@ -5,29 +5,31 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_onoff
*/
-class SettingOnoff extends SettingNumeric {
-
+class SettingOnoff extends SettingNumeric
+{
/**
* We treat the strings 'false' and 'off' as false
* @inheritdoc
*/
- protected function cleanValue($value) {
- if($value === null) return null;
-
- if(is_string($value)) {
- if(strtolower($value) === 'false') return 0;
- if(strtolower($value) === 'off') return 0;
- if(trim($value) === '') return 0;
+ protected function cleanValue($value)
+ {
+ if ($value === null) return null;
+
+ if (is_string($value)) {
+ if (strtolower($value) === 'false') return 0;
+ if (strtolower($value) === 'off') return 0;
+ if (trim($value) === '') return 0;
}
return (int) (bool) $value;
}
/** @inheritdoc */
- public function html(\admin_plugin_config $plugin, $echo = false) {
+ public function html(\admin_plugin_config $plugin, $echo = false)
+ {
$disable = '';
- if($this->isProtected()) {
+ if ($this->isProtected()) {
$value = $this->protected;
$disable = ' disabled="disabled"';
} else {
@@ -40,16 +42,17 @@ class SettingOnoff extends SettingNumeric {
$label = '<label for="config___' . $key . '">' . $this->prompt($plugin) . '</label>';
$input = '<div class="input"><input id="config___' . $key . '" name="config[' . $key .
']" type="checkbox" class="checkbox" value="1"' . $checked . $disable . '/></div>';
- return array($label, $input);
+ return [$label, $input];
}
/** @inheritdoc */
- public function update($input) {
- if($this->isProtected()) return false;
+ public function update($input)
+ {
+ if ($this->isProtected()) return false;
$input = ($input) ? 1 : 0;
$value = is_null($this->local) ? $this->default : $this->local;
- if($value == $input) return false;
+ if ($value == $input) return false;
$this->local = $input;
return true;
diff --git a/lib/plugins/config/core/Setting/SettingPassword.php b/lib/plugins/config/core/Setting/SettingPassword.php
index 9d9c53377..e56a1338f 100644
--- a/lib/plugins/config/core/Setting/SettingPassword.php
+++ b/lib/plugins/config/core/Setting/SettingPassword.php
@@ -5,16 +5,17 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_password
*/
-class SettingPassword extends SettingString {
-
+class SettingPassword extends SettingString
+{
protected $code = 'plain'; // mechanism to be used to obscure passwords
/** @inheritdoc */
- public function update($input) {
- if($this->isProtected()) return false;
- if(!$input) return false;
+ public function update($input)
+ {
+ if ($this->isProtected()) return false;
+ if (!$input) return false;
- if($this->pattern && !preg_match($this->pattern, $input)) {
+ if ($this->pattern && !preg_match($this->pattern, $input)) {
$this->error = true;
$this->input = $input;
return false;
@@ -25,7 +26,8 @@ class SettingPassword extends SettingString {
}
/** @inheritdoc */
- public function html(\admin_plugin_config $plugin, $echo = false) {
+ public function html(\admin_plugin_config $plugin, $echo = false)
+ {
$disable = $this->isProtected() ? 'disabled="disabled"' : '';
@@ -34,6 +36,6 @@ class SettingPassword extends SettingString {
$label = '<label for="config___' . $key . '">' . $this->prompt($plugin) . '</label>';
$input = '<input id="config___' . $key . '" name="config[' . $key .
']" autocomplete="off" type="password" class="edit" value="" ' . $disable . ' />';
- return array($label, $input);
+ return [$label, $input];
}
}
diff --git a/lib/plugins/config/core/Setting/SettingRegex.php b/lib/plugins/config/core/Setting/SettingRegex.php
index b38f0a560..7ec3a4d81 100644
--- a/lib/plugins/config/core/Setting/SettingRegex.php
+++ b/lib/plugins/config/core/Setting/SettingRegex.php
@@ -5,24 +5,25 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_regex
*/
-class SettingRegex extends SettingString {
-
+class SettingRegex extends SettingString
+{
protected $delimiter = '/'; // regex delimiter to be used in testing input
protected $pregflags = 'ui'; // regex pattern modifiers to be used in testing input
/** @inheritdoc */
- public function update($input) {
+ public function update($input)
+ {
// let parent do basic checks, value, not changed, etc.
$local = $this->local;
- if(!parent::update($input)) return false;
+ if (!parent::update($input)) return false;
$this->local = $local;
// see if the regex compiles and runs (we don't check for effectiveness)
$regex = $this->delimiter . $input . $this->delimiter . $this->pregflags;
$lastError = error_get_last();
@preg_match($regex, 'testdata');
- if(preg_last_error() != PREG_NO_ERROR || error_get_last() != $lastError) {
+ if (preg_last_error() != PREG_NO_ERROR || error_get_last() !== $lastError) {
$this->input = $input;
$this->error = true;
return false;
diff --git a/lib/plugins/config/core/Setting/SettingRenderer.php b/lib/plugins/config/core/Setting/SettingRenderer.php
index 37ba9c70a..10b3e33f8 100644
--- a/lib/plugins/config/core/Setting/SettingRenderer.php
+++ b/lib/plugins/config/core/Setting/SettingRenderer.php
@@ -1,4 +1,5 @@
<?php
+
/**
* additional setting classes specific to these settings
*
@@ -10,17 +11,19 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_renderer
*/
-class SettingRenderer extends SettingMultichoice {
- protected $prompts = array();
- protected $format = null;
+class SettingRenderer extends SettingMultichoice
+{
+ protected $prompts = [];
+ protected $format;
/** @inheritdoc */
- public function initialize($default = null, $local = null, $protected = null) {
+ public function initialize($default = null, $local = null, $protected = null)
+ {
$format = $this->format;
- foreach(plugin_list('renderer') as $plugin) {
+ foreach (plugin_list('renderer') as $plugin) {
$renderer = plugin_load('renderer', $plugin);
- if(method_exists($renderer, 'canRender') && $renderer->canRender($format)) {
+ if (method_exists($renderer, 'canRender') && $renderer->canRender($format)) {
$this->choices[] = $plugin;
$info = $renderer->getInfo();
@@ -32,13 +35,14 @@ class SettingRenderer extends SettingMultichoice {
}
/** @inheritdoc */
- public function html(\admin_plugin_config $plugin, $echo = false) {
+ public function html(\admin_plugin_config $plugin, $echo = false)
+ {
// make some language adjustments (there must be a better way)
// transfer some plugin names to the config plugin
- foreach($this->choices as $choice) {
- if(!$plugin->getLang($this->key . '_o_' . $choice)) {
- if(!isset($this->prompts[$choice])) {
+ foreach ($this->choices as $choice) {
+ if (!$plugin->getLang($this->key . '_o_' . $choice)) {
+ if (!isset($this->prompts[$choice])) {
$plugin->addLang(
$this->key . '_o_' . $choice,
sprintf($plugin->getLang('renderer__core'), $choice)
diff --git a/lib/plugins/config/core/Setting/SettingSavedir.php b/lib/plugins/config/core/Setting/SettingSavedir.php
index 43e428dd3..a429b7a38 100644
--- a/lib/plugins/config/core/Setting/SettingSavedir.php
+++ b/lib/plugins/config/core/Setting/SettingSavedir.php
@@ -5,16 +5,17 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_savedir
*/
-class SettingSavedir extends SettingString {
-
+class SettingSavedir extends SettingString
+{
/** @inheritdoc */
- public function update($input) {
- if($this->isProtected()) return false;
+ public function update($input)
+ {
+ if ($this->isProtected()) return false;
$value = is_null($this->local) ? $this->default : $this->local;
- if($value == $input) return false;
+ if ($value == $input) return false;
- if(!init_path($input)) {
+ if (!init_path($input)) {
$this->error = true;
$this->input = $input;
return false;
diff --git a/lib/plugins/config/core/Setting/SettingSepchar.php b/lib/plugins/config/core/Setting/SettingSepchar.php
index 57cd0ae92..db9e9d694 100644
--- a/lib/plugins/config/core/Setting/SettingSepchar.php
+++ b/lib/plugins/config/core/Setting/SettingSepchar.php
@@ -5,12 +5,13 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_sepchar
*/
-class SettingSepchar extends SettingMultichoice {
-
+class SettingSepchar extends SettingMultichoice
+{
/** @inheritdoc */
- public function __construct($key, $param = null) {
+ public function __construct($key, $param = null)
+ {
$str = '_-.';
- for($i = 0; $i < strlen($str); $i++) $this->choices[] = $str[$i];
+ for ($i = 0; $i < strlen($str); $i++) $this->choices[] = $str[$i];
// call foundation class constructor
parent::__construct($key, $param);
diff --git a/lib/plugins/config/core/Setting/SettingString.php b/lib/plugins/config/core/Setting/SettingString.php
index b819407b7..090108501 100644
--- a/lib/plugins/config/core/Setting/SettingString.php
+++ b/lib/plugins/config/core/Setting/SettingString.php
@@ -5,20 +5,20 @@ namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_string
*/
-class SettingString extends Setting {
+class SettingString extends Setting
+{
/** @inheritdoc */
- public function html(\admin_plugin_config $plugin, $echo = false) {
+ public function html(\admin_plugin_config $plugin, $echo = false)
+ {
$disable = '';
- if($this->isProtected()) {
+ if ($this->isProtected()) {
$value = $this->protected;
$disable = 'disabled="disabled"';
+ } elseif ($echo && $this->error) {
+ $value = $this->input;
} else {
- if($echo && $this->error) {
- $value = $this->input;
- } else {
- $value = is_null($this->local) ? $this->default : $this->local;
- }
+ $value = is_null($this->local) ? $this->default : $this->local;
}
$key = htmlspecialchars($this->key);
@@ -27,6 +27,6 @@ class SettingString extends Setting {
$label = '<label for="config___' . $key . '">' . $this->prompt($plugin) . '</label>';
$input = '<input id="config___' . $key . '" name="config[' . $key .
']" type="text" class="edit" value="' . $value . '" ' . $disable . '/>';
- return array($label, $input);
+ return [$label, $input];
}
}
diff --git a/lib/plugins/config/core/Setting/SettingUndefined.php b/lib/plugins/config/core/Setting/SettingUndefined.php
index fa46a9f1d..e70c90cd7 100644
--- a/lib/plugins/config/core/Setting/SettingUndefined.php
+++ b/lib/plugins/config/core/Setting/SettingUndefined.php
@@ -8,23 +8,27 @@ use dokuwiki\plugin\config\core\Configuration;
* A do-nothing class used to detect settings with no metadata entry.
* Used internaly to hide undefined settings, and generate the undefined settings list.
*/
-class SettingUndefined extends SettingHidden {
-
+class SettingUndefined extends SettingHidden
+{
protected $errorMessage = '_msg_setting_undefined';
/** @inheritdoc */
- public function shouldHaveDefault() {
+ public function shouldHaveDefault()
+ {
return false;
}
/** @inheritdoc */
- public function html(\admin_plugin_config $plugin, $echo = false) {
+ public function html(\admin_plugin_config $plugin, $echo = false)
+ {
// determine the name the meta key would be called
- if(preg_match(
- '/^(?:plugin|tpl)' . Configuration::KEYMARKER . '.*?' . Configuration::KEYMARKER . '(.*)$/',
- $this->getKey(),
- $undefined_setting_match
- )) {
+ if (
+ preg_match(
+ '/^(?:plugin|tpl)' . Configuration::KEYMARKER . '.*?' . Configuration::KEYMARKER . '(.*)$/',
+ $this->getKey(),
+ $undefined_setting_match
+ )
+ ) {
$undefined_setting_key = $undefined_setting_match[1];
} else {
$undefined_setting_key = $this->getKey();
@@ -34,7 +38,6 @@ class SettingUndefined extends SettingHidden {
'conf' . '[\'' . $this->getArrayKey() . '\']</span>';
$input = $plugin->getLang($this->errorMessage);
- return array($label, $input);
+ return [$label, $input];
}
-
}
diff --git a/lib/plugins/config/core/Writer.php b/lib/plugins/config/core/Writer.php
index 18aa9ee02..6751b88ba 100644
--- a/lib/plugins/config/core/Writer.php
+++ b/lib/plugins/config/core/Writer.php
@@ -1,13 +1,15 @@
<?php
namespace dokuwiki\plugin\config\core;
+
use dokuwiki\plugin\config\core\Setting\Setting;
use dokuwiki\Logger;
/**
* Writes the settings to the correct local file
*/
-class Writer {
+class Writer
+{
/** @var string header info */
protected $header = 'Dokuwiki\'s Main Configuration File - Local Settings';
@@ -17,7 +19,8 @@ class Writer {
/**
* Writer constructor.
*/
- public function __construct() {
+ public function __construct()
+ {
global $config_cascade;
$this->savefile = end($config_cascade['main']['local']);
}
@@ -28,36 +31,37 @@ class Writer {
* @param Setting[] $settings
* @throws \Exception
*/
- public function save($settings) {
+ public function save($settings)
+ {
global $conf;
- if($this->isLocked()) throw new \Exception('no save');
+ if ($this->isLocked()) throw new \Exception('no save');
// backup current file (remove any existing backup)
- if(file_exists($this->savefile)) {
- if(file_exists($this->savefile . '.bak.php')) @unlink($this->savefile . '.bak.php');
- if(!io_rename($this->savefile, $this->savefile . '.bak.php')) throw new \Exception('no backup');
+ if (file_exists($this->savefile)) {
+ if (file_exists($this->savefile . '.bak.php')) @unlink($this->savefile . '.bak.php');
+ if (!io_rename($this->savefile, $this->savefile . '.bak.php')) throw new \Exception('no backup');
}
- if(!$fh = @fopen($this->savefile, 'wb')) {
+ if (!$fh = @fopen($this->savefile, 'wb')) {
io_rename($this->savefile . '.bak.php', $this->savefile); // problem opening, restore the backup
throw new \Exception('no save');
}
$out = '';
- foreach($settings as $setting) {
- if($setting->shouldBeSaved()) {
+ foreach ($settings as $setting) {
+ if ($setting->shouldBeSaved()) {
$out .= $setting->out('conf', 'php');
}
}
- if($out === '') {
+ if ($out === '') {
throw new \Exception('empty config');
}
$out = $this->getHeader() . $out;
fwrite($fh, $out);
fclose($fh);
- if($conf['fperm']) chmod($this->savefile, $conf['fperm']);
+ if ($conf['fperm']) chmod($this->savefile, $conf['fperm']);
$this->opcacheUpdate($this->savefile);
}
@@ -68,8 +72,9 @@ class Writer {
*
* @throws \Exception when the config isn't writable
*/
- public function touch() {
- if($this->isLocked()) throw new \Exception('no save');
+ public function touch()
+ {
+ if ($this->isLocked()) throw new \Exception('no save');
@touch($this->savefile);
$this->opcacheUpdate($this->savefile);
}
@@ -80,11 +85,12 @@ class Writer {
* @todo this should probably be moved to core
* @param string $file
*/
- protected function opcacheUpdate($file) {
- if(!function_exists('opcache_invalidate')) return;
+ protected function opcacheUpdate($file)
+ {
+ if (!function_exists('opcache_invalidate')) return;
set_error_handler(function ($errNo, $errMsg) {
- Logger::debug('Unable to invalidate opcache: ' . $errMsg); }
- );
+ Logger::debug('Unable to invalidate opcache: ' . $errMsg);
+ });
opcache_invalidate($file);
restore_error_handler();
}
@@ -95,10 +101,11 @@ class Writer {
*
* @return bool true: locked, false: writable
*/
- public function isLocked() {
- if(!$this->savefile) return true;
- if(!is_writable(dirname($this->savefile))) return true;
- if(file_exists($this->savefile) && !is_writable($this->savefile)) return true;
+ public function isLocked()
+ {
+ if (!$this->savefile) return true;
+ if (!is_writable(dirname($this->savefile))) return true;
+ if (file_exists($this->savefile) && !is_writable($this->savefile)) return true;
return false;
}
@@ -107,20 +114,21 @@ class Writer {
*
* @return string
*/
- protected function getHeader() {
- return join(
+ protected function getHeader()
+ {
+ return implode(
"\n",
- array(
+ [
'<?php',
'/*',
' * ' . $this->header,
' * Auto-generated by config plugin',
- ' * Run for user: ' . (isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] : 'Unknown'),
+ ' * Run for user: ' . ($_SERVER['REMOTE_USER'] ?? 'Unknown'),
' * Date: ' . date('r'),
' */',
'',
''
- )
+ ]
);
}
}