jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/330421 )
Change subject: Inject dependencies to the constructor of API\SearchEntities
......................................................................
Inject dependencies to the constructor of API\SearchEntities
Also removes an optional $modulePrefix parameter from the constructor.
Default empty value has never been overridden, so just pass it to
parent class constructor.
Change-Id: If837daa5c0e7f19c26188a9d65955eade6d7adc1
---
M repo/Wikibase.php
M repo/includes/Api/SearchEntities.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/Api/SearchEntitiesTest.php
4 files changed, 42 insertions(+), 49 deletions(-)
Approvals:
jenkins-bot: Verified
Thiemo Mättig (WMDE): Looks good to me, approved
diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index ec6618c..b378cc9 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -203,7 +203,33 @@
);
}
];
- $wgAPIModules['wbsearchentities'] =
Wikibase\Repo\Api\SearchEntities::class;
+ $wgAPIModules['wbsearchentities'] = [
+ 'class' => Wikibase\Repo\Api\SearchEntities::class,
+ 'factory' => function( ApiMain $mainModule, $moduleName ) {
+ $repo =
Wikibase\Repo\WikibaseRepo::getDefaultInstance();
+
+ $entitySearchHelper = new
Wikibase\Repo\Api\EntitySearchHelper(
+ $repo->getEntityTitleLookup(),
+ $repo->getEntityIdParser(),
+ $repo->newTermSearchInteractor(
$repo->getUserLanguage()->getCode() ),
+ new
Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookup(
+ $repo->getTermLookup(),
+ $repo->getLanguageFallbackChainFactory()
+ ->newFromLanguage(
$repo->getUserLanguage() )
+ )
+ );
+
+ return new Wikibase\Repo\Api\SearchEntities(
+ $mainModule,
+ $moduleName,
+ $entitySearchHelper,
+ $repo->getEntityTitleLookup(),
+ $repo->getTermsLanguages(),
+ $repo->getEnabledEntityTypes(),
+ $repo->getSettings()->getSetting(
'conceptBaseUri' )
+ );
+ },
+ ];
$wgAPIModules['wbsetaliases'] = [
'class' => Wikibase\Repo\Api\SetAliases::class,
'factory' => function ( ApiMain $mainModule, $moduleName ) {
diff --git a/repo/includes/Api/SearchEntities.php
b/repo/includes/Api/SearchEntities.php
index 2b33f47..d8b84d6 100644
--- a/repo/includes/Api/SearchEntities.php
+++ b/repo/includes/Api/SearchEntities.php
@@ -50,52 +50,26 @@
/**
* @param ApiMain $mainModule
* @param string $moduleName
- * @param string $modulePrefix
+ * @param EntityTitleLookup $entityTitleLookup
+ * @param ContentLanguages $termLanguages
+ * @param string[] $entityTypes
+ * @param string $conceptBaseUri
*
* @see ApiBase::__construct
*/
- public function __construct( ApiMain $mainModule, $moduleName,
$modulePrefix = '' ) {
- parent::__construct( $mainModule, $moduleName, $modulePrefix );
-
- $repo = WikibaseRepo::getDefaultInstance();
- $entitySearchHelper = new EntitySearchHelper(
- $repo->getEntityTitleLookup(),
- $repo->getEntityIdParser(),
- $repo->newTermSearchInteractor(
$this->getLanguage()->getCode() ),
- new LanguageFallbackLabelDescriptionLookup(
- $repo->getTermLookup(),
- $repo->getLanguageFallbackChainFactory()
- ->newFromLanguage( $this->getLanguage()
)
- )
- );
-
- $this->setServices(
- $entitySearchHelper,
- $repo->getEntityTitleLookup(),
- $repo->getTermsLanguages(),
- $repo->getEnabledEntityTypes(),
- $repo->getSettings()->getSetting( 'conceptBaseUri' )
- );
- }
-
- /**
- * Override services, for use for testing.
- *
- * @param EntitySearchHelper $entitySearchHelper
- * @param EntityTitleLookup $titleLookup
- * @param ContentLanguages $termLanguages
- * @param array $entityTypes
- * @param string $conceptBaseUri
- */
- public function setServices(
+ public function __construct(
+ ApiMain $mainModule,
+ $moduleName,
EntitySearchHelper $entitySearchHelper,
- EntityTitleLookup $titleLookup,
+ EntityTitleLookup $entityTitleLookup,
ContentLanguages $termLanguages,
array $entityTypes,
$conceptBaseUri
) {
+ parent::__construct( $mainModule, $moduleName, '' );
+
$this->entitySearchHelper = $entitySearchHelper;
- $this->titleLookup = $titleLookup;
+ $this->titleLookup = $entityTitleLookup;
$this->termsLanguages = $termLanguages;
$this->entityTypes = $entityTypes;
$this->conceptBaseUri = $conceptBaseUri;
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index b00f0ad..b381542 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -521,7 +521,7 @@
/**
* @return Language
*/
- private function getUserLanguage() {
+ public function getUserLanguage() {
global $wgLang;
// TODO: define a LanguageProvider service instead of using a
global directly.
diff --git a/repo/tests/phpunit/includes/Api/SearchEntitiesTest.php
b/repo/tests/phpunit/includes/Api/SearchEntitiesTest.php
index 0d3945b..9ef2694 100644
--- a/repo/tests/phpunit/includes/Api/SearchEntitiesTest.php
+++ b/repo/tests/phpunit/includes/Api/SearchEntitiesTest.php
@@ -126,18 +126,11 @@
private function callApiModule( array $params, EntitySearchHelper
$entitySearchHelper = null ) {
$module = new SearchEntities(
$this->getApiMain( $params ),
- 'wbsearchentities'
- );
-
- if ( $entitySearchHelper == null ) {
- $entitySearchHelper = $this->getMockEntitySearchHelper(
$params );
- }
-
- $module->setServices(
- $entitySearchHelper,
+ 'wbsearchentities',
+ $entitySearchHelper ?:
$this->getMockEntitySearchHelper( $params ),
$this->getMockTitleLookup(),
$this->getContentLanguages(),
- array( 'item', 'property' ),
+ [ 'item', 'property' ],
'concept:'
);
--
To view, visit https://gerrit.wikimedia.org/r/330421
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If837daa5c0e7f19c26188a9d65955eade6d7adc1
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: WMDE-leszek <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits