From d6b0fc1ab57d27cfd0cd28674a577b859aab4030 Mon Sep 17 00:00:00 2001 From: Arne Heizmann Date: Sat, 31 Jul 2004 14:13:07 +0000 Subject: [PATCH] Allowing for piped links inside template variables; by Emmanuel Engelhart http://mail.wikipedia.org/pipermail/wikitech-l/2004-July/011776.html ff. --- includes/Parser.php | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index ebccf2ce05..57600b3229 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -1524,6 +1524,31 @@ class Parser return $text; } + # Split template arguments + function getTemplateArgs( $argsString ) { + if ( $argsString === '' ) { + return array(); + } + + $args = explode( '|', substr( $argsString, 1 ) ); + + # If any of the arguments contains a '[[' but no ']]', it needs to be + # merged with the next arg because the '|' character between belongs + # to the link syntax and not the template parameter syntax. + $argc = count($args); + $i = 0; + for ( $i = 0; $i < $argc-1; $i++ ) { + if ( substr_count ( $args[$i], "[[" ) != substr_count ( $args[$i], "]]" ) ) { + $args[$i] .= "|".$args[$i+1]; + array_splice($args, $i+1, 1); + $i--; + $argc--; + } + } + + return $args; + } + function braceSubstitution( $matches ) { global $wgLinkCache, $wgLang; $fname = 'Parser::braceSubstitution'; @@ -1540,11 +1565,8 @@ class Parser $newline = $matches[1]; $part1 = $matches[2]; # If the third subpattern matched anything, it will start with | - if ( $matches[3] !== '' ) { - $args = explode( '|', substr( $matches[3], 1 ) ); - } else { - $args = array(); - } + + $args = $this->getTemplateArgs($matches[3]); $argc = count( $args ); # {{{}}} -- 2.20.1