From 9aa0e6c6087e616511fc95d1650ca9b608edece8 Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Wed, 26 Jan 2011 08:16:45 +0800 Subject: Like others, there's no need to define $sectionedits as private, and it prevents plugins that ought to handle headers from working and require a lot of ugly workarounds (such as header2). If there's a concern, "protected" may be another choice. --- inc/parser/xhtml.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/parser') diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 9405d9420..b502b4f6b 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -29,7 +29,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { var $doc = ''; // will contain the whole document var $toc = array(); // will contain the Table of Contents - private $sectionedits = array(); // A stack of section edit data + var $sectionedits = array(); // A stack of section edit data var $headers = array(); var $footnotes = array(); -- cgit v1.2.3 From 08162f005f3ced0555de590dc1a53155af99d998 Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Wed, 26 Jan 2011 08:25:21 +0800 Subject: Fixes an issue of metadata missing on links with empty altname. FS#2144 --- inc/parser/metadata.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index fc2c8cbc5..bd396e2b4 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -455,16 +455,16 @@ class Doku_Renderer_metadata extends Doku_Renderer { global $conf; $isImage = false; - if (is_null($title)){ + if (is_array($title)){ + if($title['title']) return '['.$title['title'].']'; + } else if (is_null($title) || trim($title)==''){ if (useHeading('content') && $id){ $heading = p_get_first_heading($id,false); if ($heading) return $heading; } return $default; - } else if (is_string($title)){ + } else { return $title; - } else if (is_array($title)){ - if($title['title']) return '['.$title['title'].']'; } } -- cgit v1.2.3 From b5a0b131e99eb6028e5ca5fed9c798982cdfe168 Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Wed, 26 Jan 2011 08:33:01 +0800 Subject: First attempt to improve rewrite blocks; also eliminates post-paragraph starting single linebreaks. --- inc/parser/handler.php | 124 +++++++++++++++++++------------------------------ 1 file changed, 49 insertions(+), 75 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 4d0b56b44..3bd3a3b3c 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1489,6 +1489,11 @@ class Doku_Handler_Block { } } + function openParagraph($pos){ + $this->calls[] = array('p_open',array(), $pos); + $this->inParagraph = true; + } + /** * Close a paragraph if needed * @@ -1548,7 +1553,7 @@ class Doku_Handler_Block { $this->closeParagraph($call[2]); } $this->calls[] = $call; - + $this->skipEolKey = $key+1; continue; } @@ -1561,104 +1566,73 @@ class Doku_Handler_Block { if ($this->removeFromStack()) { $this->calls[] = array('p_open',array(), $call[2]); } + $this->skipEolKey = $key+1; continue; } - if ( !$this->atStart ) { - - if ( $cname == 'eol' ) { - - // Check this isn't an eol instruction to skip... - if ( $this->skipEolKey != $key ) { - // Look to see if the next instruction is an EOL - if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) { - - if ( $this->inParagraph ) { - //$this->calls[] = array('p_close',array(), $call[2]); - $this->closeParagraph($call[2]); - } - - $this->calls[] = array('p_open',array(), $call[2]); - $this->inParagraph = true; - - - // Mark the next instruction for skipping - $this->skipEolKey = $key+1; - - }else{ - //if this is just a single eol make a space from it - $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2])); - } - } + // Always opens a paragraph on stack start + // If this is a block start, it will soon be closed later + if ( $this->atStart ) { + $this->openParagraph($call[2]); + $this->atStart = false; + $this->skipEolKey = $key; + } + if ( $cname == 'eol' ) { - } else { + // Check this isn't an eol instruction to skip... + if ( $this->skipEolKey != $key ) { + // Look to see if the next instruction is an EOL + if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) { - $storeCall = true; - if ( $this->inParagraph && (in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open))) { - $this->closeParagraph($call[2]); - $this->calls[] = $call; - $storeCall = false; - } - - if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) { if ( $this->inParagraph ) { $this->closeParagraph($call[2]); } - if ( $storeCall ) { - $this->calls[] = $call; - $storeCall = false; - } - - // This really sucks and suggests this whole class sucks but... - if ( isset($calls[$key+1])) { - $cname_plusone = $calls[$key+1][0]; - if ($cname_plusone == 'plugin') { - $cname_plusone = 'plugin'.$calls[$key+1][1][0]; - - // plugin test, true if plugin has a state which precludes it requiring blockOpen or blockClose - $plugin_plusone = true; - $plugin_test = ($call[$key+1][1][2] == DOKU_LEXER_MATCHED) || ($call[$key+1][1][2] == DOKU_LEXER_MATCHED); - } else { - $plugin_plusone = false; - } - if ((!in_array($cname_plusone, $this->blockOpen) && !in_array($cname_plusone, $this->blockClose)) || - ($plugin_plusone && $plugin_test) - ) { - - $this->calls[] = array('p_open',array(), $call[2]); - $this->inParagraph = true; - } - } - } - - if ( $storeCall ) { - $this->addCall($call); + $this->openParagraph($call[2]); + // Mark the next instruction for skipping + $this->skipEolKey = $key+1; + } else { + //if this is just a single eol make a space from it + $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2])); } - + } else { + $this->skipEolKey = $key+1; } } else { - // Unless there's already a block at the start, start a paragraph - if ( !in_array($cname,$this->blockOpen) ) { - $this->calls[] = array('p_open',array(), $call[2]); - if ( $call[0] != 'eol' ) { + $storeCall = true; + if ( $this->inParagraph && (in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open))) { + $this->closeParagraph($call[2]); + $this->calls[] = $call; + $storeCall = false; + // Mark next eol(s) for skipping + $this->skipEolKey = $key+1; + } + + if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) { + if ( $this->inParagraph ) { + $this->closeParagraph($call[2]); + } + if ( $storeCall ) { $this->calls[] = $call; + $storeCall = false; } - $this->atStart = false; - $this->inParagraph = true; - } else { + $this->openParagraph($call[2]); + // Mark next eol(s) for skipping + $this->skipEolKey = $key+1; + } + if ( $storeCall ) { $this->addCall($call); - $this->atStart = false; } - } } if ( $this->inParagraph ) { + $call = end($this->calls); + $cname = $call[0]; if ( $cname == 'p_open' ) { // Ditch the last call array_pop($this->calls); -- cgit v1.2.3 From 9569a107742372a9dcfac06600e3d59c289ba142 Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Wed, 26 Jan 2011 11:06:41 +0800 Subject: Major rework of rewrite block in handler.php. (FS#2145) -Simplify the algorithm. May improve performance. -Treat footnote as pure block and section as pure stack. -Remove post-p-open and pre-p-close linefeeds. Affects the effect of xbr plugin. --- inc/parser/handler.php | 201 ++++++++++++++++--------------------------------- 1 file changed, 66 insertions(+), 135 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 3bd3a3b3c..e7eb94dd2 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1427,14 +1427,8 @@ class Doku_Handler_Table { * @author Harry Fuecks */ class Doku_Handler_Block { - var $calls = array(); - - var $blockStack = array(); - - var $inParagraph = false; - var $atStart = true; - var $skipEolKey = -1; + var $skipEol = false; // Blocks these should not be inside paragraphs var $blockOpen = array( @@ -1442,9 +1436,9 @@ class Doku_Handler_Block { 'listu_open','listo_open','listitem_open','listcontent_open', 'table_open','tablerow_open','tablecell_open','tableheader_open', 'quote_open', - 'section_open', // Needed to prevent p_open between header and section_open 'code','file','hr','preformatted','rss', 'htmlblock','phpblock', + 'footnote_open', ); var $blockClose = array( @@ -1452,18 +1446,18 @@ class Doku_Handler_Block { 'listu_close','listo_close','listitem_close','listcontent_close', 'table_close','tablerow_close','tablecell_close','tableheader_close', 'quote_close', - 'section_close', // Needed to prevent p_close after section_close 'code','file','hr','preformatted','rss', 'htmlblock','phpblock', + 'footnote_close', ); // Stacks can contain paragraphs var $stackOpen = array( - 'footnote_open','section_open', + 'section_open', ); var $stackClose = array( - 'footnote_close','section_close', + 'section_close', ); @@ -1489,9 +1483,11 @@ class Doku_Handler_Block { } } - function openParagraph($pos){ + function openParagraph($pos){ + if ($this->inParagraph) return; $this->calls[] = array('p_open',array(), $pos); - $this->inParagraph = true; + $this->inParagraph = true; + $this->skipEol = true; } /** @@ -1501,7 +1497,8 @@ class Doku_Handler_Block { * * @author Andreas Gohr */ - function closeParagraph($pos){ + function closeParagraph($pos){ + if (!$this->inParagraph) return; // look back if there was any content - we don't want empty paragraphs $content = ''; for($i=count($this->calls)-1; $i>=0; $i--){ @@ -1518,11 +1515,29 @@ class Doku_Handler_Block { if(trim($content)==''){ //remove the whole paragraph array_splice($this->calls,$i); - }else{ + }else{ + // remove ending linebreaks in the paragraph + $i=count($this->calls)-1; + if ($this->calls[$i][0] == 'cdata') $this->calls[$i][1][0] = rtrim($this->calls[$i][1][0],DOKU_PARSER_EOL); $this->calls[] = array('p_close',array(), $pos); } - $this->inParagraph = false; + $this->inParagraph = false; + $this->skipEol = true; + } + + function addCall($call) { + $key = count($this->calls); + if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) { + $this->calls[$key-1][1][0] .= $call[1][0]; + } else { + $this->calls[] = $call; + } + } + + // simple version of addCall, without checking cdata + function storeCall($call) { + $this->calls[] = $call; } /** @@ -1530,155 +1545,71 @@ class Doku_Handler_Block { * * @author Harry Fuecks * @author Andreas Gohr - * @todo This thing is really messy and should be rewritten */ function process($calls) { + // open first paragraph + $this->openParagraph(0); foreach ( $calls as $key => $call ) { $cname = $call[0]; - if($cname == 'plugin') { + if ($cname == 'plugin') { $cname='plugin_'.$call[1][0]; - $plugin = true; $plugin_open = (($call[1][2] == DOKU_LEXER_ENTER) || ($call[1][2] == DOKU_LEXER_SPECIAL)); $plugin_close = (($call[1][2] == DOKU_LEXER_EXIT) || ($call[1][2] == DOKU_LEXER_SPECIAL)); } else { $plugin = false; } - - // Process blocks which are stack like... (contain linefeeds) - if ( in_array($cname,$this->stackOpen ) && (!$plugin || $plugin_open) ) { - - // Hack - footnotes shouldn't immediately contain a p_open - if ($this->addToStack($cname != 'footnote_open')) { - $this->closeParagraph($call[2]); - } - $this->calls[] = $call; - $this->skipEolKey = $key+1; + /* stack */ + if ( in_array($cname,$this->stackClose ) && (!$plugin || $plugin_close)) { + $this->closeParagraph($call[2]); + $this->storeCall($call); + $this->openParagraph($call[2]); continue; } - - if ( in_array($cname,$this->stackClose ) && (!$plugin || $plugin_close)) { - - if ( $this->inParagraph ) { - $this->closeParagraph($call[2]); - } - $this->calls[] = $call; - if ($this->removeFromStack()) { - $this->calls[] = array('p_open',array(), $call[2]); - } - $this->skipEolKey = $key+1; + if ( in_array($cname,$this->stackOpen ) && (!$plugin || $plugin_open) ) { + $this->closeParagraph($call[2]); + $this->storeCall($call); + $this->openParagraph($call[2]); continue; } - - // Always opens a paragraph on stack start - // If this is a block start, it will soon be closed later - if ( $this->atStart ) { + /* block */ + // If it's a substition it opens and closes at the same call. + // To make sure next paragraph is correctly started, let close go first. + if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) { + $this->closeParagraph($call[2]); + $this->storeCall($call); $this->openParagraph($call[2]); - $this->atStart = false; - $this->skipEolKey = $key; + continue; } - + if ( in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open)) { + $this->closeParagraph($call[2]); + $this->storeCall($call); + continue; + } + /* eol */ if ( $cname == 'eol' ) { - // Check this isn't an eol instruction to skip... - if ( $this->skipEolKey != $key ) { - // Look to see if the next instruction is an EOL + if ( !$this->skipEol ) { + // Next is EOL => double eol => mark as paragraph if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) { - - if ( $this->inParagraph ) { - $this->closeParagraph($call[2]); - } + $this->closeParagraph($call[2]); $this->openParagraph($call[2]); - // Mark the next instruction for skipping - $this->skipEolKey = $key+1; } else { //if this is just a single eol make a space from it $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2])); } - } else { - $this->skipEolKey = $key+1; } - - - } else { - - $storeCall = true; - if ( $this->inParagraph && (in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open))) { - $this->closeParagraph($call[2]); - $this->calls[] = $call; - $storeCall = false; - // Mark next eol(s) for skipping - $this->skipEolKey = $key+1; - } - - if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) { - if ( $this->inParagraph ) { - $this->closeParagraph($call[2]); - } - if ( $storeCall ) { - $this->calls[] = $call; - $storeCall = false; - } - $this->openParagraph($call[2]); - // Mark next eol(s) for skipping - $this->skipEolKey = $key+1; - } - if ( $storeCall ) { - $this->addCall($call); - } - } - - } - - if ( $this->inParagraph ) { - $call = end($this->calls); - $cname = $call[0]; - if ( $cname == 'p_open' ) { - // Ditch the last call - array_pop($this->calls); - } else if ( !in_array($cname, $this->blockClose) ) { - //$this->calls[] = array('p_close',array(), $call[2]); - $this->closeParagraph($call[2]); - } else { - $last_call = array_pop($this->calls); - //$this->calls[] = array('p_close',array(), $call[2]); - $this->closeParagraph($call[2]); - $this->calls[] = $last_call; + continue; } + /* normal */ + $this->addCall($call); + $this->skipEol = false; } - + // close last paragraph + $call = end($this->calls); + $this->closeParagraph($call[2]); return $this->calls; } - - /** - * - * @return bool true when a p_close() is required - */ - function addToStack($newStart = true) { - $ret = $this->inParagraph; - $this->blockStack[] = array($this->atStart, $this->inParagraph); - $this->atStart = $newStart; - $this->inParagraph = false; - - return $ret; - } - - function removeFromStack() { - $state = array_pop($this->blockStack); - $this->atStart = $state[0]; - $this->inParagraph = $state[1]; - - return $this->inParagraph; - } - - function addCall($call) { - $key = count($this->calls); - if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) { - $this->calls[$key-1][1][0] .= $call[1][0]; - } else { - $this->calls[] = $call; - } - } } //Setup VIM: ex: et ts=4 : -- cgit v1.2.3 From 5d190f120cede5be1da521fd1dc6e1beb0be394e Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 6 Feb 2011 11:28:35 +0100 Subject: URLs may contain brackets [] FS#2137 --- inc/parser/parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/parser') diff --git a/inc/parser/parser.php b/inc/parser/parser.php index b93760f3a..a1f9c9fe6 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -870,7 +870,7 @@ class Doku_Parser_Mode_externallink extends Doku_Parser_Mode { if(count($this->patterns)) return; $ltrs = '\w'; - $gunk = '/\#~:.?+=&%@!\-'; + $gunk = '/\#~:.?+=&%@!\-\[\]'; $punc = '.:?\-;,'; $host = $ltrs.$punc; $any = $ltrs.$gunk.$punc; -- cgit v1.2.3 From c34c77725873a495f375a815dd89be723cd2a512 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 6 Feb 2011 12:12:05 +0100 Subject: make IPv6 links in link syntax FS#2137 --- inc/parser/parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/parser') diff --git a/inc/parser/parser.php b/inc/parser/parser.php index a1f9c9fe6..a7764ee9c 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -828,7 +828,7 @@ class Doku_Parser_Mode_internallink extends Doku_Parser_Mode { function connectTo($mode) { // Word boundaries? - $this->Lexer->addSpecialPattern("\[\[.+?\]\]",$mode,'internallink'); + $this->Lexer->addSpecialPattern("\[\[(?:(?:.*?\[.*?\])|.+?)\]\]",$mode,'internallink'); } function getSort() { -- cgit v1.2.3 From 3893df8e5068f411ba16c2e37096e47c4ad102f2 Mon Sep 17 00:00:00 2001 From: Christopher Smith Date: Sun, 6 Feb 2011 15:16:10 +0000 Subject: FS#2154 unset call writers in finalise() to prevent circular references and help PHP garbage collection for PHP < 5.3 --- inc/parser/handler.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'inc/parser') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 4d0b56b44..85a353dca 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -720,6 +720,7 @@ class Doku_Handler_CallWriter { // function is required, but since this call writer is first/highest in // the chain it is not required to do anything function finalise() { + unset($this->Handler); } } @@ -764,6 +765,7 @@ class Doku_Handler_Nest { $this->process(); $this->CallWriter->finalise(); + unset($this->CallWriter); } function process() { @@ -817,6 +819,7 @@ class Doku_Handler_List { $this->process(); $this->CallWriter->finalise(); + unset($this->CallWriter); } //------------------------------------------------------------------------ @@ -1014,6 +1017,7 @@ class Doku_Handler_Preformatted { $this->process(); $this->CallWriter->finalise(); + unset($this->CallWriter); } function process() { @@ -1070,6 +1074,7 @@ class Doku_Handler_Quote { $this->process(); $this->CallWriter->finalise(); + unset($this->CallWriter); } function process() { @@ -1165,6 +1170,7 @@ class Doku_Handler_Table { $this->process(); $this->CallWriter->finalise(); + unset($this->CallWriter); } //------------------------------------------------------------------------ -- cgit v1.2.3 From b17e20ac9cca30b612968d02f06fa9c5df5c01f0 Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sun, 6 Feb 2011 18:54:38 +0000 Subject: merged branch 'danny0838:rewrite_block' and resolved conflict --- inc/parser/handler.php | 241 +++++++++++++++--------------------------------- inc/parser/metadata.php | 8 +- inc/parser/xhtml.php | 2 +- 3 files changed, 78 insertions(+), 173 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 85a353dca..26a560c3c 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1433,14 +1433,8 @@ class Doku_Handler_Table { * @author Harry Fuecks */ class Doku_Handler_Block { - var $calls = array(); - - var $blockStack = array(); - - var $inParagraph = false; - var $atStart = true; - var $skipEolKey = -1; + var $skipEol = false; // Blocks these should not be inside paragraphs var $blockOpen = array( @@ -1448,9 +1442,9 @@ class Doku_Handler_Block { 'listu_open','listo_open','listitem_open','listcontent_open', 'table_open','tablerow_open','tablecell_open','tableheader_open', 'quote_open', - 'section_open', // Needed to prevent p_open between header and section_open 'code','file','hr','preformatted','rss', 'htmlblock','phpblock', + 'footnote_open', ); var $blockClose = array( @@ -1458,18 +1452,18 @@ class Doku_Handler_Block { 'listu_close','listo_close','listitem_close','listcontent_close', 'table_close','tablerow_close','tablecell_close','tableheader_close', 'quote_close', - 'section_close', // Needed to prevent p_close after section_close 'code','file','hr','preformatted','rss', 'htmlblock','phpblock', + 'footnote_close', ); // Stacks can contain paragraphs var $stackOpen = array( - 'footnote_open','section_open', + 'section_open', ); var $stackClose = array( - 'footnote_close','section_close', + 'section_close', ); @@ -1495,6 +1489,13 @@ class Doku_Handler_Block { } } + function openParagraph($pos){ + if ($this->inParagraph) return; + $this->calls[] = array('p_open',array(), $pos); + $this->inParagraph = true; + $this->skipEol = true; + } + /** * Close a paragraph if needed * @@ -1503,6 +1504,7 @@ class Doku_Handler_Block { * @author Andreas Gohr */ function closeParagraph($pos){ + if (!$this->inParagraph) return; // look back if there was any content - we don't want empty paragraphs $content = ''; for($i=count($this->calls)-1; $i>=0; $i--){ @@ -1520,10 +1522,28 @@ class Doku_Handler_Block { //remove the whole paragraph array_splice($this->calls,$i); }else{ + // remove ending linebreaks in the paragraph + $i=count($this->calls)-1; + if ($this->calls[$i][0] == 'cdata') $this->calls[$i][1][0] = rtrim($this->calls[$i][1][0],DOKU_PARSER_EOL); $this->calls[] = array('p_close',array(), $pos); } $this->inParagraph = false; + $this->skipEol = true; + } + + function addCall($call) { + $key = count($this->calls); + if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) { + $this->calls[$key-1][1][0] .= $call[1][0]; + } else { + $this->calls[] = $call; + } + } + + // simple version of addCall, without checking cdata + function storeCall($call) { + $this->calls[] = $call; } /** @@ -1531,186 +1551,71 @@ class Doku_Handler_Block { * * @author Harry Fuecks * @author Andreas Gohr - * @todo This thing is really messy and should be rewritten */ function process($calls) { + // open first paragraph + $this->openParagraph(0); foreach ( $calls as $key => $call ) { $cname = $call[0]; - if($cname == 'plugin') { + if ($cname == 'plugin') { $cname='plugin_'.$call[1][0]; - $plugin = true; $plugin_open = (($call[1][2] == DOKU_LEXER_ENTER) || ($call[1][2] == DOKU_LEXER_SPECIAL)); $plugin_close = (($call[1][2] == DOKU_LEXER_EXIT) || ($call[1][2] == DOKU_LEXER_SPECIAL)); } else { $plugin = false; } - - // Process blocks which are stack like... (contain linefeeds) + /* stack */ + if ( in_array($cname,$this->stackClose ) && (!$plugin || $plugin_close)) { + $this->closeParagraph($call[2]); + $this->storeCall($call); + $this->openParagraph($call[2]); + continue; + } if ( in_array($cname,$this->stackOpen ) && (!$plugin || $plugin_open) ) { - - // Hack - footnotes shouldn't immediately contain a p_open - if ($this->addToStack($cname != 'footnote_open')) { - $this->closeParagraph($call[2]); - } - $this->calls[] = $call; - + $this->closeParagraph($call[2]); + $this->storeCall($call); + $this->openParagraph($call[2]); continue; } - - if ( in_array($cname,$this->stackClose ) && (!$plugin || $plugin_close)) { - - if ( $this->inParagraph ) { - $this->closeParagraph($call[2]); - } - $this->calls[] = $call; - if ($this->removeFromStack()) { - $this->calls[] = array('p_open',array(), $call[2]); - } + /* block */ + // If it's a substition it opens and closes at the same call. + // To make sure next paragraph is correctly started, let close go first. + if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) { + $this->closeParagraph($call[2]); + $this->storeCall($call); + $this->openParagraph($call[2]); continue; } - - if ( !$this->atStart ) { - - if ( $cname == 'eol' ) { - - // Check this isn't an eol instruction to skip... - if ( $this->skipEolKey != $key ) { - // Look to see if the next instruction is an EOL - if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) { - - if ( $this->inParagraph ) { - //$this->calls[] = array('p_close',array(), $call[2]); - $this->closeParagraph($call[2]); - } - - $this->calls[] = array('p_open',array(), $call[2]); - $this->inParagraph = true; - - - // Mark the next instruction for skipping - $this->skipEolKey = $key+1; - - }else{ - //if this is just a single eol make a space from it - $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2])); - } - } - - - } else { - - $storeCall = true; - if ( $this->inParagraph && (in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open))) { + if ( in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open)) { + $this->closeParagraph($call[2]); + $this->storeCall($call); + continue; + } + /* eol */ + if ( $cname == 'eol' ) { + // Check this isn't an eol instruction to skip... + if ( !$this->skipEol ) { + // Next is EOL => double eol => mark as paragraph + if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) { $this->closeParagraph($call[2]); - $this->calls[] = $call; - $storeCall = false; - } - - if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) { - if ( $this->inParagraph ) { - $this->closeParagraph($call[2]); - } - if ( $storeCall ) { - $this->calls[] = $call; - $storeCall = false; - } - - // This really sucks and suggests this whole class sucks but... - if ( isset($calls[$key+1])) { - $cname_plusone = $calls[$key+1][0]; - if ($cname_plusone == 'plugin') { - $cname_plusone = 'plugin'.$calls[$key+1][1][0]; - - // plugin test, true if plugin has a state which precludes it requiring blockOpen or blockClose - $plugin_plusone = true; - $plugin_test = ($call[$key+1][1][2] == DOKU_LEXER_MATCHED) || ($call[$key+1][1][2] == DOKU_LEXER_MATCHED); - } else { - $plugin_plusone = false; - } - if ((!in_array($cname_plusone, $this->blockOpen) && !in_array($cname_plusone, $this->blockClose)) || - ($plugin_plusone && $plugin_test) - ) { - - $this->calls[] = array('p_open',array(), $call[2]); - $this->inParagraph = true; - } - } - } - - if ( $storeCall ) { - $this->addCall($call); - } - - } - - - } else { - - // Unless there's already a block at the start, start a paragraph - if ( !in_array($cname,$this->blockOpen) ) { - $this->calls[] = array('p_open',array(), $call[2]); - if ( $call[0] != 'eol' ) { - $this->calls[] = $call; + $this->openParagraph($call[2]); + } else { + //if this is just a single eol make a space from it + $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2])); } - $this->atStart = false; - $this->inParagraph = true; - } else { - $this->addCall($call); - $this->atStart = false; } - - } - - } - - if ( $this->inParagraph ) { - if ( $cname == 'p_open' ) { - // Ditch the last call - array_pop($this->calls); - } else if ( !in_array($cname, $this->blockClose) ) { - //$this->calls[] = array('p_close',array(), $call[2]); - $this->closeParagraph($call[2]); - } else { - $last_call = array_pop($this->calls); - //$this->calls[] = array('p_close',array(), $call[2]); - $this->closeParagraph($call[2]); - $this->calls[] = $last_call; + continue; } + /* normal */ + $this->addCall($call); + $this->skipEol = false; } - + // close last paragraph + $call = end($this->calls); + $this->closeParagraph($call[2]); return $this->calls; } - - /** - * - * @return bool true when a p_close() is required - */ - function addToStack($newStart = true) { - $ret = $this->inParagraph; - $this->blockStack[] = array($this->atStart, $this->inParagraph); - $this->atStart = $newStart; - $this->inParagraph = false; - - return $ret; - } - - function removeFromStack() { - $state = array_pop($this->blockStack); - $this->atStart = $state[0]; - $this->inParagraph = $state[1]; - - return $this->inParagraph; - } - - function addCall($call) { - $key = count($this->calls); - if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) { - $this->calls[$key-1][1][0] .= $call[1][0]; - } else { - $this->calls[] = $call; - } - } } //Setup VIM: ex: et ts=4 : diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index fc2c8cbc5..bd396e2b4 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -455,16 +455,16 @@ class Doku_Renderer_metadata extends Doku_Renderer { global $conf; $isImage = false; - if (is_null($title)){ + if (is_array($title)){ + if($title['title']) return '['.$title['title'].']'; + } else if (is_null($title) || trim($title)==''){ if (useHeading('content') && $id){ $heading = p_get_first_heading($id,false); if ($heading) return $heading; } return $default; - } else if (is_string($title)){ + } else { return $title; - } else if (is_array($title)){ - if($title['title']) return '['.$title['title'].']'; } } diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 9405d9420..b502b4f6b 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -29,7 +29,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { var $doc = ''; // will contain the whole document var $toc = array(); // will contain the Table of Contents - private $sectionedits = array(); // A stack of section edit data + var $sectionedits = array(); // A stack of section edit data var $headers = array(); var $footnotes = array(); -- cgit v1.2.3 From 14739a206f851219daa577abdfd7489d86b0072b Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 6 Feb 2011 20:28:39 +0100 Subject: Revert "merged branch 'danny0838:rewrite_block' and resolved conflict" Anika's merge did not pul in the individual patches as one would expect. Then I messed up when trying to fix this by merging with danny's repo again but used the wrong branch. So we're still missing two patches. To have them apply cleanly I have to revert Anika's merge here. Another merge for the missing two patches will follow. This reverts commit b17e20ac9cca30b612968d02f06fa9c5df5c01f0. --- inc/parser/handler.php | 241 +++++++++++++++++++++++++++++++++--------------- inc/parser/metadata.php | 8 +- inc/parser/xhtml.php | 2 +- 3 files changed, 173 insertions(+), 78 deletions(-) (limited to 'inc/parser') diff --git a/inc/parser/handler.php b/inc/parser/handler.php index 26a560c3c..85a353dca 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -1433,8 +1433,14 @@ class Doku_Handler_Table { * @author Harry Fuecks */ class Doku_Handler_Block { + var $calls = array(); - var $skipEol = false; + + var $blockStack = array(); + + var $inParagraph = false; + var $atStart = true; + var $skipEolKey = -1; // Blocks these should not be inside paragraphs var $blockOpen = array( @@ -1442,9 +1448,9 @@ class Doku_Handler_Block { 'listu_open','listo_open','listitem_open','listcontent_open', 'table_open','tablerow_open','tablecell_open','tableheader_open', 'quote_open', + 'section_open', // Needed to prevent p_open between header and section_open 'code','file','hr','preformatted','rss', 'htmlblock','phpblock', - 'footnote_open', ); var $blockClose = array( @@ -1452,18 +1458,18 @@ class Doku_Handler_Block { 'listu_close','listo_close','listitem_close','listcontent_close', 'table_close','tablerow_close','tablecell_close','tableheader_close', 'quote_close', + 'section_close', // Needed to prevent p_close after section_close 'code','file','hr','preformatted','rss', 'htmlblock','phpblock', - 'footnote_close', ); // Stacks can contain paragraphs var $stackOpen = array( - 'section_open', + 'footnote_open','section_open', ); var $stackClose = array( - 'section_close', + 'footnote_close','section_close', ); @@ -1489,13 +1495,6 @@ class Doku_Handler_Block { } } - function openParagraph($pos){ - if ($this->inParagraph) return; - $this->calls[] = array('p_open',array(), $pos); - $this->inParagraph = true; - $this->skipEol = true; - } - /** * Close a paragraph if needed * @@ -1504,7 +1503,6 @@ class Doku_Handler_Block { * @author Andreas Gohr */ function closeParagraph($pos){ - if (!$this->inParagraph) return; // look back if there was any content - we don't want empty paragraphs $content = ''; for($i=count($this->calls)-1; $i>=0; $i--){ @@ -1522,28 +1520,10 @@ class Doku_Handler_Block { //remove the whole paragraph array_splice($this->calls,$i); }else{ - // remove ending linebreaks in the paragraph - $i=count($this->calls)-1; - if ($this->calls[$i][0] == 'cdata') $this->calls[$i][1][0] = rtrim($this->calls[$i][1][0],DOKU_PARSER_EOL); $this->calls[] = array('p_close',array(), $pos); } $this->inParagraph = false; - $this->skipEol = true; - } - - function addCall($call) { - $key = count($this->calls); - if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) { - $this->calls[$key-1][1][0] .= $call[1][0]; - } else { - $this->calls[] = $call; - } - } - - // simple version of addCall, without checking cdata - function storeCall($call) { - $this->calls[] = $call; } /** @@ -1551,71 +1531,186 @@ class Doku_Handler_Block { * * @author Harry Fuecks * @author Andreas Gohr + * @todo This thing is really messy and should be rewritten */ function process($calls) { - // open first paragraph - $this->openParagraph(0); foreach ( $calls as $key => $call ) { $cname = $call[0]; - if ($cname == 'plugin') { + if($cname == 'plugin') { $cname='plugin_'.$call[1][0]; + $plugin = true; $plugin_open = (($call[1][2] == DOKU_LEXER_ENTER) || ($call[1][2] == DOKU_LEXER_SPECIAL)); $plugin_close = (($call[1][2] == DOKU_LEXER_EXIT) || ($call[1][2] == DOKU_LEXER_SPECIAL)); } else { $plugin = false; } - /* stack */ - if ( in_array($cname,$this->stackClose ) && (!$plugin || $plugin_close)) { - $this->closeParagraph($call[2]); - $this->storeCall($call); - $this->openParagraph($call[2]); - continue; - } + + // Process blocks which are stack like... (contain linefeeds) if ( in_array($cname,$this->stackOpen ) && (!$plugin || $plugin_open) ) { - $this->closeParagraph($call[2]); - $this->storeCall($call); - $this->openParagraph($call[2]); - continue; - } - /* block */ - // If it's a substition it opens and closes at the same call. - // To make sure next paragraph is correctly started, let close go first. - if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) { - $this->closeParagraph($call[2]); - $this->storeCall($call); - $this->openParagraph($call[2]); + + // Hack - footnotes shouldn't immediately contain a p_open + if ($this->addToStack($cname != 'footnote_open')) { + $this->closeParagraph($call[2]); + } + $this->calls[] = $call; + continue; } - if ( in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open)) { - $this->closeParagraph($call[2]); - $this->storeCall($call); + + if ( in_array($cname,$this->stackClose ) && (!$plugin || $plugin_close)) { + + if ( $this->inParagraph ) { + $this->closeParagraph($call[2]); + } + $this->calls[] = $call; + if ($this->removeFromStack()) { + $this->calls[] = array('p_open',array(), $call[2]); + } continue; } - /* eol */ - if ( $cname == 'eol' ) { - // Check this isn't an eol instruction to skip... - if ( !$this->skipEol ) { - // Next is EOL => double eol => mark as paragraph - if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) { + + if ( !$this->atStart ) { + + if ( $cname == 'eol' ) { + + // Check this isn't an eol instruction to skip... + if ( $this->skipEolKey != $key ) { + // Look to see if the next instruction is an EOL + if ( isset($calls[$key+1]) && $calls[$key+1][0] == 'eol' ) { + + if ( $this->inParagraph ) { + //$this->calls[] = array('p_close',array(), $call[2]); + $this->closeParagraph($call[2]); + } + + $this->calls[] = array('p_open',array(), $call[2]); + $this->inParagraph = true; + + + // Mark the next instruction for skipping + $this->skipEolKey = $key+1; + + }else{ + //if this is just a single eol make a space from it + $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2])); + } + } + + + } else { + + $storeCall = true; + if ( $this->inParagraph && (in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open))) { $this->closeParagraph($call[2]); - $this->openParagraph($call[2]); - } else { - //if this is just a single eol make a space from it - $this->addCall(array('cdata',array(DOKU_PARSER_EOL), $call[2])); + $this->calls[] = $call; + $storeCall = false; } + + if ( in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) { + if ( $this->inParagraph ) { + $this->closeParagraph($call[2]); + } + if ( $storeCall ) { + $this->calls[] = $call; + $storeCall = false; + } + + // This really sucks and suggests this whole class sucks but... + if ( isset($calls[$key+1])) { + $cname_plusone = $calls[$key+1][0]; + if ($cname_plusone == 'plugin') { + $cname_plusone = 'plugin'.$calls[$key+1][1][0]; + + // plugin test, true if plugin has a state which precludes it requiring blockOpen or blockClose + $plugin_plusone = true; + $plugin_test = ($call[$key+1][1][2] == DOKU_LEXER_MATCHED) || ($call[$key+1][1][2] == DOKU_LEXER_MATCHED); + } else { + $plugin_plusone = false; + } + if ((!in_array($cname_plusone, $this->blockOpen) && !in_array($cname_plusone, $this->blockClose)) || + ($plugin_plusone && $plugin_test) + ) { + + $this->calls[] = array('p_open',array(), $call[2]); + $this->inParagraph = true; + } + } + } + + if ( $storeCall ) { + $this->addCall($call); + } + } - continue; + + + } else { + + // Unless there's already a block at the start, start a paragraph + if ( !in_array($cname,$this->blockOpen) ) { + $this->calls[] = array('p_open',array(), $call[2]); + if ( $call[0] != 'eol' ) { + $this->calls[] = $call; + } + $this->atStart = false; + $this->inParagraph = true; + } else { + $this->addCall($call); + $this->atStart = false; + } + } - /* normal */ - $this->addCall($call); - $this->skipEol = false; + } - // close last paragraph - $call = end($this->calls); - $this->closeParagraph($call[2]); + + if ( $this->inParagraph ) { + if ( $cname == 'p_open' ) { + // Ditch the last call + array_pop($this->calls); + } else if ( !in_array($cname, $this->blockClose) ) { + //$this->calls[] = array('p_close',array(), $call[2]); + $this->closeParagraph($call[2]); + } else { + $last_call = array_pop($this->calls); + //$this->calls[] = array('p_close',array(), $call[2]); + $this->closeParagraph($call[2]); + $this->calls[] = $last_call; + } + } + return $this->calls; } + + /** + * + * @return bool true when a p_close() is required + */ + function addToStack($newStart = true) { + $ret = $this->inParagraph; + $this->blockStack[] = array($this->atStart, $this->inParagraph); + $this->atStart = $newStart; + $this->inParagraph = false; + + return $ret; + } + + function removeFromStack() { + $state = array_pop($this->blockStack); + $this->atStart = $state[0]; + $this->inParagraph = $state[1]; + + return $this->inParagraph; + } + + function addCall($call) { + $key = count($this->calls); + if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) { + $this->calls[$key-1][1][0] .= $call[1][0]; + } else { + $this->calls[] = $call; + } + } } //Setup VIM: ex: et ts=4 : diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index bd396e2b4..fc2c8cbc5 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -455,16 +455,16 @@ class Doku_Renderer_metadata extends Doku_Renderer { global $conf; $isImage = false; - if (is_array($title)){ - if($title['title']) return '['.$title['title'].']'; - } else if (is_null($title) || trim($title)==''){ + if (is_null($title)){ if (useHeading('content') && $id){ $heading = p_get_first_heading($id,false); if ($heading) return $heading; } return $default; - } else { + } else if (is_string($title)){ return $title; + } else if (is_array($title)){ + if($title['title']) return '['.$title['title'].']'; } } diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index b502b4f6b..9405d9420 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -29,7 +29,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { var $doc = ''; // will contain the whole document var $toc = array(); // will contain the Table of Contents - var $sectionedits = array(); // A stack of section edit data + private $sectionedits = array(); // A stack of section edit data var $headers = array(); var $footnotes = array(); -- cgit v1.2.3 From f25fcf537e1a3223cce417ba01dc63d79b80a6f7 Mon Sep 17 00:00:00 2001 From: Michael Hamann Date: Wed, 9 Feb 2011 11:14:09 +0100 Subject: Make the regex for internal links more restrictive This fixes a PCRE backtrack error that occurred on large pages like :users on dokuwiki.org. --- inc/parser/parser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/parser') diff --git a/inc/parser/parser.php b/inc/parser/parser.php index a7764ee9c..e47ce56fa 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -828,7 +828,7 @@ class Doku_Parser_Mode_internallink extends Doku_Parser_Mode { function connectTo($mode) { // Word boundaries? - $this->Lexer->addSpecialPattern("\[\[(?:(?:.*?\[.*?\])|.+?)\]\]",$mode,'internallink'); + $this->Lexer->addSpecialPattern("\[\[(?:(?:[^[\]]*?\[.*?\])|.+?)\]\]",$mode,'internallink'); } function getSort() { -- cgit v1.2.3