Liangent has uploaded a new change for review. https://gerrit.wikimedia.org/r/90636
Change subject: Fix {{#property: }} calls for missing property on wikis with LanguageConverter ...................................................................... Fix {{#property: }} calls for missing property on wikis with LanguageConverter Change-Id: Iada5fbd8736753622af734e3494d0b3fa0109f68 --- M client/includes/parserhooks/PropertyParserFunction.php M client/tests/phpunit/includes/parserhooks/PropertyParserFunctionTest.php 2 files changed, 14 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/36/90636/1 diff --git a/client/includes/parserhooks/PropertyParserFunction.php b/client/includes/parserhooks/PropertyParserFunction.php index bc9a53d..a143ad9 100644 --- a/client/includes/parserhooks/PropertyParserFunction.php +++ b/client/includes/parserhooks/PropertyParserFunction.php @@ -80,11 +80,13 @@ */ public function processRenderedArray( $textArray ) { // We got arrays, so they must have already checked that variants are being used. - $text = '-{'; + $text = ''; foreach ( $textArray as $variantCode => $variantText ) { $text .= "$variantCode:$variantText;"; } - $text .= '}-'; + if ( $text !== '' ) { + $text = '-{' . $text . '}-'; + } return $text; } @@ -161,7 +163,13 @@ foreach ( $variants as $variantCode ) { $variantLanguage = \Language::factory( $variantCode ); - $textArray[$variantCode] = $this->renderInLanguage( $propertyLabel, $variantLanguage ); + $variantText = $this->renderInLanguage( $propertyLabel, $variantLanguage ); + // LanguageConverter doesn't handle empty strings correctly, and it's more difficult + // to fix the issue there, as it's using empty string as a special value. + // Also keeping the ability to check a missing property with {{#if: }} is another reason. + if ( $variantText !== '' ) { + $textArray[$variantCode] = $variantText; + } } return $textArray; diff --git a/client/tests/phpunit/includes/parserhooks/PropertyParserFunctionTest.php b/client/tests/phpunit/includes/parserhooks/PropertyParserFunctionTest.php index 6b49bbd..655e203 100644 --- a/client/tests/phpunit/includes/parserhooks/PropertyParserFunctionTest.php +++ b/client/tests/phpunit/includes/parserhooks/PropertyParserFunctionTest.php @@ -95,6 +95,9 @@ 'zh-cn' => 'fo<ob>ar', 'zh-tw' => 'FO<OB>AR', ), '-{zh-cn:fo<ob>ar;zh-tw:FO<OB>AR;}-' ), + // Don't create "-{}-" for empty input, + // to keep the ability to check a missing property with {{#if: }}. + array( \Parser::OT_HTML, array(), '' ), ); } -- To view, visit https://gerrit.wikimedia.org/r/90636 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iada5fbd8736753622af734e3494d0b3fa0109f68 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Liangent <liang...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits