Jeroen De Dauw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/64494
Change subject: Improvements to EntityContentFactory
......................................................................
Improvements to EntityContentFactory
Change-Id: I563d902b3d6a5c9b84b4a43652dc8d0f90c7d57b
---
M DataModel/DataModel/Snak/PropertyValueSnak.php
M lib/tests/phpunit/store/WikiPageEntityLookupTest.php
M repo/includes/WikibaseRepo.php
M repo/includes/content/EntityContentFactory.php
M repo/tests/phpunit/includes/content/EntityContentFactoryTest.php
5 files changed, 64 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/94/64494/1
diff --git a/DataModel/DataModel/Snak/PropertyValueSnak.php
b/DataModel/DataModel/Snak/PropertyValueSnak.php
index 2a9e3db..fcc4d7b 100644
--- a/DataModel/DataModel/Snak/PropertyValueSnak.php
+++ b/DataModel/DataModel/Snak/PropertyValueSnak.php
@@ -124,6 +124,7 @@
* The DataValue
*
* @since 0.3
+ * @deprecated since 0.4
*
* @param EntityId $propertyId
* @param mixed $rawDataValue
diff --git a/lib/tests/phpunit/store/WikiPageEntityLookupTest.php
b/lib/tests/phpunit/store/WikiPageEntityLookupTest.php
index cacbe41..1b9636e 100644
--- a/lib/tests/phpunit/store/WikiPageEntityLookupTest.php
+++ b/lib/tests/phpunit/store/WikiPageEntityLookupTest.php
@@ -111,6 +111,7 @@
throw new \MWException( "Can't generate test entities
in a client database." );
}
+ // FIXME: this is using repo functionality
$content =
\Wikibase\EntityContentFactory::singleton()->newFromEntity( $entity );
$status = $content->save( "storeTestEntity" );
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index d63ec1b..62e40f2 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -5,6 +5,7 @@
use DataTypes\DataTypeFactory;
use ValueFormatters\FormatterOptions;
use ValueParsers\ParserOptions;
+use Wikibase\EntityContentFactory;
use Wikibase\Lib\EntityIdFormatter;
use Wikibase\Lib\EntityIdLabelFormatter;
use Wikibase\Lib\EntityIdParser;
@@ -84,6 +85,20 @@
/**
* @since 0.4
*
+ * @return EntityContentFactory
+ */
+ public function getEntityContentFactory() {
+ $entityNamespaces = $this->settings->getSetting(
'entityNamespaces' );
+
+ return new EntityContentFactory(
+ $this->getIdFormatter(),
+ is_array( $entityNamespaces ) ? array_keys(
$entityNamespaces ) : array()
+ );
+ }
+
+ /**
+ * @since 0.4
+ *
* @return EntityIdFormatter
*/
public function getIdFormatter() {
diff --git a/repo/includes/content/EntityContentFactory.php
b/repo/includes/content/EntityContentFactory.php
index 6e47e9b..10f71c5 100644
--- a/repo/includes/content/EntityContentFactory.php
+++ b/repo/includes/content/EntityContentFactory.php
@@ -1,7 +1,13 @@
<?php
namespace Wikibase;
-use MWException, Title, WikiPage, Revision;
+
+use MWException;
+use Title;
+use WikiPage;
+use Revision;
+use Wikibase\Lib\EntityIdFormatter;
+use Wikibase\Repo\WikibaseRepo;
/**
* Factory for EntityContent objects.
@@ -33,6 +39,7 @@
/**
* @since 0.2
+ * @deprecated since 0.4
*
* @return EntityContentFactory
*/
@@ -40,10 +47,24 @@
static $instance = false;
if ( $instance === false ) {
- $instance = new static();
+ $instance =
WikibaseRepo::newInstance()->getEntityContentFactory();
}
return $instance;
+ }
+
+ // TODO: inject this map and allow extensions to somehow extend it
+ protected static $typeMap = array(
+ Item::ENTITY_TYPE => CONTENT_MODEL_WIKIBASE_ITEM,
+ Property::ENTITY_TYPE => CONTENT_MODEL_WIKIBASE_PROPERTY,
+ );
+
+ protected $idFormatter;
+ protected $contentModelIds;
+
+ public function __construct( EntityIdFormatter $idFormatter, array
$contentModelIds ) {
+ $this->idFormatter = $idFormatter;
+ $this->contentModelIds = $contentModelIds;
}
/**
@@ -62,15 +83,13 @@
/**
* Returns a list of content model IDs that are used to represent
Wikibase entities.
- * Configured via $wgWBRepoSettings['entityNamespaces'].
*
* @since 0.2
*
* @return array An array of string content model IDs.
*/
public function getEntityContentModels() {
- $namespaces = Settings::get( 'entityNamespaces' );
- return is_array( $namespaces ) ? array_keys( $namespaces ) :
array();
+ return $this->contentModelIds;
}
/**
@@ -139,7 +158,7 @@
*/
public function getTitleForId( EntityId $id ) {
return Title::newFromText(
- $id->getPrefixedId(),
+ $this->idFormatter->format( $id ),
NamespaceUtils::getEntityNamespace(
self::$typeMap[$id->getEntityType()] )
);
}
@@ -177,12 +196,6 @@
return $revision->getContent();
}
-
- // TODO: move to sane place
- protected static $typeMap = array(
- Item::ENTITY_TYPE => CONTENT_MODEL_WIKIBASE_ITEM,
- Property::ENTITY_TYPE => CONTENT_MODEL_WIKIBASE_PROPERTY,
- );
/**
* Constructs a new EntityContent from an Entity.
diff --git a/repo/tests/phpunit/includes/content/EntityContentFactoryTest.php
b/repo/tests/phpunit/includes/content/EntityContentFactoryTest.php
index 14f0787..709f541 100644
--- a/repo/tests/phpunit/includes/content/EntityContentFactoryTest.php
+++ b/repo/tests/phpunit/includes/content/EntityContentFactoryTest.php
@@ -1,10 +1,11 @@
<?php
namespace Wikibase\Test;
+
use Wikibase\EntityContentFactory;
/**
- * Tests for the Wikibase\EntityContentFactory class.
+ * @covers Wikibase\EntityContentFactory
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -30,19 +31,35 @@
* @group Wikibase
* @group WikibaseEntity
* @group WikibaseContent
- * @group Database
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
-class EntityContentFactoryTest extends \MediaWikiTestCase {
+class EntityContentFactoryTest extends \PHPUnit_Framework_TestCase {
public function testGetEntityContentModels() {
- $this->assertInternalType( 'array',
EntityContentFactory::singleton()->getEntityContentModels() );
+ $contentModelIds = array( 42, 1337, 9001 );
+
+ $factory = new EntityContentFactory(
+ $this->newMockIdFormatter(),
+ $contentModelIds
+ );
+
+ $this->assertEquals( $contentModelIds,
$factory->getEntityContentModels() );
+ }
+
+ protected function newMockIdFormatter() {
+ $idFormatter = $this->getMockBuilder(
'Wikibase\Lib\EntityIdFormatter' )
+ ->disableOriginalConstructor()->getMock();
+
+ return $idFormatter;
}
public function testIsEntityContentModel() {
- $factory = EntityContentFactory::singleton();
+ $factory = new EntityContentFactory(
+ $this->newMockIdFormatter(),
+ array( 42, 1337, 9001 )
+ );
foreach ( $factory->getEntityContentModels() as $type ) {
$this->assertTrue( $factory->isEntityContentModel(
$type ) );
--
To view, visit https://gerrit.wikimedia.org/r/64494
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I563d902b3d6a5c9b84b4a43652dc8d0f90c7d57b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits