diff --git a/includes/Hooks.php b/includes/Hooks.php index 332c6df..2fe4ca6 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -53,16 +53,22 @@ class Hooks { } /** - * Passes config variables to skins.vector.search ResourceLoader module. + * Generates config variables for skins.vector.search Resource Loader module (defined in + * skin.json). + * * @param ResourceLoaderContext $context * @param Config $config - * @return array + * @return array */ public static function getVectorWvuiSearchResourceLoaderConfig( ResourceLoaderContext $context, Config $config - ) { - return $config->get( 'VectorWvuiSearchOptions' ); + ): array { + $result = $config->get( 'VectorWvuiSearchOptions' ); + $result['highlightQuery'] = + VectorServices::getLanguageService()->canWordsBeSplitSafely( $context->getLanguage() ); + + return $result; } /** diff --git a/includes/Services/LanguageService.php b/includes/Services/LanguageService.php new file mode 100644 index 0000000..c750977 --- /dev/null +++ b/includes/Services/LanguageService.php @@ -0,0 +1,45 @@ +splittableLanguages = [ + 'ar', 'ary', 'arz', 'ckb', 'fa', 'glk', 'ks', 'mzn', 'pnb', 'ps', 'sd', 'skr', 'ug', 'ur', + 'as', 'bn', 'bpy', + 'awa', 'bh', 'dty', 'gom', 'hi', 'ks', 'mai', 'mr', 'ne', 'new', 'pi', 'sa', + 'gu', + 'pa', + 'kn', 'tcy', + 'km', + 'ml', + 'or', + 'si', + 'ta', + 'te', + ]; + } + + /** + * Gets whether or not we can split words arbitrarily, for example when highlighting the user's query in the search + * autocomplete widget. + * + * @param string $code + * @return bool + */ + public function canWordsBeSplitSafely( string $code ): bool { + return !in_array( $code, $this->splittableLanguages ); + } +} diff --git a/includes/VectorServices.php b/includes/VectorServices.php index e093d32..9add2a4 100644 --- a/includes/VectorServices.php +++ b/includes/VectorServices.php @@ -4,6 +4,7 @@ namespace Vector; use MediaWiki\MediaWikiServices; use Vector\FeatureManagement\FeatureManager; +use Vector\Services\LanguageService; /** * A service locator for services specific to Vector. @@ -24,4 +25,13 @@ final class VectorServices { public static function getFeatureManager(): FeatureManager { return MediaWikiServices::getInstance()->getService( Constants::SERVICE_FEATURE_MANAGER ); } + + /** + * Gets the language service. + * + * @return LanguageService + */ + public static function getLanguageService(): LanguageService { + return new LanguageService(); + } } diff --git a/skin.json b/skin.json index 88e7f6f..80ba08d 100644 --- a/skin.json +++ b/skin.json @@ -277,8 +277,7 @@ "VectorWvuiSearchOptions": { "value": { "showThumbnail": true, - "showDescription": true, - "highlightQuery": true + "showDescription": true } }, "VectorDefaultSidebarVisibleForAuthorisedUser": {