From 2571786c763e04c7abbf27c2245a5720878dc3f1 Mon Sep 17 00:00:00 2001 From: LarsDW223 <lars_paulsen@web.de> Date: Thu, 18 May 2017 12:07:15 +0200 Subject: [PATCH] always redirect to correct section Across workflow 'show - sectionedit - save/cancel' explicitly transmit header id to the server. So the server can always redirect to the correct section even if headings have the same name. Fixes #1364. --- inc/actions.php | 62 +++++--------------------------------------- inc/html.php | 8 ++++-- inc/parser/xhtml.php | 13 ++++++---- 3 files changed, 20 insertions(+), 63 deletions(-) diff --git a/inc/actions.php b/inc/actions.php index 218a03491..6aa29f3bf 100644 --- a/inc/actions.php +++ b/inc/actions.php @@ -87,13 +87,18 @@ function act_draftdel($act){ function act_redirect($id,$preact){ global $PRE; global $TEXT; + global $INPUT; $opts = array( 'id' => $id, 'preact' => $preact ); //get section name when coming from section edit - if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ + if ($INPUT->has('hid')) { + // Use explicitly transmitted header id + $opts['fragment'] = $INPUT->str('hid'); + } else if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ + // Fallback to old mechanism $check = false; //Byref $opts['fragment'] = sectionID($match[0], $check); } @@ -114,60 +119,5 @@ function act_redirect_execute($opts){ send_redirect($go); } -/** - * Validate POST data - * - * Validates POST data for a subscribe or unsubscribe request. This is the - * default action for the event ACTION_HANDLE_SUBSCRIBE. - * - * @author Adrian Lang <lang@cosmocode.de> - * - * @param array &$params the parameters: target, style and action - * @throws Exception - */ -function subscription_handle_post(&$params) { - global $INFO; - global $lang; - /* @var Input $INPUT */ - global $INPUT; - - // Get and validate parameters. - if (!isset($params['target'])) { - throw new Exception('no subscription target given'); - } - $target = $params['target']; - $valid_styles = array('every', 'digest'); - if (substr($target, -1, 1) === ':') { - // Allow “list†subscribe style since the target is a namespace. - $valid_styles[] = 'list'; - } - $style = valid_input_set('style', $valid_styles, $params, - 'invalid subscription style given'); - $action = valid_input_set('action', array('subscribe', 'unsubscribe'), - $params, 'invalid subscription action given'); - - // Check other conditions. - if ($action === 'subscribe') { - if ($INFO['userinfo']['mail'] === '') { - throw new Exception($lang['subscr_subscribe_noaddress']); - } - } elseif ($action === 'unsubscribe') { - $is = false; - foreach($INFO['subscribed'] as $subscr) { - if ($subscr['target'] === $target) { - $is = true; - } - } - if ($is === false) { - throw new Exception(sprintf($lang['subscr_not_subscribed'], - $INPUT->server->str('REMOTE_USER'), - prettyprint_id($target))); - } - // subscription_set deletes a subscription if style = null. - $style = null; - } - - $params = compact('target', 'style', 'action'); -} //Setup VIM: ex: et ts=2 : diff --git a/inc/html.php b/inc/html.php index 2897d01c1..a5983ec87 100644 --- a/inc/html.php +++ b/inc/html.php @@ -91,7 +91,7 @@ function html_denied() { function html_secedit($text,$show=true){ global $INFO; - $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )?\[(\d+-\d*)\] -->#'; + $regexp = '#<!-- EDIT(\d+) ([A-Z_]+) (?:"([^"]*)" )(?:"([^"]*)" )?\[(\d+-\d*)\] -->#'; if(!$INFO['writable'] || !$show || $INFO['rev']){ return preg_replace($regexp,'',$text); @@ -114,8 +114,9 @@ function html_secedit($text,$show=true){ 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) === 5) { + if (count($matches) === 6) { $data['name'] = $matches[3]; } @@ -1865,6 +1866,9 @@ function html_edit(){ } $form->addHidden('target', $data['target']); + if ($INPUT->has('hid')) { + $form->addHidden('hid', $INPUT->str('hid')); + } $form->addElement(form_makeOpenTag('div', array('id'=>'wiki__editbar', 'class'=>'editBar'))); $form->addElement(form_makeOpenTag('div', array('id'=>'size__ctl'))); $form->addElement(form_makeCloseTag('div')); diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index e60d7d38b..07db96b1c 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -66,8 +66,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * * @author Adrian Lang <lang@cosmocode.de> */ - public function startSectionEdit($start, $type, $title = null) { - $this->sectionedits[] = array(++$this->lastsecid, $start, $type, $title); + public function startSectionEdit($start, $type, $title = null, $hid = null) { + $this->sectionedits[] = array(++$this->lastsecid, $start, $type, $title, $hid); return 'sectionedit'.$this->lastsecid; } @@ -78,8 +78,8 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * * @author Adrian Lang <lang@cosmocode.de> */ - public function finishSectionEdit($end = null) { - list($id, $start, $type, $title) = array_pop($this->sectionedits); + public function finishSectionEdit($end = null, $hid = null) { + list($id, $start, $type, $title, $hid) = array_pop($this->sectionedits); if(!is_null($end) && $end <= $start) { return; } @@ -87,6 +87,9 @@ class Doku_Renderer_xhtml extends Doku_Renderer { if(!is_null($title)) { $this->doc .= '"'.str_replace('"', '', $title).'" '; } + if(!is_null($hid)) { + $this->doc .= '"'.$hid.'" '; + } $this->doc .= "[$start-".(is_null($end) ? '' : $end).'] -->'; } @@ -217,7 +220,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // write the header $this->doc .= DOKU_LF.'<h'.$level; if($level <= $conf['maxseclevel']) { - $this->doc .= ' class="'.$this->startSectionEdit($pos, 'section', $text).'"'; + $this->doc .= ' class="'.$this->startSectionEdit($pos, 'section', $text, $hid).'"'; } $this->doc .= ' id="'.$hid.'">'; $this->doc .= $this->_xmlEntities($text); -- GitLab