From 72d89f96f31af5c92f96fa16f0d1adf15c0bf4e8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 7 Jan 2014 19:16:54 +0100 Subject: remove duplicate plugin code for syntax plugins This makes Doku_Parser_Mode inherit from DokuWiki_Plugin which allows for the removal of a bunch of duplicate code form DokuWiki_Syntax_Plugin. This makes the code easier to maintain and makes sure all DokuWiki plugins are actual instances of DokuWiki_Plugin. However this adds a bunch of functions to the "normal" parser modes that don't need them which could have performance/RAM implications. --- lib/plugins/syntax.php | 186 ------------------------------------------------- 1 file changed, 186 deletions(-) (limited to 'lib/plugins/syntax.php') diff --git a/lib/plugins/syntax.php b/lib/plugins/syntax.php index 8df5abb08..bc2c6447c 100644 --- a/lib/plugins/syntax.php +++ b/lib/plugins/syntax.php @@ -15,30 +15,6 @@ if(!defined('DOKU_INC')) die(); class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { var $allowedModesSetup = false; - var $localised = false; // set to true by setupLocale() after loading language dependent strings - var $lang = array(); // array to hold language dependent strings, best accessed via ->getLang() - var $configloaded = false; // set to true by loadConfig() after loading plugin configuration variables - var $conf = array(); // array to hold plugin settings, best accessed via ->getConf() - - /** - * General Info - * - * Needs to return a associative array with the following values: - * - * author - Author of the plugin - * email - Email address to contact the author - * date - Last modified date of the plugin in YYYY-MM-DD format - * name - Name of the plugin - * desc - Short description of the plugin (Text only) - * url - Website with more information on the plugin (eg. syntax description) - */ - function getInfo(){ - $parts = explode('_',get_class($this)); - $info = DOKU_PLUGIN.'/'.$parts[2].'/plugin.info.txt'; - if(@file_exists($info)) return confToHash($info); - trigger_error('getInfo() not implemented in '.get_class($this).' and '.$info.' not found', E_USER_WARNING); - return array(); - } /** * Syntax Type @@ -144,167 +120,5 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { return parent::accepts($mode); } - - // plugin introspection methods - // extract from class name, format = _plugin_[_] - function getPluginType() { list($t) = explode('_', get_class($this), 2); return $t; } - function getPluginName() { list($t, $p, $n) = explode('_', get_class($this), 4); return $n; } - - /** - * Get the name of the component of the current class - * - * @return string component name - */ - function getPluginComponent() { list($t, $p, $n, $c) = explode('_', get_class($this), 4); return (isset($c)?$c:''); } - - // localisation methods - /** - * getLang($id) - * - * use this function to access plugin language strings - * to try to minimise unnecessary loading of the strings when the plugin doesn't require them - * e.g. when info plugin is querying plugins for information about themselves. - * - * @param string $id id of the string to be retrieved - * @return string string in appropriate language or english if not available - */ - function getLang($id) { - if (!$this->localised) $this->setupLocale(); - - return (isset($this->lang[$id]) ? $this->lang[$id] : ''); - } - - /** - * locale_xhtml($id) - * - * retrieve a language dependent wiki page and pass to xhtml renderer for display - * plugin equivalent of p_locale_xhtml() - * - * @param string $id id of language dependent wiki page - * @return string parsed contents of the wiki page in xhtml format - */ - function locale_xhtml($id) { - return p_cached_output($this->localFN($id)); - } - - /** - * localFN($id) - * prepends appropriate path for a language dependent filename - * plugin equivalent of localFN() - */ - function localFN($id) { - global $conf; - $plugin = $this->getPluginName(); - $file = DOKU_CONF.'/plugin_lang/'.$plugin.'/'.$conf['lang'].'/'.$id.'.txt'; - if (!@file_exists($file)){ - $file = DOKU_PLUGIN.$plugin.'/lang/'.$conf['lang'].'/'.$id.'.txt'; - if(!@file_exists($file)){ - //fall back to english - $file = DOKU_PLUGIN.$plugin.'/lang/en/'.$id.'.txt'; - } - } - return $file; - } - - /** - * setupLocale() - * reads all the plugins language dependent strings into $this->lang - * this function is automatically called by getLang() - */ - function setupLocale() { - if ($this->localised) return; - - global $conf; // definitely don't invoke "global $lang" - $path = DOKU_PLUGIN.$this->getPluginName().'/lang/'; - - $lang = array(); - // don't include once, in case several plugin components require the same language file - @include($path.'en/lang.php'); - if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php'); - - $this->lang = $lang; - $this->localised = true; - } - - // configuration methods - /** - * getConf($setting) - * - * use this function to access plugin configuration variables - */ - function getConf($setting) { - - if(!$this->configloaded) { $this->loadConfig(); } - - return $this->conf[$setting]; - } - - /** - * loadConfig() - * merges the plugin's default settings with any local settings - * this function is automatically called through getConf() - */ - function loadConfig() { - global $conf; - - $defaults = $this->readDefaultSettings(); - $plugin = $this->getPluginName(); - - foreach($defaults as $key => $value) { - if(isset($conf['plugin'][$plugin][$key])) continue; - $conf['plugin'][$plugin][$key] = $value; - } - - $this->configloaded = true; - $this->conf =& $conf['plugin'][$plugin]; - } - - /** - * read the plugin's default configuration settings from conf/default.php - * this function is automatically called through getConf() - * - * @return array setting => value - */ - function readDefaultSettings() { - - $path = DOKU_PLUGIN.$this->getPluginName().'/conf/'; - $conf = array(); - - if(@file_exists($path.'default.php')) { - include($path.'default.php'); - } - - return $conf; - } - - /** - * Loads a given helper plugin (if enabled) - * - * @author Esther Brunner - * - * @param string $name name of plugin to load - * @param bool $msg if a message should be displayed in case the plugin is not available - * - * @return object helper plugin object - */ - function loadHelper($name, $msg = true) { - if(!plugin_isdisabled($name)) { - $obj = plugin_load('helper', $name); - } else { - $obj = null; - } - if(is_null($obj) && $msg) msg("Helper plugin $name is not available or invalid.", -1); - return $obj; - } - - /** - * Allow the plugin to prevent DokuWiki from reusing an instance - * - * @return bool false if the plugin has to be instantiated - */ - function isSingleton() { - return true; - } - } //Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From 5a3e1f53b18728d500b3505f4fbd8c78848120e0 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 7 Jan 2014 19:35:57 +0100 Subject: reintroduce a tiny bit of duplication This reads some duplication in the from of haveing a Doku_Parser_Mode and Doku_Parser_Mode_Plugin class which are basically the same but only the latter extends DokuWiki_Plugin. This avoids the performance/RAM problems mentioned in my previous commit. An interface keeps both logically together. With PHP 5.4 further deduplication could be done via Traits. --- lib/plugins/syntax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/plugins/syntax.php') diff --git a/lib/plugins/syntax.php b/lib/plugins/syntax.php index bc2c6447c..7ab9c30e1 100644 --- a/lib/plugins/syntax.php +++ b/lib/plugins/syntax.php @@ -12,7 +12,7 @@ if(!defined('DOKU_INC')) die(); * All DokuWiki plugins to extend the parser/rendering mechanism * need to inherit from this class */ -class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode { +class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { var $allowedModesSetup = false; -- cgit v1.2.3 From 3cd4fc17379f0f917d5e1ed4d20decfb662aaf32 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Wed, 5 Mar 2014 22:18:08 +0000 Subject: remove '&' from object parameters, PHP5 style not E_ALL --- lib/plugins/syntax.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/plugins/syntax.php') diff --git a/lib/plugins/syntax.php b/lib/plugins/syntax.php index 7ab9c30e1..ec90993cf 100644 --- a/lib/plugins/syntax.php +++ b/lib/plugins/syntax.php @@ -66,7 +66,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * @param Doku_Handler $handler Reference to the Doku_Handler object * @return array Return an array with all data you want to use in render */ - function handle($match, $state, $pos, Doku_Handler &$handler){ + function handle($match, $state, $pos, Doku_Handler $handler){ trigger_error('handle() not implemented in '.get_class($this), E_USER_WARNING); } @@ -93,7 +93,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * @param $data array data created by handler() * @return boolean rendered correctly? */ - function render($format, Doku_Renderer &$renderer, $data) { + function render($format, Doku_Renderer $renderer, $data) { trigger_error('render() not implemented in '.get_class($this), E_USER_WARNING); } -- cgit v1.2.3 From a96178004fc8b519df17f6cb907e1c067b964bb2 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Thu, 6 Mar 2014 20:03:30 +0000 Subject: remove reference to reference from comments --- lib/plugins/syntax.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/plugins/syntax.php') diff --git a/lib/plugins/syntax.php b/lib/plugins/syntax.php index ec90993cf..42a4903ec 100644 --- a/lib/plugins/syntax.php +++ b/lib/plugins/syntax.php @@ -63,7 +63,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * @param string $match The text matched by the patterns * @param int $state The lexer state for the match * @param int $pos The character position of the matched text - * @param Doku_Handler $handler Reference to the Doku_Handler object + * @param Doku_Handler $handler The Doku_Handler object * @return array Return an array with all data you want to use in render */ function handle($match, $state, $pos, Doku_Handler $handler){ @@ -89,7 +89,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * created * * @param $format string output format being rendered - * @param $renderer Doku_Renderer reference to the current renderer object + * @param $renderer Doku_Renderer the current renderer object * @param $data array data created by handler() * @return boolean rendered correctly? */ -- cgit v1.2.3 From 7ac0b9fe750a5713353e6edce51493a8a75c4f6f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 25 May 2014 12:24:14 +0200 Subject: just some more doc blocks --- lib/plugins/syntax.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/plugins/syntax.php') diff --git a/lib/plugins/syntax.php b/lib/plugins/syntax.php index 42a4903ec..4a301f927 100644 --- a/lib/plugins/syntax.php +++ b/lib/plugins/syntax.php @@ -20,9 +20,12 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * Syntax Type * * Needs to return one of the mode types defined in $PARSER_MODES in parser.php + * + * @return string */ function getType(){ trigger_error('getType() not implemented in '.get_class($this), E_USER_WARNING); + return ''; } /** @@ -31,6 +34,8 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * Defines the mode types for other dokuwiki markup that maybe nested within the * plugin's own markup. Needs to return an array of one or more of the mode types * defined in $PARSER_MODES in parser.php + * + * @return array */ function getAllowedTypes() { return array(); @@ -47,6 +52,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * 'stack' - Special case. Plugin wraps other paragraphs. * * @see Doku_Handler_Block + * @return string */ function getPType(){ return 'normal'; @@ -99,7 +105,10 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { } /** - * There should be no need to override these functions + * There should be no need to override this function + * + * @param string $mode + * @return bool */ function accepts($mode) { -- cgit v1.2.3 From 253d4b48ec708eb42033862dc15c8576f44a48ed Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 15:32:05 +0200 Subject: more PHPDocs, unused var, small bit code reformatting --- lib/plugins/syntax.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/plugins/syntax.php') diff --git a/lib/plugins/syntax.php b/lib/plugins/syntax.php index 4a301f927..7acf681e4 100644 --- a/lib/plugins/syntax.php +++ b/lib/plugins/syntax.php @@ -52,6 +52,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * 'stack' - Special case. Plugin wraps other paragraphs. * * @see Doku_Handler_Block + * * @return string */ function getPType(){ @@ -94,9 +95,9 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * The contents of the $data array depends on what the handler() function above * created * - * @param $format string output format being rendered - * @param $renderer Doku_Renderer the current renderer object - * @param $data array data created by handler() + * @param string $format output format being rendered + * @param Doku_Renderer $renderer the current renderer object + * @param array $data data created by handler() * @return boolean rendered correctly? */ function render($format, Doku_Renderer $renderer, $data) { -- cgit v1.2.3 From cded11250d495f6039a20f1036c64ea7b230ceb2 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 3 Dec 2014 00:09:45 +0100 Subject: phpdocs syntax plugin base class --- lib/plugins/syntax.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/plugins/syntax.php') diff --git a/lib/plugins/syntax.php b/lib/plugins/syntax.php index 4a301f927..7d2daa70d 100644 --- a/lib/plugins/syntax.php +++ b/lib/plugins/syntax.php @@ -70,7 +70,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * @param int $state The lexer state for the match * @param int $pos The character position of the matched text * @param Doku_Handler $handler The Doku_Handler object - * @return array Return an array with all data you want to use in render + * @return bool|array Return an array with all data you want to use in render, false don't add an instruction */ function handle($match, $state, $pos, Doku_Handler $handler){ trigger_error('handle() not implemented in '.get_class($this), E_USER_WARNING); @@ -97,7 +97,7 @@ class DokuWiki_Syntax_Plugin extends Doku_Parser_Mode_Plugin { * @param $format string output format being rendered * @param $renderer Doku_Renderer the current renderer object * @param $data array data created by handler() - * @return boolean rendered correctly? + * @return boolean rendered correctly? (however, returned value is not used at the moment) */ function render($format, Doku_Renderer $renderer, $data) { trigger_error('render() not implemented in '.get_class($this), E_USER_WARNING); -- cgit v1.2.3