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/upgradeplugindirectory | |
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/upgradeplugindirectory')
-rw-r--r-- | lib/plugins/upgradeplugindirectory/action.php | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/lib/plugins/upgradeplugindirectory/action.php b/lib/plugins/upgradeplugindirectory/action.php new file mode 100644 index 000000000..9461299df --- /dev/null +++ b/lib/plugins/upgradeplugindirectory/action.php @@ -0,0 +1,97 @@ +<?php +/** + * Action Plugin: + * Upgrades the plugin directory from the "old style" of disabling plugins to the new style + * + * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) + * @author Christopher Smith <chris@jalakai.co.uk> + */ + +if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); +if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +require_once(DOKU_PLUGIN.'action.php'); + +/** + * All DokuWiki plugins to extend the parser/rendering mechanism + * need to inherit from this class + */ +class action_plugin_upgradeplugindirectory extends DokuWiki_Action_Plugin { + + /** + * return some info + */ + function getInfo(){ + return array( + 'author' => 'Christopher Smith', + 'email' => 'chris@jalakai.co.uk', + 'date' => '2009-01-18', + 'name' => 'Upgrade Plugin Directory', + 'desc' => 'Silently updates plugin disabled indicator to new more efficient format', + 'url' => 'http://wiki.splitbrain.org/plugin:upgradeplugindirectory', + ); + } + + /* + * plugin should use this method to register its handlers with the dokuwiki's event controller + */ + function register(&$controller) { + $controller->register_hook('DOKUWIKI_STARTED','BEFORE', $this, 'handle_upgrade','before'); + } + + function handle_upgrade(&$event, $param) { + global $plugin_controller; + $attempts = 0; + $success = 0; + $updated = 0; + $failures = array(); + $badclean = array(); + + if (empty($plugin_controller)) return; + + $plugins = $plugin_controller->getList('',true); // get all plugins + foreach ($plugins as $plugin) { + if ($this->plugin_isdisabled_oldstyle($plugin)) { + $attempts++; + if (@$plugin_controller->disable($plugin)) { + $updated++; + if ($this->plugin_clean($plugin)) { + $success++; + } else { + $badclean[] = $plugin; + } + } else { + $failures[] = $plugin; + } + } + } + + if ($attempts && auth_isAdmin()) { + $level = $failures ? -1 : ($badclean ? 2 : 1); + msg("Plugin Directory Upgrade, $updated/$attempts plugins updated, $success/$attempts cleaned.",$level); + if ($badclean) msg("- the following disabled plugins were updated, but their directories couldn't be cleaned: ".join(',',$badclean),$level); + if ($failures) { + msg("- the following disabled plugins couldn't be updated, please update by hand: ".join(',',$failures),$level); + } + msg("For more information see http://www.dokuwiki.org/update",$level); + } + + // no failures, our job is done, disable ourself + if (!$failures) { + $plugin_controller->disable($this->getPluginName()); + // redirect to let dokuwiki start cleanly with plugins disabled. + act_redirect($ID,'upgradeplugindirectory'); + } + + } + + /* old style plugin isdisabled function */ + function plugin_isdisabled_oldstyle($name) { + return @file_exists(DOKU_PLUGIN.$name.'/disabled'); + } + + function plugin_clean($name) { + return @unlink(DOKU_PLUGIN.$name.'.disabled/disabled'); + } +} + +//Setup VIM: ex: et ts=4 enc=utf-8 :
\ No newline at end of file |