r4452 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r4451‎ | r4452 | r4453 >
Date:14:13, 31 July 2004
Author:timwi
Status:old
Tags:
Comment:
Allowing for piped links inside template variables; by Emmanuel Engelhart
http://mail.wikipedia.org/pipermail/wikitech-l/2004-July/011776.html ff.
Modified paths:
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -1524,6 +1524,31 @@
15251525 return $text;
15261526 }
15271527
 1528+ # Split template arguments
 1529+ function getTemplateArgs( $argsString ) {
 1530+ if ( $argsString === '' ) {
 1531+ return array();
 1532+ }
 1533+
 1534+ $args = explode( '|', substr( $argsString, 1 ) );
 1535+
 1536+ # If any of the arguments contains a '[[' but no ']]', it needs to be
 1537+ # merged with the next arg because the '|' character between belongs
 1538+ # to the link syntax and not the template parameter syntax.
 1539+ $argc = count($args);
 1540+ $i = 0;
 1541+ for ( $i = 0; $i < $argc-1; $i++ ) {
 1542+ if ( substr_count ( $args[$i], "[[" ) != substr_count ( $args[$i], "]]" ) ) {
 1543+ $args[$i] .= "|".$args[$i+1];
 1544+ array_splice($args, $i+1, 1);
 1545+ $i--;
 1546+ $argc--;
 1547+ }
 1548+ }
 1549+
 1550+ return $args;
 1551+ }
 1552+
15281553 function braceSubstitution( $matches ) {
15291554 global $wgLinkCache, $wgLang;
15301555 $fname = 'Parser::braceSubstitution';
@@ -1540,11 +1565,8 @@
15411566 $newline = $matches[1];
15421567 $part1 = $matches[2];
15431568 # If the third subpattern matched anything, it will start with |
1544 - if ( $matches[3] !== '' ) {
1545 - $args = explode( '|', substr( $matches[3], 1 ) );
1546 - } else {
1547 - $args = array();
1548 - }
 1569+
 1570+ $args = $this->getTemplateArgs($matches[3]);
15491571 $argc = count( $args );
15501572
15511573 # {{{}}}

Follow-up revisions

RevisionCommit summaryAuthorDate
r16925(bug 6835): Removing the includes/Parser.php::getTemplateArgs() function, bec...nickj05:45, 11 October 2006

Status & tagging log