From 92b1a4175052229c7839da606fbf81ac085b6f8b Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Tue, 16 Mar 2004 02:17:33 +0000 Subject: [PATCH] Fix sourceforge bug 872981 Render [[[link]]] as [link] Render [[[link|text]]] as [text] UNTESTED with $wgLang->linkPrefixExtension() true --- includes/Parser.php | 19 ++++++++++++++++++- includes/Tokenizer.php | 3 ++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index 11812bf62e..3764a612f4 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -591,12 +591,16 @@ class Parser # Every call to the tokenizer returns a new token. while ( $token = $tokenizer->nextToken() ) { +echo $token["type"]."
"; switch ( $token["type"] ) { case "text": # simple text with no further markup $txt = $token["text"]; break; + case "[[[": + # remember the tag opened with 3 [ + $threeopen = true; case "[[": # link opening tag. # FIXME : Treat orphaned open tags (stack not empty when text is over) @@ -604,10 +608,13 @@ class Parser array_push( $tokenStack, $token ); $txt=""; break; + + case "]]]": case "]]": # link close tag. # get text from stack, glue it together, and call the code to handle a # link + if ( count( $tokenStack ) == 0 ) { # stack empty. Found a ]] without an opening [[ @@ -615,14 +622,16 @@ class Parser } else { $linkText = ""; $lastToken = array_pop( $tokenStack ); - while ( $lastToken["type"] != "[[" ) + while ( !(($lastToken["type"] == "[[[") or ($lastToken["type"] == "[[")) ) { if( !empty( $lastToken["text"] ) ) { $linkText = $lastToken["text"] . $linkText; } $lastToken = array_pop( $tokenStack ); } + $txt = $linkText ."]]"; + if( isset( $lastToken["text"] ) ) { $prefix = $lastToken["text"]; } else { @@ -636,6 +645,14 @@ class Parser $txt .= $nextToken["text"]; } $txt = $this->handleInternalLink( $txt, $prefix ); + + # did the tag start with 3 [ ? + if($threeopen) { + # show the first as text + $txt = "[".$txt; + $threeopen=false; + } + } $tagIsOpen = (count( $tokenStack ) != 0); break; diff --git a/includes/Tokenizer.php b/includes/Tokenizer.php index e563a7c8e5..2771319641 100644 --- a/includes/Tokenizer.php +++ b/includes/Tokenizer.php @@ -34,7 +34,8 @@ class Tokenizer { if ( $wgLang->linkPrefixExtension() ) { $regex .= "|([a-zA-Z\x80-\xff]+)\[\["; } else { - $regex .= "|\[\["; + # end tag that can start with 3 [ + $regex .= "|\[\[\[?"; } # Closing link $regex .= "|\]\]"; -- 2.20.1