Bene has uploaded a new change for review.
https://gerrit.wikimedia.org/r/276751
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/Specials/SpecialEntitiesWithoutPageTest.php
6 files changed, 37 insertions(+), 28 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/51/276751/1
diff --git a/client/tests/phpunit/includes/Changes/ChangeRunCoalescerTest.php
b/client/tests/phpunit/includes/Changes/ChangeRunCoalescerTest.php
index 3bcd735..f02e1b5 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\Lib\Store\EntityRevisionLookup;
use Wikibase\Test\MockRepository;
use Wikibase\Test\TestChanges;
@@ -161,18 +160,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 c912ea8..a6d2b8f 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -1177,6 +1177,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() {
diff --git
a/repo/tests/phpunit/includes/Specials/SpecialEntitiesWithoutPageTest.php
b/repo/tests/phpunit/includes/Specials/SpecialEntitiesWithoutPageTest.php
index 4e0af2e..2dbaa7f 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' )
)
);
}
--
To view, visit https://gerrit.wikimedia.org/r/276751
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I039a7ddb468d4631aae08fdaf63a2df48d54cabd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits