From 685bdd2e6c508c47a360b2dbf1beea318f7f99cd Mon Sep 17 00:00:00 2001 From: Ben Coburn Date: Sat, 20 May 2006 12:37:18 +0200 Subject: config plugin ui update 20060520 This patch hides settings that are missing config metadata and optionally provides a list of warnings about settings that are not properly configured. - Warnings about settings are listed if $conf['allowdebug'] is true. - Warnings are listed by the $conf string as it appears in local.php. - Warnings show the $meta string as it would appear in the correct settings metadata file. - There are 3 kinds of warnings. - undefined There is no $meta information defined for this setting. - no class The setting class specified in $meta can not be found. This setting does have a $meta entry. - no default The setting is missing a default value. The setting does have a $meta entry with a valid setting class. - Note: Settings with metadata but other warnings are allowed to appear in the normal config settings list. Also... - Templates can now define their own settings classes. - Removed an XHTML validation error from the first patch. - More language strings to go with the new warnings. The warnings under the 'Undefined Settings' heading are intended to provide developers with a list of any settings that they have forgotten to finish preparing for the config plugin. This list should be blank for stable releases. darcs-hash:20060520103718-05dcb-6d4e6bce78498cbf9d087e27d52e4aa30917b0a5.gz --- lib/plugins/config/admin.php | 49 ++++++++++++++++++++++++-- lib/plugins/config/lang/en/lang.php | 6 ++++ lib/plugins/config/settings/config.class.php | 51 ++++++++++++++++++++++++++-- lib/plugins/config/settings/extra.class.php | 5 --- 4 files changed, 101 insertions(+), 10 deletions(-) (limited to 'lib/plugins') diff --git a/lib/plugins/config/admin.php b/lib/plugins/config/admin.php index cae1c3e42..649318ef9 100644 --- a/lib/plugins/config/admin.php +++ b/lib/plugins/config/admin.php @@ -4,6 +4,7 @@ * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Christopher Smith + * @author Ben Coburn */ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); @@ -91,6 +92,7 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { * output appropriate html */ function html() { + $allow_debug = $GLOBALS['conf']['allowdebug']; // avoid global $conf; here. global $lang; global $ID; @@ -112,11 +114,19 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { ptln('
'); $this->_print_h1('dokuwiki_settings', $this->getLang('_header_dokuwiki')); + $undefined_settings = array(); $in_fieldset = false; $first_plugin_fieldset = true; $first_template_fieldset = true; foreach($this->_config->setting as $setting) { - if (is_a($setting, 'setting_fieldset')) { + if (is_a($setting, 'setting_hidden')) { + // skip hidden (and undefined) settings + if ($allow_debug && is_a($setting, 'setting_undefined')) { + $undefined_settings[] = $setting; + } else { + continue; + } + } else if (is_a($setting, 'setting_fieldset')) { // config setting group if ($in_fieldset) { ptln(' '); @@ -131,7 +141,7 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { $this->_print_h1('template_settings', $this->getLang('_header_template')); $first_template_fieldset = false; } - ptln('
'); + ptln('
'); ptln(' '.$setting->prompt($this).''); ptln(' '); } else { @@ -153,6 +163,30 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { ptln(' '); } + // show undefined settings list + if ($allow_debug && !empty($undefined_settings)) { + 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('
'); + ptln('
'); + $undefined_setting_match = array(); + foreach($undefined_settings as $setting) { + if (preg_match('/^(?:plugin|tpl)'.CM_KEYMARKER.'.*?'.CM_KEYMARKER.'(.*)$/', $setting->_key, $undefined_setting_match)) { + $undefined_setting_key = $undefined_setting_match[1]; + } else { + $undefined_setting_key = $setting->_key; + } + ptln(' '); + ptln(' '); + ptln(' '); + ptln(' '); + } + ptln('
$'.$this->_config->_name.'[\''.$setting->_out_key().'\']'.$this->getLang('_msg_'.get_class($setting)).'
'); + ptln('
'); + } + + // finish up form ptln('

'); ptln(' '); ptln(' '); @@ -270,7 +304,10 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { * @author Ben Coburn */ function _print_config_toc() { + $allow_debug = $GLOBALS['conf']['allowdebug']; // avoid global $conf; here. + // gather toc data + $has_undefined = false; $toc = array('conf'=>array(), 'plugin'=>array(), 'template'=>null); foreach($this->_config->setting as $setting) { if (is_a($setting, 'setting_fieldset')) { @@ -281,6 +318,8 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { } else { $toc['conf'][] = $setting; } + } else if (!$has_undefined && is_a($setting, 'setting_undefined')) { + $has_undefined = true; } } @@ -326,6 +365,12 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin { 'type' => 'ul', 'level' => 2); } + if ($has_undefined && $allow_debug) { + $xhtml_toc[] = array('hid' => 'undefined_settings', + 'title' => $this->getLang('_header_undefined'), + 'type' => 'ul', + 'level' => 1); + } // use the xhtml renderer to make the toc require_once(DOKU_INC.'inc/parser/xhtml.php'); diff --git a/lib/plugins/config/lang/en/lang.php b/lib/plugins/config/lang/en/lang.php index 5e2599419..dce4b0faf 100644 --- a/lib/plugins/config/lang/en/lang.php +++ b/lib/plugins/config/lang/en/lang.php @@ -22,6 +22,7 @@ $lang['_configuration_manager'] = 'Configuration Manager'; //same as heading in $lang['_header_dokuwiki'] = 'DokuWiki Settings'; $lang['_header_plugin'] = 'Plugin Settings'; $lang['_header_template'] = 'Template Settings'; +$lang['_header_undefined'] = 'Undefined Settings'; /* --- Config Setting Groups --- */ $lang['_basic'] = 'Basic Settings'; @@ -40,6 +41,11 @@ $lang['_network'] = 'Network Settings'; $lang['_plugin_sufix'] = 'Plugin Settings'; $lang['_template_sufix'] = 'Template Settings'; +/* --- Undefined Setting Messages --- */ +$lang['_msg_setting_undefined'] = 'No setting metadata.'; +$lang['_msg_setting_no_class'] = 'No setting class.'; +$lang['_msg_setting_no_default'] = 'No default value.'; + /* -------------------- Config Options --------------------------- */ $lang['fmode'] = 'File creation mode'; diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php index 1ef1662ef..105d6c83a 100644 --- a/lib/plugins/config/settings/config.class.php +++ b/lib/plugins/config/settings/config.class.php @@ -1,8 +1,9 @@ + * @author Ben Coburn */ if (!class_exists('configuration')) { @@ -51,6 +52,7 @@ if (!class_exists('configuration')) { function retrieve_settings() { global $conf; + $no_default_check = array('setting_fieldset', 'setting_undefined', 'setting_no_class'); if (!$this->_loaded) { $default = array_merge($this->_read_config($this->_default_file), $this->get_plugintpl_default($conf['template'])); @@ -64,14 +66,21 @@ if (!class_exists('configuration')) { if (isset($this->_metadata[$key])) { $class = $this->_metadata[$key][0]; $class = ($class && class_exists('setting_'.$class)) ? 'setting_'.$class : 'setting'; + if ($class=='setting') { + $this->setting[] = new setting_no_class($key,$param); + } $param = $this->_metadata[$key]; array_shift($param); } else { - $class = 'setting'; + $class = 'setting_undefined'; $param = NULL; } + if (!in_array($class, $no_default_check) && !isset($default[$key])) { + $this->setting[] = new setting_no_default($key,$param); + } + $this->setting[$key] = new $class($key,$param); $this->setting[$key]->initialize($default[$key],$local[$key],$protected[$key]); } @@ -223,7 +232,7 @@ if (!class_exists('configuration')) { if (@file_exists(DOKU_PLUGIN.$plugin.$file)){ $meta = array(); @include(DOKU_PLUGIN.$plugin.$file); - @include(DOKU_PLUGIN.$plugin.$class); + @include(DOKU_PLUGIN.$plugin.$class); if (!empty($meta)) { $metadata['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.'plugin_settings_name'] = array('fieldset'); } @@ -240,6 +249,7 @@ if (!class_exists('configuration')) { if (@file_exists(DOKU_TPLINC.$file)){ $meta = array(); @include(DOKU_TPLINC.$file); + @include(DOKU_TPLINC.$class); if (!empty($meta)) { $metadata['tpl'.CM_KEYMARKER.$tpl.CM_KEYMARKER.'template_settings_name'] = array('fieldset'); } @@ -616,6 +626,41 @@ if (!class_exists('setting_dirchoice')) { } +if (!class_exists('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 extends setting { + // A do-nothing class used to detect the 'fieldset' type. + // Used to start a new settings "display-group". + } +} + +if (!class_exists('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. + } +} + +if (!class_exists('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. + } +} + +if (!class_exists('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. + } +} + + /** * Provide php_strip_whitespace (php5 function) functionality * diff --git a/lib/plugins/config/settings/extra.class.php b/lib/plugins/config/settings/extra.class.php index 715acb53b..260f32eaf 100644 --- a/lib/plugins/config/settings/extra.class.php +++ b/lib/plugins/config/settings/extra.class.php @@ -79,8 +79,3 @@ if (!class_exists('setting_im_convert')) { } } -if (!class_exists('setting_fieldset')) { - class setting_fieldset extends setting_string { - //do-nothing class used to detect the 'fieldset' type. - } -} -- cgit v1.2.3