search: Disable query highlight for some languages

Following on from I551414b1, disable query highlighting for the list of
languages provided by @TJones in T281797.

The user's interface language can be different from the wiki's content
language and so the former is not available at configuration time. Thus,
we fetch the user's interface language at request time. Fortunately,
@TJones' list of languages is small so there should be little
perceivable performance impact from the perpective of the user.

Additional changes:

- Remove the config.VectorWvuiSearchOptions.value.highlightQuery
  property from skin.json

Bug: T281797
Change-Id: Ib39736a93fa64e82253f88551d125413e672558b
This commit is contained in:
Sam Smith 2021-06-30 13:51:04 +01:00
parent 5029ce11e4
commit 445ba883a2
4 changed files with 66 additions and 6 deletions

View File

@ -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<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": {