diff options
author | Gerrit Uitslag <klapinklapin@gmail.com> | 2014-10-01 15:32:05 +0200 |
---|---|---|
committer | Gerrit Uitslag <klapinklapin@gmail.com> | 2014-10-01 15:32:05 +0200 |
commit | 253d4b48ec708eb42033862dc15c8576f44a48ed (patch) | |
tree | d8673e304f0deaacb7a20a31cba7b82744a00bed /lib/plugins/config | |
parent | 42ea7f447f39fbc2f79eaaec31f8c10ede59c5d0 (diff) | |
download | rpg-253d4b48ec708eb42033862dc15c8576f44a48ed.tar.gz rpg-253d4b48ec708eb42033862dc15c8576f44a48ed.tar.bz2 |
more PHPDocs, unused var, small bit code reformatting
Diffstat (limited to 'lib/plugins/config')
-rw-r--r-- | lib/plugins/config/admin.php | 45 | ||||
-rw-r--r-- | lib/plugins/config/settings/config.class.php | 208 | ||||
-rw-r--r-- | lib/plugins/config/settings/extra.class.php | 96 |
3 files changed, 327 insertions, 22 deletions
diff --git a/lib/plugins/config/admin.php b/lib/plugins/config/admin.php index 835d27775..9202a221b 100644 --- a/lib/plugins/config/admin.php +++ b/lib/plugins/config/admin.php @@ -32,6 +32,9 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { var $_session_started = false; var $_localised_prompts = false; + /** + * @return int + */ function getMenuSort() { return 100; } /** @@ -40,14 +43,20 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { function handle() { global $ID, $INPUT; - if (!$this->_restore_session()) return $this->_close_session(); - if ($INPUT->int('save') != 1) return $this->_close_session(); - if (!checkSecurityToken()) return $this->_close_session(); + if(!$this->_restore_session() || $INPUT->int('save') != 1 || !checkSecurityToken()) { + $this->_close_session(); + return; + } - if (is_null($this->_config)) { $this->_config = new configuration($this->_file); } + if(is_null($this->_config)) { + $this->_config = new configuration($this->_file); + } // don't go any further if the configuration is locked - if ($this->_config->_locked) return $this->_close_session(); + if($this->_config->locked) { + $this->_close_session(); + return; + } $this->_input = $INPUT->arr('config'); @@ -104,6 +113,7 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { formSecurityToken(); $this->_print_h1('dokuwiki_settings', $this->getLang('_header_dokuwiki')); + /** @var setting[] $undefined_settings */ $undefined_settings = array(); $in_fieldset = false; $first_plugin_fieldset = true; @@ -162,7 +172,17 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { // show undefined settings list if ($allow_debug && !empty($undefined_settings)) { - function _setting_natural_comparison($a, $b) { return strnatcmp($a->_key, $b->_key); } + /** + * Callback for sorting settings + * + * @param setting $a + * @param setting $b + * @return int if $a is lower/equal/higher than $b + */ + function _setting_natural_comparison($a, $b) { + return strnatcmp($a->_key, $b->_key); + } + usort($undefined_settings, '_setting_natural_comparison'); $this->_print_h1('undefined_settings', $this->getLang('_header_undefined')); ptln('<fieldset>'); @@ -235,6 +255,9 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { if ($this->_session_started) session_write_close(); } + /** + * @param bool $prompts + */ function setupLocale($prompts=false) { parent::setupLocale(); @@ -245,6 +268,9 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { } + /** + * @return bool + */ function _setup_localised_plugin_prompts() { global $conf; @@ -299,6 +325,8 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { * Generates a two-level table of contents for the config plugin. * * @author Ben Coburn <btcoburn@silicodon.net> + * + * @return array */ function getTOC() { if (is_null($this->_config)) { $this->_config = new configuration($this->_file); } @@ -328,6 +356,7 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { $t[] = html_mktocitem('configuration_manager', $this->getLang('_configuration_manager'), 1); $t[] = html_mktocitem('dokuwiki_settings', $this->getLang('_header_dokuwiki'), 1); + /** @var setting $setting */ foreach($toc['conf'] as $setting) { $name = $setting->prompt($this); $t[] = html_mktocitem($setting->_key, $name, 2); @@ -352,6 +381,10 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { return $t; } + /** + * @param string $id + * @param string $text + */ function _print_h1($id, $text) { ptln('<h1 id="'.$id.'">'.$text.'</h1>'); } diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php index 30e7a2133..cbf6ea452 100644 --- a/lib/plugins/config/settings/config.class.php +++ b/lib/plugins/config/settings/config.class.php @@ -10,7 +10,9 @@ if(!defined('CM_KEYMARKER')) define('CM_KEYMARKER','____'); if (!class_exists('configuration')) { - + /** + * Class configuration + */ class configuration { var $_name = 'conf'; // name of the config variable found in the files (overridden by $config['varname']) @@ -151,6 +153,8 @@ if (!class_exists('configuration')) { /** * Update last modified time stamp of the config file + * + * @return bool */ public function touch_settings(){ if ($this->locked) return false; @@ -285,6 +289,10 @@ if (!class_exists('configuration')) { /** * not used ... conf's contents are an array! * reduce any multidimensional settings to one dimension using CM_KEYMARKER + * + * @param $conf + * @param string $prefix + * @return array */ protected function _flatten($conf,$prefix='') { @@ -403,6 +411,9 @@ if (!class_exists('configuration')) { } if (!class_exists('setting')) { + /** + * Class setting + */ class setting { var $_key = ''; @@ -452,7 +463,7 @@ if (!class_exists('setting')) { * - if changed value passes error check, set $this->_local to the new value * * @param mixed $input the new value - * @return boolean true if changed, false otherwise (incl. on error) + * @return boolean true if changed, false otherwise (also on error) */ public function update($input) { if (is_null($input)) return false; @@ -476,10 +487,9 @@ if (!class_exists('setting')) { * * @param DokuWiki_Plugin $plugin object of config plugin * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting - * @return array(string $label_html, string $input_html) + * @return array with content array(string $label_html, string $input_html) */ public function html(&$plugin, $echo=false) { - $value = ''; $disable = ''; if ($this->is_protected()) { @@ -503,6 +513,10 @@ if (!class_exists('setting')) { /** * Generate string to save setting value to file according to $fmt + * + * @param string $var name of variable + * @param string $fmt save format + * @return string */ public function out($var, $fmt='php') { @@ -603,12 +617,15 @@ if (!class_exists('setting')) { if (!class_exists('setting_array')) { + /** + * Class setting_array + */ class setting_array extends setting { /** * Create an array from a string * - * @param $string + * @param string $string * @return array */ protected function _from_string($string){ @@ -622,7 +639,7 @@ if (!class_exists('setting_array')) { /** * Create a string from an array * - * @param $array + * @param array $array * @return string */ protected function _from_array($array){ @@ -657,13 +674,23 @@ if (!class_exists('setting_array')) { return true; } + /** + * Escaping + * + * @param string $string + * @return string + */ protected function _escape($string) { $tr = array("\\" => '\\\\', "'" => '\\\''); return "'".strtr( cleanText($string), $tr)."'"; } /** - * generate string to save setting value to file according to $fmt + * Generate string to save setting value to file according to $fmt + * + * @param string $var name of variable + * @param string $fmt save format + * @return string */ function out($var, $fmt='php') { @@ -680,8 +707,14 @@ if (!class_exists('setting_array')) { return $out; } + /** + * Build html for label and input of setting + * + * @param DokuWiki_Plugin $plugin object of config plugin + * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting + * @return array with content array(string $label_html, string $input_html) + */ function html(&$plugin, $echo=false) { - $value = ''; $disable = ''; if ($this->is_protected()) { @@ -706,9 +739,18 @@ if (!class_exists('setting_array')) { } if (!class_exists('setting_string')) { + /** + * Class setting_string + */ class setting_string extends setting { + /** + * Build html for label and input of setting + * + * @param DokuWiki_Plugin $plugin object of config plugin + * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting + * @return array with content array(string $label_html, string $input_html) + */ function html(&$plugin, $echo=false) { - $value = ''; $disable = ''; if ($this->is_protected()) { @@ -733,10 +775,21 @@ if (!class_exists('setting_string')) { } if (!class_exists('setting_password')) { + /** + * Class setting_password + */ class setting_password extends setting_string { var $_code = 'plain'; // mechanism to be used to obscure passwords + /** + * update changed setting with user provided value $input + * - if changed value fails error check, save it to $this->_input (to allow echoing later) + * - if changed value passes error check, set $this->_local to the new value + * + * @param mixed $input the new value + * @return boolean true if changed, false otherwise (also on error) + */ function update($input) { if ($this->is_protected()) return false; if (!$input) return false; @@ -751,9 +804,15 @@ if (!class_exists('setting_password')) { return true; } + /** + * Build html for label and input of setting + * + * @param DokuWiki_Plugin $plugin object of config plugin + * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting + * @return array with content array(string $label_html, string $input_html) + */ function html(&$plugin, $echo=false) { - $value = ''; $disable = $this->is_protected() ? 'disabled="disabled"' : ''; $key = htmlspecialchars($this->_key); @@ -766,7 +825,9 @@ if (!class_exists('setting_password')) { } if (!class_exists('setting_email')) { - + /** + * Class setting_email + */ class setting_email extends setting_string { var $_multiple = false; var $_placeholders = false; @@ -830,7 +891,17 @@ if (!class_exists('setting_email')) { * @deprecated 2013-02-16 */ if (!class_exists('setting_richemail')) { + /** + * Class setting_richemail + */ class setting_richemail extends setting_email { + /** + * update changed setting with user provided value $input + * - if changed value fails error check, save it + * + * @param mixed $input the new value + * @return boolean true if changed, false otherwise (also on error) + */ function update($input) { $this->_placeholders = true; return parent::update($input); @@ -840,6 +911,9 @@ if (!class_exists('setting_richemail')) { if (!class_exists('setting_numeric')) { + /** + * Class setting_numeric + */ class setting_numeric extends setting_string { // This allows for many PHP syntax errors... // var $_pattern = '/^[-+\/*0-9 ]*$/'; @@ -848,6 +922,14 @@ if (!class_exists('setting_numeric')) { var $_min = null; var $_max = null; + /** + * update changed setting with user provided value $input + * - if changed value fails error check, save it to $this->_input (to allow echoing later) + * - if changed value passes error check, set $this->_local to the new value + * + * @param mixed $input the new value + * @return boolean true if changed, false otherwise (also on error) + */ function update($input) { $local = $this->_local; $valid = parent::update($input); @@ -864,6 +946,13 @@ if (!class_exists('setting_numeric')) { return $valid; } + /** + * Generate string to save setting value to file according to $fmt + * + * @param string $var name of variable + * @param string $fmt save format + * @return string + */ function out($var, $fmt='php') { if ($this->is_protected()) return ''; @@ -882,6 +971,9 @@ if (!class_exists('setting_numeric')) { } if (!class_exists('setting_numericopt')) { + /** + * Class setting_numericopt + */ class setting_numericopt extends setting_numeric { // just allow an empty config var $_pattern = '/^(|[-]?[0-9]+(?:[-+*][0-9]+)*)$/'; @@ -889,10 +981,18 @@ if (!class_exists('setting_numericopt')) { } if (!class_exists('setting_onoff')) { + /** + * Class setting_onoff + */ class setting_onoff extends setting_numeric { - + /** + * Build html for label and input of setting + * + * @param DokuWiki_Plugin $plugin object of config plugin + * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting + * @return array with content array(string $label_html, string $input_html) + */ function html(&$plugin, $echo = false) { - $value = ''; $disable = ''; if ($this->is_protected()) { @@ -910,6 +1010,14 @@ if (!class_exists('setting_onoff')) { return array($label,$input); } + /** + * update changed setting with user provided value $input + * - if changed value fails error check, save it to $this->_input (to allow echoing later) + * - if changed value passes error check, set $this->_local to the new value + * + * @param mixed $input the new value + * @return boolean true if changed, false otherwise (also on error) + */ function update($input) { if ($this->is_protected()) return false; @@ -924,12 +1032,21 @@ if (!class_exists('setting_onoff')) { } if (!class_exists('setting_multichoice')) { + /** + * Class setting_multichoice + */ class setting_multichoice extends setting_string { var $_choices = array(); var $lang; //some custom language strings are stored in setting + /** + * Build html for label and input of setting + * + * @param DokuWiki_Plugin $plugin object of config plugin + * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting + * @return array with content array(string $label_html, string $input_html) + */ function html(&$plugin, $echo = false) { - $value = ''; $disable = ''; $nochoice = ''; @@ -972,6 +1089,14 @@ if (!class_exists('setting_multichoice')) { return array($label,$input); } + /** + * update changed setting with user provided value $input + * - if changed value fails error check, save it to $this->_input (to allow echoing later) + * - if changed value passes error check, set $this->_local to the new value + * + * @param mixed $input the new value + * @return boolean true if changed, false otherwise (also on error) + */ function update($input) { if (is_null($input)) return false; if ($this->is_protected()) return false; @@ -989,10 +1114,20 @@ if (!class_exists('setting_multichoice')) { if (!class_exists('setting_dirchoice')) { + /** + * Class setting_dirchoice + */ class setting_dirchoice extends setting_multichoice { var $_dir = ''; + /** + * Receives current values for the setting $key + * + * @param mixed $default default setting value + * @param mixed $local local setting value + * @param mixed $protected protected setting value + */ function initialize($default,$local,$protected) { // populate $this->_choices with a list of directories @@ -1018,12 +1153,18 @@ if (!class_exists('setting_dirchoice')) { if (!class_exists('setting_hidden')) { + /** + * Class setting_hidden + */ class setting_hidden extends setting { // Used to explicitly ignore a setting in the configuration manager. } } if (!class_exists('setting_fieldset')) { + /** + * Class setting_fieldset + */ class setting_fieldset extends setting { // A do-nothing class used to detect the 'fieldset' type. // Used to start a new settings "display-group". @@ -1031,6 +1172,9 @@ if (!class_exists('setting_fieldset')) { } if (!class_exists('setting_undefined')) { + /** + * Class setting_undefined + */ class setting_undefined extends setting_hidden { // A do-nothing class used to detect settings with no metadata entry. // Used internaly to hide undefined settings, and generate the undefined settings list. @@ -1038,6 +1182,9 @@ if (!class_exists('setting_undefined')) { } if (!class_exists('setting_no_class')) { + /** + * Class setting_no_class + */ class setting_no_class extends setting_undefined { // 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. @@ -1045,6 +1192,9 @@ if (!class_exists('setting_no_class')) { } if (!class_exists('setting_no_default')) { + /** + * Class setting_no_default + */ class setting_no_default extends setting_undefined { // A do-nothing class used to detect settings with no default value. // Used internaly to hide undefined settings, and generate the undefined settings list. @@ -1052,11 +1202,22 @@ if (!class_exists('setting_no_default')) { } if (!class_exists('setting_multicheckbox')) { + /** + * Class setting_multicheckbox + */ class setting_multicheckbox extends setting_string { var $_choices = array(); var $_combine = array(); + /** + * update changed setting with user provided value $input + * - if changed value fails error check, save it to $this->_input (to allow echoing later) + * - if changed value passes error check, set $this->_local to the new value + * + * @param mixed $input the new value + * @return boolean true if changed, false otherwise (also on error) + */ function update($input) { if ($this->is_protected()) return false; @@ -1077,9 +1238,15 @@ if (!class_exists('setting_multicheckbox')) { return true; } + /** + * Build html for label and input of setting + * + * @param DokuWiki_Plugin $plugin object of config plugin + * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting + * @return array with content array(string $label_html, string $input_html) + */ function html(&$plugin, $echo=false) { - $value = ''; $disable = ''; if ($this->is_protected()) { @@ -1141,6 +1308,9 @@ if (!class_exists('setting_multicheckbox')) { /** * convert comma separated list to an array and combine any complimentary values + * + * @param string $str + * @return array */ function _str2array($str) { $array = explode(',',$str); @@ -1164,6 +1334,9 @@ if (!class_exists('setting_multicheckbox')) { /** * convert array of values + other back to a comma separated list, incl. splitting any combined values + * + * @param array $input + * @return string */ function _array2str($input) { @@ -1192,6 +1365,9 @@ if (!class_exists('setting_multicheckbox')) { } if (!class_exists('setting_regex')){ + /** + * Class setting_regex + */ class setting_regex extends setting_string { var $_delimiter = '/'; // regex delimiter to be used in testing input @@ -1215,7 +1391,7 @@ if (!class_exists('setting_regex')){ // 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(); - $ok = @preg_match($regex,'testdata'); + @preg_match($regex,'testdata'); if (preg_last_error() != PREG_NO_ERROR || error_get_last() != $lastError) { $this->_input = $input; $this->_error = true; diff --git a/lib/plugins/config/settings/extra.class.php b/lib/plugins/config/settings/extra.class.php index 02171fb77..232a8177f 100644 --- a/lib/plugins/config/settings/extra.class.php +++ b/lib/plugins/config/settings/extra.class.php @@ -6,8 +6,15 @@ */ if (!class_exists('setting_sepchar')) { + /** + * Class setting_sepchar + */ class setting_sepchar extends setting_multichoice { + /** + * @param string $key + * @param array|null $param array with metadata of setting + */ function setting_sepchar($key,$param=null) { $str = '_-.'; for ($i=0;$i<strlen($str);$i++) $this->_choices[] = $str{$i}; @@ -19,8 +26,19 @@ if (!class_exists('setting_sepchar')) { } if (!class_exists('setting_savedir')) { + /** + * Class setting_savedir + */ class setting_savedir extends setting_string { + /** + * update changed setting with user provided value $input + * - if changed value fails error check, save it to $this->_input (to allow echoing later) + * - if changed value passes error check, set $this->_local to the new value + * + * @param mixed $input the new value + * @return boolean true if changed, false otherwise (also on error) + */ function update($input) { if ($this->is_protected()) return false; @@ -40,9 +58,20 @@ if (!class_exists('setting_savedir')) { } if (!class_exists('setting_authtype')) { + /** + * Class setting_authtype + */ class setting_authtype extends setting_multichoice { + /** + * Receives current values for the setting $key + * + * @param mixed $default default setting value + * @param mixed $local local setting value + * @param mixed $protected protected setting value + */ function initialize($default,$local,$protected) { + /** @var $plugin_controller Doku_Plugin_Controller */ global $plugin_controller; // retrieve auth types provided by plugins @@ -53,7 +82,16 @@ if (!class_exists('setting_authtype')) { parent::initialize($default,$local,$protected); } + /** + * update changed setting with user provided value $input + * - if changed value fails error check, save it to $this->_input (to allow echoing later) + * - if changed value passes error check, set $this->_local to the new value + * + * @param mixed $input the new value + * @return boolean true if changed, false otherwise (also on error) + */ function update($input) { + /** @var $plugin_controller Doku_Plugin_Controller */ global $plugin_controller; // is an update possible/requested? @@ -92,8 +130,19 @@ if (!class_exists('setting_authtype')) { } if (!class_exists('setting_im_convert')) { + /** + * Class setting_im_convert + */ class setting_im_convert extends setting_string { + /** + * update changed setting with user provided value $input + * - if changed value fails error check, save it to $this->_input (to allow echoing later) + * - if changed value passes error check, set $this->_local to the new value + * + * @param mixed $input the new value + * @return boolean true if changed, false otherwise (also on error) + */ function update($input) { if ($this->is_protected()) return false; @@ -115,8 +164,18 @@ if (!class_exists('setting_im_convert')) { } if (!class_exists('setting_disableactions')) { + /** + * Class setting_disableactions + */ class setting_disableactions extends setting_multicheckbox { + /** + * Build html for label and input of setting + * + * @param DokuWiki_Plugin $plugin object of config plugin + * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting + * @return array with content array(string $label_html, string $input_html) + */ function html(&$plugin, $echo=false) { global $lang; @@ -134,10 +193,20 @@ if (!class_exists('setting_disableactions')) { } if (!class_exists('setting_compression')) { + /** + * Class setting_compression + */ class setting_compression extends setting_multichoice { var $_choices = array('0'); // 0 = no compression, always supported + /** + * Receives current values for the setting $key + * + * @param mixed $default default setting value + * @param mixed $local local setting value + * @param mixed $protected protected setting value + */ function initialize($default,$local,$protected) { // populate _choices with the compression methods supported by this php installation @@ -150,10 +219,20 @@ if (!class_exists('setting_compression')) { } if (!class_exists('setting_license')) { + /** + * Class setting_license + */ class setting_license extends setting_multichoice { var $_choices = array(''); // none choosen + /** + * Receives current values for the setting $key + * + * @param mixed $default default setting value + * @param mixed $local local setting value + * @param mixed $protected protected setting value + */ function initialize($default,$local,$protected) { global $license; @@ -169,10 +248,20 @@ if (!class_exists('setting_license')) { if (!class_exists('setting_renderer')) { + /** + * Class setting_renderer + */ class setting_renderer extends setting_multichoice { var $_prompts = array(); var $_format = null; + /** + * Receives current values for the setting $key + * + * @param mixed $default default setting value + * @param mixed $local local setting value + * @param mixed $protected protected setting value + */ function initialize($default,$local,$protected) { $format = $this->_format; @@ -189,6 +278,13 @@ if (!class_exists('setting_renderer')) { parent::initialize($default,$local,$protected); } + /** + * Build html for label and input of setting + * + * @param DokuWiki_Plugin $plugin object of config plugin + * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting + * @return array with content array(string $label_html, string $input_html) + */ function html(&$plugin, $echo=false) { // make some language adjustments (there must be a better way) |