diff --git a/_test/tests/inc/html_secedit_pattern.test.php b/_test/tests/inc/html_secedit_pattern.test.php new file mode 100644 index 0000000000000000000000000000000000000000..1c0107801463ff6627ee291ca4eacd366bc05473 --- /dev/null +++ b/_test/tests/inc/html_secedit_pattern.test.php @@ -0,0 +1,58 @@ +<?php + +class html_scedit_pattern_test extends DokuWikiTest { + + + public function dataProviderForTestSecEditPattern() { + return [ + [ + '<!-- EDIT5 SECTION "Plugins" "plugins" [1406-] -->', + [ + 'secid' => '5', + 'target' => 'SECTION', + 'name' => 'Plugins', + 'hid' => 'plugins', + 'range' => '1406-', + ], + 'basic section edit', + ], + [ + '<!-- EDIT10 TABLE "" "table4" [11908-14014] -->', + [ + 'secid' => '10', + 'target' => 'TABLE', + 'name' => '', + 'hid' => 'table4', + 'range' => '11908-14014', + ], + 'table edit' + ], + [ + '<!-- EDIT2 PLUGIN_DATA [27-432] -->', + [ + 'secid' => '2', + 'target' => 'PLUGIN_DATA', + 'name' => '', + 'hid' => '', + 'range' => '27-432', + ], + 'data plugin' + ], + ]; + } + + /** + * @dataProvider dataProviderForTestSecEditPattern + * + * @param $text + * @param $expectedMatches + * @param $msg + */ + public function testSecEditPattern($text, $expectedMatches, $msg) { + preg_match(SEC_EDIT_PATTERN, $text, $matches); + foreach ($expectedMatches as $key => $expected_value) { + $this->assertSame($expected_value, $matches[$key], $msg); + } + } + +} diff --git a/inc/ActionRouter.php b/inc/ActionRouter.php index 7a58d22c59cc03e7957a2199464453e1565a3992..7e6fddd16ec10a3925e1b68db75c8cd75703892c 100644 --- a/inc/ActionRouter.php +++ b/inc/ActionRouter.php @@ -68,16 +68,24 @@ class ActionRouter { * Instantiates the right class, runs permission checks and pre-processing and * sets $action * - * @param string $actionname + * @param string $actionname this is passed as a reference to $ACT, for plugin backward compatibility * @triggers ACTION_ACT_PREPROCESS */ - protected function setupAction($actionname) { + protected function setupAction(&$actionname) { $presetup = $actionname; try { - $this->action = $this->loadAction($actionname); - $this->checkAction($this->action); - $this->action->preProcess(); + // give plugins an opportunity to process the actionname + $evt = new \Doku_Event('ACTION_ACT_PREPROCESS', $actionname); + if ($evt->advise_before()) { + $this->action = $this->loadAction($actionname); + $this->checkAction($this->action); + $this->action->preProcess(); + } else { + // event said the action should be kept, assume action plugin will handle it later + $this->action = new Plugin($actionname); + } + $evt->advise_after(); } catch(ActionException $e) { // we should have gotten a new action @@ -97,21 +105,9 @@ class ActionRouter { $this->transitionAction($presetup, $actionname); } catch(NoActionException $e) { - // give plugins an opportunity to process the actionname - $evt = new \Doku_Event('ACTION_ACT_PREPROCESS', $actionname); - if($evt->advise_before()) { - if($actionname == $presetup) { - // no plugin changed the action, complain and switch to show - msg('Action unknown: ' . hsc($actionname), -1); - $actionname = 'show'; - } - $this->transitionAction($presetup, $actionname); - } else { - // event said the action should be kept, assume action plugin will handle it later - $this->action = new Plugin($actionname); - } - $evt->advise_after(); - + msg('Action unknown: ' . hsc($actionname), -1); + $actionname = 'show'; + $this->transitionAction($presetup, $actionname); } catch(\Exception $e) { $this->handleFatalException($e); } diff --git a/inc/html.php b/inc/html.php index 9fa121db9c95cf2a0dcd40109118dceead690ef7..350c65f076f92349246ab0e3f7104d4fa3c9ab91 100644 --- a/inc/html.php +++ b/inc/html.php @@ -8,6 +8,10 @@ if(!defined('DOKU_INC')) die('meh.'); if(!defined('NL')) define('NL',"\n"); +if (!defined('SEC_EDIT_PATTERN')) { + define('SEC_EDIT_PATTERN', '#<!-- EDIT(?<secid>\d+) (?<target>[A-Z_]+) (?:"(?<name>[^"]*)" )?(?:"(?<hid>[^"]*)" )?\[(?<range>\d+-\d*)\] -->#'); +} + /** * Convenience function to quickly build a wikilink @@ -91,13 +95,11 @@ function html_denied() { function html_secedit($text,$show=true){ global $INFO; - $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )(?:"([^"]*)" )?\[(\d+-\d*)\] -->#'; - if(!$INFO['writable'] || !$show || $INFO['rev']){ - return preg_replace($regexp,'',$text); + return preg_replace(SEC_EDIT_PATTERN,'',$text); } - return preg_replace_callback($regexp, + return preg_replace_callback(SEC_EDIT_PATTERN, 'html_secedit_button', $text); } @@ -112,12 +114,16 @@ function html_secedit($text,$show=true){ * @triggers HTML_SECEDIT_BUTTON */ function html_secedit_button($matches){ - $data = array('secid' => $matches[1], - 'target' => strtolower($matches[2]), - 'hid' => strtolower($matches[4]), - 'range' => $matches[count($matches) - 1]); - if (count($matches) === 6) { - $data['name'] = $matches[3]; + $data = array('secid' => $matches['secid'], + 'target' => strtolower($matches['target']), + 'range' => $matches['range']); + + if (!empty($matches['hid'])) { + $data['hid'] = strtolower($matches['hid']); + } + + if (!empty($matches['name'])) { + $data['name'] = $matches['name']; } return trigger_event('HTML_SECEDIT_BUTTON', $data, diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index dbac1a9822bd73f9ce0447a8b4f768f6e497450a..042aba111ce81f601e5a1d09a3d33d291252f368 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1339,7 +1339,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $class .= ' ' . $classes; } if($pos !== null) { - $class .= ' '.$this->startSectionEdit($pos, 'table'); + $hid = $this->_headerToLink($class, true); + $class .= ' '.$this->startSectionEdit($pos, 'table', '', $hid); } $this->doc .= '<div class="'.$class.'"><table class="inline">'. DOKU_LF;