diff --git a/includes/ParserPower.php b/includes/ParserPower.php index fc10d47..0f114cd 100644 --- a/includes/ParserPower.php +++ b/includes/ParserPower.php @@ -69,12 +69,22 @@ class ParserPower { */ public static function arrangeParams( PPFrame $frame, array $unexpandedParams ) { $params = []; + + if ( isset( $unexpandedParams[0] ) && is_string( $unexpandedParams[0] ) ) { + $pair = explode( '=', array_shift( $unexpandedParams ), 2 ); + if ( count( $pair ) === 2 ) { + $params[trim( $pair[0] )] = trim( $pair[1] ); + } else { + $params[] = trim( $pair[0] ); + } + } + foreach ( $unexpandedParams as $unexpandedParam ) { - $param = explode( '=', $frame->expand( $unexpandedParam ), 2 ); - if ( count( $param ) == 2 ) { - $params[trim( $param[0] )] = trim( $param[1] ); + $bits = $unexpandedParam->splitArg(); + if ( $bits['index'] === '' ) { + $params[ParserPower::expand( $frame, $bits['name'] )] = ParserPower::expand( $frame, $bits['value'] ); } else { - $params[] = trim( $param[0] ); + $params[] = ParserPower::expand( $frame, $bits['value'] ); } } diff --git a/includes/SimpleFunctions.php b/includes/SimpleFunctions.php index 7eff5f2..03dcee8 100644 --- a/includes/SimpleFunctions.php +++ b/includes/SimpleFunctions.php @@ -334,17 +334,27 @@ public static function ueswitchRender( Parser $parser, PPFrame $frame, array $pa return [ '', 'noparse' => false ]; } - $lastItem = $frame->expand( $params[count( $params ) - 1] ); + $lastBits = $params[count( $params ) - 1]->splitArg(); + $frame->expand( $lastBits['name'] ); + $lastValue = $frame->expand( $lastBits['value'] ); + $default = ''; $mwDefaultFound = false; $mwDefault = $parser->getMagicWordFactory()->get( 'default' ); $keyFound = false; foreach ( $params as $param ) { - $pair = explode( '=', $frame->expand( $param ), 2 ); + $bits = $param->splitArg(); + if ( $bits['index'] === '' ) { + $key = ParserPower::expand( $frame, $bits['name'] ); + $value = ParserPower::expand( $frame, $bits['value'] ); + } else { + $key = ParserPower::expand( $frame, $bits['value'] ); + $value = null; + } if ( !$keyFound ) { - $key = ParserPower::unescape( trim( $pair[0] ) ); + $key = ParserPower::unescape( $key ); if ( $key === $switchKey ) { $keyFound = true; } elseif ( $mwDefault->matchStartToEnd( $key ) ) { @@ -352,18 +362,18 @@ public static function ueswitchRender( Parser $parser, PPFrame $frame, array $pa } } - if ( count( $pair ) > 1 ) { + if ( $value !== null ) { if ( $keyFound ) { - return [ ParserPower::unescape( trim( $pair[1] ) ), 'noparse' => false ]; + return [ ParserPower::unescape( $value ), 'noparse' => false ]; } elseif ( $mwDefaultFound ) { - $default = $pair[1]; + $default = $value; $mwDefaultFound = false; } } } - if ( strpos( $lastItem, '=' ) === false ) { - $default = $lastItem; + if ( $lastBits['index'] !== '' ) { + $default = $lastValue; } return [ ParserPower::expand( $frame, $default, ParserPower::UNESCAPE ), 'noparse' => false ]; }