jenkins-bot has submitted this change and it was merged.
Change subject: Only allow enabled entity types in api modules
......................................................................
Only allow enabled entity types in api modules
This changes calls to EntityFactory's getEntityTypes to the function in
WikibaseRepo called getEnabledEntityTypes which is what we really want
when providing an api module to create new entities.
Change-Id: I9f85e4dc841d4295fc2eaac5061b7084a8030b87
---
M lib/includes/EntityTypeDefinitions.php
M repo/includes/Api/EditEntity.php
M repo/includes/Api/QuerySearchEntities.php
M repo/includes/Api/SearchEntities.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/Api/WikibaseApiTestCase.php
6 files changed, 26 insertions(+), 9 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/includes/EntityTypeDefinitions.php
b/lib/includes/EntityTypeDefinitions.php
index 6f23644..c2c44cf 100644
--- a/lib/includes/EntityTypeDefinitions.php
+++ b/lib/includes/EntityTypeDefinitions.php
@@ -51,6 +51,13 @@
}
/**
+ * @return string[] a list of all defined entity types
+ */
+ public function getEntityTypes() {
+ return array_keys( $this->entityTypeDefinitions );
+ }
+
+ /**
* @param string $field
*
* @return mixed
diff --git a/repo/includes/Api/EditEntity.php b/repo/includes/Api/EditEntity.php
index 254ff30..2ece96e 100644
--- a/repo/includes/Api/EditEntity.php
+++ b/repo/includes/Api/EditEntity.php
@@ -93,6 +93,11 @@
private $entityFactory;
/**
+ * @var string[]
+ */
+ private $enabledEntityTypes;
+
+ /**
* @see ModifyEntity::__construct
*
* @param ApiMain $mainModule
@@ -112,6 +117,7 @@
$this->idParser = $wikibaseRepo->getEntityIdParser();
$this->statementDeserializer =
$wikibaseRepo->getExternalFormatStatementDeserializer();
$this->entityFactory = $wikibaseRepo->getEntityFactory();
+ $this->enabledEntityTypes =
$wikibaseRepo->getEnabledEntityTypes();
$changeOpFactoryProvider =
$wikibaseRepo->getChangeOpFactoryProvider();
$this->termChangeOpFactory =
$changeOpFactoryProvider->getFingerprintChangeOpFactory();
@@ -814,7 +820,7 @@
self::PARAM_DFLT => false
),
'new' => array(
- self::PARAM_TYPE =>
$this->entityFactory->getEntityTypes(),
+ self::PARAM_TYPE =>
$this->enabledEntityTypes,
),
)
);
diff --git a/repo/includes/Api/QuerySearchEntities.php
b/repo/includes/Api/QuerySearchEntities.php
index 4f908f8..9459fcf 100644
--- a/repo/includes/Api/QuerySearchEntities.php
+++ b/repo/includes/Api/QuerySearchEntities.php
@@ -65,7 +65,7 @@
$entitySearchHelper,
$repo->getEntityTitleLookup(),
$repo->getTermsLanguages(),
- $repo->getEntityFactory()->getEntityTypes()
+ $repo->getEnabledEntityTypes()
);
}
diff --git a/repo/includes/Api/SearchEntities.php
b/repo/includes/Api/SearchEntities.php
index 2ec4a37..919528b 100644
--- a/repo/includes/Api/SearchEntities.php
+++ b/repo/includes/Api/SearchEntities.php
@@ -75,7 +75,7 @@
$entitySearchHelper,
$repo->getEntityTitleLookup(),
$repo->getTermsLanguages(),
- $repo->getEntityFactory()->getEntityTypes(),
+ $repo->getEnabledEntityTypes(),
$repo->getSettings()->getSetting( 'conceptBaseUri' )
);
}
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 4cda335..25dcfb3 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -1009,7 +1009,9 @@
// Create a new ValueFormatterFactory, and override the
formatter for entity IDs.
$valueFormatterFactory = $this->newValueFormatterFactory();
- foreach ( $this->getEntityFactory()->getEntityTypes() as
$entityType ) {
+
+ // Iterate through all defined entity types
+ foreach ( $this->entityTypeDefinitions->getEntityTypes() as
$entityType ) {
$valueFormatterFactory->setFormatterFactoryCallback(
"PT:wikibase-$entityType",
function ( $format, FormatterOptions $options )
use ( $idFormatter ) {
diff --git a/repo/tests/phpunit/includes/Api/WikibaseApiTestCase.php
b/repo/tests/phpunit/includes/Api/WikibaseApiTestCase.php
index 07340dd..2dac777 100644
--- a/repo/tests/phpunit/includes/Api/WikibaseApiTestCase.php
+++ b/repo/tests/phpunit/includes/Api/WikibaseApiTestCase.php
@@ -345,20 +345,22 @@
* @param array $response
*/
protected function assertResultHasEntityType( array $response ) {
- $entityFactory =
WikibaseRepo::getDefaultInstance()->getEntityFactory();
+ $wikibaseRepo = WikibaseRepo::getDefaultInstance();
if ( isset( $response['entity'] ) ) {
if ( isset( $response['entity']['type'] ) ) {
- $this->assertTrue(
- $entityFactory->isEntityType(
$response['entity']['type'] ),
+ $this->assertContains(
+ $response['entity']['type'],
+ $wikibaseRepo->getEnabledEntityTypes(),
"Missing valid 'type' in response."
);
}
} elseif ( isset( $response['entities'] ) ) {
foreach ( $response['entities'] as $entity ) {
if ( isset( $entity['type'] ) ) {
- $this->assertTrue(
- $entityFactory->isEntityType(
$entity['type'] ),
+ $this->assertContains(
+ $entity['type'],
+
$wikibaseRepo->getEnabledEntityTypes(),
"Missing valid 'type' in
response."
);
}
--
To view, visit https://gerrit.wikimedia.org/r/277892
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9f85e4dc841d4295fc2eaac5061b7084a8030b87
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits