diff --git a/includes/ListFunctions.php b/includes/ListFunctions.php index a4a7be9..9377e82 100644 --- a/includes/ListFunctions.php +++ b/includes/ListFunctions.php @@ -405,15 +405,14 @@ public static function lstcntRender( Parser $parser, PPFrame $frame, array $para $list = ParserPower::expand( $frame, $params[0] ?? '' ); if ( $list === '' ) { - return [ '0', 'noparse' => false ]; + return '0'; } $sep = ParserPower::expand( $frame, $params[1] ?? ',', ParserPower::UNESCAPE ); $sep = $parser->getStripState()->unstripNoWiki( $sep ); - $count = count( self::arrayTrimUnescape( self::explodeList( $sep, $list ) ) ); - return [ $count, 'noparse' => false ]; + return count( self::arrayTrimUnescape( self::explodeList( $sep, $list ) ) ); } /** @@ -428,7 +427,7 @@ public static function lstsepRender( Parser $parser, PPFrame $frame, array $para $inList = ParserPower::expand( $frame, $params[0] ?? '' ); if ( $inList === '' ) { - return [ '', 'noparse' => false ]; + return ''; } $inSep = ParserPower::expand( $frame, $params[1] ?? ',', ParserPower::UNESCAPE ); @@ -437,7 +436,7 @@ public static function lstsepRender( Parser $parser, PPFrame $frame, array $para $inSep = $parser->getStripState()->unstripNoWiki( $inSep ); $values = self::arrayTrimUnescape( self::explodeList( $inSep, $inList ) ); - return [ implode( $outSep, $values ), 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, implode( $outSep, $values ) ); } /** @@ -452,7 +451,7 @@ public static function lstelemRender( Parser $parser, PPFrame $frame, array $par $inList = ParserPower::expand( $frame, $params[0] ?? '' ); if ( $inList === '' ) { - return [ '', 'noparse' => false ]; + return ''; } $inSep = ParserPower::expand( $frame, $params[1] ?? ',', ParserPower::UNESCAPE ); @@ -467,7 +466,7 @@ public static function lstelemRender( Parser $parser, PPFrame $frame, array $par $value = self::arrayElementTrimUnescape( $index, self::explodeList( $inSep, $inList ) ); - return [ $value, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $value ); } /** @@ -482,7 +481,7 @@ public static function lstsubRender( Parser $parser, PPFrame $frame, array $para $inList = ParserPower::expand( $frame, $params[0] ?? '' ); if ( $inList === '' ) { - return [ '', 'noparse' => false ]; + return ''; } $inSep = ParserPower::expand( $frame, $params[1] ?? ',', ParserPower::UNESCAPE ); @@ -505,9 +504,9 @@ public static function lstsubRender( Parser $parser, PPFrame $frame, array $para $values = self::arrayTrimSliceUnescape( $offset, $length, self::explodeList( $inSep, $inList ) ); if ( count( $values ) > 0 ) { - return [ implode( $outSep, $values ), 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, implode( $outSep, $values ) ); } else { - return [ '', 'noparse' => false ]; + return ''; } } @@ -523,7 +522,7 @@ public static function lstfndRender( Parser $parser, PPFrame $frame, array $para $list = ParserPower::expand( $frame, $params[1] ?? '' ); if ( $list === '' ) { - return [ '', 'noparse' => false ]; + return ''; } $item = ParserPower::expand( $frame, $params[0] ?? '', ParserPower::UNESCAPE ); @@ -537,17 +536,17 @@ public static function lstfndRender( Parser $parser, PPFrame $frame, array $para if ( $csOption ) { foreach ( $values as $value ) { if ( $value === $item ) { - return [ $value, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $value ); } } } else { foreach ( $values as $value ) { if ( strtolower( $value ) === strtolower( $item ) ) { - return [ $value, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $value ); } } } - return [ '', 'noparse' => false ]; + return ''; } /** @@ -562,7 +561,7 @@ public static function lstindRender( Parser $parser, PPFrame $frame, array $para $list = ParserPower::expand( $frame, $params[1] ?? '' ); if ( $list === '' ) { - return [ '', 'noparse' => false ]; + return ''; } $item = ParserPower::expand( $frame, $params[0] ?? '', ParserPower::UNESCAPE ); @@ -578,17 +577,13 @@ public static function lstindRender( Parser $parser, PPFrame $frame, array $para if ( $options & self::INDEX_CS ) { for ( $index = $count - 1; $index > -1; --$index ) { if ( $values[$index] === $item ) { - return [ strval( ( $options & self::INDEX_NEG ) ? $index - $count : $index + 1 ), - 'noparse' => false - ]; + return strval( ( $options & self::INDEX_NEG ) ? $index - $count : $index + 1 ); } } } else { for ( $index = $count - 1; $index > -1; --$index ) { if ( strtolower( $values[$index] ) === strtolower( $item ) ) { - return [ strval( ( $options & self::INDEX_NEG ) ? $index - $count : $index + 1 ), - 'noparse' => false - ]; + return strval( ( $options & self::INDEX_NEG ) ? $index - $count : $index + 1 ); } } } @@ -596,22 +591,18 @@ public static function lstindRender( Parser $parser, PPFrame $frame, array $para if ( $options & self::INDEX_CS ) { for ( $index = 0; $index < $count; ++$index ) { if ( $values[$index] === $item ) { - return [ strval( ( $options & self::INDEX_NEG ) ? $index - $count : $index + 1 ), - 'noparse' => false - ]; + return strval( ( $options & self::INDEX_NEG ) ? $index - $count : $index + 1 ); } } } else { for ( $index = 0; $index < $count; ++$index ) { if ( strtolower( $values[$index] ) === strtolower( $item ) ) { - return [ strval( ( $options & self::INDEX_NEG ) ? $index - $count : $index + 1 ), - 'noparse' => false - ]; + return strval( ( $options & self::INDEX_NEG ) ? $index - $count : $index + 1 ); } } } } - return [ '', 'noparse' => false ]; + return ''; } /** @@ -627,7 +618,7 @@ public static function lstappRender( Parser $parser, PPFrame $frame, array $para $value = ParserPower::expand( $frame, $params[2] ?? '', ParserPower::UNESCAPE ); if ( $list === '' ) { - return [ $value, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $value ); } $sep = ParserPower::expand( $frame, $params[1] ?? ',', ParserPower::UNESCAPE ); @@ -638,7 +629,7 @@ public static function lstappRender( Parser $parser, PPFrame $frame, array $para if ( $value !== '' ) { $values[] = $value; } - return [ implode( $sep, $values ), 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, implode( $sep, $values ) ); } /** @@ -654,7 +645,7 @@ public static function lstprepRender( Parser $parser, PPFrame $frame, array $par $list = ParserPower::expand( $frame, $params[2] ?? '' ); if ( $list === '' ) { - return [ $value, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $value ); } $sep = ParserPower::expand( $frame, $params[1] ?? '', ParserPower::UNESCAPE ); @@ -665,7 +656,7 @@ public static function lstprepRender( Parser $parser, PPFrame $frame, array $par if ( $value !== '' ) { array_unshift( $values, $value ); } - return [ implode( $sep, $values ), 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, implode( $sep, $values ) ); } /** @@ -681,7 +672,7 @@ public static function lstjoinRender( Parser $parser, PPFrame $frame, array $par $inList2 = ParserPower::expand( $frame, $params[2] ?? '' ); if ( $inList1 === '' && $inList2 === '' ) { - return [ '', 'noparse' => false ]; + return ''; } if ( $inList1 === '' ) { @@ -702,29 +693,26 @@ public static function lstjoinRender( Parser $parser, PPFrame $frame, array $par $outSep = ParserPower::expand( $frame, $params[4] ?? ',\_', ParserPower::UNESCAPE ); - return [ implode( $outSep, array_merge( $values1, $values2 ) ), 'noparse' => false ]; + $values = array_merge( $values1, $values2 ); + return ParserPower::evaluateUnescaped( $parser, $frame, implode( $outSep, $values ) ); } /** * Replaces the indicated token in the pattern with the input value. * - * @param Parser $parser The parser object. - * @param PPFrame $frame The parser frame object. * @param string $inValue The value to change into one or more template parameters. * @param string $token The token to replace. * @param string $pattern Pattern containing token to be replaced with the input value. * @return string The result of the token replacement within the pattern. */ - private static function applyPattern( Parser $parser, PPFrame $frame, $inValue, $token, $pattern ) { - return ParserPower::applyPattern( $parser, $frame, $inValue, $token, $pattern ); + private static function applyPattern( $inValue, $token, $pattern ) { + return ParserPower::applyPattern( $inValue, $token, $pattern ); } /** * Replaces the indicated index token in the pattern with the given index and the token * in the pattern with the input value. * - * @param Parser $parser The parser object. - * @param PPFrame $frame The parser frame object. * @param string $inValue The value to change into one or more template parameters. * @param int $indexToken The token to replace with the index, or null/empty value to skip index replacement. * @param int $index The numeric index of this value. @@ -732,23 +720,13 @@ private static function applyPattern( Parser $parser, PPFrame $frame, $inValue, * @param string $pattern Pattern containing token to be replaced with the input value. * @return string The result of the token replacement within the pattern. */ - private static function applyPatternWithIndex( - Parser $parser, - PPFrame $frame, - $inValue, - $indexToken, - $index, - $token, - $pattern - ) { - return ParserPower::applyPatternWithIndex( $parser, $frame, $inValue, $indexToken, $index, $token, $pattern ); + private static function applyPatternWithIndex( $inValue, $indexToken, $index, $token, $pattern ) { + return ParserPower::applyPatternWithIndex( $inValue, $indexToken, $index, $token, $pattern ); } /** * Breaks the input value into fields and then replaces the indicated tokens in the pattern with those field values. * - * @param Parser $parser The parser object. - * @param PPFrame $frame The parser frame object. * @param string $inValue The value to change into one or more template parameters * @param string $fieldSep The delimiter separating the fields in the value. * @param array $tokens The list of tokens to replace. @@ -756,24 +734,14 @@ private static function applyPatternWithIndex( * @param string $pattern Pattern containing tokens to be replaced by field values. * @return string The result of the token replacement within the pattern. */ - private static function applyFieldPattern( - Parser $parser, - PPFrame $frame, - $inValue, - $fieldSep, - array $tokens, - $tokenCount, - $pattern - ) { - return ParserPower::applyFieldPattern( $parser, $frame, $inValue, $fieldSep, $tokens, $tokenCount, $pattern ); + private static function applyFieldPattern( $inValue, $fieldSep, array $tokens, $tokenCount, $pattern ) { + return ParserPower::applyFieldPattern( $inValue, $fieldSep, $tokens, $tokenCount, $pattern ); } /** * Replaces the index token with the given index, and then breaks the input value into fields and then replaces the * indicated tokens in the pattern with those field values. * - * @param Parser $parser The parser object. - * @param PPFrame $frame The parser frame object. * @param string $inValue The value to change into one or more template parameters * @param string $fieldSep The delimiter separating the fields in the value. * @param int $indexToken The token to replace with the index, or null/empty value to skip index replacement. @@ -784,8 +752,6 @@ private static function applyFieldPattern( * @return string The result of the token replacement within the pattern. */ private static function applyFieldPatternWithIndex( - Parser $parser, - PPFrame $frame, $inValue, $fieldSep, $indexToken, @@ -795,8 +761,6 @@ private static function applyFieldPatternWithIndex( $pattern ) { return ParserPower::applyFieldPatternWithIndex( - $parser, - $frame, $inValue, $fieldSep, $indexToken, @@ -838,7 +802,6 @@ private static function applyIntroAndOutro( $intro, $content, $outro, $countToke * @return string The result of the template. */ private static function applyTemplate( Parser $parser, PPFrame $frame, $inValue, $template, $fieldSep ) { - $inValue = trim( $inValue ); if ( $inValue === '' ) { return; } @@ -859,7 +822,10 @@ private static function applyTemplate( Parser $parser, PPFrame $frame, $inValue, if ( $outValue instanceof PPNode_Hash_Array ) { $outValue = $outValue->value; } - return $parser->replaceVariables( implode( '', $outValue ), $frame ); + $outValue = implode( '', $outValue ); + + $outValue = $parser->preprocessToDom( $outValue, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); + return ParserPower::expand( $frame, $outValue ); } /** @@ -875,7 +841,7 @@ private static function filterListByInclusion( array $inValues, $values, $valueS if ( $valueSep !== '' ) { $includeValues = self::arrayTrimUnescape( self::explodeList( $valueSep, $values ) ); } else { - $includeValues = [ ParserPower::unescape( trim( $values ) ) ]; + $includeValues = [ ParserPower::unescape( $values ) ]; } $outValues = []; @@ -911,7 +877,7 @@ private static function filterListByExclusion( array $inValues, $values, $valueS if ( $valueSep !== '' ) { $excludeValues = self::arrayTrimUnescape( self::explodeList( $valueSep, $values ) ); } else { - $excludeValues = [ ParserPower::unescape( trim( $values ) ) ]; + $excludeValues = [ ParserPower::unescape( $values ) ]; } $outValues = []; @@ -963,10 +929,8 @@ private static function filterFromListByPattern( $tokenCount = count( $tokens ); $index = 1; foreach ( $inValues as $value ) { - if ( trim( $value ) !== '' ) { + if ( $value !== '' ) { $result = self::applyFieldPatternWithIndex( - $parser, - $frame, $value, $fieldSep, $indexToken, @@ -975,7 +939,9 @@ private static function filterFromListByPattern( $tokenCount, $pattern ); - $result = $parser->replaceVariables( ParserPower::unescape( trim( $result ) ), $frame ); + $result = $parser->preprocessToDom( $result, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); + $result = ParserPower::expand( $frame, $result, ParserPower::UNESCAPE ); + $result = $parser->replaceVariables( $result, $frame ); if ( strtolower( $result ) !== 'remove' ) { $outValues[] = $value; } @@ -985,17 +951,11 @@ private static function filterFromListByPattern( } else { $index = 1; foreach ( $inValues as $value ) { - if ( trim( $value ) !== '' ) { - $result = self::applyPatternWithIndex( - $parser, - $frame, - $value, - $indexToken, - $index, - $token, - $pattern - ); - $result = $parser->replaceVariables( ParserPower::unescape( $result ), $frame ); + if ( $value !== '' ) { + $result = self::applyPatternWithIndex( $value, $indexToken, $index, $token, $pattern ); + $result = $parser->preprocessToDom( $result, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); + $result = ParserPower::expand( $frame, $result, ParserPower::UNESCAPE ); + $result = $parser->replaceVariables( $result, $frame ); if ( strtolower( $result ) !== 'remove' ) { $outValues[] = $value; } @@ -1045,7 +1005,7 @@ public static function listfilterRender( Parser $parser, PPFrame $frame, array $ $default = ParserPower::expand( $frame, $params["default"] ?? '', ParserPower::UNESCAPE ); if ( $inList === '' ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } $keepValues = ParserPower::expand( $frame, $params["keep"] ?? '' ); @@ -1060,7 +1020,7 @@ public static function listfilterRender( Parser $parser, PPFrame $frame, array $ $indexToken = ParserPower::expand( $frame, $params["indextoken"] ?? '', ParserPower::NO_VARS | ParserPower::UNESCAPE ); $token = ParserPower::expand( $frame, $params["token"] ?? '', ParserPower::NO_VARS | ParserPower::UNESCAPE ); $tokenSep = ParserPower::expand( $frame, $params["tokensep"] ?? ',', ParserPower::UNESCAPE ); - $pattern = $params["pattern"] ?? ''; + $pattern = ParserPower::expand( $frame, $params["pattern"] ?? '', ParserPower::NO_VARS ); $outSep = ParserPower::expand( $frame, $params["outsep"] ?? ',\_', ParserPower::UNESCAPE ); $countToken = ParserPower::expand( $frame, $params["counttoken"] ?? '', ParserPower::NO_VARS | ParserPower::UNESCAPE ); $intro = ParserPower::expand( $frame, $params["intro"] ?? '', ParserPower::UNESCAPE ); @@ -1091,12 +1051,13 @@ public static function listfilterRender( Parser $parser, PPFrame $frame, array $ } if ( count( $outValues ) === 0 ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } - $outList = implode( $outSep, $outValues ); $count = strval( count( $outValues ) ); - return [ self::applyIntroAndOutro( $intro, $outList, $outro, $countToken, $count ), 'noparse' => false ]; + $outList = self::applyIntroAndOutro( $intro, implode( $outSep, $outValues ), $outro, $countToken, $count ); + + return ParserPower::evaluateUnescaped( $parser, $frame, $outList ); } /** @@ -1111,7 +1072,7 @@ public static function lstfltrRender( Parser $parser, PPFrame $frame, array $par $inList = ParserPower::expand( $frame, $params[2] ?? '' ); if ( $inList === '' ) { - return [ '', 'noparse' => false ]; + return ''; } $values = ParserPower::expand( $frame, $params[0] ?? '' ); @@ -1128,9 +1089,9 @@ public static function lstfltrRender( Parser $parser, PPFrame $frame, array $par $outValues = self::filterListByInclusion( $inValues, $values, $valueSep, $csOption ); if ( count( $outValues ) > 0 ) { - return [ implode( $outSep, $outValues ), 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, implode( $outSep, $outValues ) ); } else { - return [ '', 'noparse' => false ]; + return ''; } } @@ -1146,7 +1107,7 @@ public static function lstrmRender( Parser $parser, PPFrame $frame, array $param $inList = ParserPower::expand( $frame, $params[1] ?? '' ); if ( $inList === '' ) { - return [ '', 'noparse' => false ]; + return ''; } $value = ParserPower::expand( $frame, $params[0] ?? '' ); @@ -1162,9 +1123,9 @@ public static function lstrmRender( Parser $parser, PPFrame $frame, array $param $outValues = self::filterListByExclusion( $inValues, $value, '', $csOption ); if ( count( $outValues ) > 0 ) { - return [ implode( $outSep, $outValues ), 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, implode( $outSep, $outValues ) ); } else { - return [ '', 'noparse' => false ]; + return ''; } } @@ -1195,7 +1156,7 @@ public static function lstcntuniqRender( Parser $parser, PPFrame $frame, array $ $inList = ParserPower::expand( $frame, $params[0] ?? '' ); if ( $inList === '' ) { - return [ '0', 'noparse' => false ]; + return '0'; } $sep = ParserPower::expand( $frame, $params[1] ?? ',', ParserPower::UNESCAPE ); @@ -1206,7 +1167,7 @@ public static function lstcntuniqRender( Parser $parser, PPFrame $frame, array $ $values = self::arrayTrimUnescape( self::explodeList( $sep, $inList ) ); $values = self::reduceToUniqueValues( $values, $csOption ); - return [ strval( count( $values ) ), 'noparse' => false ]; + return strval( count( $values ) ); } /** @@ -1239,10 +1200,8 @@ private static function reduceToUniqueValuesByKeyPattern( $tokenCount = count( $tokens ); $index = 1; foreach ( $inValues as $value ) { - if ( trim( $value ) !== '' ) { + if ( $value !== '' ) { $key = self::applyFieldPatternWithIndex( - $parser, - $frame, $value, $fieldSep, $indexToken, @@ -1251,7 +1210,9 @@ private static function reduceToUniqueValuesByKeyPattern( $tokenCount, $pattern ); - $key = $parser->replaceVariables( ParserPower::unescape( $key ), $frame ); + $key = $parser->preprocessToDom( $key, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); + $key = ParserPower::expand( $frame, $key, ParserPower::UNESCAPE ); + $key = $parser->replaceVariables( $key, $frame ); if ( !in_array( $key, $previousKeys ) ) { $previousKeys[] = $key; $outValues[] = $value; @@ -1262,9 +1223,11 @@ private static function reduceToUniqueValuesByKeyPattern( } else { $index = 1; foreach ( $inValues as $value ) { - if ( trim( $value ) !== '' ) { - $key = self::applyPatternWithIndex( $parser, $frame, $value, $indexToken, $index, $token, $pattern ); - $key = $parser->replaceVariables( ParserPower::unescape( $key ), $frame ); + if ( $value !== '' ) { + $key = self::applyPatternWithIndex( $value, $indexToken, $index, $token, $pattern ); + $key = $parser->preprocessToDom( $key, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); + $key = ParserPower::expand( $frame, $key, ParserPower::UNESCAPE ); + $key = $parser->replaceVariables( $key, $frame ); if ( !in_array( $key, $previousKeys ) ) { $previousKeys[] = $key; $outValues[] = $value; @@ -1325,7 +1288,7 @@ public static function listuniqueRender( Parser $parser, PPFrame $frame, array $ $default = ParserPower::expand( $frame, $params["default"] ?? '', ParserPower::UNESCAPE ); if ( $inList === '' ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } $uniqueCS = ParserPower::expand( $frame, $params["uniquecs"] ?? '' ); @@ -1335,7 +1298,7 @@ public static function listuniqueRender( Parser $parser, PPFrame $frame, array $ $indexToken = ParserPower::expand( $frame, $params["indextoken"] ?? '', ParserPower::NO_VARS | ParserPower::UNESCAPE ); $token = ParserPower::expand( $frame, $params["token"] ?? '', ParserPower::NO_VARS | ParserPower::UNESCAPE ); $tokenSep = ParserPower::expand( $frame, $params["tokensep"] ?? ',', ParserPower::UNESCAPE ); - $pattern = $params["pattern"] ?? ''; + $pattern = ParserPower::expand( $frame, $params["pattern"] ?? '', ParserPower::NO_VARS ); $outSep = ParserPower::expand( $frame, $params["outsep"] ?? ',\_', ParserPower::UNESCAPE ); $countToken = ParserPower::expand( $frame, $params["counttoken"] ?? '', ParserPower::NO_VARS | ParserPower::UNESCAPE ); $intro = ParserPower::expand( $frame, $params["intro"] ?? '', ParserPower::UNESCAPE ); @@ -1365,9 +1328,9 @@ public static function listuniqueRender( Parser $parser, PPFrame $frame, array $ } else { $outValues = self::reduceToUniqueValues( $inValues, $uniqueCS ); } - $outList = implode( $outSep, $outValues ); $count = strval( count( $outValues ) ); - return [ self::applyIntroAndOutro( $intro, $outList, $outro, $countToken, $count ), 'noparse' => false ]; + $outList = self::applyIntroAndOutro( $intro, implode( $outSep, $outValues ), $outro, $countToken, $count ); + return ParserPower::evaluateUnescaped( $parser, $frame, $outList ); } /** @@ -1382,7 +1345,7 @@ public static function lstuniqRender( Parser $parser, PPFrame $frame, array $par $inList = ParserPower::expand( $frame, $params[0] ?? '' ); if ( $inList === '' ) { - return [ '', 'noparse' => false ]; + return ''; } $inSep = ParserPower::expand( $frame, $params[1] ?? ',', ParserPower::UNESCAPE ); @@ -1394,7 +1357,7 @@ public static function lstuniqRender( Parser $parser, PPFrame $frame, array $par $values = self::arrayTrimUnescape( self::explodeList( $inSep, $inList ) ); $values = self::reduceToUniqueValues( $values, $csOption ); - return [ implode( $outSep, $values ), 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, implode( $outSep, $values ) ); } /** @@ -1463,10 +1426,8 @@ private static function generateSortKeysByPattern( $tokenCount = count( $tokens ); $index = 1; foreach ( $values as $value ) { - if ( trim( $value ) !== '' ) { + if ( $value !== '' ) { $key = self::applyFieldPatternWithIndex( - $parser, - $frame, $value, $fieldSep, $indexToken, @@ -1475,7 +1436,9 @@ private static function generateSortKeysByPattern( $tokenCount, $pattern ); - $key = $parser->replaceVariables( ParserPower::unescape( $key ), $frame ); + $key = $parser->preprocessToDom( $key, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); + $key = ParserPower::expand( $frame, $key, ParserPower::UNESCAPE ); + $key = $parser->replaceVariables( $key, $frame ); $pairedValues[] = [ $key, $value ]; ++$index; } @@ -1483,9 +1446,11 @@ private static function generateSortKeysByPattern( } else { $index = 1; foreach ( $values as $value ) { - if ( trim( $value ) !== '' ) { - $key = self::applyPatternWithIndex( $parser, $frame, $value, $indexToken, $index, $token, $pattern ); - $key = $parser->replaceVariables( ParserPower::unescape( $key ), $frame ); + if ( $value !== '' ) { + $key = self::applyPatternWithIndex( $value, $indexToken, $index, $token, $pattern ); + $key = $parser->preprocessToDom( $key, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); + $key = ParserPower::expand( $frame, $key, ParserPower::UNESCAPE ); + $key = $parser->replaceVariables( $key, $frame ); $pairedValues[] = [ $key, $value ]; ++$index; } @@ -1618,7 +1583,7 @@ public static function listsortRender( Parser $parser, PPFrame $frame, array $pa $default = ParserPower::expand( $frame, $params["default"] ?? '', ParserPower::UNESCAPE ); if ( $inList === '' ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } $template = ParserPower::expand( $frame, $params["template"] ?? '' ); @@ -1627,7 +1592,7 @@ public static function listsortRender( Parser $parser, PPFrame $frame, array $pa $indexToken = ParserPower::expand( $frame, $params["indextoken"] ?? '', ParserPower::NO_VARS | ParserPower::UNESCAPE ); $token = ParserPower::expand( $frame, $params["token"] ?? '', ParserPower::NO_VARS | ParserPower::UNESCAPE ); $tokenSep = ParserPower::expand( $frame, $params["tokensep"] ?? ',', ParserPower::UNESCAPE ); - $pattern = $params["pattern"] ?? ''; + $pattern = ParserPower::expand( $frame, $params["pattern"] ?? '', ParserPower::NO_VARS ); $outSep = ParserPower::expand( $frame, $params["outsep"] ?? ',\_', ParserPower::UNESCAPE ); $sortOptions = ParserPower::expand( $frame, $params["sortoptions"] ?? '' ); $subsort = ParserPower::expand( $frame, $params["subsort"] ?? '' ); @@ -1673,12 +1638,12 @@ public static function listsortRender( Parser $parser, PPFrame $frame, array $pa } if ( count( $values ) === 0 ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } - $outList = implode( $outSep, $values ); $count = strval( count( $values ) ); - return [ self::applyIntroAndOutro( $intro, $outList, $outro, $countToken, $count ), 'noparse' => false ]; + $outList = self::applyIntroAndOutro( $intro, implode( $outSep, $values ), $outro, $countToken, $count ); + return ParserPower::evaluateUnescaped( $parser, $frame, $outList ); } /** @@ -1693,7 +1658,7 @@ public static function lstsrtRender( Parser $parser, PPFrame $frame, array $para $inList = ParserPower::expand( $frame, $params[0] ?? '' ); if ( $inList === '' ) { - return [ '', 'noparse' => false ]; + return ''; } $inSep = ParserPower::expand( $frame, $params[1] ?? ',', ParserPower::UNESCAPE ); @@ -1705,7 +1670,7 @@ public static function lstsrtRender( Parser $parser, PPFrame $frame, array $para $values = self::arrayTrimUnescape( self::explodeList( $inSep, $inList ) ); $values = self::sortList( $values, $sortOptions ); - return [ implode( $outSep, $values ), 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, implode( $outSep, $values ) ); } /** @@ -1750,7 +1715,7 @@ private static function applyPatternToList( $default ) { if ( $inList === '' ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } $inSep = $parser->getStripState()->unstripNoWiki( $inSep ); @@ -1771,10 +1736,8 @@ private static function applyPatternToList( $tokens = array_map( 'trim', explode( $tokenSep, $token ) ); $tokenCount = count( $tokens ); foreach ( $inValues as $inValue ) { - if ( trim( $inValue ) !== '' ) { + if ( $inValue !== '' ) { $outValue = self::applyFieldPatternWithIndex( - $parser, - $frame, $inValue, $fieldSep, $indexToken, @@ -1783,6 +1746,8 @@ private static function applyPatternToList( $tokenCount, $pattern ); + $outValue = $parser->preprocessToDom( $outValue, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); + $outValue = ParserPower::expand( $frame, $outValue, ParserPower::UNESCAPE ); if ( $outValue !== '' ) { $outValues[] = $outValue; ++$index; @@ -1791,8 +1756,10 @@ private static function applyPatternToList( } } else { foreach ( $inValues as $inValue ) { - if ( trim( $inValue ) !== '' ) { - $outValue = self::applyPatternWithIndex( $parser, $frame, $inValue, $indexToken, $index, $token, $pattern ); + if ( $inValue !== '' ) { + $outValue = self::applyPatternWithIndex( $inValue, $indexToken, $index, $token, $pattern ); + $outValue = $parser->preprocessToDom( $outValue, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); + $outValue = ParserPower::expand( $frame, $outValue, ParserPower::UNESCAPE ); if ( $outValue !== '' ) { $outValues[] = $outValue; ++$index; @@ -1810,14 +1777,14 @@ private static function applyPatternToList( } if ( count( $outValues ) === 0 ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } if ( $countToken !== null && $countToken !== '' ) { $intro = str_replace( $countToken, strval( count( $outValues ) ), $intro ); $outro = str_replace( $countToken, strval( count( $outValues ) ), $outro ); } - return [ $intro . implode( $outSep, $outValues ) . $outro, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $intro . implode( $outSep, $outValues ) . $outro ); } /** @@ -1856,7 +1823,7 @@ private static function applyTemplateToList( $default ) { if ( $inList === '' ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } $inSep = $parser->getStripState()->unstripNoWiki( $inSep ); @@ -1884,12 +1851,12 @@ private static function applyTemplateToList( } if ( count( $outValues ) === 0 ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } - $outList = implode( $outSep, $outValues ); $count = strval( count( $outValues ) ); - return [ self::applyIntroAndOutro( $intro, $outList, $outro, $countToken, $count ), 'noparse' => false ]; + $outList = self::applyIntroAndOutro( $intro, implode( $outSep, $outValues ), $outro, $countToken, $count ); + return ParserPower::evaluateUnescaped( $parser, $frame, $outList ); } /** @@ -1908,7 +1875,7 @@ public static function listmapRender( Parser $parser, PPFrame $frame, array $par $default = ParserPower::expand( $frame, $params["default"] ?? '', ParserPower::UNESCAPE ); if ( $inList === '' ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } $template = ParserPower::expand( $frame, $params["template"] ?? '' ); @@ -1917,7 +1884,7 @@ public static function listmapRender( Parser $parser, PPFrame $frame, array $par $indexToken = ParserPower::expand( $frame, $params["indextoken"] ?? '', ParserPower::NO_VARS | ParserPower::UNESCAPE ); $token = ParserPower::expand( $frame, $params["token"] ?? '', ParserPower::NO_VARS | ParserPower::UNESCAPE ); $tokenSep = ParserPower::expand( $frame, $params["tokensep"] ?? ',', ParserPower::UNESCAPE ); - $pattern = $params["pattern"] ?? ''; + $pattern = ParserPower::expand( $frame, $params["pattern"] ?? '', ParserPower::NO_VARS ); $outSep = ParserPower::expand( $frame, $params["outsep"] ?? ',\_', ParserPower::UNESCAPE ); $sortMode = ParserPower::expand( $frame, $params["sortmode"] ?? '' ); $sortOptions = ParserPower::expand( $frame, $params["sortoptions"] ?? '' ); @@ -1982,12 +1949,12 @@ public static function lstmapRender( Parser $parser, PPFrame $frame, array $para $inList = ParserPower::expand( $frame, $params[0] ?? '' ); if ( $inList === '' ) { - return [ '', 'noparse' => false ]; + return ''; } $inSep = ParserPower::expand( $frame, $params[1] ?? ',', ParserPower::UNESCAPE ); $token = ParserPower::expand( $frame, $params[2] ?? 'x', ParserPower::NO_VARS | ParserPower::UNESCAPE ); - $pattern = $params[3] ?? 'x'; + $pattern = ParserPower::expand( $frame, $params[3] ?? 'x', ParserPower::NO_VARS ); $outSep = ParserPower::expand( $frame, $params[4] ?? ',\_', ParserPower::UNESCAPE ); $sortMode = ParserPower::expand( $frame, $params[5] ?? '' ); $sortOptions = ParserPower::expand( $frame, $params[6] ?? '' ); @@ -2028,7 +1995,7 @@ public static function lstmaptempRender( Parser $parser, PPFrame $frame, array $ $inList = ParserPower::expand( $frame, $params[0] ?? '' ); if ( $inList === '' ) { - return [ '', 'noparse' => false ]; + return ''; } $template = ParserPower::expand( $frame, $params[1] ?? '' ); @@ -2083,8 +2050,6 @@ private static function applyTwoSetFieldPattern( array $tokens2, $pattern ) { - $inValue1 = trim( $inValue1 ); - $inValue2 = trim( $inValue2 ); $tokenCount1 = count( $tokens1 ); $tokenCount2 = count( $tokens2 ); @@ -2108,7 +2073,7 @@ private static function applyTwoSetFieldPattern( } } $outValue = $parser->preprocessToDom( $outValue, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); - return ParserPower::expand( $frame, $outValue, ParserPower::UNESCAPE ); + return ParserPower::expand( $frame, $outValue ); } /** @@ -2173,12 +2138,12 @@ private static function iterativeListMerge( while ( count( $otherValues ) > 0 ) { $value2 = $matchParams[$valueIndex2] = $mergeParams[$valueIndex2] = array_shift( $otherValues ); $doMerge = call_user_func_array( $applyFunction, $matchParams ); - $doMerge = $parser->replaceVariables( ParserPower::unescape( trim( $doMerge ) ), $frame ); + $doMerge = $parser->replaceVariables( ParserPower::unescape( $doMerge ), $frame ); $doMerge = self::decodeBool( $doMerge ); if ( $doMerge ) { $value1 = call_user_func_array( $applyFunction, $mergeParams ); - $value1 = $parser->replaceVariables( ParserPower::unescape( trim( $value1 ) ), $frame ); + $value1 = $parser->replaceVariables( ParserPower::unescape( $value1 ), $frame ); $matchParams[$valueIndex1] = $mergeParams[$valueIndex1] = $value1; } else { $inValues[] = $value2; @@ -2236,7 +2201,7 @@ private static function mergeListByPattern( $default ) { if ( $inList === '' ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } $inSep = $parser->getStripState()->unstripNoWiki( $inSep ); @@ -2273,12 +2238,12 @@ private static function mergeListByPattern( } if ( count( $outValues ) === 0 ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } - $outList = implode( $outSep, $outValues ); $count = strval( count( $outValues ) ); - return [ self::applyIntroAndOutro( $intro, $outList, $outro, $countToken, $count ), 'noparse' => false ]; + $outList = self::applyIntroAndOutro( $intro, implode( $outSep, $outValues ), $outro, $countToken, $count ); + return ParserPower::evaluateUnescaped( $parser, $frame, $outList ); } /** @@ -2317,7 +2282,7 @@ private static function mergeListByTemplate( $default ) { if ( $inList === '' ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } $inSep = $parser->getStripState()->unstripNoWiki( $inSep ); @@ -2342,12 +2307,12 @@ private static function mergeListByTemplate( ); if ( count( $outValues ) === 0 ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } - $outList = implode( $outSep, $outValues ); $count = strval( count( $outValues ) ); - return [ self::applyIntroAndOutro( $intro, $outList, $outro, $countToken, $count ), 'noparse' => false ]; + $outList = self::applyIntroAndOutro( $intro, implode( $outSep, $outValues ), $outro, $countToken, $count ); + return ParserPower::evaluateUnescaped( $parser, $frame, $outList ); } /** @@ -2366,7 +2331,7 @@ public static function listmergeRender( Parser $parser, PPFrame $frame, array $p $default = ParserPower::expand( $frame, $params["default"] ?? '', ParserPower::UNESCAPE ); if ( $inList === '' ) { - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } $matchTemplate = ParserPower::expand( $frame, $params["matchtemplate"] ?? '' ); @@ -2376,8 +2341,8 @@ public static function listmergeRender( Parser $parser, PPFrame $frame, array $p $token1 = ParserPower::expand( $frame, $params["token1"] ?? '', ParserPower::NO_VARS | ParserPower::UNESCAPE ); $token2 = ParserPower::expand( $frame, $params["token2"] ?? '', ParserPower::NO_VARS | ParserPower::UNESCAPE ); $tokenSep = ParserPower::expand( $frame, $params["tokensep"] ?? ',', ParserPower::UNESCAPE ); - $matchPattern = $params["matchpattern"] ?? ''; - $mergePattern = $params["mergepattern"] ?? ''; + $matchPattern = ParserPower::expand( $frame, $params["matchpattern"] ?? '', ParserPower::NO_VARS ); + $mergePattern = ParserPower::expand( $frame, $params["mergepattern"] ?? '', ParserPower::NO_VARS ); $outSep = ParserPower::expand( $frame, $params["outsep"] ?? ',\_', ParserPower::UNESCAPE ); $sortMode = ParserPower::expand( $frame, $params["sortmode"] ?? '' ); $sortOptions = ParserPower::expand( $frame, $params["sortoptions"] ?? '' ); diff --git a/includes/ParserPower.php b/includes/ParserPower.php index 0f114cd..609f03a 100644 --- a/includes/ParserPower.php +++ b/includes/ParserPower.php @@ -13,6 +13,7 @@ use Parser; use PPFrame; +use Preprocessor; class ParserPower { /** @@ -125,6 +126,30 @@ public static function expand( PPFrame $frame, $input, $flags = 0 ) { return $expanded; } + /** + * Replace variables within a text, that has been unescaped. + * In this context, template arguments can not be used. + * + * @param Parser $parser + * @param PPFrame $frame + * @param string $text + * @return string + */ + public static function evaluateUnescaped( Parser $parser, PPFrame $frame, $text ) { + if ( $text === '' ) { + return ''; + } + + if ( $frame->isTemplate() ) { + $dom = $parser->preprocessToDom( $text, Preprocessor::DOM_FOR_INCLUSION ); + $frame = $frame->newChild(); + } else { + $dom = $parser->preprocessToDom( $text ); + } + + return $frame->expand( $dom ); + } + /** * Replaces all escape sequences with the appropriate characters. It should be calling *after* trimming strings to * protect any leading or trailing whitespace that was escaped. @@ -222,23 +247,19 @@ public static function escape( $input ) { /** * Replaces the indicated token in the pattern with the input value. * - * @param Parser $parser The parser object. - * @param PPFrame $frame The parser frame object. * @param string $inValue The value to change into one or more template parameters. * @param string $token The token to replace. * @param string $pattern Pattern containing token to be replaced with the input value. * @return string The result of the token replacement within the pattern. */ - public static function applyPattern( Parser $parser, PPFrame $frame, $inValue, $token, $pattern ) { - return self::applyPatternWithIndex( $parser, $frame, $inValue, '', 0, $token, $pattern ); + public static function applyPattern( $inValue, $token, $pattern ) { + return self::applyPatternWithIndex( $inValue, '', 0, $token, $pattern ); } /** * Replaces the indicated index token in the pattern with the given index and the token in the * pattern with the input value. * - * @param Parser $parser The parser object. - * @param PPFrame $frame The parser frame object. * @param string $inValue The value to change into one or more template parameters. * @param string $indexToken The token to replace with the index, or null/empty value to skip index replacement. * @param int $index The numeric index of this value. @@ -246,36 +267,25 @@ public static function applyPattern( Parser $parser, PPFrame $frame, $inValue, $ * @param string $pattern Pattern containing token to be replaced with the input value. * @return string The result of the token replacement within the pattern. */ - public static function applyPatternWithIndex( - Parser $parser, - PPFrame $frame, - $inValue, - $indexToken, - $index, - $token, - $pattern - ) { - $inValue = trim( $inValue ); - if ( trim( $pattern ) !== '' ) { - $outValue = self::expand( $frame, $pattern, self::NO_VARS ); - if ( $indexToken !== null && $indexToken !== '' ) { - $outValue = str_replace( $indexToken, strval( $index ), $outValue ); - } - if ( $token !== null && $token !== '' ) { - $outValue = str_replace( $token, $inValue, $outValue ); - } - } else { - $outValue = $inValue; + public static function applyPatternWithIndex( $inValue, $indexToken, $index, $token, $pattern ) { + if ( $pattern === '' ) { + return $inValue; + } + + $outValue = $pattern; + if ( $indexToken !== null && $indexToken !== '' ) { + $outValue = str_replace( $indexToken, strval( $index ), $outValue ); } - $outValue = $parser->preprocessToDom( $outValue, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); - return self::expand( $frame, $outValue, self::UNESCAPE ); + if ( $token !== null && $token !== '' ) { + $outValue = str_replace( $token, $inValue, $outValue ); + } + + return $outValue; } /** * Breaks the input value into fields and then replaces the indicated tokens in the pattern with those field values. * - * @param Parser $parser The parser object. - * @param PPFrame $frame The parser frame object. * @param string $inValue The value to change into one or more template parameters * @param string $fieldSep The delimiter separating the fields in the value. * @param array $tokens The list of tokens to replace. @@ -283,34 +293,14 @@ public static function applyPatternWithIndex( * @param string $pattern Pattern containing tokens to be replaced by field values. * @return string The result of the token replacement within the pattern. */ - public static function applyFieldPattern( - Parser $parser, - PPFrame $frame, - $inValue, - $fieldSep, - array $tokens, - $tokenCount, - $pattern - ) { - return self::applyFieldPatternWithIndex( - $parser, - $frame, - $inValue, - $fieldSep, - '', - 0, - $tokens, - $tokenCount, - $pattern - ); + public static function applyFieldPattern( $inValue, $fieldSep, array $tokens, $tokenCount, $pattern ) { + return self::applyFieldPatternWithIndex( $inValue, $fieldSep, '', 0, $tokens, $tokenCount, $pattern ); } /** * Replaces the index token with the given index, and then breaks the input value into fields and then replaces the * indicated tokens in the pattern with those field values. * - * @param Parser $parser The parser object. - * @param PPFrame $frame The parser frame object. * @param string $inValue The value to change into one or more template parameters * @param string $fieldSep The delimiter separating the fields in the value. * @param int $indexToken The token to replace with the index, or null/empty value to skip index replacement. @@ -321,8 +311,6 @@ public static function applyFieldPattern( * @return string The result of the token replacement within the pattern. */ public static function applyFieldPatternWithIndex( - Parser $parser, - PPFrame $frame, $inValue, $fieldSep, $indexToken, @@ -331,21 +319,20 @@ public static function applyFieldPatternWithIndex( $tokenCount, $pattern ) { - $inValue = trim( $inValue ); - if ( trim( $pattern ) !== '' ) { - $outValue = self::expand( $frame, $pattern, self::NO_VARS ); - if ( $indexToken !== null && $indexToken !== '' ) { - $outValue = str_replace( $indexToken, strval( $index ), $outValue ); - } - $fields = explode( $fieldSep, $inValue, $tokenCount ); - $fieldCount = count( $fields ); - for ( $i = 0; $i < $tokenCount; $i++ ) { - $outValue = str_replace( $tokens[$i], ( $i < $fieldCount ) ? $fields[$i] : '', $outValue ); - } - } else { - $outValue = $inValue; + if ( $pattern === '' ) { + return $inValue; + } + + $outValue = $pattern; + if ( $indexToken !== null && $indexToken !== '' ) { + $outValue = str_replace( $indexToken, strval( $index ), $outValue ); } - $outValue = $parser->preprocessToDom( $outValue, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); - return self::expand( $frame, $outValue, self::UNESCAPE ); + $fields = explode( $fieldSep, $inValue, $tokenCount ); + $fieldCount = count( $fields ); + for ( $i = 0; $i < $tokenCount; $i++ ) { + $outValue = str_replace( $tokens[$i], ( $i < $fieldCount ) ? $fields[$i] : '', $outValue ); + } + + return $outValue; } } diff --git a/includes/SimpleFunctions.php b/includes/SimpleFunctions.php index 00fdf3b..b451e14 100644 --- a/includes/SimpleFunctions.php +++ b/includes/SimpleFunctions.php @@ -62,9 +62,7 @@ public static function setup( &$parser ) { * @return array The function output along with relevant parser options. */ public static function trimRender( Parser $parser, PPFrame $frame, array $params ) { - $text = ParserPower::expand( $frame, $params[0] ?? '' ); - - return [ $text, 'noparse' => false ]; + return ParserPower::expand( $frame, $params[0] ?? '' ); } /** @@ -79,7 +77,7 @@ public static function trimRender( Parser $parser, PPFrame $frame, array $params public static function uescRender( Parser $parser, PPFrame $frame, array $params ) { $text = ParserPower::expand( $frame, $params[0] ?? '', ParserPower::UNESCAPE ); - return [ $text, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $text ); } /** @@ -95,7 +93,7 @@ public static function uescRender( Parser $parser, PPFrame $frame, array $params public static function uescnowikiRender( Parser $parser, PPFrame $frame, array $params ) { $text = ParserPower::expand( $frame, $params[0] ?? '', ParserPower::UNESCAPE ); - return [ '' . $text . '', 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, '' . $text . '' ); } /** @@ -108,9 +106,9 @@ public static function uescnowikiRender( Parser $parser, PPFrame $frame, array $ * @return array The function output along with relevant parser options. */ public static function trimuescRender( Parser $parser, PPFrame $frame, array $params ) { - $text = ParserPower::expand( $frame, $params[0] ?? '', ParserPower::UNESCAPE ); + $text = trim( ParserPower::expand( $frame, $params[0] ?? '', ParserPower::UNESCAPE ) ); - return [ trim( $text ), 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $text ); } /** @@ -127,7 +125,7 @@ public static function trimuescRender( Parser $parser, PPFrame $frame, array $pa public static function linkpageRender( $text, array $attribs, Parser $parser, PPFrame $frame ) { $text = $parser->replaceVariables( $text, $frame ); - if ( $text ) { + if ( $text !== '' ) { $text = preg_replace_callback( '/\[\[(.*?)\]\]/', [ __CLASS__, 'linkpageReplace' ], $text ); } @@ -192,11 +190,7 @@ public static function linktextReplace( $matches ) { * @return array The function output along with relevant parser options. */ public static function escRender( $text, array $attribs, Parser $parser, PPFrame $frame ) { - $text = ParserPower::escape( $text ); - - $text = $parser->replaceVariables( $text, $frame ); - - return [ $text, 'markerType' => 'none' ]; + return [ ParserPower::escape( $text ), 'markerType' => 'none' ]; } /** @@ -216,7 +210,7 @@ public static function ueifRender( Parser $parser, PPFrame $frame, array $params $value = ParserPower::expand( $frame, $params[2] ?? '', ParserPower::UNESCAPE ); } - return [ $value, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $value ); } /** @@ -232,11 +226,11 @@ public static function orRender( Parser $parser, PPFrame $frame, array $params ) $inValue = ParserPower::expand( $frame, $param ); if ( $inValue !== '' ) { - return [ $inValue, 'noparse' => false ]; + return $inValue; } } - return [ '', 'noparse' => false ]; + return ''; } /** @@ -252,11 +246,12 @@ public static function ueorRender( Parser $parser, PPFrame $frame, array $params $inValue = ParserPower::expand( $frame, $param ); if ( $inValue !== '' ) { - return [ ParserPower::unescape( $inValue ), 'noparse' => false ]; + $inValue = ParserPower::unescape( $inValue ); + return ParserPower::evaluateUnescaped( $parser, $frame, $inValue ); } } - return [ '', 'noparse' => false ]; + return ''; } /** @@ -277,7 +272,7 @@ public static function ueifeqRender( Parser $parser, PPFrame $frame, array $para $value = ParserPower::expand( $frame, $params[3] ?? '', ParserPower::UNESCAPE ); } - return [ $value, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $value ); } /** @@ -294,7 +289,11 @@ public static function tokenRender( Parser $parser, PPFrame $frame, array $param $token = ParserPower::expand( $frame, $params[1] ?? 'x', ParserPower::UNESCAPE ); $pattern = $params[2] ?? 'x'; - return [ ParserPower::applyPattern( $parser, $frame, $inValue, $token, $pattern ), 'noparse' => false ]; + $outValue = ParserPower::applyPattern( $inValue, $token, $pattern ); + $outValue = $parser->preprocessToDom( $outValue, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); + $outValue = ParserPower::expand( $frame, $outValue, ParserPower::UNESCAPE ); + + return ParserPower::evaluateUnescaped( $parser, $frame, $outValue ); } /** @@ -310,14 +309,17 @@ public static function tokenifRender( Parser $parser, PPFrame $frame, array $par if ( $inValue === '' ) { $default = ParserPower::expand( $frame, $params[3] ?? '', ParserPower::UNESCAPE ); - - return [ $default, 'noparse' => false ]; + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } $token = ParserPower::expand( $frame, $params[1] ?? 'x', ParserPower::UNESCAPE ); $pattern = $params[2] ?? 'x'; - return [ ParserPower::applyPattern( $parser, $frame, $inValue, $token, $pattern ), 'noparse' => false ]; + $outValue = ParserPower::applyPattern( $inValue, $token, $pattern ); + $outValue = $parser->preprocessToDom( $outValue, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); + $outValue = ParserPower::expand( $frame, $outValue, ParserPower::UNESCAPE ); + + return ParserPower::evaluateUnescaped( $parser, $frame, $outValue ); } /** @@ -332,7 +334,7 @@ public static function ueswitchRender( Parser $parser, PPFrame $frame, array $pa $switchKey = isset( $params[0] ) ? ParserPower::expand( $frame, array_shift( $params ), ParserPower::UNESCAPE ) : ''; if ( count( $params ) === 0 ) { - return [ '', 'noparse' => false ]; + return ''; } $lastBits = $params[count( $params ) - 1]->splitArg(); @@ -365,7 +367,8 @@ public static function ueswitchRender( Parser $parser, PPFrame $frame, array $pa if ( $value !== null ) { if ( $keyFound ) { - return [ ParserPower::unescape( $value ), 'noparse' => false ]; + $value = ParserPower::unescape( $value ); + return ParserPower::evaluateUnescaped( $parser, $frame, $value ); } elseif ( $mwDefaultFound ) { $default = $value; $mwDefaultFound = false; @@ -376,7 +379,8 @@ public static function ueswitchRender( Parser $parser, PPFrame $frame, array $pa if ( $lastBits['index'] !== '' ) { $default = $lastValue; } - return [ ParserPower::expand( $frame, $default, ParserPower::UNESCAPE ), 'noparse' => false ]; + $default = ParserPower::expand( $frame, $default, ParserPower::UNESCAPE ); + return ParserPower::evaluateUnescaped( $parser, $frame, $default ); } /** @@ -504,7 +508,7 @@ public static function arraymaptemplateRender( $parser, $frame, $args ) { public static function argmapRender( Parser $parser, PPFrame $frame, array $args ) { if ( !isset( $args[0] ) ) { - return [ '', 'noparse' => false ]; + return ''; } // sort arguments, this is to disregard the position of named arguments