jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/366609 )
Change subject: Move configvars whitelist into Api/ConfigDump ...................................................................... Move configvars whitelist into Api/ConfigDump and add test to make sure that everything needed during fixture test are exported by the API. Bug: T156497 Change-Id: I875fc9aebbc9c6c8de4c9ff0551f212fbd1cb158 --- M CirrusSearch.php M docs/settings.txt M includes/Api/ConfigDump.php M includes/SearchConfig.php M tests/unit/SearcherTest.php 5 files changed, 163 insertions(+), 142 deletions(-) Approvals: Smalyshev: Looks good to me, but someone else must approve Tjones: Looks good to me, but someone else must approve EBernhardson: Looks good to me, approved jenkins-bot: Verified diff --git a/CirrusSearch.php b/CirrusSearch.php index 19b03a2..e65a723 100644 --- a/CirrusSearch.php +++ b/CirrusSearch.php @@ -794,78 +794,6 @@ ]; /** - * Dumpable config parameters. These are known not to include any private - * information and thus safe to include in the config dump. To disable the - * config dump entirely add this to your configuration after including: - * CirrusSearch.php: - * $wgApiModules['cirrus-config-dump'] = 'ApiDisabled'; - */ -$wgCirrusSearchConfigDumpWhiteList = [ - 'servers', - 'connectionAttempts', - 'shardCount', - 'replicas', - 'slowSearch', - 'useExperimentalHighlighter', - 'optimizeIndexForExperimentalHighlighter', - 'namespaceMappings', - 'extraIndexes', - 'updateShardTimeout', - 'clientSideUpdateTimeout', - 'searchShardTimeout', - 'clientSizeSearchTimeout', - 'maintenanceTimeout', - 'prefixSearchStartsWithAnyWord', - 'phraseSlop', - 'phraseRescoreBoost', - 'phraseRescoreWindowSize', - 'functionRescoreWindowSize', - 'moreAccurateScoringMode', - 'phraseSuggestUseText', - 'phraseSuggestUseOpeningText', - 'indexedRedirects', - 'linkedArticlesToUpdate', - 'unlikedArticlesToUpdate', - 'weights', - 'allFields', - 'boostOpening', - 'nearMatchWeight', - 'stemmedWeight', - 'namespaceWeights', - 'defaultNamespaceWeight', - 'talkNamespaceWeight', - 'languageWeight', - 'preferRecentDefaultDecayPortion', - 'preferRecentUnspecifiedDecayPortion', - 'preferRecentDefaultHalfLife', - 'moreLikeThisConfig', - 'showNowUsing', - 'interwikiSources', - 'interwikiCacheTime', - 'refreshInterval', - 'bannedPlugins', - 'updateConflictRetryCount', - 'fragmentSize', - 'mainPageCacheWarmer', - 'cacheWarmers', - 'boostLinks', - 'indexAllocation', - 'fullTextQueryBuilderProfile', - 'rescoreProfile', - 'prefixSearchRescoreProfile', - 'similarityProfile', - 'crossProjectProfiles', - 'crossProjectOrder', - 'crossProjectSearchBlackList', - 'extraIndexBoostTemplates', - 'enableCrossProjectSearch', - 'enableAltLanguage', - 'enableArchive', - 'useIcuFolding', - 'useIcuTokenizer', -]; - -/** * Pool Counter key. If you use the PoolCounter extension, this can help segment your wiki's * traffic into separate queues. This has no effect in vanilla MediaWiki and most people can * just leave this as it is. diff --git a/docs/settings.txt b/docs/settings.txt index 215e48e..fbab779 100644 --- a/docs/settings.txt +++ b/docs/settings.txt @@ -937,70 +937,6 @@ or _host it requires you to configure the host keys/values on your server(s) See also: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/index-modules-allocation.html -; $wgCirrusSearchConfigDumpWhiteList - -Default: - $wgCirrusSearchConfigDumpWhiteList = [ - 'servers', - 'connectionAttempts', - 'shardCount', - 'replicas', - 'slowSearch', - 'useExperimentalHighlighter', - 'optimizeIndexForExperimentalHighlighter', - 'namespaceMappings', - 'extraIndexes', - 'updateShardTimeout', - 'clientSideUpdateTimeout', - 'searchShardTimeout', - 'clientSizeSearchTimeout', - 'maintenanceTimeout', - 'prefixSearchStartsWithAnyWord', - 'phraseSlop', - 'phraseRescoreBoost', - 'phraseRescoreWindowSize', - 'functionRescoreWindowSize', - 'moreAccurateScoringMode', - 'phraseSuggestMaxErrors', - 'phraseSuggestConfidence', - 'phraseSuggestUseText', - 'phraseSuggestUseOpeningText', - 'indexedRedirects', - 'linkedArticlesToUpdate', - 'unlikedArticlesToUpdate', - 'weights', - 'allFields', - 'boostOpening', - 'nearMatchWeight', - 'stemmedWeight', - 'namespaceWeights', - 'defaultNamespaceWeight', - 'talkNamespaceWeight', - 'languageWeight', - 'preferRecentDefaultDecayPortion', - 'preferRecentUnspecifiedDecayPortion', - 'preferRecentDefaultHalfLife', - 'moreLikeThisConfig', - 'showNowUsing', - 'interwikiSources', - 'interwikiCacheTime', - 'refreshInterval', - 'bannedPlugins', - 'updateConflictRetryCount', - 'fragmentSize', - 'mainPageCacheWarmer', - 'cacheWarmers', - 'boostLinks', - 'indexAllocation', - ]; - -Dumpable config parameters. These are known not to include any private -information and thus safe to include in the config dump. To disable the -config dump entirely add this to your configuration after including: -CirrusSearch.php: - $wgApiModules['cirrus-config-dump'] = 'ApiDisabled'; - - ; $wgCirrusSearchPoolCounterKey Default: diff --git a/includes/Api/ConfigDump.php b/includes/Api/ConfigDump.php index 4a31a08..61b8de6 100644 --- a/includes/Api/ConfigDump.php +++ b/includes/Api/ConfigDump.php @@ -21,18 +21,117 @@ * http://www.gnu.org/copyleft/gpl.html */ class ConfigDump extends ApiBase { - public function execute() { - global $wgCirrusSearchConfigDumpWhiteList; + public static $WHITE_LIST = [ + 'CirrusSearchServers', + 'CirrusSearchConnectionAttempts', + 'CirrusSearchSlowSearch', + 'CirrusSearchUseExperimentalHighlighter', + 'CirrusSearchOptimizeIndexForExperimentalHighlighter', + 'CirrusSearchNamespaceMappings', + 'CirrusSearchExtraIndexes', + 'CirrusSearchUpdateShardTimeout', + 'CirrusSearchClientSideUpdateTimeout', + 'CirrusSearchSearchShardTimeout', + 'CirrusSearchClientSizeSearchTimeout', + 'CirrusSearchMaintenanceTimeout', + 'CirrusSearchPrefixSearchStartsWithAnyWord', + 'CirrusSearchPhraseSlop', + 'CirrusSearchPhraseRescoreBoost', + 'CirrusSearchPhraseRescoreWindowSize', + 'CirrusSearchFunctionRescoreWindowSize', + 'CirrusSearchMoreAccurateScoringMode', + 'CirrusSearchPhraseSuggestUseText', + 'CirrusSearchPhraseSuggestUseOpeningText', + 'CirrusSearchIndexedRedirects', + 'CirrusSearchLinkedArticlesToUpdate', + 'CirrusSearchUnlikedArticlesToUpdate', + 'CirrusSearchWeights', + 'CirrusSearchAllFields', + 'CirrusSearchBoostOpening', + 'CirrusSearchNearMatchWeight', + 'CirrusSearchStemmedWeight', + 'CirrusSearchNamespaceWeights', + 'CirrusSearchDefaultNamespaceWeight', + 'CirrusSearchTalkNamespaceWeight', + 'CirrusSearchLanguageWeight', + 'CirrusSearchPreferRecentDefaultDecayPortion', + 'CirrusSearchPreferRecentUnspecifiedDecayPortion', + 'CirrusSearchPreferRecentDefaultHalfLife', + 'CirrusSearchMoreLikeThisConfig', + 'CirrusSearchInterwikiSources', + 'CirrusSearchInterwikiCacheTime', + 'CirrusSearchRefreshInterval', + 'CirrusSearchFragmentSize', + 'CirrusSearchMainPageCacheWarmer', + 'CirrusSearchCacheWarmers', + 'CirrusSearchBoostLinks', + 'CirrusSearchIndexAllocation', + 'CirrusSearchFullTextQueryBuilderProfile', + 'CirrusSearchRescoreProfile', + 'CirrusSearchPrefixSearchRescoreProfile', + 'CirrusSearchSimilarityProfile', + 'CirrusSearchCrossProjectProfiles', + 'CirrusSearchCrossProjectOrder', + 'CirrusSearchCrossProjectSearchBlackList', + 'CirrusSearchExtraIndexBoostTemplates', + 'CirrusSearchEnableCrossProjectSearch', + 'CirrusSearchEnableAltLanguage', + 'CirrusSearchEnableArchive', + 'CirrusSearchUseIcuFolding', + 'CirrusSearchUseIcuTokenizer', + // All the config below was added when moving this data + // from CirrusSearch config to a static array in this class + 'CirrusSearchDevelOptions', + 'CirrusSearchPrefixIds', + 'CirrusSearchMoreLikeThisFields', + 'CirrusSearchMoreLikeThisTTL', + 'CirrusSearchFiletypeAliases', + 'CirrusSearchDefaultCluster', + 'CirrusSearchClientSideConnectTimeout', + 'CirrusSearchClusters', + 'CirrusSearchExtraBackendLatency', + 'CirrusSearchAllowLeadingWildcard', + 'CirrusSearchClientSideSearchTimeout', + 'CirrusSearchStripQuestionMarks', + 'CirrusSearchFullTextQueryBuilderProfiles', + 'CirrusSearchEnableRegex', + 'CirrusSearchWikimediaExtraPlugin', + 'CirrusSearchRegexMaxDeterminizedStates', + 'CirrusSearchMaxIncategoryOptions', + 'CirrusSearchEnablePhraseSuggest', + 'CirrusSearchClusterOverrides', + 'CirrusSearchRescoreProfiles', + 'CirrusSearchRescoreFunctionScoreChains', + 'CirrusSearchNumCrossProjectSearchResults', + 'CirrusSearchLanguageToWikiMap', + 'CirrusSearchWikiToNameMap', + 'CirrusSearchIncLinksAloneW', + 'CirrusSearchIncLinksAloneK', + 'CirrusSearchIncLinksAloneA', + 'CirrusSearchNewCrossProjectPage', + 'CirrusSearchQueryStringMaxDeterminizedStates', + 'CirrusSearchElasticQuirks', + 'CirrusSearchPhraseSuggestSettings', + 'CirrusSearchPhraseSuggestMaxErrors', + 'CirrusSearchPhraseSuggestReverseField', + 'CirrusSearchBoostTemplates', + 'CirrusSearchIgnoreOnWikiBoostTemplates', + 'CirrusSearchAllFieldsForRescore', + 'CirrusSearchIndexBaseName', + 'LanguageCode', + 'ContentNamespaces', + ]; - $prefix = 'wgCirrusSearch'; + public function execute() { + $prefix = 'wg'; foreach ( $GLOBALS as $key => $value ) { // Only output cirrus configuration if ( strpos( $key, $prefix ) === false ) { continue; } - $key = lcfirst( substr( $key, strlen( $prefix ) ) ); // Only output the whitelisted cirrus configuration - if ( in_array( $key, $wgCirrusSearchConfigDumpWhiteList ) ) { + $key = substr( $key, strlen( $prefix ) ); + if ( in_array( $key, self::$WHITE_LIST ) ) { $this->getResult()->addValue( null, $key, $value ); } } diff --git a/includes/SearchConfig.php b/includes/SearchConfig.php index f8e9de8..4d49ddd 100644 --- a/includes/SearchConfig.php +++ b/includes/SearchConfig.php @@ -32,7 +32,7 @@ * Wiki variables prefix. * @var string */ - private $prefix = ''; + protected $prefix = ''; /** * Wiki id or null for current wiki diff --git a/tests/unit/SearcherTest.php b/tests/unit/SearcherTest.php index b668212..22ab736 100644 --- a/tests/unit/SearcherTest.php +++ b/tests/unit/SearcherTest.php @@ -10,6 +10,21 @@ */ class SearcherTest extends CirrusTestCase { + public function setUp() { + parent::setUp(); + MediaWikiServices::getInstance()->getConfigFactory()->register( 'CirrusSearch', + function () { + return new SearchConfigUsageDecorator(); + } + ); + } + + public function tearDown() { + MediaWikiServices::getInstance() + ->resetServiceForTesting( 'ConfigFactory' ); + parent::tearDown(); + } + public function searchTextProvider() { $configs = [ 'default' => [], @@ -134,6 +149,28 @@ // Finally compare some things $this->assertEquals( $expected, $elasticQuery, $encodedQuery ); } + $this->assertConfigIsExported(); + } + + private function assertConfigIsExported() { + try { + $notInApi = []; + $notInSearchConfig = []; + foreach ( array_keys( SearchConfigUsageDecorator::getUsedConfigKeys() ) as $k ) { + if ( !in_array( $k, \CirrusSearch\Api\ConfigDump::$WHITE_LIST ) ) { + $notInApi[] = $k; + } + if ( preg_match( '/^CirrusSearch/', $k ) == 0 ) { + if ( !in_array( 'wg' . $k, SearchConfig::getNonCirrusConfigVarNames() ) ) { + $notInSearchConfig[] = $k; + } + } + } + $this->assertEmpty( $notInApi, implode( ',', $notInApi ) . " are exported from \CirrusSearch\Api\ConfigDump" ); + $this->assertEmpty( $notInSearchConfig, implode( ',', $notInApi ) . " are allowed in SearchConfig::getNonCirrusConfigVarNames()" ); + } finally { + SearchConfigUsageDecorator::resetUsedConfigKeys(); + } } private function normalizeNow( array $query ) { @@ -232,3 +269,24 @@ } } } + +class SearchConfigUsageDecorator extends SearchConfig { + private static $usedConfigKeys = []; + + public function get( $name ) { + $val = parent::get( $name ); + // Some config vars are objects.. (e.g. wgContLang) + if ( !is_object( $val ) ) { + static::$usedConfigKeys[$this->prefix . $name] = true; + } + return $val; + } + + public static function getUsedConfigKeys() { + return static::$usedConfigKeys; + } + + public static function resetUsedConfigKeys() { + static::$usedConfigKeys = []; + } +} -- To view, visit https://gerrit.wikimedia.org/r/366609 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I875fc9aebbc9c6c8de4c9ff0551f212fbd1cb158 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/CirrusSearch Gerrit-Branch: master Gerrit-Owner: DCausse <dcau...@wikimedia.org> Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: Gehel <guillaume.leder...@wikimedia.org> Gerrit-Reviewer: Smalyshev <smalys...@wikimedia.org> Gerrit-Reviewer: Tjones <tjo...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits