From e8b5a4f91c8a6e230a6cfe13c43dc9ddce31e253 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 28 Jul 2012 12:02:06 +0200 Subject: fix E_STRICT errors FS#2427 This commit fixes all E_STRICT messages shown when running the test suite. There might be more problems not covered by tests, yet. For compatibility reasons with plugins, E_STRICT errors are still supressed. --- ...serutils_set_metadata_during_rendering.test.php | 3 +- inc/SafeFN.class.php | 12 +++---- inc/events.php | 2 +- inc/parser/metadata.php | 41 ---------------------- inc/parser/renderer.php | 2 +- inc/parserutils.php | 2 +- inc/plugin.php | 2 +- lib/plugins/action.php | 2 +- lib/plugins/popularity/action.php | 2 +- lib/plugins/safefnrecode/action.php | 2 +- lib/plugins/testing/action.php | 3 +- 11 files changed, 17 insertions(+), 56 deletions(-) diff --git a/_test/tests/inc/parserutils_set_metadata_during_rendering.test.php b/_test/tests/inc/parserutils_set_metadata_during_rendering.test.php index 0683848f1..f08785ca2 100644 --- a/_test/tests/inc/parserutils_set_metadata_during_rendering.test.php +++ b/_test/tests/inc/parserutils_set_metadata_during_rendering.test.php @@ -50,7 +50,8 @@ class parserutils_set_metadata_during_rendering_test extends DokuWikiTest { function helper_set_metadata($event, $meta) { if ($this->active) { p_set_metadata($this->id, $meta, false, true); - $key = array_pop(array_keys($meta)); + $keys = array_keys($meta); + $key = array_pop($keys); $this->assertTrue(is_string($meta[$key])); // ensure we really have a key // ensure that the metadata property hasn't been set previously $this->assertNotEquals($meta[$key], p_get_metadata($this->id, $key)); diff --git a/inc/SafeFN.class.php b/inc/SafeFN.class.php index ab05b9eae..b9e4a2b2a 100644 --- a/inc/SafeFN.class.php +++ b/inc/SafeFN.class.php @@ -44,7 +44,7 @@ class SafeFN { * * @author Christopher Smith */ - public function encode($filename) { + public static function encode($filename) { return self::unicode_to_safe(utf8_to_unicode($filename)); } @@ -73,15 +73,15 @@ class SafeFN { * * @author Christopher Smith */ - public function decode($filename) { + public static function decode($filename) { return unicode_to_utf8(self::safe_to_unicode(strtolower($filename))); } - public function validate_printable_utf8($printable_utf8) { + public static function validate_printable_utf8($printable_utf8) { return !preg_match('#[\x01-\x1f]#',$printable_utf8); } - public function validate_safe($safe) { + public static function validate_safe($safe) { return !preg_match('#[^'.self::$plain.self::$post_indicator.self::$pre_indicator.']#',$safe); } @@ -93,7 +93,7 @@ class SafeFN { * * @author Christopher Smith */ - private function unicode_to_safe($unicode) { + private static function unicode_to_safe($unicode) { $safe = ''; $converted = false; @@ -126,7 +126,7 @@ class SafeFN { * * @author Christopher Smith */ - private function safe_to_unicode($safe) { + private static function safe_to_unicode($safe) { $unicode = array(); $split = preg_split('#(?=['.self::$post_indicator.self::$pre_indicator.'])#',$safe,-1,PREG_SPLIT_NO_EMPTY); diff --git a/inc/events.php b/inc/events.php index 4e81f85c8..f7b1a7a16 100644 --- a/inc/events.php +++ b/inc/events.php @@ -132,7 +132,7 @@ class Doku_Event_Handler { $pluginlist = plugin_list('action'); foreach ($pluginlist as $plugin_name) { - $plugin =& plugin_load('action',$plugin_name); + $plugin = plugin_load('action',$plugin_name); if ($plugin !== null) $plugin->register($this); } diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 8bfdc3b9c..8638ffa6a 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -133,27 +133,6 @@ class Doku_Renderer_metadata extends Doku_Renderer { } } - function strong_open(){} - function strong_close(){} - - function emphasis_open(){} - function emphasis_close(){} - - function underline_open(){} - function underline_close(){} - - function monospace_open(){} - function monospace_close(){} - - function subscript_open(){} - function subscript_close(){} - - function superscript_open(){} - function superscript_close(){} - - function deleted_open(){} - function deleted_close(){} - /** * Callback for footnote start syntax * @@ -218,14 +197,6 @@ class Doku_Renderer_metadata extends Doku_Renderer { if ($this->capture) $this->doc .= $text; } - function php($text){} - - function phpblock($text){} - - function html($text){} - - function htmlblock($text){} - function preformatted($text){ if ($this->capture) $this->doc .= $text; } @@ -393,18 +364,6 @@ class Doku_Renderer_metadata extends Doku_Renderer { $params['refresh']; } - function table_open($maxcols = NULL, $numrows = NULL){} - function table_close(){} - - function tablerow_open(){} - function tablerow_close(){} - - function tableheader_open($colspan = 1, $align = NULL, $rowspan = 1){} - function tableheader_close(){} - - function tablecell_open($colspan = 1, $align = NULL, $rowspan = 1){} - function tablecell_close(){} - //---------------------------------------------------------- // Utils diff --git a/inc/parser/renderer.php b/inc/parser/renderer.php index 0923e6896..2c78f220a 100644 --- a/inc/parser/renderer.php +++ b/inc/parser/renderer.php @@ -62,7 +62,7 @@ class Doku_Renderer extends DokuWiki_Plugin { //handle plugin rendering function plugin($name,$data){ - $plugin =& plugin_load('syntax',$name); + $plugin = plugin_load('syntax',$name); if($plugin != null){ $plugin->render($this->getFormat(),$this,$data); } diff --git a/inc/parserutils.php b/inc/parserutils.php index 20f992ba2..58920cbea 100644 --- a/inc/parserutils.php +++ b/inc/parserutils.php @@ -570,7 +570,7 @@ function p_get_parsermodes(){ $obj = null; foreach($pluginlist as $p){ /** @var DokuWiki_Syntax_Plugin $obj */ - if(!$obj =& plugin_load('syntax',$p)) continue; //attempt to load plugin into $obj + if(!$obj = plugin_load('syntax',$p)) continue; //attempt to load plugin into $obj $PARSER_MODES[$obj->getType()][] = "plugin_$p"; //register mode type //add to modes $modes[] = array( diff --git a/inc/plugin.php b/inc/plugin.php index d2fe3818d..b0518346d 100644 --- a/inc/plugin.php +++ b/inc/plugin.php @@ -191,7 +191,7 @@ class DokuWiki_Plugin { */ function loadHelper($name, $msg){ if (!plugin_isdisabled($name)){ - $obj =& plugin_load('helper',$name); + $obj = plugin_load('helper',$name); }else{ $obj = null; } diff --git a/lib/plugins/action.php b/lib/plugins/action.php index 885bd7c96..a2ad969d7 100644 --- a/lib/plugins/action.php +++ b/lib/plugins/action.php @@ -17,7 +17,7 @@ class DokuWiki_Action_Plugin extends DokuWiki_Plugin { /** * Registers a callback function for a given event */ - function register($controller) { + function register(Doku_Event_Handler $controller) { trigger_error('register() not implemented in '.get_class($this), E_USER_WARNING); } } diff --git a/lib/plugins/popularity/action.php b/lib/plugins/popularity/action.php index bf11efba6..1c7a2f65d 100644 --- a/lib/plugins/popularity/action.php +++ b/lib/plugins/popularity/action.php @@ -18,7 +18,7 @@ class action_plugin_popularity extends Dokuwiki_Action_Plugin { /** * Register its handlers with the dokuwiki's event controller */ - function register(&$controller) { + function register(Doku_Event_Handler $controller) { $controller->register_hook('INDEXER_TASKS_RUN', 'AFTER', $this, '_autosubmit', array()); } diff --git a/lib/plugins/safefnrecode/action.php b/lib/plugins/safefnrecode/action.php index 5d3eaae3a..aae11c437 100644 --- a/lib/plugins/safefnrecode/action.php +++ b/lib/plugins/safefnrecode/action.php @@ -13,7 +13,7 @@ require_once DOKU_PLUGIN.'action.php'; class action_plugin_safefnrecode extends DokuWiki_Action_Plugin { - public function register(Doku_Event_Handler &$controller) { + public function register(Doku_Event_Handler $controller) { $controller->register_hook('INDEXER_TASKS_RUN', 'BEFORE', $this, 'handle_indexer_tasks_run'); diff --git a/lib/plugins/testing/action.php b/lib/plugins/testing/action.php index e829847b6..a242ab0b7 100644 --- a/lib/plugins/testing/action.php +++ b/lib/plugins/testing/action.php @@ -7,7 +7,8 @@ * @author Tobias Sarnowski */ class action_plugin_testing extends DokuWiki_Action_Plugin { - function register(&$controller) { + + function register(Doku_Event_Handler $controller) { $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'dokuwikiStarted'); } -- cgit v1.2.3 From a0df75e62c09594d1d1ed11be9a911badab0699e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Mon, 17 Sep 2012 11:08:34 +0300 Subject: add index file similar to fileicons to show active smileys --- lib/images/smileys/index.php | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 lib/images/smileys/index.php diff --git a/lib/images/smileys/index.php b/lib/images/smileys/index.php new file mode 100644 index 000000000..9a2905b33 --- /dev/null +++ b/lib/images/smileys/index.php @@ -0,0 +1,48 @@ + + + + simleys + + + + + + +
+ '; +} +?> +
+ +
+ '; +} +?> +
+ + + -- cgit v1.2.3 From d12bd962d0cacbaad479be04cc953c607212756f Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 31 Oct 2012 16:33:22 +0100 Subject: added test for isHiddenPage() --- _test/tests/inc/pageutils_isHiddenPage.test.php | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 _test/tests/inc/pageutils_isHiddenPage.test.php diff --git a/_test/tests/inc/pageutils_isHiddenPage.test.php b/_test/tests/inc/pageutils_isHiddenPage.test.php new file mode 100644 index 000000000..8f2fcebea --- /dev/null +++ b/_test/tests/inc/pageutils_isHiddenPage.test.php @@ -0,0 +1,37 @@ +prepare(''); + + $this->assertFalse(isHiddenPage('test')); + } + + function testHiddenOffAdmin(){ + $this->prepare('^:test$', 'admin'); + + $this->assertFalse(isHiddenPage('test')); + } + + function testHiddenOnMatch(){ + $this->prepare(); + + $this->assertTrue(isHiddenPage('test')); + } + + function testHiddenOnNoMatch(){ + $this->prepare(); + + $this->assertFalse(isHiddenPage('another')); + } + +} +//Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From 8449cc9d82848df24eb88a73dd81d7e048933287 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Wed, 31 Oct 2012 16:51:54 +0100 Subject: added event PAGEUTILS_ID_HIDEPAGE --- _test/tests/inc/PageUtilsIsHiddenPage.test.php | 49 +++++++++++++++++++++++++ _test/tests/inc/pageutils_isHiddenPage.test.php | 37 ------------------- inc/pageutils.php | 8 ++++ 3 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 _test/tests/inc/PageUtilsIsHiddenPage.test.php delete mode 100644 _test/tests/inc/pageutils_isHiddenPage.test.php diff --git a/_test/tests/inc/PageUtilsIsHiddenPage.test.php b/_test/tests/inc/PageUtilsIsHiddenPage.test.php new file mode 100644 index 000000000..153d0e8f6 --- /dev/null +++ b/_test/tests/inc/PageUtilsIsHiddenPage.test.php @@ -0,0 +1,49 @@ +prepare(''); + + $this->assertFalse(isHiddenPage('test')); + } + + function testHiddenOffAdmin(){ + $this->prepare('^:test$', 'admin'); + + $this->assertFalse(isHiddenPage('test')); + } + + function testHiddenOnMatch(){ + $this->prepare(); + + $this->assertTrue(isHiddenPage('test')); + } + + function testHiddenOnNoMatch(){ + $this->prepare(); + + $this->assertFalse(isHiddenPage('another')); + } + + function testEventHandler() { + global $EVENT_HANDLER; + $this->prepare(); + $EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'BEFORE', $this, 'alwaysHide'); + + $this->assertFalse(isHiddenPage('test')); + } + + function alwaysHide(Doku_Event &$event, $params) { + $event->data['hide'] = true; + } + +} +//Setup VIM: ex: et ts=4 : diff --git a/_test/tests/inc/pageutils_isHiddenPage.test.php b/_test/tests/inc/pageutils_isHiddenPage.test.php deleted file mode 100644 index 8f2fcebea..000000000 --- a/_test/tests/inc/pageutils_isHiddenPage.test.php +++ /dev/null @@ -1,37 +0,0 @@ -prepare(''); - - $this->assertFalse(isHiddenPage('test')); - } - - function testHiddenOffAdmin(){ - $this->prepare('^:test$', 'admin'); - - $this->assertFalse(isHiddenPage('test')); - } - - function testHiddenOnMatch(){ - $this->prepare(); - - $this->assertTrue(isHiddenPage('test')); - } - - function testHiddenOnNoMatch(){ - $this->prepare(); - - $this->assertFalse(isHiddenPage('another')); - } - -} -//Setup VIM: ex: et ts=4 : diff --git a/inc/pageutils.php b/inc/pageutils.php index 55cc081a1..853d3fb4d 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -538,6 +538,14 @@ function getCacheName($data,$ext=''){ function isHiddenPage($id){ global $conf; global $ACT; + + $data = array( + 'id' => $id, + 'hidden' => false + ); + trigger_event('PAGEUTILS_ID_HIDEPAGE', $id); + + if ($data['hidden']) return true; if(empty($conf['hidepages'])) return false; if($ACT == 'admin') return false; -- cgit v1.2.3 From fb55b51ef82bc3066173e7547500d9e79c410e34 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Mon, 5 Nov 2012 10:57:42 +0100 Subject: changed PAGEUTILS_ID_HIDEPAGE to has BEFORE/AFTER --- _test/tests/inc/PageUtilsIsHiddenPage.test.php | 52 ++++++++++++++++++++++++-- inc/pageutils.php | 22 ++++++----- 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/_test/tests/inc/PageUtilsIsHiddenPage.test.php b/_test/tests/inc/PageUtilsIsHiddenPage.test.php index 153d0e8f6..a7077862e 100644 --- a/_test/tests/inc/PageUtilsIsHiddenPage.test.php +++ b/_test/tests/inc/PageUtilsIsHiddenPage.test.php @@ -33,16 +33,62 @@ class PageUtilsIsHiddenPageTest extends DokuWikiTest { $this->assertFalse(isHiddenPage('another')); } - function testEventHandler() { + function testEventHandlerBefore() { global $EVENT_HANDLER; $this->prepare(); $EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'BEFORE', $this, 'alwaysHide'); - $this->assertFalse(isHiddenPage('test')); + $this->assertTrue(isHiddenPage('another')); } function alwaysHide(Doku_Event &$event, $params) { - $event->data['hide'] = true; + $event->data['hidden'] = true; + } + + function testEventHandlerBeforeAndPrevent() { + global $EVENT_HANDLER; + $this->prepare(); + $EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'BEFORE', $this, 'showBefore'); + + $this->assertFalse(isHiddenPage('test')); + } + + function showBefore(Doku_Event &$event, $params) { + $event->data['hidden'] = false; + $event->preventDefault(); + $event->stopPropagation(); + } + + function testEventHandlerAfter() { + global $EVENT_HANDLER; + $this->prepare(); + $EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'AFTER', $this, 'alwaysHide'); + + $this->assertTrue(isHiddenPage('another')); + } + + function testEventHandlerAfterHide() { + global $EVENT_HANDLER; + $this->prepare(); + $EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'AFTER', $this, 'hideBeforeWithoutPrevent'); + + $this->assertTrue(isHiddenPage('another')); + } + + function hideBeforeWithoutPrevent(Doku_Event &$event, $params) { + $event->data['hidden'] = true; + } + + function testEventHandlerAfterShow() { + global $EVENT_HANDLER; + $this->prepare(); + $EVENT_HANDLER->register_hook('PAGEUTILS_ID_HIDEPAGE', 'AFTER', $this, 'showAfter'); + + $this->assertFalse(isHiddenPage('test')); + } + + function showAfter(Doku_Event &$event, $params) { + $event->data['hidden'] = false; } } diff --git a/inc/pageutils.php b/inc/pageutils.php index 853d3fb4d..3bb10883f 100644 --- a/inc/pageutils.php +++ b/inc/pageutils.php @@ -536,23 +536,25 @@ function getCacheName($data,$ext=''){ * @author Andreas Gohr */ function isHiddenPage($id){ - global $conf; - global $ACT; - $data = array( 'id' => $id, 'hidden' => false ); - trigger_event('PAGEUTILS_ID_HIDEPAGE', $id); + trigger_event('PAGEUTILS_ID_HIDEPAGE', $data, '_isHiddenPage'); + return $data['hidden']; +} - if ($data['hidden']) return true; - if(empty($conf['hidepages'])) return false; - if($ACT == 'admin') return false; +function _isHiddenPage(&$data) { + global $conf; + global $ACT; - if(preg_match('/'.$conf['hidepages'].'/ui',':'.$id)){ - return true; + if ($data['hidden']) return; + if(empty($conf['hidepages'])) return; + if($ACT == 'admin') return; + + if(preg_match('/'.$conf['hidepages'].'/ui',':'.$data['id'])){ + $data['hidden'] = true; } - return false; } /** -- cgit v1.2.3 From bfd975d26ab51152ac6a256827ffda93b15df48b Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 6 Nov 2012 20:58:38 +0100 Subject: fix regression bug in HTTPClient FS#2621 In the recent refactoring of the HTTPClient, a problem with certain systems was reintroduced. On these systems a select() call always waits for a timeout on the first call before working properly on the second call. This patch reintroduces the shorter timeouts with usleep rate limiting again. Since this bug is not reproducible on other systems it can't be unit tested unfortunately. --- inc/HTTPClient.php | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/inc/HTTPClient.php b/inc/HTTPClient.php index a25846c31..c4cfcbf7c 100644 --- a/inc/HTTPClient.php +++ b/inc/HTTPClient.php @@ -509,15 +509,17 @@ class HTTPClient { if(feof($socket)) throw new HTTPClientException("Socket disconnected while writing $message"); - // wait for stream ready or timeout - self::selecttimeout($this->timeout - $time_used, $sec, $usec); - if(@stream_select($sel_r, $sel_w, $sel_e, $sec, $usec) !== false){ - // write to stream - $nbytes = fwrite($socket, substr($data,$written,4096)); - if($nbytes === false) - throw new HTTPClientException("Failed writing to socket while sending $message", -100); - $written += $nbytes; + // wait for stream ready or timeout (1sec) + if(@stream_select($sel_r,$sel_w,$sel_e,1) === false){ + usleep(1000); + continue; } + + // write to stream + $nbytes = fwrite($socket, substr($data,$written,4096)); + if($nbytes === false) + throw new HTTPClientException("Failed writing to socket while sending $message", -100); + $written += $nbytes; } } @@ -556,15 +558,17 @@ class HTTPClient { } if ($to_read > 0) { - // wait for stream ready or timeout - self::selecttimeout($this->timeout - $time_used, $sec, $usec); - if(@stream_select($sel_r, $sel_w, $sel_e, $sec, $usec) !== false){ - $bytes = fread($socket, $to_read); - if($bytes === false) - throw new HTTPClientException("Failed reading from socket while reading $message", -100); - $r_data .= $bytes; - $to_read -= strlen($bytes); + // wait for stream ready or timeout (1sec) + if(@stream_select($sel_r,$sel_w,$sel_e,1) === false){ + usleep(1000); + continue; } + + $bytes = fread($socket, $to_read); + if($bytes === false) + throw new HTTPClientException("Failed reading from socket while reading $message", -100); + $r_data .= $bytes; + $to_read -= strlen($bytes); } } while ($to_read > 0 && strlen($r_data) < $nbytes); return $r_data; @@ -595,11 +599,13 @@ class HTTPClient { if(feof($socket)) throw new HTTPClientException("Premature End of File (socket) while reading $message"); - // wait for stream ready or timeout - self::selecttimeout($this->timeout - $time_used, $sec, $usec); - if(@stream_select($sel_r, $sel_w, $sel_e, $sec, $usec) !== false){ - $r_data = fgets($socket, 1024); + // wait for stream ready or timeout (1sec) + if(@stream_select($sel_r,$sel_w,$sel_e,1) === false){ + usleep(1000); + continue; } + + $r_data = fgets($socket, 1024); } while (!preg_match('/\n$/',$r_data)); return $r_data; } @@ -629,14 +635,6 @@ class HTTPClient { return ((float)$usec + (float)$sec); } - /** - * Calculate seconds and microseconds - */ - static function selecttimeout($time, &$sec, &$usec){ - $sec = floor($time); - $usec = (int)(($time - $sec) * 1000000); - } - /** * convert given header string to Header array * -- cgit v1.2.3 From 63d9b82068e796869bf6ff648623acd33be27ebe Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 7 Nov 2012 00:28:12 +0100 Subject: avoid multiple paralell update checks we now touch the messages before the actual update happens. this should lower the chance of more than one update check running at a time. --- inc/infoutils.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/infoutils.php b/inc/infoutils.php index 7ceeae8f1..dfd6554e7 100644 --- a/inc/infoutils.php +++ b/inc/infoutils.php @@ -25,12 +25,12 @@ function checkUpdateMessages(){ // check if new messages needs to be fetched if($lm < time()-(60*60*24) || $lm < @filemtime(DOKU_INC.DOKU_SCRIPT)){ + @touch($cf); dbglog("checkUpdatesMessages(): downloading messages.txt"); $http = new DokuHTTPClient(); - $http->timeout = 8; + $http->timeout = 12; $data = $http->get(DOKU_MESSAGEURL.$updateVersion); io_saveFile($cf,$data); - @touch($cf); }else{ dbglog("checkUpdatesMessages(): messages.txt up to date"); $data = io_readFile($cf); -- cgit v1.2.3 From a731ed1d6736ca405b3559adfd9500affcc59412 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Thu, 8 Nov 2012 22:48:07 +0100 Subject: added PCRE UTF-8 checks to do=check FS#2636 --- inc/infoutils.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/inc/infoutils.php b/inc/infoutils.php index dfd6554e7..0dc7092ad 100644 --- a/inc/infoutils.php +++ b/inc/infoutils.php @@ -176,6 +176,13 @@ function check(){ msg('mb_string extension not available - PHP only replacements will be used',0); } + if (!preg_match("/^.$/u", "ñ")) { + msg('PHP is missing UTF-8 support in Perl-Compatible Regular Expressions (PCRE)', -1); + } + if (!preg_match("/^\pL$/u", "ñ")) { + msg('PHP is missing Unicode properties support in Perl-Compatible Regular Expressions (PCRE)', -1); + } + $loc = setlocale(LC_ALL, 0); if(!$loc){ msg('No valid locale is set for your PHP setup. You should fix this',-1); -- cgit v1.2.3 From 89d02586756515c9fb68a348e99a787d95e999a2 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 10 Nov 2012 18:12:39 +0100 Subject: config manager: removed dead/commented code --- lib/plugins/config/settings/config.class.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php index 8c48018d7..ebf638526 100644 --- a/lib/plugins/config/settings/config.class.php +++ b/lib/plugins/config/settings/config.class.php @@ -45,14 +45,8 @@ if (!class_exists('configuration')) { $this->_local_files = $config_cascade['main']['local']; $this->_protected_files = $config_cascade['main']['protected']; -# if (isset($file['default'])) $this->_default_file = $file['default']; -# if (isset($file['local'])) $this->_local_file = $file['local']; -# if (isset($file['protected'])) $this->_protected_file = $file['protected']; - $this->locked = $this->_is_locked(); - $this->_metadata = array_merge($meta, $this->get_plugintpl_metadata($conf['template'])); - $this->retrieve_settings(); } @@ -147,7 +141,6 @@ if (!class_exists('configuration')) { if (!$file) return array(); $config = array(); -# $file = eval('return '.$file.';'); if ($this->_format == 'php') { @@ -195,9 +188,6 @@ if (!class_exists('configuration')) { function _out_footer() { $out = ''; if ($this->_format == 'php') { - # if ($this->_protected_file) { - # $out .= "\n@include(".$this->_protected_file.");\n"; - # } $out .= "\n// end auto-generated content\n"; } @@ -209,7 +199,6 @@ if (!class_exists('configuration')) { function _is_locked() { if (!$this->_local_files) return true; -# $local = eval('return '.$this->_local_file.';'); $local = $this->_local_files[0]; if (!is_writable(dirname($local))) return true; @@ -425,8 +414,6 @@ if (!class_exists('setting')) { $out = ''; if ($fmt=='php') { - // translation string needs to be improved FIXME - $tr = array("\n"=>'\n', "\r"=>'\r', "\t"=>'\t', "\\" => '\\\\', "'" => '\\\''); $tr = array("\\" => '\\\\', "'" => '\\\''); $out = '$'.$var."['".$this->_out_key()."'] = '".strtr($this->_local, $tr)."';\n"; -- cgit v1.2.3 From b8f41ef0bac4e82cb3b02cd318efaddbaaeb1a78 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 10 Nov 2012 18:13:09 +0100 Subject: config manager: let PHP parse the config file Until now, the config manager did read and parse the various PHP config files itself. This fails for more complex setups like arrays. I'm not really sure why this was done. This patch replaces the parsing with a simple include() call. Everything still seems to work. --- lib/plugins/config/settings/config.class.php | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php index ebf638526..722c8df7b 100644 --- a/lib/plugins/config/settings/config.class.php +++ b/lib/plugins/config/settings/config.class.php @@ -139,32 +139,13 @@ if (!class_exists('configuration')) { function _read_config($file) { if (!$file) return array(); + if (!file_exists($file)) return array(); $config = array(); if ($this->_format == 'php') { - - if(@file_exists($file)){ - $contents = @php_strip_whitespace($file); - }else{ - $contents = ''; - } - $pattern = '/\$'.$this->_name.'\[[\'"]([^=]+)[\'"]\] ?= ?(.*?);(?=[^;]*(?:\$'.$this->_name.'|$))/s'; - $matches=array(); - preg_match_all($pattern,$contents,$matches,PREG_SET_ORDER); - - for ($i=0; $i'\\','\\\''=>'\'','\\"'=>'"')); - - $config[$key] = $value; - } + include($file); + $config = ${$this->_name}; } return $config; -- cgit v1.2.3 From 60dd32d957e6c4ce2d969c45cc60497f55a39abe Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 10 Nov 2012 18:18:05 +0100 Subject: added 'array' type for config manager This allows to use simple arrays in the config file but have a comma separated list in the config manager. --- lib/plugins/config/settings/config.class.php | 104 ++++++++++++++++++++++++ lib/plugins/config/settings/config.metadata.php | 3 + 2 files changed, 107 insertions(+) diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php index 722c8df7b..e4a638eb0 100644 --- a/lib/plugins/config/settings/config.class.php +++ b/lib/plugins/config/settings/config.class.php @@ -435,6 +435,110 @@ if (!class_exists('setting')) { } } + +if (!class_exists('setting_array')) { + class setting_array extends setting { + + /** + * Create an array from a string + * + * @param $string + * @return array + */ + protected function _from_string($string){ + $array = explode(',', $string); + $array = array_map('trim', $array); + $array = array_filter($array); + $array = array_unique($array); + return $array; + } + + /** + * Create a string from an array + * + * @param $array + * @return string + */ + protected function _from_array($array){ + return join(', ', (array) $array); + } + + /** + * update setting with user provided value $input + * if value fails error check, save it + * + * @param string $input + * @return bool true if changed, false otherwise (incl. on error) + */ + function update($input) { + if (is_null($input)) return false; + if ($this->is_protected()) return false; + + $input = $this->_from_string($input); + + $value = is_null($this->_local) ? $this->_default : $this->_local; + if ($value == $input) return false; + + foreach($input as $item){ + if ($this->_pattern && !preg_match($this->_pattern,$item)) { + $this->_error = true; + $this->_input = $input; + return false; + } + } + + $this->_local = $input; + return true; + } + + protected function _escape($string) { + $tr = array("\\" => '\\\\', "'" => '\\\''); + return "'".strtr( cleanText($string), $tr)."'"; + } + + /** + * generate string to save setting value to file according to $fmt + */ + function out($var, $fmt='php') { + + if ($this->is_protected()) return ''; + if (is_null($this->_local) || ($this->_default == $this->_local)) return ''; + + $out = ''; + + if ($fmt=='php') { + $vals = array_map(array($this, '_escape'), $this->_local); + $out = '$'.$var."['".$this->_out_key()."'] = array(".join(', ',$vals).");\n"; + } + + return $out; + } + + function html(&$plugin, $echo=false) { + $value = ''; + $disable = ''; + + if ($this->is_protected()) { + $value = $this->_protected; + $disable = 'disabled="disabled"'; + } else { + if ($echo && $this->_error) { + $value = $this->_input; + } else { + $value = is_null($this->_local) ? $this->_default : $this->_local; + } + } + + $key = htmlspecialchars($this->_key); + $value = htmlspecialchars($this->_from_array($value)); + + $label = ''; + $input = ''; + return array($label,$input); + } + } +} + if (!class_exists('setting_string')) { class setting_string extends setting { function html(&$plugin, $echo=false) { diff --git a/lib/plugins/config/settings/config.metadata.php b/lib/plugins/config/settings/config.metadata.php index 3607f56c6..582452917 100644 --- a/lib/plugins/config/settings/config.metadata.php +++ b/lib/plugins/config/settings/config.metadata.php @@ -32,6 +32,9 @@ * separated list of checked choices * 'fieldset' - used to group configuration settings, but is not itself a setting. To make this clear in * the language files the keys for this type should start with '_'. + * 'array' - a simple (one dimensional) array of string values, shown as comma separated list in the + * config manager but saved as PHP array(). Values may not contain commas themselves. + * _pattern matching on the array values supported. * * Single Setting (source: settings/extra.class.php) * ------------------------------------------------- -- cgit v1.2.3 From d30b165d18ab3a6868d3b3e96e7bac782fb58441 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 16 Nov 2012 13:28:15 +0100 Subject: Revert "config manager: let PHP parse the config file" This reverts commit b8f41ef0bac4e82cb3b02cd318efaddbaaeb1a78. We had good reasons for parsing the file ourselves. For example to keep expressions like 7*60*60*24 intact. --- lib/plugins/config/settings/config.class.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php index e4a638eb0..e71a7e5f9 100644 --- a/lib/plugins/config/settings/config.class.php +++ b/lib/plugins/config/settings/config.class.php @@ -139,13 +139,32 @@ if (!class_exists('configuration')) { function _read_config($file) { if (!$file) return array(); - if (!file_exists($file)) return array(); $config = array(); if ($this->_format == 'php') { - include($file); - $config = ${$this->_name}; + + if(@file_exists($file)){ + $contents = @php_strip_whitespace($file); + }else{ + $contents = ''; + } + $pattern = '/\$'.$this->_name.'\[[\'"]([^=]+)[\'"]\] ?= ?(.*?);(?=[^;]*(?:\$'.$this->_name.'|$))/s'; + $matches=array(); + preg_match_all($pattern,$contents,$matches,PREG_SET_ORDER); + + for ($i=0; $i'\\','\\\''=>'\'','\\"'=>'"')); + + $config[$key] = $value; + } } return $config; -- cgit v1.2.3 From cba21baacb4880eefd35279b0589e035c5a5c78e Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 16 Nov 2012 13:59:17 +0100 Subject: started to add some unit tests to config manager Parsing the config file should be completely tested before we can rely on it and safely extend it. This just adds the first very basic tests. --- lib/plugins/config/_test/configuration.test.php | 31 +++++++++++++++++++++++++ lib/plugins/config/_test/data/config.php | 14 +++++++++++ lib/plugins/config/_test/data/metadata.php | 11 +++++++++ lib/plugins/config/settings/config.class.php | 3 +++ 4 files changed, 59 insertions(+) create mode 100644 lib/plugins/config/_test/configuration.test.php create mode 100644 lib/plugins/config/_test/data/config.php create mode 100644 lib/plugins/config/_test/data/metadata.php diff --git a/lib/plugins/config/_test/configuration.test.php b/lib/plugins/config/_test/configuration.test.php new file mode 100644 index 000000000..eeeff61a3 --- /dev/null +++ b/lib/plugins/config/_test/configuration.test.php @@ -0,0 +1,31 @@ +config = dirname(__FILE__).'/data/config.php'; + $this->meta = dirname(__FILE__).'/data/metadata.php'; + require_once(dirname(__FILE__).'/../settings/config.class.php'); + } + + function test_readconfig() { + $confmgr = new configuration($this->meta); + + $conf = $confmgr->_read_config($this->config); + + //print_r($conf); + + $this->assertEquals('42', $conf['int1']); + $this->assertEquals('6*7', $conf['int2']); + + $this->assertEquals('Hello World', $conf['str1']); + $this->assertEquals('G\'day World', $conf['str2']); + $this->assertEquals('Hello World', $conf['str3']); + $this->assertEquals("Hello 'World'", $conf['str4']); + $this->assertEquals('Hello "World"', $conf['str5']); + } + +} \ No newline at end of file diff --git a/lib/plugins/config/_test/data/config.php b/lib/plugins/config/_test/data/config.php new file mode 100644 index 000000000..4ed450e93 --- /dev/null +++ b/lib/plugins/config/_test/data/config.php @@ -0,0 +1,14 @@ + */ + +if(!defined('CM_KEYMARKER')) define('CM_KEYMARKER','____'); + if (!class_exists('configuration')) { class configuration { -- cgit v1.2.3 From a24fc53e2623640cf5e2d00de741c1b67c9bb294 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 16 Nov 2012 14:48:14 +0100 Subject: added failing test for array type --- lib/plugins/config/_test/configuration.test.php | 2 ++ lib/plugins/config/_test/data/config.php | 2 ++ lib/plugins/config/_test/data/metadata.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/lib/plugins/config/_test/configuration.test.php b/lib/plugins/config/_test/configuration.test.php index eeeff61a3..ee03f3849 100644 --- a/lib/plugins/config/_test/configuration.test.php +++ b/lib/plugins/config/_test/configuration.test.php @@ -26,6 +26,8 @@ class plugin_config_configuration_test extends DokuWikiTest { $this->assertEquals('Hello World', $conf['str3']); $this->assertEquals("Hello 'World'", $conf['str4']); $this->assertEquals('Hello "World"', $conf['str5']); + + $this->assertEquals(array('foo', 'bar', 'baz'), $conf['arr1']); } } \ No newline at end of file diff --git a/lib/plugins/config/_test/data/config.php b/lib/plugins/config/_test/data/config.php index 4ed450e93..15d6359ad 100644 --- a/lib/plugins/config/_test/data/config.php +++ b/lib/plugins/config/_test/data/config.php @@ -10,5 +10,7 @@ $conf['str3'] = "Hello World"; $conf['str4'] = "Hello 'World'"; $conf['str5'] = "Hello \"World\""; +$conf['arr1'] = array('foo','bar','baz'); + $conf['foo']['bar'] = 'x1'; $conf['foo']['baz'] = 'x2'; diff --git a/lib/plugins/config/_test/data/metadata.php b/lib/plugins/config/_test/data/metadata.php index 34ab42be7..12902e525 100644 --- a/lib/plugins/config/_test/data/metadata.php +++ b/lib/plugins/config/_test/data/metadata.php @@ -9,3 +9,5 @@ $meta['str3'] = array('string'); $meta['str4'] = array('string'); $meta['str5'] = array('string'); +$meta['arr1'] = array('array'); + -- cgit v1.2.3