Skip to content

Commit

Permalink
Allow plugins to specify that they have to be instantiated
Browse files Browse the repository at this point in the history
Plugins may return false in isSingleton to let plugin_load return a new
instance every time it is called.
Renderer plugins are not loaded with $new set to true, but instead specify
themself that they are not singletons. This behaviour allows the odt renderer
to keep working (see #1598).
  • Loading branch information
adrianheine committed Mar 29, 2010
1 parent ea6dfbc commit f6ec8df
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
9 changes: 9 additions & 0 deletions inc/parser/renderer.php
Expand Up @@ -49,6 +49,15 @@ function getFormat(){
trigger_error('getFormat() not implemented in '.get_class($this), E_USER_WARNING);
}

/**
* Allow the plugin to prevent DokuWiki from reusing an instance
*
* @return bool false if the plugin has to be instantiated
*/
function isSingleton() {
return false;
}


//handle plugin rendering
function plugin($name,$data){
Expand Down
2 changes: 1 addition & 1 deletion inc/parserutils.php
Expand Up @@ -585,7 +585,7 @@ function & p_get_renderer($mode) {
// Maybe a plugin/component is available?
list($plugin, $component) = $plugin_controller->_splitName($rname);
if (!$plugin_controller->isdisabled($plugin)){
$Renderer =& $plugin_controller->load('renderer',$rname, true);
$Renderer =& $plugin_controller->load('renderer',$rname);
}

if(is_null($Renderer)){
Expand Down
6 changes: 3 additions & 3 deletions inc/plugin.php
Expand Up @@ -231,12 +231,12 @@ function render($text, $format='xhtml') {
}

/**
* Allow the plugin to prevent DokuWiki creating a second instance of itself
* Allow the plugin to prevent DokuWiki from reusing an instance
*
* @return bool true if the plugin can not be instantiated more than once
* @return bool false if the plugin has to be instantiated
*/
function isSingleton() {
return false;
return true;
}

// deprecated functions
Expand Down
2 changes: 1 addition & 1 deletion inc/plugincontroller.class.php
Expand Up @@ -66,7 +66,7 @@ function &load($type,$name,$new=false){

//plugin already loaded?
if(!empty($DOKU_PLUGINS[$type][$name])){
if ($new && !$DOKU_PLUGINS[$type][$name]->isSingleton()) {
if ($new || !$DOKU_PLUGINS[$type][$name]->isSingleton()) {
$class = $type.'_plugin_'.$name;
return class_exists($class) ? new $class : null;
} else {
Expand Down
8 changes: 0 additions & 8 deletions lib/plugins/syntax.php
Expand Up @@ -266,13 +266,5 @@ function readDefaultSettings() {
return $conf;
}

/**
* Allow the plugin to prevent DokuWiki creating a second instance of itself
*
* @return bool true if the plugin can not be instantiated more than once
*/
function isSingleton() {
return false;
}
}
//Setup VIM: ex: et ts=4 enc=utf-8 :

0 comments on commit f6ec8df

Please sign in to comment.