Merge "search: Disable query highlight for some languages"

This commit is contained in:
jenkins-bot 2021-06-30 21:01:01 +00:00 committed by Gerrit Code Review
commit 91aeef476d
4 changed files with 66 additions and 6 deletions

View file

@ -39,16 +39,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<string,mixed>
*/
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;
}
/**

View file

@ -0,0 +1,45 @@
<?php
namespace Vector\Services;
class LanguageService {
/**
* The list of language codes for those languages that the search autocomplete widget cannot
* split a word on a Unicode code point followed by one or many combining marks (also code
* points).
*
* This list was compiled by [@TJones](https://phabricator.wikimedia.org/p/TJones/) as part
* of [T281797](https://phabricator.wikimedia.org/T281797).
*
* @var string[]
*/
private $splittableLanguages;
public function __construct() {
$this->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 );
}
}

View file

@ -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();
}
}

View file

@ -277,8 +277,7 @@
"VectorWvuiSearchOptions": {
"value": {
"showThumbnail": true,
"showDescription": true,
"highlightQuery": true
"showDescription": true
}
},
"VectorDefaultSidebarVisibleForAuthorisedUser": {