From 10e43949456b8da1c4514f0eb674c306139df05b Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Sun, 18 Jan 2009 20:01:43 +0100 Subject: Major rework of pluginutils This patch completely reworks pluginutils to: - reduce the number of file accesses to enumerate and load plugins - change the way disabled plugins are recorded. a disabled plugin will now have ".disabled" added to its directory name (this halves the number of file accesses required to enumerate installed plugins) - place the guts of pluginutils code inside a class, Doku_Plugin_Controller, the existing access routines are preserved and no changes are required. - add two globals, $plugin_controller_class & $plugin_controller this allows preload.php to define its own plugin controller class - update config plugin to support new plugin structure config plugin now issues a PLUGIN_CONFIG_PLUGINLIST event before it finalizes the list of plugins it will be working with. Handlers of this event can remove plugins from the list. - update plugin manager plugin to support new plugin structure plugin manager now issues a PLUGIN_PLUGINMANAGER_PLUGINLIST event similarly to config plugin. - plugin manager updated to redirect after changes to plugins and to use msg() Finally, this patch contains a one-shot action plugin which will automatically convert a plugins directory from the old style disabled file to the new style. Note for darcs users, the new disabled format will mean a couple of old oneshot plugins, importoldchangelog and importoldindex, will have their directory names changed, which could lead to darcs wanting to record the change. darcs-hash:20090118190143-f07c6-d2e79af546a49a4af5817dd0c5cc27066e67c4d0.gz --- lib/plugins/config/settings/config.class.php | 60 ++++++++++++++++------------ 1 file changed, 34 insertions(+), 26 deletions(-) (limited to 'lib/plugins/config') diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php index 8610f2c81..c3531d6f3 100644 --- a/lib/plugins/config/settings/config.class.php +++ b/lib/plugins/config/settings/config.class.php @@ -237,6 +237,21 @@ if (!class_exists('configuration')) { return $out; } + function get_plugin_list() { + if (is_null($this->_plugin_list)) { + $list = plugin_list('',true); // all plugins, including disabled ones + + // remove this plugin from the list + $idx = array_search('config',$list); + unset($list[$idx]); + + trigger_event('PLUGIN_CONFIG_PLUGINLIST',$list); + $this->_plugin_list = $list; + } + + return $this->_plugin_list; + } + /** * load metadata for plugin and template settings */ @@ -245,25 +260,20 @@ if (!class_exists('configuration')) { $class = '/conf/settings.class.php'; $metadata = array(); - if ($dh = opendir(DOKU_PLUGIN)) { - while (false !== ($plugin = readdir($dh))) { - if ($plugin == '.' || $plugin == '..' || $plugin == 'tmp' || $plugin == 'config') continue; - if (is_file(DOKU_PLUGIN.$plugin)) continue; - - if (@file_exists(DOKU_PLUGIN.$plugin.$file)){ - $meta = array(); - @include(DOKU_PLUGIN.$plugin.$file); - @include(DOKU_PLUGIN.$plugin.$class); - if (!empty($meta)) { - $metadata['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.'plugin_settings_name'] = array('fieldset'); - } - foreach ($meta as $key => $value){ - if ($value[0]=='fieldset') { continue; } //plugins only get one fieldset - $metadata['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.$key] = $value; - } + foreach ($this->get_plugin_list() as $plugin) { + $plugin_dir = plugin_directory($plugin); + if (@file_exists(DOKU_PLUGIN.$plugin_dir.$file)){ + $meta = array(); + @include(DOKU_PLUGIN.$plugin_dir.$file); + @include(DOKU_PLUGIN.$plugin_dir.$class); + if (!empty($meta)) { + $metadata['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.'plugin_settings_name'] = array('fieldset'); + } + foreach ($meta as $key => $value){ + if ($value[0]=='fieldset') { continue; } //plugins only get one fieldset + $metadata['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.$key] = $value; } } - closedir($dh); } // the same for the active template @@ -290,17 +300,15 @@ if (!class_exists('configuration')) { $file = '/conf/default.php'; $default = array(); - if ($dh = opendir(DOKU_PLUGIN)) { - while (false !== ($plugin = readdir($dh))) { - if (@file_exists(DOKU_PLUGIN.$plugin.$file)){ - $conf = array(); - @include(DOKU_PLUGIN.$plugin.$file); - foreach ($conf as $key => $value){ - $default['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.$key] = $value; - } + foreach ($this->get_plugin_list() as $plugin) { + $plugin_dir = plugin_directory($plugin); + if (@file_exists(DOKU_PLUGIN.$plugin_dir.$file)){ + $conf = array(); + @include(DOKU_PLUGIN.$plugin_dir.$file); + foreach ($conf as $key => $value){ + $default['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.$key] = $value; } } - closedir($dh); } // the same for the active template -- cgit v1.2.3