From 1843bbd051a3e72e7180cf0851f53d4cebb4853f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 22 Jan 2014 10:07:21 +0100 Subject: rename render() to render_text() in Doku_Plugin. #496 --- inc/plugin.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'inc/plugin.php') diff --git a/inc/plugin.php b/inc/plugin.php index dccd37bd9..95bdaee2b 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -238,11 +238,36 @@ class DokuWiki_Plugin { return "$title"; } + /** + * A fallback to provide access to the old render() method + * + * Since syntax plugins provide their own render method with a different signature and they now + * inherit from Doku_Plugin we can no longer have a render() method here (Strict Standards Violation). + * Instead use render_text() + * + * @deprecated 2014-01-22 + * @param $name + * @param $arguments + * @return null|string + */ + function __call($name, $arguments) { + if($name == 'render'){ + if(!isset($arguments[1])) $arguments[1] = 'xhtml'; + return $this->render_text($arguments[0], $arguments[1]); + } + trigger_error("no such method $name", E_ERROR); + return null; + } + /** * output text string through the parser, allows dokuwiki markup to be used * very ineffecient for small pieces of data - try not to use + * + * @param string $text wiki markup to parse + * @param string $format output format + * @return null|string */ - function render($text, $format='xhtml') { + function render_text($text, $format='xhtml') { return p_render($format, p_get_instructions($text),$info); } -- cgit v1.2.3 From 481343c25e1c66a6bc789de47ea9f8e257b67be1 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 9 Apr 2014 10:27:52 +0200 Subject: our code may only throw user errors --- inc/plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/plugin.php') diff --git a/inc/plugin.php b/inc/plugin.php index 95bdaee2b..7de4fbd74 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -255,7 +255,7 @@ class DokuWiki_Plugin { if(!isset($arguments[1])) $arguments[1] = 'xhtml'; return $this->render_text($arguments[0], $arguments[1]); } - trigger_error("no such method $name", E_ERROR); + trigger_error("no such method $name", E_USER_ERROR); return null; } -- cgit v1.2.3 From 1419a485e3ac0c507ef073f0b816bd41f7e4a5cd Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 10 May 2014 15:49:53 +0200 Subject: log deprecated function calls FS#2399 This introduces a new dbg_deprecated() function which allows for easy marking of deprecated functions. Each call is logged to the debuglog when debuggin is enabled. --- inc/plugin.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/plugin.php') diff --git a/inc/plugin.php b/inc/plugin.php index 7de4fbd74..e0112ef56 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -252,6 +252,7 @@ class DokuWiki_Plugin { */ function __call($name, $arguments) { if($name == 'render'){ + dbg_deprecated('render_text()'); if(!isset($arguments[1])) $arguments[1] = 'xhtml'; return $this->render_text($arguments[0], $arguments[1]); } -- cgit v1.2.3 From 38fb1fc7a9bbb1e70f0f24352891601b2e0856d6 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Tue, 13 May 2014 21:57:50 +0200 Subject: extend lang file cascade, so users can override some lang strings Fixes #692 --- inc/plugin.php | 1 + 1 file changed, 1 insertion(+) (limited to 'inc/plugin.php') diff --git a/inc/plugin.php b/inc/plugin.php index 7de4fbd74..dd374a4a4 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -124,6 +124,7 @@ class DokuWiki_Plugin { // 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'); + @include(DOKU_CONF.'plugin_lang/'.$this->getPluginName().'/'.$conf['lang'].'/lang.php'); $this->lang = $lang; $this->localised = true; -- cgit v1.2.3 From e5c4f36ca69d275977de01d6f85c5af43e92bb87 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Tue, 13 May 2014 22:16:27 +0200 Subject: Improve missing plugin.info.txt message. --- inc/plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/plugin.php') diff --git a/inc/plugin.php b/inc/plugin.php index 7de4fbd74..fda177716 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -36,8 +36,8 @@ class DokuWiki_Plugin { if(@file_exists($info)) return confToHash($info); msg('getInfo() not implemented in '.get_class($this). - ' and '.$info.' not found.
This is a bug in the '. - $parts[2].' plugin and should be reported to the '. + ' and '.$info.' not found.
Do you have installed the last version of the plugin? '. + 'If that is the case, this is a bug in the '. $parts[2].' plugin and should be reported to the '. 'plugin author.',-1); return array( 'date' => '0000-00-00', -- cgit v1.2.3 From ca86c17e1b77515f6e03e1a95538dc547a9217ac Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Tue, 13 May 2014 22:18:02 +0200 Subject: Reformat getInfo function with previous commit, Fixes #681 --- inc/plugin.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'inc/plugin.php') diff --git a/inc/plugin.php b/inc/plugin.php index fda177716..b97d8f0c2 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -30,18 +30,18 @@ class DokuWiki_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'; + function getInfo() { + $parts = explode('_', get_class($this)); + $info = DOKU_PLUGIN . '/' . $parts[2] . '/plugin.info.txt'; if(@file_exists($info)) return confToHash($info); - msg('getInfo() not implemented in '.get_class($this). - ' and '.$info.' not found.
Do you have installed the last version of the plugin? '. - 'If that is the case, this is a bug in the '. $parts[2].' plugin and should be reported to the '. - 'plugin author.',-1); + msg('getInfo() not implemented in ' . get_class($this) . + ' and ' . $info . ' not found.
Do you have installed the last version of the plugin? ' . + 'If that is the case, this is a bug in the ' . $parts[2] . ' plugin and should be reported to the ' . + 'plugin author.', -1); return array( - 'date' => '0000-00-00', - 'name' => $parts[2].' plugin', + 'date' => '0000-00-00', + 'name' => $parts[2] . ' plugin', ); } -- cgit v1.2.3 From dc6ff004a94faa44d41f2747cc6a0141d072d6e8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 4 Jul 2014 15:50:54 +0200 Subject: rephrased error message. #681 --- inc/plugin.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'inc/plugin.php') diff --git a/inc/plugin.php b/inc/plugin.php index fd19ba668..fbfc0325f 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -35,10 +35,11 @@ class DokuWiki_Plugin { $info = DOKU_PLUGIN . '/' . $parts[2] . '/plugin.info.txt'; if(@file_exists($info)) return confToHash($info); - msg('getInfo() not implemented in ' . get_class($this) . - ' and ' . $info . ' not found.
Do you have installed the last version of the plugin? ' . - 'If that is the case, this is a bug in the ' . $parts[2] . ' plugin and should be reported to the ' . - 'plugin author.', -1); + msg( + 'getInfo() not implemented in ' . get_class($this) . ' and ' . $info . ' not found.
' . + 'Verify you\'re running the latest version of the plugin. If the problem persists, send a ' . + 'bug report to the author of the ' . $parts[2] . ' plugin.', -1 + ); return array( 'date' => '0000-00-00', 'name' => $parts[2] . ' plugin', -- cgit v1.2.3 From dd7a6159c4224a6a3dda22a1f35f5fb13b06ec2e Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sun, 28 Sep 2014 13:27:05 +0200 Subject: use config cascade for loading of localizations --- inc/plugin.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'inc/plugin.php') diff --git a/inc/plugin.php b/inc/plugin.php index dd374a4a4..f632e3dd0 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -114,17 +114,29 @@ class DokuWiki_Plugin { * this function is automatically called by getLang() */ function setupLocale() { - if ($this->localised) return; + if($this->localised) return; - global $conf; // definitely don't invoke "global $lang" - $path = DOKU_PLUGIN.$this->getPluginName().'/lang/'; + global $conf, $config_cascade; // 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'); - @include(DOKU_CONF.'plugin_lang/'.$this->getPluginName().'/'.$conf['lang'].'/lang.php'); + @include($path . 'en/lang.php'); + foreach($config_cascade['lang']['plugin'] as $config_file) { + if(@file_exists($config_file . $this->getPluginName() . '/en/lang.php')) { + include($config_file . $this->getPluginName() . '/en/lang.php'); + } + } + + if($conf['lang'] != 'en') { + @include($path . $conf['lang'] . '/lang.php'); + foreach($config_cascade['lang']['plugin'] as $config_file) { + if(@file_exists($config_file . $this->getPluginName() . '/' . $conf['lang'] . '/lang.php')) { + include($config_file . $this->getPluginName() . '/' . $conf['lang'] . '/lang.php'); + } + } + } $this->lang = $lang; $this->localised = true; -- cgit v1.2.3 From 73411587cb6d2c54aefebe90c87799c4aa1d31ec Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sun, 28 Sep 2014 13:40:54 +0200 Subject: visibility plugin methods --- inc/plugin.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'inc/plugin.php') diff --git a/inc/plugin.php b/inc/plugin.php index f632e3dd0..1ec92e2d7 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -30,7 +30,7 @@ class DokuWiki_Plugin { * desc - Short description of the plugin (Text only) * url - Website with more information on the plugin (eg. syntax description) */ - function getInfo(){ + public function getInfo(){ $parts = explode('_',get_class($this)); $info = DOKU_PLUGIN.'/'.$parts[2].'/plugin.info.txt'; if(@file_exists($info)) return confToHash($info); @@ -47,15 +47,15 @@ class DokuWiki_Plugin { // plugin introspection methods // extract from class name, format = _plugin_[_] - function getPluginType() { + public function getPluginType() { list($t) = explode('_', get_class($this), 2); return $t; } - function getPluginName() { + public function getPluginName() { list($t, $p, $n) = explode('_', get_class($this), 4); return $n; } - function getPluginComponent() { + public function getPluginComponent() { list($t, $p, $n, $c) = explode('_', get_class($this), 4); return (isset($c)?$c:''); } @@ -70,7 +70,7 @@ class DokuWiki_Plugin { * @param string $id id of the string to be retrieved * @return string string in appropriate language or english if not available */ - function getLang($id) { + public function getLang($id) { if (!$this->localised) $this->setupLocale(); return (isset($this->lang[$id]) ? $this->lang[$id] : ''); @@ -85,7 +85,7 @@ class DokuWiki_Plugin { * @param string $id id of language dependent wiki page * @return string parsed contents of the wiki page in xhtml format */ - function locale_xhtml($id) { + public function locale_xhtml($id) { return p_cached_output($this->localFN($id)); } @@ -94,7 +94,7 @@ class DokuWiki_Plugin { * prepends appropriate path for a language dependent filename * plugin equivalent of localFN() */ - function localFN($id) { + public function localFN($id) { global $conf; $plugin = $this->getPluginName(); $file = DOKU_CONF.'plugin_lang/'.$plugin.'/'.$conf['lang'].'/'.$id.'.txt'; @@ -152,7 +152,7 @@ class DokuWiki_Plugin { * @param mixed $notset what to return if the setting is not available * @return mixed */ - function getConf($setting, $notset=false){ + public function getConf($setting, $notset=false){ if (!$this->configloaded){ $this->loadConfig(); } @@ -189,7 +189,7 @@ class DokuWiki_Plugin { * * @return array setting => value */ - function readDefaultSettings() { + protected function readDefaultSettings() { $path = DOKU_PLUGIN.$this->getPluginName().'/conf/'; $conf = array(); @@ -211,7 +211,7 @@ class DokuWiki_Plugin { * * @return object helper plugin object */ - function loadHelper($name, $msg = true){ + public function loadHelper($name, $msg = true){ $obj = plugin_load('helper',$name); if (is_null($obj) && $msg) msg("Helper plugin $name is not available or invalid.",-1); return $obj; @@ -224,7 +224,7 @@ class DokuWiki_Plugin { * email * standardised function to generate an email link according to obfuscation settings */ - function email($email, $name='', $class='', $more='') { + public function email($email, $name='', $class='', $more='') { if (!$email) return $name; $email = obfuscate($email); if (!$name) $name = $email; @@ -236,7 +236,7 @@ class DokuWiki_Plugin { * external_link * standardised function to generate an external link according to conf settings */ - function external_link($link, $title='', $class='', $target='', $more='') { + public function external_link($link, $title='', $class='', $target='', $more='') { global $conf; $link = htmlentities($link); @@ -263,7 +263,7 @@ class DokuWiki_Plugin { * @param $arguments * @return null|string */ - function __call($name, $arguments) { + public function __call($name, $arguments) { if($name == 'render'){ if(!isset($arguments[1])) $arguments[1] = 'xhtml'; return $this->render_text($arguments[0], $arguments[1]); @@ -280,7 +280,7 @@ class DokuWiki_Plugin { * @param string $format output format * @return null|string */ - function render_text($text, $format='xhtml') { + public function render_text($text, $format='xhtml') { return p_render($format, p_get_instructions($text),$info); } @@ -289,7 +289,7 @@ class DokuWiki_Plugin { * * @return bool false if the plugin has to be instantiated */ - function isSingleton() { + public function isSingleton() { return true; } } -- cgit v1.2.3 From 21d806cd5466991b4790c5e6b37a40ae35f1eecb Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Sun, 28 Sep 2014 14:44:17 +0200 Subject: improve some scrutinizer issues different types unused vars PHPDocs --- inc/plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/plugin.php') diff --git a/inc/plugin.php b/inc/plugin.php index 92a8efd62..80689e389 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -53,11 +53,11 @@ class DokuWiki_Plugin { return $t; } public function getPluginName() { - list($t, $p, $n) = explode('_', get_class($this), 4); + list(/* $t */, /* $p */, $n) = explode('_', get_class($this), 4); return $n; } public function getPluginComponent() { - list($t, $p, $n, $c) = explode('_', get_class($this), 4); + list(/* $t */, /* $p */, /* $n */, $c) = explode('_', get_class($this), 4); return (isset($c)?$c:''); } -- cgit v1.2.3 From 42ea7f447f39fbc2f79eaaec31f8c10ede59c5d0 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 11:30:27 +0200 Subject: Many PHPDocs, some unused and dyn declared vars many PHPDocs some unused variables some dynamically declared variables declared --- inc/plugin.php | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'inc/plugin.php') diff --git a/inc/plugin.php b/inc/plugin.php index fbfc0325f..8432b21b2 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -48,14 +48,25 @@ class DokuWiki_Plugin { // plugin introspection methods // extract from class name, format = _plugin_[_] + /** + * @return string plugin type + */ function getPluginType() { list($t) = explode('_', get_class($this), 2); return $t; } + + /** + * @return string plugin name + */ function getPluginName() { list($t, $p, $n) = explode('_', get_class($this), 4); return $n; } + + /** + * @return string component name + */ function getPluginComponent() { list($t, $p, $n, $c) = explode('_', get_class($this), 4); return (isset($c)?$c:''); @@ -91,9 +102,11 @@ class DokuWiki_Plugin { } /** - * localFN($id) - * prepends appropriate path for a language dependent filename + * Prepends appropriate path for a language dependent filename * plugin equivalent of localFN() + * + * @param string $id id of localization file + * @return string wiki text */ function localFN($id) { global $conf; @@ -110,9 +123,8 @@ class DokuWiki_Plugin { } /** - * setupLocale() - * reads all the plugins language dependent strings into $this->lang - * this function is automatically called by getLang() + * Reads all the plugins language dependent strings into $this->lang + * this function is automatically called by getLang() */ function setupLocale() { if ($this->localised) return; @@ -196,8 +208,7 @@ class DokuWiki_Plugin { * * @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 + * @return DokuWiki_Plugin|null helper plugin object */ function loadHelper($name, $msg = true){ $obj = plugin_load('helper',$name); @@ -211,6 +222,12 @@ class DokuWiki_Plugin { /** * email * standardised function to generate an email link according to obfuscation settings + * + * @param string $email + * @param string $name + * @param string $class + * @param string $more + * @return string html */ function email($email, $name='', $class='', $more='') { if (!$email) return $name; @@ -223,6 +240,13 @@ class DokuWiki_Plugin { /** * external_link * standardised function to generate an external link according to conf settings + * + * @param string $link + * @param string $title + * @param string $class + * @param string $target + * @param string $more + * @return string */ function external_link($link, $title='', $class='', $target='', $more='') { global $conf; @@ -247,8 +271,9 @@ class DokuWiki_Plugin { * Instead use render_text() * * @deprecated 2014-01-22 - * @param $name - * @param $arguments + * + * @param string $name + * @param array $arguments * @return null|string */ function __call($name, $arguments) { @@ -265,7 +290,7 @@ class DokuWiki_Plugin { * output text string through the parser, allows dokuwiki markup to be used * very ineffecient for small pieces of data - try not to use * - * @param string $text wiki markup to parse + * @param string $text wiki markup to parse * @param string $format output format * @return null|string */ -- cgit v1.2.3 From 7e8500eea1e53b1de0e0f70400664afa442cd08d Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Thu, 2 Oct 2014 14:55:24 +0200 Subject: PHPDocs and some improvements --- inc/plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'inc/plugin.php') diff --git a/inc/plugin.php b/inc/plugin.php index 8432b21b2..3bab560cb 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -60,7 +60,7 @@ class DokuWiki_Plugin { * @return string plugin name */ function getPluginName() { - list($t, $p, $n) = explode('_', get_class($this), 4); + list(/* $t */, /* $p */, $n) = explode('_', get_class($this), 4); return $n; } @@ -68,7 +68,7 @@ class DokuWiki_Plugin { * @return string component name */ function getPluginComponent() { - list($t, $p, $n, $c) = explode('_', get_class($this), 4); + list(/* $t */, /* $p */, /* $n */, $c) = explode('_', get_class($this), 4); return (isset($c)?$c:''); } -- cgit v1.2.3 From 79e79377626799a77c11aa7849cb9c64305590c8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 7 Jan 2015 10:47:45 +0100 Subject: Remove error supression for file_exists() In an older version of PHP a file_exists() call would issue a warning when the file did not exist. This was fixed in later PHP releases. Since we require PHP 5.3 now, there's no need to supress any error here anymore. This might even give a minor performance boost. --- inc/plugin.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'inc/plugin.php') diff --git a/inc/plugin.php b/inc/plugin.php index 9d9b2044c..f2ad95e2e 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -33,7 +33,7 @@ class DokuWiki_Plugin { public function getInfo(){ $parts = explode('_', get_class($this)); $info = DOKU_PLUGIN . '/' . $parts[2] . '/plugin.info.txt'; - if(@file_exists($info)) return confToHash($info); + if(file_exists($info)) return confToHash($info); msg( 'getInfo() not implemented in ' . get_class($this) . ' and ' . $info . ' not found.
' . @@ -112,9 +112,9 @@ class DokuWiki_Plugin { global $conf; $plugin = $this->getPluginName(); $file = DOKU_CONF.'plugin_lang/'.$plugin.'/'.$conf['lang'].'/'.$id.'.txt'; - if (!@file_exists($file)){ + if (!file_exists($file)){ $file = DOKU_PLUGIN.$plugin.'/lang/'.$conf['lang'].'/'.$id.'.txt'; - if(!@file_exists($file)){ + if(!file_exists($file)){ //fall back to english $file = DOKU_PLUGIN.$plugin.'/lang/en/'.$id.'.txt'; } @@ -137,7 +137,7 @@ class DokuWiki_Plugin { // don't include once, in case several plugin components require the same language file @include($path . 'en/lang.php'); foreach($config_cascade['lang']['plugin'] as $config_file) { - if(@file_exists($config_file . $this->getPluginName() . '/en/lang.php')) { + if(file_exists($config_file . $this->getPluginName() . '/en/lang.php')) { include($config_file . $this->getPluginName() . '/en/lang.php'); } } @@ -145,7 +145,7 @@ class DokuWiki_Plugin { if($conf['lang'] != 'en') { @include($path . $conf['lang'] . '/lang.php'); foreach($config_cascade['lang']['plugin'] as $config_file) { - if(@file_exists($config_file . $this->getPluginName() . '/' . $conf['lang'] . '/lang.php')) { + if(file_exists($config_file . $this->getPluginName() . '/' . $conf['lang'] . '/lang.php')) { include($config_file . $this->getPluginName() . '/' . $conf['lang'] . '/lang.php'); } } @@ -207,7 +207,7 @@ class DokuWiki_Plugin { $path = DOKU_PLUGIN.$this->getPluginName().'/conf/'; $conf = array(); - if (@file_exists($path.'default.php')) { + if (file_exists($path.'default.php')) { include($path.'default.php'); } -- cgit v1.2.3