mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-28 09:30:17 +00:00
Merge "search: Disable query highlight for some languages"
This commit is contained in:
commit
91aeef476d
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
45
includes/Services/LanguageService.php
Normal file
45
includes/Services/LanguageService.php
Normal 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 );
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue