jenkins-bot has submitted this change and it was merged.
Change subject: Remove usage of EntityFactory where not needed
......................................................................
Remove usage of EntityFactory where not needed
This removes usages of EntityFactory where it can be easily replaced with
a better alternative.
Change-Id: I039a7ddb468d4631aae08fdaf63a2df48d54cabd
---
M client/tests/phpunit/includes/Changes/ChangeRunCoalescerTest.php
M repo/includes/Api/ApiHelperFactory.php
M repo/includes/Specials/SpecialEntitiesWithoutPage.php
M repo/includes/Specials/SpecialEntitiesWithoutPageFactory.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/Api/ApiHelperFactoryTest.php
M repo/tests/phpunit/includes/Specials/SpecialEntitiesWithoutPageTest.php
M repo/tests/phpunit/includes/WikibaseRepoTest.php
8 files changed, 69 insertions(+), 35 deletions(-)
Approvals:
Jonas Kress (WMDE): Looks good to me, but someone else must approve
Daniel Kinzler: Looks good to me, approved
Thiemo Mättig (WMDE): Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/client/tests/phpunit/includes/Changes/ChangeRunCoalescerTest.php
b/client/tests/phpunit/includes/Changes/ChangeRunCoalescerTest.php
index b957717..c0f0a03 100644
--- a/client/tests/phpunit/includes/Changes/ChangeRunCoalescerTest.php
+++ b/client/tests/phpunit/includes/Changes/ChangeRunCoalescerTest.php
@@ -11,7 +11,6 @@
use Wikibase\DataModel\Services\Diff\ItemDiffer;
use Wikibase\DataModel\SiteLink;
use Wikibase\EntityChange;
-use Wikibase\EntityFactory;
use Wikibase\ItemChange;
use Wikibase\Lib\Store\EntityRevisionLookup;
use Wikibase\Test\MockRepository;
@@ -162,18 +161,17 @@
);
$lookup = $this->getEntityRevisionLookup();
- $entityFactory = new EntityFactory( $entityClasses );
$itemId = new ItemId( $objectId );
if ( $revA === 0 ) {
- $oldEntity = $entityFactory->newEmpty(
Item::ENTITY_TYPE );
+ $oldEntity = new Item();
} else {
$oldEntity = $lookup->getEntityRevision( $itemId, $revA
)->getEntity();
}
if ( $revB === 0 ) {
- $newEntity = $entityFactory->newEmpty(
Item::ENTITY_TYPE );
+ $newEntity = new Item();
} else {
$newEntity = $lookup->getEntityRevision( $itemId, $revB
)->getEntity();
}
diff --git a/repo/includes/Api/ApiHelperFactory.php
b/repo/includes/Api/ApiHelperFactory.php
index 1ed4b72..a5ecaf7 100644
--- a/repo/includes/Api/ApiHelperFactory.php
+++ b/repo/includes/Api/ApiHelperFactory.php
@@ -8,7 +8,6 @@
use Wikibase\DataModel\SerializerFactory;
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup;
use Wikibase\EditEntityFactory;
-use Wikibase\EntityFactory;
use Wikibase\Lib\Store\EntityRevisionLookup;
use Wikibase\Lib\Store\EntityTitleLookup;
use Wikibase\Repo\Localizer\ExceptionLocalizer;
@@ -41,11 +40,6 @@
private $dataTypeLookup;
/**
- * @var EntityFactory
- */
- private $entityFactory;
-
- /**
* @var SummaryFormatter
*/
private $summaryFormatter;
@@ -69,7 +63,6 @@
EntityTitleLookup $titleLookup,
ExceptionLocalizer $exceptionLocalizer,
PropertyDataTypeLookup $dataTypeLookup,
- EntityFactory $entityFactory,
SiteStore $siteStore,
SummaryFormatter $summaryFormatter,
EntityRevisionLookup $entityRevisionLookup,
@@ -78,7 +71,6 @@
$this->titleLookup = $titleLookup;
$this->exceptionLocalizer = $exceptionLocalizer;
$this->dataTypeLookup = $dataTypeLookup;
- $this->entityFactory = $entityFactory;
$this->siteStore = $siteStore;
$this->summaryFormatter = $summaryFormatter;
$this->entityRevisionLookup = $entityRevisionLookup;
diff --git a/repo/includes/Specials/SpecialEntitiesWithoutPage.php
b/repo/includes/Specials/SpecialEntitiesWithoutPage.php
index 6ee26fd..3b27608 100644
--- a/repo/includes/Specials/SpecialEntitiesWithoutPage.php
+++ b/repo/includes/Specials/SpecialEntitiesWithoutPage.php
@@ -4,7 +4,6 @@
use HTMLForm;
use Wikibase\DataModel\Entity\EntityId;
-use Wikibase\EntityFactory;
use Wikibase\Lib\ContentLanguages;
use Wikibase\Repo\Store\EntityPerPage;
@@ -49,9 +48,9 @@
private $entityPerPage;
/**
- * @var EntityFactory
+ * @var string[]
*/
- private $entityFactory;
+ private $entityTypes;
/**
* @var ContentLanguages
@@ -63,7 +62,7 @@
* @param string $termType One of the TermIndexEntry::TYPE_...
constants.
* @param string $legendMsg
* @param EntityPerPage $entityPerPage
- * @param EntityFactory $entityFactory
+ * @param string[] $entityTypes
* @param ContentLanguages $termsLanguages
*/
public function __construct(
@@ -71,7 +70,7 @@
$termType,
$legendMsg,
EntityPerPage $entityPerPage,
- EntityFactory $entityFactory,
+ array $entityTypes,
ContentLanguages $termsLanguages
) {
parent::__construct( $name );
@@ -79,7 +78,7 @@
$this->termType = $termType;
$this->legendMsg = $legendMsg;
$this->entityPerPage = $entityPerPage;
- $this->entityFactory = $entityFactory;
+ $this->entityTypes = $entityTypes;
$this->termsLanguages = $termsLanguages;
}
@@ -129,7 +128,7 @@
if ( $this->type === '' ) {
$this->type = null;
}
- if ( $this->type !== null &&
!$this->entityFactory->isEntityType( $this->type ) ) {
+ if ( $this->type !== null && !in_array( $this->type,
$this->entityTypes ) ) {
$this->showErrorHTML( $this->msg(
'wikibase-entitieswithoutlabel-invalid-type', $this->type )->parse() );
$this->type = null;
}
@@ -142,7 +141,8 @@
$options = array(
$this->msg(
'wikibase-entitieswithoutlabel-label-alltypes' )->text() => ''
);
- foreach ( $this->entityFactory->getEntityTypes() as $type ) {
+
+ foreach ( $this->entityTypes as $type ) {
// Messages: wikibase-entity-item,
wikibase-entity-property, wikibase-entity-query
$options[$this->msg( 'wikibase-entity-' . $type
)->text()] = $type;
}
diff --git a/repo/includes/Specials/SpecialEntitiesWithoutPageFactory.php
b/repo/includes/Specials/SpecialEntitiesWithoutPageFactory.php
index 6f67470..706b787 100644
--- a/repo/includes/Specials/SpecialEntitiesWithoutPageFactory.php
+++ b/repo/includes/Specials/SpecialEntitiesWithoutPageFactory.php
@@ -23,7 +23,7 @@
return new self(
$wikibaseRepo->getStore()->newEntityPerPage(),
- $wikibaseRepo->getEntityFactory(),
+ $wikibaseRepo->getEnabledEntityTypes(),
$wikibaseRepo->getTermsLanguages()
);
}
@@ -42,22 +42,27 @@
private $entityPerPage;
/**
- * @var EntityFactory
+ * @var string[]
*/
- private $entityFactory;
+ private $entityTypes;
/**
* @var ContentLanguages
*/
private $termsLanguages;
+ /**
+ * @param EntityPerPage $entityPerPage
+ * @param string[] $entityTypes
+ * @param ContentLanguages $termsLanguages
+ */
public function __construct(
EntityPerPage $entityPerPage,
- EntityFactory $entityFactory,
+ array $entityTypes,
ContentLanguages $termsLanguages
) {
$this->entityPerPage = $entityPerPage;
- $this->entityFactory = $entityFactory;
+ $this->entityTypes = $entityTypes;
$this->termsLanguages = $termsLanguages;
}
@@ -72,7 +77,7 @@
TermIndexEntry::TYPE_LABEL,
'wikibase-entitieswithoutlabel-legend',
$this->entityPerPage,
- $this->entityFactory,
+ $this->entityTypes,
$this->termsLanguages
);
}
@@ -88,7 +93,7 @@
TermIndexEntry::TYPE_DESCRIPTION,
'wikibase-entitieswithoutdescription-legend',
$this->entityPerPage,
- $this->entityFactory,
+ $this->entityTypes,
$this->termsLanguages
);
}
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 01486d9..2ba58f0 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -1190,6 +1190,20 @@
}
/**
+ * @return string[]
+ */
+ public function getEnabledEntityTypes() {
+ $entityTypeByContentModel = array_flip(
$this->getContentModelMappings() );
+
+ return array_map(
+ function( $contentModel ) use (
$entityTypeByContentModel ) {
+ return $entityTypeByContentModel[$contentModel];
+ },
+ array_keys( $this->settings->getSetting(
'entityNamespaces' ) )
+ );
+ }
+
+ /**
* @return EntityContentDataCodec
*/
public function getEntityContentDataCodec() {
@@ -1430,7 +1444,6 @@
$this->getEntityTitleLookup(),
$this->getExceptionLocalizer(),
$this->getPropertyDataTypeLookup(),
- $this->getEntityFactory(),
$this->getSiteStore(),
$this->getSummaryFormatter(),
$this->getEntityRevisionLookup( 'uncached' ),
diff --git a/repo/tests/phpunit/includes/Api/ApiHelperFactoryTest.php
b/repo/tests/phpunit/includes/Api/ApiHelperFactoryTest.php
index e32d60f..52abfce 100644
--- a/repo/tests/phpunit/includes/Api/ApiHelperFactoryTest.php
+++ b/repo/tests/phpunit/includes/Api/ApiHelperFactoryTest.php
@@ -16,7 +16,6 @@
use Wikibase\Repo\Api\EntitySavingHelper;
use Wikibase\Repo\Api\ResultBuilder;
use Wikibase\Repo\Localizer\ExceptionLocalizer;
-use Wikibase\Repo\WikibaseRepo;
use Wikibase\SummaryFormatter;
/**
@@ -35,7 +34,6 @@
$titleLookup = $this->getMock( EntityTitleLookup::class );
$exceptionLocalizer = $this->getMock( ExceptionLocalizer::class
);
$dataTypeLookup = $this->getMock( PropertyDataTypeLookup::class
);
- $entityFactory =
WikibaseRepo::getDefaultInstance()->getEntityFactory();
$summaryFormatter = $this->getMockBuilder(
SummaryFormatter::class )
->disableOriginalConstructor()->getMock();
$entityRevisionLookup = $this->getMock(
EntityRevisionLookup::class );
@@ -46,7 +44,6 @@
$titleLookup,
$exceptionLocalizer,
$dataTypeLookup,
- $entityFactory,
new HashSiteStore(),
$summaryFormatter,
$entityRevisionLookup,
diff --git
a/repo/tests/phpunit/includes/Specials/SpecialEntitiesWithoutPageTest.php
b/repo/tests/phpunit/includes/Specials/SpecialEntitiesWithoutPageTest.php
index d7222ed..9bb6358 100644
--- a/repo/tests/phpunit/includes/Specials/SpecialEntitiesWithoutPageTest.php
+++ b/repo/tests/phpunit/includes/Specials/SpecialEntitiesWithoutPageTest.php
@@ -37,7 +37,7 @@
TermIndexEntry::TYPE_LABEL,
'wikibase-entitieswithoutlabel-legend',
$wikibaseRepo->getStore()->newEntityPerPage(),
- $wikibaseRepo->getEntityFactory(),
+ array( 'item', 'property' ),
new StaticContentLanguages( array( 'acceptedlanguage' )
)
);
}
diff --git a/repo/tests/phpunit/includes/WikibaseRepoTest.php
b/repo/tests/phpunit/includes/WikibaseRepoTest.php
index 4edb82c..544e1fa 100644
--- a/repo/tests/phpunit/includes/WikibaseRepoTest.php
+++ b/repo/tests/phpunit/includes/WikibaseRepoTest.php
@@ -20,6 +20,7 @@
use Wikibase\DataModel\Services\Statement\StatementGuidValidator;
use Wikibase\DataModel\Services\Term\TermBuffer;
use Wikibase\EditEntityFactory;
+use Wikibase\EntityFactory;
use Wikibase\InternalSerialization\DeserializerFactory as
InternalDeserializerFactory;
use Wikibase\InternalSerialization\SerializerFactory;
use Wikibase\LanguageFallbackChainFactory;
@@ -248,6 +249,31 @@
}
}
+ public function testGetEntityFactory() {
+ $entityFactory = $this->getWikibaseRepo()->getEntityFactory();
+ $this->assertInstanceOf( EntityFactory::class, $entityFactory );
+ }
+
+ public function testGetEnabledEntityTypes() {
+ $entityTypeDefinitions = array(
+ 'foo' => array( 'content-model-id' => 'foo-model' ),
+ 'bar' => array( 'content-model-id' => 'bar-model' ),
+ );
+ $wikibaseRepo = $this->getWikibaseRepo( array(),
$entityTypeDefinitions );
+ $wikibaseRepo->getSettings()->setSetting(
+ 'entityNamespaces',
+ array(
+ 'foo-model' => 100,
+ 'bar-model' => 102
+ )
+ );
+
+ $this->assertSame(
+ array( 'foo', 'bar' ),
+ $wikibaseRepo->getEnabledEntityTypes()
+ );
+ }
+
public function testGetExceptionLocalizer() {
$localizer = $this->getWikibaseRepo()->getExceptionLocalizer();
$this->assertInstanceOf( ExceptionLocalizer::class, $localizer
);
@@ -356,15 +382,18 @@
}
/**
+ * @param array[] $dataTypeDefinitios
+ * @param array[] $entityTypeDefinitions
+ *
* @return WikibaseRepo
*/
- private function getWikibaseRepo() {
+ private function getWikibaseRepo( $dataTypeDefinitios = array(),
$entityTypeDefinitions = array() ) {
$language = Language::factory( 'qqx' );
$settings = new SettingsArray(
WikibaseRepo::getDefaultInstance()->getSettings()->getArrayCopy() );
return new WikibaseRepo(
$settings,
- new DataTypeDefinitions( array() ),
- new EntityTypeDefinitions( array() ),
+ new DataTypeDefinitions( $dataTypeDefinitios ),
+ new EntityTypeDefinitions( $entityTypeDefinitions ),
$language
);
}
--
To view, visit https://gerrit.wikimedia.org/r/276751
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I039a7ddb468d4631aae08fdaf63a2df48d54cabd
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Bene <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits