diff options
author | Chris Smith <chris.eureka@jalakai.co.uk> | 2009-01-18 20:01:43 +0100 |
---|---|---|
committer | Chris Smith <chris.eureka@jalakai.co.uk> | 2009-01-18 20:01:43 +0100 |
commit | 10e43949456b8da1c4514f0eb674c306139df05b (patch) | |
tree | 695afffd75a7b6e13bf81f5d342043c71e266a18 /lib/plugins/plugin | |
parent | ca2b464bb4f7cab9b83cd6e2508c6079e3f948cc (diff) | |
download | rpg-10e43949456b8da1c4514f0eb674c306139df05b.tar.gz rpg-10e43949456b8da1c4514f0eb674c306139df05b.tar.bz2 |
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
Diffstat (limited to 'lib/plugins/plugin')
-rw-r--r-- | lib/plugins/plugin/admin.php | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/lib/plugins/plugin/admin.php b/lib/plugins/plugin/admin.php index a5c906a0b..237fe11b8 100644 --- a/lib/plugins/plugin/admin.php +++ b/lib/plugins/plugin/admin.php @@ -105,8 +105,7 @@ class admin_plugin_plugin extends DokuWiki_Admin_Plugin { $this->plugin = null; } - $this->plugin_list = plugin_list('', true); - sort($this->plugin_list); + $this->_get_plugin_list(); // verify $_REQUEST vars if (in_array($this->cmd, $this->commands)) { @@ -127,6 +126,7 @@ class admin_plugin_plugin extends DokuWiki_Admin_Plugin { $this->handler = & new $class($this, $this->plugin); $this->msg = $this->handler->process(); + } /** @@ -138,18 +138,25 @@ class admin_plugin_plugin extends DokuWiki_Admin_Plugin { // enable direct access to language strings $this->setupLocale(); + $this->_get_plugin_list(); if ($this->handler === NULL) $this->handler = & new ap_manage($this, $this->plugin); - if (!$this->plugin_list) { - $this->plugin_list = plugin_list('',true); - sort($this->plugin_list); - } ptln('<div id="plugin__manager">'); $this->handler->html(); ptln('</div><!-- #plugin_manager -->'); } + function _get_plugin_list() { + if (empty($this->plugin_list)) { + $list = plugin_list('',true); // all plugins, including disabled ones + sort($list); + trigger_event('PLUGIN_PLUGINMANAGER_PLUGINLIST',$list); + $this->plugin_list = $list; + } + return $this->plugin_list; + } + } class ap_manage { @@ -266,16 +273,23 @@ class ap_manage { * Refresh plugin list */ function refresh() { - - $this->manager->plugin_list = plugin_list('',true); - sort($this->manager->plugin_list); + global $MSG; + + //are there any undisplayed messages? keep them in session for display + if (isset($MSG) && count($MSG)){ + //reopen session, store data and close session again + @session_start(); + $_SESSION[DOKU_COOKIE]['msg'] = $MSG; + session_write_close(); + } // expire dokuwiki caches // touching local.php expires wiki page, JS and CSS caches @touch(DOKU_CONF.'local.php'); // update latest plugin date - FIXME - return (!$this->manager->error); + header('Location: '.wl($ID).'?do=admin&page=plugin'); + exit(); } function download($url, $overwrite=false) { @@ -336,6 +350,7 @@ class ap_manage { if ($tmp) ap_delete($tmp); if (!$this->manager->error) { + msg('Plugin package ('.count($this->downloaded).' plugin'.(count($this->downloaded) != 1?'s':'').': '.join(',',$this->downloaded).') successfully installed.',1); $this->refresh(); return true; } @@ -368,7 +383,7 @@ class ap_manage { function plugin_readlog($plugin, $field) { static $log = array(); - $file = DOKU_PLUGIN.$plugin.'/manager.dat'; + $file = DOKU_PLUGIN.plugin_directory($plugin).'/manager.dat'; if (!isset($log[$plugin])) { $tmp = @file_get_contents($file); @@ -380,7 +395,7 @@ class ap_manage { return $log[$plugin]; } - $match = array(); + $match = array(); if (preg_match_all('/'.$field.'=(.*)$/m',$log[$plugin], $match)) return implode("\n", $match[1]); @@ -429,9 +444,10 @@ class ap_manage { function process() { - if (!ap_delete(DOKU_PLUGIN.$this->manager->plugin)) { + if (!ap_delete(DOKU_PLUGIN.plugin_directory($this->manager->plugin))) { $this->manager->error = sprintf($this->lang['error_delete'],$this->manager->plugin); } else { + msg("Plugin {$this->manager->plugin} successfully deleted."); $this->refresh(); } } @@ -589,6 +605,7 @@ class ap_manage { function process() { global $plugin_protected; + $count_enabled = $count_disabled = 0; $this->enabled = isset($_REQUEST['enabled']) ? $_REQUEST['enabled'] : array(); @@ -601,14 +618,23 @@ class ap_manage { if ($new != $old) { switch ($new) { // enable plugin - case true : plugin_enable($plugin); break; - case false: plugin_disable($plugin); break; + case true : + plugin_enable($plugin); + $count_enabled++; + break; + case false: + plugin_disable($plugin); + $count_disabled++; + break; } } } // refresh plugins, including expiring any dokuwiki cache(s) - $this->refresh(); + if ($count_enabled || $count_disabled) { + msg("Plugin state saved, $count_enabled plugins enabled, $count_disabled plugins disabled."); + $this->refresh(); + } } } @@ -732,7 +758,7 @@ class ap_manage { global $plugin_types; $components = array(); - $path = DOKU_PLUGIN.$plugin.'/'; + $path = DOKU_PLUGIN.plugin_directory($plugin).'/'; foreach ($plugin_types as $type) { if (@file_exists($path.$type.'.php')) { $components[] = array('name'=>$plugin, 'type'=>$type); continue; } |