Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/172590

Change subject: Introduce EntityViewFactory and adjust SnakFormatterFactory
......................................................................

Introduce EntityViewFactory and adjust SnakFormatterFactory

Now we are able to inject the LabelLookup with appropriate TermLookup,
into the WikibaseValueFormatterBuilders and provide it as an argument
to OutputFormatSnakFormatterFactory::getSnakFormatter method.

For EntityView, this allows the EntityInfoTermLookup to be used,
though that is not yet done in this patch.

Change-Id: I31a18f05ec9d1723661f7ca526562faaa7c41bf6
---
M 
client/includes/DataAccess/PropertyParserFunction/PropertyClaimsRendererFactory.php
M client/includes/WikibaseClient.php
M client/includes/scribunto/Scribunto_LuaWikibaseEntityLibrary.php
M 
client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyClaimsRendererFactoryTest.php
M lib/includes/formatters/OutputFormatSnakFormatterFactory.php
M lib/includes/formatters/WikibaseSnakFormatterBuilders.php
M lib/includes/formatters/WikibaseValueFormatterBuilders.php
M lib/tests/phpunit/formatters/OutputFormatSnakFormatterFactoryTest.php
M lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php
M lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
M repo/includes/Diff/EntityContentDiffView.php
M repo/includes/EntityParserOutputGenerator.php
M repo/includes/EntityParserOutputGeneratorFactory.php
M repo/includes/EntityView.php
M repo/includes/ItemView.php
M repo/includes/ParserOutputJsConfigBuilder.php
M repo/includes/PropertyView.php
M repo/includes/View/ClaimsView.php
A repo/includes/View/EntityViewFactory.php
M repo/includes/WikibaseRepo.php
M repo/includes/actions/EditEntityAction.php
M repo/includes/content/EntityContent.php
M repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php
M repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php
M repo/tests/phpunit/includes/ParserOutputJsConfigBuilderTest.php
M repo/tests/phpunit/includes/View/ClaimsViewTest.php
A repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
27 files changed, 804 insertions(+), 459 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/90/172590/3

diff --git 
a/client/includes/DataAccess/PropertyParserFunction/PropertyClaimsRendererFactory.php
 
b/client/includes/DataAccess/PropertyParserFunction/PropertyClaimsRendererFactory.php
index ef2eccd..110ac68 100644
--- 
a/client/includes/DataAccess/PropertyParserFunction/PropertyClaimsRendererFactory.php
+++ 
b/client/includes/DataAccess/PropertyParserFunction/PropertyClaimsRendererFactory.php
@@ -11,6 +11,7 @@
 use Wikibase\Lib\SnakFormatter;
 use Wikibase\Client\Usage\ParserOutputUsageAccumulator;
 use Wikibase\Client\Usage\UsageAccumulator;
+use Wikibase\Lib\WikibaseValueFormatterBuilders;
 
 /**
  * @since 0.5
@@ -46,21 +47,29 @@
        private $languageAwareRenderers = array();
 
        /**
+        * @var WikibaseValueFormatterBuilders
+        */
+       private $valueFormatterBuilders;
+
+       /**
         * @param PropertyIdResolver $propertyIdResolver
         * @param SnaksFinder $snaksFinder
         * @param LanguageFallbackChainFactory $languageFallbackChainFactory
         * @param OutputFormatSnakFormatterFactory $snakFormatterFactory
+        * @param WikibaseValueFormatterBuilders $valueFormatterBuilders
         */
        public function __construct(
                PropertyIdResolver $propertyIdResolver,
                SnaksFinder $snaksFinder,
                LanguageFallbackChainFactory $languageFallbackChainFactory,
-               OutputFormatSnakFormatterFactory $snakFormatterFactory
+               OutputFormatSnakFormatterFactory $snakFormatterFactory,
+               WikibaseValueFormatterBuilders $valueFormatterBuilders
        ) {
                $this->propertyIdResolver = $propertyIdResolver;
                $this->snaksFinder = $snaksFinder;
                $this->languageFallbackChainFactory = 
$languageFallbackChainFactory;
                $this->snakFormatterFactory = $snakFormatterFactory;
+               $this->valueFormatterBuilders = $valueFormatterBuilders;
        }
 
        /**
@@ -186,6 +195,7 @@
 
                $snakFormatter = $this->snakFormatterFactory->getSnakFormatter(
                        SnakFormatter::FORMAT_WIKI,
+                       $this->valueFormatterBuilders,
                        $options
                );
 
diff --git a/client/includes/WikibaseClient.php 
b/client/includes/WikibaseClient.php
index 5161ee8..52db144 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -44,6 +44,8 @@
 use Wikibase\Lib\Serializers\ForbiddenSerializer;
 use Wikibase\Lib\Store\EntityContentDataCodec;
 use Wikibase\Lib\Store\EntityLookup;
+use Wikibase\Lib\Store\EntityRetrievingTermLookup;
+use Wikibase\Lib\Store\LanguageLabelLookup;
 use Wikibase\Lib\WikibaseDataTypeBuilders;
 use Wikibase\Lib\WikibaseSnakFormatterBuilders;
 use Wikibase\Lib\WikibaseValueFormatterBuilders;
@@ -464,20 +466,25 @@
         * @return OutputFormatSnakFormatterFactory
         */
        private function newSnakFormatterFactory() {
-               $valueFormatterBuilders = new WikibaseValueFormatterBuilders(
-                       $this->getEntityLookup(),
-                       $this->contentLanguage
-               );
-
-               $builders = new WikibaseSnakFormatterBuilders(
-                       $valueFormatterBuilders,
+               $snakFormatterBuilders = new WikibaseSnakFormatterBuilders(
                        $this->getPropertyDataTypeLookup(),
                        $this->getDataTypeFactory()
                );
 
-               $factory = new OutputFormatSnakFormatterFactory( 
$builders->getSnakFormatterBuildersForFormats() );
+               return new OutputFormatSnakFormatterFactory( 
$snakFormatterBuilders );
+       }
 
-               return $factory;
+       /**
+        * @return WikibaseValueFormatterBuilders
+        */
+       public function getValueFormatterBuilders() {
+               $termLookup = new EntityRetrievingTermLookup( 
$this->getEntityLookup() );
+
+               return new WikibaseValueFormatterBuilders(
+                       $this->getEntityLookup(),
+                       $this->contentLanguage,
+                       new LanguageLabelLookup( $termLookup, 
$this->contentLanguage->getCode() )
+               );
        }
 
        /**
@@ -498,14 +505,11 @@
         * @return OutputFormatValueFormatterFactory
         */
        private function newValueFormatterFactory() {
-               $builders = new WikibaseValueFormatterBuilders(
-                       $this->getEntityLookup(),
-                       $this->contentLanguage
+               $builders = $this->getValueFormatterBuilders();
+
+               return new OutputFormatValueFormatterFactory(
+                       $builders->getValueFormatterBuildersForFormats()
                );
-
-               $factory = new OutputFormatValueFormatterFactory( 
$builders->getValueFormatterBuildersForFormats() );
-
-               return $factory;
        }
 
        /**
@@ -697,7 +701,8 @@
                        $propertyIdResolver,
                        $snaksFinder,
                        $this->getLanguageFallbackChainFactory(),
-                       $this->getSnakFormatterFactory()
+                       $this->getSnakFormatterFactory(),
+                       $this->getValueFormatterBuilders()
                );
        }
 
diff --git a/client/includes/scribunto/Scribunto_LuaWikibaseEntityLibrary.php 
b/client/includes/scribunto/Scribunto_LuaWikibaseEntityLibrary.php
index 67323e7..6d107cd 100644
--- a/client/includes/scribunto/Scribunto_LuaWikibaseEntityLibrary.php
+++ b/client/includes/scribunto/Scribunto_LuaWikibaseEntityLibrary.php
@@ -37,7 +37,9 @@
                $formatterOptions = new FormatterOptions( array( "language" => 
$wgContLang ) );
 
                $snakFormatter = 
$wikibaseClient->getSnakFormatterFactory()->getSnakFormatter(
-                       SnakFormatter::FORMAT_WIKI, $formatterOptions
+                       SnakFormatter::FORMAT_WIKI,
+                       $wikibaseClient->getValueFormatterBuilders(),
+                       $formatterOptions
                );
 
                $this->wbLibrary = new WikibaseLuaEntityBindings(
diff --git 
a/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyClaimsRendererFactoryTest.php
 
b/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyClaimsRendererFactoryTest.php
index 00823d1..f8d384e 100644
--- 
a/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyClaimsRendererFactoryTest.php
+++ 
b/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyClaimsRendererFactoryTest.php
@@ -114,7 +114,8 @@
                        $this->getPropertyIdResolver(),
                        $this->getSnaksFinder(),
                        $this->getLanguageFallbackChainFactory(),
-                       $this->getSnakFormatterFactory()
+                       $this->getSnakFormatterFactory(),
+                       $this->getValueFormatterBuilders()
                );
        }
 
@@ -166,6 +167,12 @@
                return $snakFormatterFactory;
        }
 
+       private function getValueFormatterBuilders() {
+               return $this->getMockBuilder( 
'Wikibase\Lib\WikibaseValueFormatterBuilders' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+       }
+
        private function getParser( $languageCode, $interfaceMessage, 
$disableContentConversion,
                $disableTitleConversion, $outputType
        ) {
diff --git a/lib/includes/formatters/OutputFormatSnakFormatterFactory.php 
b/lib/includes/formatters/OutputFormatSnakFormatterFactory.php
index 1351c87..473152d 100644
--- a/lib/includes/formatters/OutputFormatSnakFormatterFactory.php
+++ b/lib/includes/formatters/OutputFormatSnakFormatterFactory.php
@@ -1,8 +1,14 @@
 <?php
+
 namespace Wikibase\Lib;
+
+use DataTypes\DataTypeFactory;
 use InvalidArgumentException;
 use RuntimeException;
 use ValueFormatters\FormatterOptions;
+use Wikibase\DataModel\Entity\PropertyDataTypeLookup;
+use Wikibase\Lib\WikibaseSnakFormatterBuilders;
+use Wikibase\Lib\WikibaseValueFormatterBuilders;
 
 /**
  * OutputFormatSnakFormatterFactory is a service
@@ -14,9 +20,16 @@
 class OutputFormatSnakFormatterFactory {
 
        /**
-        * @var callable[]
+        * @var WikibaseSnakFormatterBuilders
         */
-       private $builders;
+       private $snakFormatterBuilders;
+
+       /**
+        * @param WikibaseSnakFormatterBuilders $snakFormatterBuilders
+        */
+       public function __construct( WikibaseSnakFormatterBuilders 
$snakFormatterBuilders ) {
+               $this->snakFormatterBuilders = $snakFormatterBuilders;
+       }
 
        /**
         * @param callable[] $builders maps formats to callable builders. Each 
builder must accept
@@ -25,7 +38,7 @@
         *
         * @throws InvalidArgumentException
         */
-       public function __construct( array $builders ) {
+       private function assertValidSnakFormatterFormatBuilders( $builders ) {
                foreach ( $builders as $format => $builder ) {
                        if ( !is_string( $format ) ) {
                                throw new InvalidArgumentException( '$builders 
must map type IDs to formatters.' );
@@ -35,8 +48,20 @@
                                throw new InvalidArgumentException( '$builders 
must contain a callable builder for each format.' );
                        }
                }
+       }
 
-               $this->builders = $builders;
+       /**
+        * @param WikibaseValueFormatterBuilders $valueFormatterBuilders
+        *
+        * @throws InvalidArgumentException if one of the builders is invalid.
+        * @return array DataType builder specs
+        */
+       private function getSnakFormatterFormatBuilders() {
+               $snakFormatterFormatBuilders = 
$this->snakFormatterBuilders->getSnakFormatterBuildersForFormats();
+
+               $this->assertValidSnakFormatterFormatBuilders( 
$snakFormatterFormatBuilders );
+
+               return $snakFormatterFormatBuilders;
        }
 
        /**
@@ -44,20 +69,27 @@
         * using the given options.
         *
         * @param string $format Use the SnakFormatter::FORMAT_XXX constants.
+        * @param WikibaseValueFormatterBuilders $valueFormatterBuilders
         * @param FormatterOptions $options
         *
         * @throws RuntimeException
         * @throws InvalidArgumentException
         * @return SnakFormatter
         */
-       public function getSnakFormatter( $format, FormatterOptions $options ) {
-               if ( !array_key_exists( $format, $this->builders ) ) {
+       public function getSnakFormatter(
+               $format,
+               WikibaseValueFormatterBuilders $valueFormatterBuilders,
+               FormatterOptions $options
+       ) {
+               $builders = $this->getSnakFormatterFormatBuilders();
+
+               if ( !array_key_exists( $format, $builders ) ) {
                        throw new InvalidArgumentException( "Unsupported 
format: $format" );
                }
 
                //TODO: cache instances based on an option hash
-               $builder = $this->builders[$format];
-               $instance = call_user_func( $builder, $this, $format, $options 
);
+               $builder = $builders[$format];
+               $instance = call_user_func( $builder, $format, 
$valueFormatterBuilders, $options );
 
                if( !( $instance instanceof SnakFormatter ) ) {
                        throw new RuntimeException( get_class( $instance ) . ' 
does not implement SnakFormatter' );
diff --git a/lib/includes/formatters/WikibaseSnakFormatterBuilders.php 
b/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
index 245b18a..e810f81 100644
--- a/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
+++ b/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
@@ -20,11 +20,6 @@
 class WikibaseSnakFormatterBuilders {
 
        /**
-        * @var WikibaseValueFormatterBuilders
-        */
-       private $valueFormatterBuilders;
-
-       /**
         * @var PropertyDataTypeLookup
         */
        private $propertyDataTypeLookup;
@@ -35,16 +30,13 @@
        private $dataTypeFactory;
 
        /**
-        * @param WikibaseValueFormatterBuilders $valueFormatterBuilders
         * @param PropertyDataTypeLookup $propertyDataTypeLookup
         * @param DataTypeFactory $dataTypeFactory
         */
        public function __construct(
-               WikibaseValueFormatterBuilders $valueFormatterBuilders,
                PropertyDataTypeLookup $propertyDataTypeLookup,
                DataTypeFactory $dataTypeFactory
        ) {
-               $this->valueFormatterBuilders = $valueFormatterBuilders;
                $this->propertyDataTypeLookup = $propertyDataTypeLookup;
                $this->dataTypeFactory = $dataTypeFactory;
        }
@@ -70,21 +62,25 @@
         * Returns a DispatchingSnakFormatter for the given format, that will 
dispatch based on
         * the snak type. The instance returned by this method will cover all 
standard snak types.
         *
-        * @param OutputFormatSnakFormatterFactory $factory
-        * @param string               $format
-        * @param FormatterOptions     $options
+        * @param string $format
+        * @param WikibaseValueFormatterBuilders $valueFormatterBuilders
+        * @param FormatterOptions $options
         *
         * @return DispatchingSnakFormatter
         */
-       public function buildDispatchingSnakFormatter( 
OutputFormatSnakFormatterFactory $factory, $format, FormatterOptions $options ) 
{
-               $this->valueFormatterBuilders->applyLanguageDefaults( $options 
);
+       public function buildDispatchingSnakFormatter(
+               $format,
+               WikibaseValueFormatterBuilders $valueFormatterBuilders,
+               FormatterOptions $options
+       ) {
+               $valueFormatterBuilders->applyLanguageDefaults( $options );
                $lang = $options->getOption( ValueFormatter::OPT_LANG );
 
                $noValueSnakFormatter = new MessageSnakFormatter( 'novalue', 
$this->getMessage( 'wikibase-snakview-snaktypeselector-novalue', $lang ), 
$format );
                $someValueSnakFormatter = new MessageSnakFormatter( 
'somevalue', $this->getMessage( 'wikibase-snakview-snaktypeselector-somevalue', 
$lang ), $format );
 
-               $factory = new OutputFormatValueFormatterFactory( 
$this->valueFormatterBuilders->getValueFormatterBuildersForFormats() );
-               $valueFormatter = 
$this->valueFormatterBuilders->buildDispatchingValueFormatter( $factory, 
$format, $options );
+               $factory = new OutputFormatValueFormatterFactory( 
$valueFormatterBuilders->getValueFormatterBuildersForFormats() );
+               $valueFormatter = 
$valueFormatterBuilders->buildDispatchingValueFormatter( $factory, $format, 
$options );
                $valueSnakFormatter = new PropertyValueSnakFormatter(
                        $format,
                        $options,
diff --git a/lib/includes/formatters/WikibaseValueFormatterBuilders.php 
b/lib/includes/formatters/WikibaseValueFormatterBuilders.php
index 414d722..b485179 100644
--- a/lib/includes/formatters/WikibaseValueFormatterBuilders.php
+++ b/lib/includes/formatters/WikibaseValueFormatterBuilders.php
@@ -14,6 +14,7 @@
 use Wikibase\LanguageFallbackChain;
 use Wikibase\LanguageFallbackChainFactory;
 use Wikibase\Lib\Store\EntityRetrievingTermLookup;
+use Wikibase\Lib\Store\LabelLookup;
 use Wikibase\Lib\Store\LanguageFallbackLabelLookup;
 use Wikibase\Lib\Store\LanguageLabelLookup;
 use Wikibase\Lib\Store\EntityLookup;
@@ -43,6 +44,11 @@
         * @var EntityTitleLookup|null
         */
        private $entityTitleLookup;
+
+       /**
+        * @var LabelLookup
+        */
+       private $labelLookup;
 
        /**
         * This determines which value is formatted how by providing a 
formatter mapping
@@ -114,10 +120,12 @@
        public function __construct(
                EntityLookup $entityLookup,
                Language $defaultLanguage,
+               LabelLookup $labelLookup = null,
                EntityTitleLookup $entityTitleLookup = null
        ) {
                $this->entityLookup = $entityLookup;
                $this->defaultLanguage = $defaultLanguage;
+               $this->labelLookup = $labelLookup;
                $this->entityTitleLookup = $entityTitleLookup;
        }
 
@@ -543,8 +551,7 @@
                FormatterOptions $options,
                WikibaseValueFormatterBuilders $builders
        ) {
-               $labelLookup = self::newLabelLookup( $options, $builders );
-               return new EntityIdLabelFormatter( $options, $labelLookup );
+               return new EntityIdLabelFormatter( $options, 
$builders->labelLookup );
        }
 
        /**
@@ -562,7 +569,7 @@
        ) {
                return new EntityIdHtmlLinkFormatter(
                        $options,
-                       self::newLabelLookup( $options, $builders ),
+                       $builders->labelLookup,
                        $builders->entityTitleLookup
                );
        }
diff --git 
a/lib/tests/phpunit/formatters/OutputFormatSnakFormatterFactoryTest.php 
b/lib/tests/phpunit/formatters/OutputFormatSnakFormatterFactoryTest.php
index 85dab6b..b3efa13 100644
--- a/lib/tests/phpunit/formatters/OutputFormatSnakFormatterFactoryTest.php
+++ b/lib/tests/phpunit/formatters/OutputFormatSnakFormatterFactoryTest.php
@@ -2,9 +2,13 @@
 
 namespace Wikibase\Lib\Test;
 
+use Language;
 use ValueFormatters\FormatterOptions;
 use ValueFormatters\StringFormatter;
+use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\Lib\OutputFormatSnakFormatterFactory;
+use Wikibase\Lib\WikibaseValueFormatterBuilders;
 
 /**
  * @covers Wikibase\Lib\OutputFormatSnakFormatterFactory
@@ -20,30 +24,54 @@
 class OutputFormatSnakFormatterFactoryTest extends \PHPUnit_Framework_TestCase 
{
 
        /**
-        * @dataProvider constructorErrorsProvider
+        * @dataProvider getSnakFormatterProvider
         */
-       public function testConstructorErrors( $builder, $error ) {
-               $this->setExpectedException( $error );
+       public function testGetSnakFormatter( $builders, $format ) {
+               $factory = new OutputFormatSnakFormatterFactory(
+                       $this->getWikibaseSnakFormatterBuilders( $builders )
+               );
 
-               $typeLookup = $this->getMock( 
'Wikibase\DataModel\Entity\PropertyDataTypeLookup' );
-               $typeLookup->expects( $this->never() )->method( 
'getDataTypeIdForProperty' );
+               $valueFormatterBuilders = $this->getValueFormatterBuilders();
+               $formatter = $factory->getSnakFormatter(
+                       $format,
+                       $valueFormatterBuilders,
+                       new FormatterOptions()
+               );
 
-               new OutputFormatSnakFormatterFactory( $builder );
+               $this->assertInstanceOf( 'Wikibase\Lib\SnakFormatter', 
$formatter );
+               $this->assertEquals( $format, $formatter->getFormat() );
        }
 
-       public function constructorErrorsProvider() {
-               $stringFormatter = new StringFormatter( new FormatterOptions() 
);
+       public function getSnakFormatterProvider() {
+               $this_ = $this;
+
+               $builders = array(
+                       'foo' => function () use ( $this_ ) { return 
$this_->makeMockSnakFormatter( 'foo', 'FOO' ); },
+                       'bar' => function () use ( $this_ ) { return 
$this_->makeMockSnakFormatter( 'bar', 'BAR' ); },
+               );
 
                return array(
-                       'keys must be strings' => array(
-                               array( 17 => $stringFormatter ),
-                               'InvalidArgumentException'
+                       'foo' => array(
+                               $builders,
+                               'foo'
                        ),
-                       'builder must be callable' => array(
-                               array( 'foo' => 17 ),
-                               'InvalidArgumentException'
+                       'bar' => array(
+                               $builders,
+                               'bar'
                        ),
                );
+       }
+
+       private function getWikibaseSnakFormatterBuilders( array $builders ) {
+               $snakFormatterBuilders = $this->getMockBuilder( 
'Wikibase\Lib\WikibaseSnakFormatterBuilders' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $snakFormatterBuilders->expects( $this->any() )
+                       ->method( 'getSnakFormatterBuildersForFormats' )
+                       ->will( $this->returnValue( $builders ) );
+
+               return $snakFormatterBuilders;
        }
 
        public function makeMockSnakFormatter( $format, $value ) {
@@ -60,34 +88,39 @@
                return $mock;
        }
 
-       /**
-        * @dataProvider getSnakFormatterProvider
-        */
-       public function testGetSnakFormatter( $builders, $format ) {
-               $factory = new OutputFormatSnakFormatterFactory( $builders );
-               $formatter = $factory->getSnakFormatter( $format, new 
FormatterOptions() );
-
-               $this->assertInstanceOf( 'Wikibase\Lib\SnakFormatter', 
$formatter );
-               $this->assertEquals( $format, $formatter->getFormat() );
+       private function getValueFormatterBuilders() {
+               return new WikibaseValueFormatterBuilders(
+                       $this->getEntityLookup(),
+                       Language::factory( 'en' ),
+                       $this->getLabelLookup()
+               );
        }
 
-       public function getSnakFormatterProvider() {
-               $this_ = $this;
-               $builders = array(
-                       'foo' => function () use ( $this_ ) { return 
$this_->makeMockSnakFormatter( 'foo', 'FOO' ); },
-                       'bar' => function () use ( $this_ ) { return 
$this_->makeMockSnakFormatter( 'bar', 'BAR' ); },
-               );
+       private function getEntityLookup() {
+               $itemId = new ItemId( 'Q5' );
 
-               return array(
-                       'foo' => array(
-                               $builders,
-                               'foo'
-                       ),
-                       'bar' => array(
-                               $builders,
-                               'bar'
-                       ),
-               );
+               $item = Item::newEmpty();
+               $item->setId( $itemId );
+               $item->setLabel( 'en', 'Label for ' . 
$itemId->getSerialization() );
+
+               $entityLookup = $this->getMock( 
'Wikibase\Lib\Store\EntityLookup' );
+               $entityLookup->expects( $this->any() )
+                       ->method( 'getEntity' )
+                       ->will( $this->returnValue( $item ) );
+
+               return $entityLookup;
+       }
+
+       private function getLabelLookup() {
+               $labelLookup = $this->getMockBuilder( 
'Wikibase\Lib\Store\LabelLookup' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $labelLookup->expects( $this->any() )
+                       ->method( 'getLabel' )
+                       ->will( $this->returnValue( 'Label for Q5' ) );
+
+               return $labelLookup;
        }
 
 }
diff --git a/lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php 
b/lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php
index 073e35d..b01143d 100644
--- a/lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php
+++ b/lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php
@@ -13,7 +13,6 @@
 use Wikibase\DataModel\Snak\PropertyNoValueSnak;
 use Wikibase\DataModel\Snak\PropertyValueSnak;
 use Wikibase\EntityFactory;
-use Wikibase\Lib\OutputFormatSnakFormatterFactory;
 use Wikibase\Lib\SnakFormatter;
 use Wikibase\Lib\WikibaseSnakFormatterBuilders;
 use Wikibase\Lib\WikibaseValueFormatterBuilders;
@@ -33,30 +32,17 @@
 
        /**
         * @param string $propertyType The property data type to use for all 
properties.
-        * @param EntityId $entityId   The Id of an entity to use for all 
entity lookups
         *
         * @return WikibaseSnakFormatterBuilders
         */
-       public function newBuilders( $propertyType, EntityId $entityId ) {
-               $typeLookup = $this->getMock( 
'Wikibase\DataModel\Entity\PropertyDataTypeLookup' );
-               $typeLookup->expects( $this->any() )
-                       ->method( 'getDataTypeIdForProperty' )
-                       ->will( $this->returnValue( $propertyType ) );
-
-               $typeMap = array(
-                       'url' => 'string',
-                       'string' => 'string',
-                       'wikibase-item' => 'wikibase-entityid',
-                       'globecoordinate' => 'globecoordinate',
+       public function newBuilders( $propertyType ) {
+               return new WikibaseSnakFormatterBuilders(
+                       $this->getPropertyDataTypeLookup( $propertyType ),
+                       $this->getDataTypeFactory()
                );
+       }
 
-               $typeFactory = $this->getMock( 'DataTypes\DataTypeFactory' );
-               $typeFactory->expects( $this->any() )
-                       ->method( 'getType' )
-                       ->will( $this->returnCallback( function ( $id ) use ( 
$typeMap ) {
-                               return new DataType( $id, $typeMap[$id], 
array() );
-                       } ) );
-
+       private function getEntityLookup( EntityId $entityId ) {
                $entity = EntityFactory::singleton()->newEmpty( 
$entityId->getEntityType() );
                $entity->setId( $entityId );
                $entity->setLabel( 'en', 'Label for ' . 
$entityId->getSerialization() );
@@ -66,14 +52,58 @@
                        ->method( 'getEntity' )
                        ->will( $this->returnValue( $entity ) );
 
-               $lang = Language::factory( 'en' );
+               return $entityLookup;
+       }
 
-               $valueFormatterBuilders = new WikibaseValueFormatterBuilders( 
$entityLookup, $lang );
-               return new WikibaseSnakFormatterBuilders( 
$valueFormatterBuilders, $typeLookup, $typeFactory );
+       private function getPropertyDataTypeLookup( $propertyType ) {
+               $propertyDataTypeLookup = $this->getMock( 
'Wikibase\DataModel\Entity\PropertyDataTypeLookup' );
+               $propertyDataTypeLookup->expects( $this->any() )
+                       ->method( 'getDataTypeIdForProperty' )
+                       ->will( $this->returnValue( $propertyType ) );
+
+               return $propertyDataTypeLookup;
+       }
+
+       private function getDataTypeFactory() {
+               $typeMap = array(
+                       'url' => 'string',
+                       'string' => 'string',
+                       'wikibase-item' => 'wikibase-entityid',
+                       'globecoordinate' => 'globecoordinate',
+               );
+
+               $dataTypeFactory = $this->getMock( 'DataTypes\DataTypeFactory' 
);
+               $dataTypeFactory->expects( $this->any() )
+                       ->method( 'getType' )
+                       ->will( $this->returnCallback( function ( $id ) use ( 
$typeMap ) {
+                               return new DataType( $id, $typeMap[$id], 
array() );
+                       } ) );
+
+               return $dataTypeFactory;
+       }
+
+       private function getValueFormatterBuilders( EntityId $entityId ) {
+               return new WikibaseValueFormatterBuilders(
+                       $this->getEntityLookup( $entityId ),
+                       Language::factory( 'en' ),
+                       $this->getLabelLookup()
+               );
+       }
+
+       private function getLabelLookup() {
+               $labelLookup = $this->getMockBuilder( 
'Wikibase\Lib\Store\LabelLookup' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $labelLookup->expects( $this->any() )
+                       ->method( 'getLabel' )
+                       ->will( $this->returnValue( 'Label for Q5' ) );
+
+               return $labelLookup;
        }
 
        public function testGetSnakFormatterBuildersForFormats() {
-               $builders = $this->newBuilders( 'string', new ItemId( 'Q5' ) );
+               $builders = $this->newBuilders( 'string' );
 
                $buildersForFormats = 
$builders->getSnakFormatterBuildersForFormats();
 
@@ -97,12 +127,11 @@
         * @dataProvider buildDispatchingSnakFormatterProvider
         */
        public function testBuildDispatchingSnakFormatter( $format, $options, 
$type, $snak, $expected ) {
-               $builders = $this->newBuilders( $type, new ItemId( 'Q5' ) );
-               $factory = new OutputFormatSnakFormatterFactory( 
$builders->getSnakFormatterBuildersForFormats() );
+               $builders = $this->newBuilders( $type );
 
                $formatter = $builders->buildDispatchingSnakFormatter(
-                       $factory,
                        $format,
+                       $this->getValueFormatterBuilders( new ItemId( 'Q5' ) ),
                        $options
                );
 
diff --git 
a/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php 
b/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
index fca38bf..2a76468 100644
--- a/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
+++ b/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php
@@ -42,9 +42,9 @@
 
        /**
         * @param EntityId $entityId The Id of an entity to use for all entity 
lookups
-        * @return WikibaseValueFormatterBuilders
+        * @return EntityLookup
         */
-       private function newWikibaseValueFormatterBuilders( EntityId $entityId 
) {
+       private function getEntityLookup( EntityId $entityId ) {
                $entity = EntityFactory::singleton()->newEmpty( 
$entityId->getEntityType() );
                $entity->setId( $entityId );
                $entity->setLabel( 'en', 'Label for ' . 
$entityId->getSerialization() );
@@ -54,7 +54,34 @@
                        ->method( 'getEntity' )
                        ->will( $this->returnValue( $entity ) );
 
-               return new WikibaseValueFormatterBuilders( $entityLookup, 
Language::factory( 'en' ) );
+               return $entityLookup;
+       }
+
+       /**
+        * @param EntityId $entityId The Id of an entity to use for all entity 
lookups
+        * @return WikibaseValueFormatterBuilders
+        */
+       private function newWikibaseValueFormatterBuilders( EntityId $entityId 
) {
+               return new WikibaseValueFormatterBuilders(
+                       $this->getEntityLookup( $entityId ),
+                       Language::factory( 'en' ),
+                       $this->getLabelLookup()
+               );
+       }
+
+       /**
+        * @return LabelLookup
+        */
+       private function getLabelLookup() {
+               $labelLookup = $this->getMockBuilder( 
'Wikibase\Lib\Store\LabelLookup' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $labelLookup->expects( $this->any() )
+                       ->method( 'getLabel' )
+                       ->will( $this->returnValue( 'Label for Q5' ) );
+
+               return $labelLookup;
        }
 
        private function newFormatterOptions( $lang = 'en' ) {
diff --git a/repo/includes/Diff/EntityContentDiffView.php 
b/repo/includes/Diff/EntityContentDiffView.php
index 6ba4dfb..22006df 100644
--- a/repo/includes/Diff/EntityContentDiffView.php
+++ b/repo/includes/Diff/EntityContentDiffView.php
@@ -86,8 +86,19 @@
                $this->propertyNameFormatter = new EscapingValueFormatter( 
$labelFormatter, 'htmlspecialchars' );
 
                $formatterFactory = $wikibaseRepo->getSnakFormatterFactory();
-               $this->detailedSnakFormatter = 
$formatterFactory->getSnakFormatter( SnakFormatter::FORMAT_HTML_DIFF, $options 
);
-               $this->terseSnakFormatter = 
$formatterFactory->getSnakFormatter( SnakFormatter::FORMAT_HTML, $options );
+               $valueFormatterBuilders = 
$wikibaseRepo->getValueFormatterBuilders();
+
+               $this->detailedSnakFormatter = 
$formatterFactory->getSnakFormatter(
+                       SnakFormatter::FORMAT_HTML_DIFF,
+                       $valueFormatterBuilders,
+                       $options
+               );
+
+               $this->terseSnakFormatter = $formatterFactory->getSnakFormatter(
+                       SnakFormatter::FORMAT_HTML,
+                       $valueFormatterBuilders,
+                       $options
+               );
 
                // @fixme inject!
                $this->diffVisualizer = new EntityDiffVisualizer(
diff --git a/repo/includes/EntityParserOutputGenerator.php 
b/repo/includes/EntityParserOutputGenerator.php
index 447484b..2a0e5f7 100644
--- a/repo/includes/EntityParserOutputGenerator.php
+++ b/repo/includes/EntityParserOutputGenerator.php
@@ -2,14 +2,25 @@
 
 namespace Wikibase;
 
+use Language;
 use ParserOutput;
+use ValueFormatters\FormatterOptions;
+use ValueFormatters\ValueFormatter;
 use Wikibase\DataModel\Entity\Entity;
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\Property;
 use Wikibase\DataModel\Entity\PropertyDataTypeLookup;
 use Wikibase\DataModel\SiteLinkList;
+use Wikibase\LanguageFallbackChain;
 use Wikibase\Lib\Serializers\SerializationOptions;
 use Wikibase\Lib\Store\EntityInfoBuilderFactory;
+use Wikibase\Lib\Store\EntityLookup;
+use Wikibase\Lib\Store\EntityRetrievingTermLookup;
 use Wikibase\Lib\Store\EntityTitleLookup;
+use Wikibase\Lib\Store\LanguageLabelLookup;
+use Wikibase\Lib\WikibaseValueFormatterBuilders;
+use Wikibase\Repo\View\EntityViewFactory;
 
 /**
  * Creates the parser output for an entity.
@@ -21,13 +32,14 @@
  *
  * @license GNU GPL v2+
  * @author Bene* < [email protected] >
+ * @author Katie Filbert < [email protected] >
  */
 class EntityParserOutputGenerator {
 
        /**
-        * @var EntityView
+        * @var EntityViewFactory
         */
-       private $entityView;
+       private $entityViewFactory;
 
        /**
         * @var ParserOutputJsConfigBuilder
@@ -35,24 +47,24 @@
        private $configBuilder;
 
        /**
-        * @var SerializationOptions
-        */
-       private $serializationOptions;
-
-       /**
         * @var EntityTitleLookup
         */
        private $entityTitleLookup;
 
        /**
-        * @var PropertyDataTypeLookup
+        * @var ValuesFinder
         */
-       private $dataTypeLookup;
+       private $valuesFinder;
 
        /**
         * @var EntityInfoBuilderFactory
         */
        private $entityInfoBuilderFactory;
+
+       /**
+        * @var LanguageFallbackChain
+        */
+       private $languageFallbackChain;
 
        /**
         * @var string
@@ -65,20 +77,20 @@
        private $referencedEntitiesFinder;
 
        public function __construct(
-               EntityView $entityView,
+               EntityViewFactory $entityViewFactory,
                ParserOutputJsConfigBuilder $configBuilder,
-               SerializationOptions $serializationOptions,
                EntityTitleLookup $entityTitleLookup,
-               PropertyDataTypeLookup $dataTypeLookup,
+               ValuesFinder $valuesFinder,
                EntityInfoBuilderFactory $entityInfoBuilderFactory,
+               LanguageFallbackChain $languageFallbackChain,
                $languageCode
        ) {
-               $this->entityView = $entityView;
+               $this->entityViewFactory = $entityViewFactory;
                $this->configBuilder = $configBuilder;
-               $this->serializationOptions = $serializationOptions;
                $this->entityTitleLookup = $entityTitleLookup;
-               $this->dataTypeLookup = $dataTypeLookup;
+               $this->valuesFinder = $valuesFinder;
                $this->entityInfoBuilderFactory = $entityInfoBuilderFactory;
+               $this->languageFallbackChain = $languageFallbackChain;
                $this->languageCode = $languageCode;
 
                $this->referencedEntitiesFinder = new 
ReferencedEntitiesFinder();
@@ -95,71 +107,88 @@
         *
         * @return ParserOutput
         */
-       public function getParserOutput( EntityRevision $entityRevision, 
$editable = true, $generateHtml = true ) {
-               $pout = new ParserOutput();
+       public function getParserOutput( EntityRevision $entityRevision, 
$editable = true,
+               $generateHtml = true
+       ) {
+               $parserOutput = new ParserOutput();
 
-               $entity =  $entityRevision->getEntity();
+               $entity = $entityRevision->getEntity();
                $snaks = $entity->getAllSnaks();
 
-               $referencedEntityIds = 
$this->referencedEntitiesFinder->findSnakLinks( $snaks );
-               $entityInfo = $this->getEntityInfo( $referencedEntityIds );
+               $usedEntityIds = 
$this->referencedEntitiesFinder->findSnakLinks( $snaks );
+               $entityInfo = $this->getEntityInfo( $usedEntityIds );
 
-               $configVars = $this->configBuilder->build(
-                       $entity,
-                       $entityInfo,
-                       $this->serializationOptions
-               );
+               $configVars = $this->configBuilder->build( $entity, $entityInfo 
);
+               $parserOutput->addJsConfigVars( $configVars );
 
-               $pout->addJsConfigVars( $configVars );
-
-               $this->addSnaksToParserOutput( $pout, $referencedEntityIds, 
$snaks );
+               $this->addLinksToParserOutput( $parserOutput, $usedEntityIds, 
$snaks );
 
                if ( $entity instanceof Item ) {
-                       $this->addBadgesToParserOutput( $pout, 
$entity->getSiteLinkList() );
+                       $this->addBadgesToParserOutput( $parserOutput, 
$entity->getSiteLinkList() );
                }
 
                if ( $generateHtml ) {
-                       $this->addHtmlToParserOutput( $pout, $entityRevision, 
$editable );
+                       $this->addHtmlToParserOutput(
+                               $parserOutput,
+                               $entityRevision,
+                               $usedEntityIds,
+                               $editable
+                       );
                }
 
                //@todo: record sitelinks as iwlinks
                //@todo: record CommonsMedia values as imagelinks
 
-               $this->addModules( $pout, $editable );
+               $this->addModules( $parserOutput, $editable );
 
                //FIXME: some places, like Special:NewItem, don't want to 
override the page title.
                //       But we still want to use OutputPage::addParserOutput 
to apply the modules etc from the ParserOutput.
                //       So, for now, we leave it to the caller to override the 
display title, if desired.
                // set the display title
-               //$pout->setTitleText( $entity>getLabel( $langCode ) );
+               //$parserOutput->setTitleText( $entity>getLabel( $langCode ) );
 
-               return $pout;
+               return $parserOutput;
        }
 
-       private function addSnaksToParserOutput( ParserOutput $pout, array 
$usedEntityIds, array $snaks ) {
-               foreach ( $usedEntityIds as $entityId ) {
-                       $pout->addLink( 
$this->entityTitleLookup->getTitleForId( $entityId ) );
+       private function addLinksToParserOutput( ParserOutput $parserOutput, 
array $usedEntityIds,
+               array $snaks
+       ) {
+               $this->addEntityLinksToParserOutput( $parserOutput, 
$usedEntityIds );
+               $this->addExternalLinksToParserOutput( $parserOutput, $snaks );
+               $this->addImageLinksToParserOutput( $parserOutput, $snaks );
+       }
+
+       private function addEntityLinksToParserOutput( ParserOutput 
$parserOutput, array $entityIds ) {
+               foreach ( $entityIds as $entityId ) {
+                       $parserOutput->addLink( 
$this->entityTitleLookup->getTitleForId( $entityId ) );
                }
+       }
 
-               $valuesFinder = new ValuesFinder( $this->dataTypeLookup );
-
+       private function addExternalLinksToParserOutput( ParserOutput 
$parserOutput, array $snaks ) {
                // treat URL values as external links ------
-               $usedUrls = $valuesFinder->findFromSnaks( $snaks, 'url' );
+               $usedUrls = $this->valuesFinder->findFromSnaks( $snaks, 'url' );
 
                foreach ( $usedUrls as $url ) {
                        $value = $url->getValue();
                        if ( is_string( $value ) ) {
-                               $pout->addExternalLink( $value );
+                               $parserOutput->addExternalLink( $value );
                        }
                }
+       }
 
-               // treat CommonsMedia values as file transclusions ------
-               $usedImages = $valuesFinder->findFromSnaks( $snaks, 
'commonsMedia' );
+       /**
+        * Treat CommonsMedia values as file transclusions
+        *
+        * @param ParserOutput $parserOutput
+        * @param array $snaks
+        */
+       private function addImageLinksToParserOutput( ParserOutput 
$parserOutput, array $snaks ) {
+               $usedImages = $this->valuesFinder->findFromSnaks( $snaks, 
'commonsMedia' );
 
                foreach ( $usedImages as $image ) {
                        $value = $image->getValue();
                        if ( is_string( $value ) ) {
-                               $pout->addImage( str_replace( ' ', '_', $value 
) );
+                               $parserOutput->addImage( str_replace( ' ', '_', 
$value ) );
                        }
                }
        }
@@ -195,23 +224,53 @@
                return $entityInfo;
        }
 
-       private function addBadgesToParserOutput( ParserOutput $pout, 
SiteLinkList $siteLinkList ) {
+       private function getEntityInfoForView( array $entityIds ) {
+               $propertyIds = array_filter( $entityIds, function ( EntityId 
$id ) {
+                       return $id->getEntityType() === Property::ENTITY_TYPE;
+               } );
+
+               $entityInfoBuilder = 
$this->entityInfoBuilderFactory->newEntityInfoBuilder( $propertyIds );
+
+               $entityInfoBuilder->removeMissing();
+
+               $entityInfoBuilder->collectTerms(
+                       array( 'label', 'description' ),
+                       array( $this->languageCode )
+               );
+
+               return $entityInfoBuilder->getEntityInfo();
+       }
+
+       private function addBadgesToParserOutput( ParserOutput $parserOutput, 
SiteLinkList $siteLinkList ) {
                foreach ( $siteLinkList as $siteLink ) {
                        foreach ( $siteLink->getBadges() as $badge ) {
-                               $pout->addLink( 
$this->entityTitleLookup->getTitleForId( $badge ) );
+                               $parserOutput->addLink( 
$this->entityTitleLookup->getTitleForId( $badge ) );
                        }
                }
        }
 
-       private function addHtmlToParserOutput( ParserOutput $pout, 
EntityRevision $entityRevision, $editable ) {
-               $html = $this->entityView->getHtml( $entityRevision, $editable 
);
-               $pout->setText( $html );
-               $pout->setExtensionData( 'wikibase-view-chunks', 
$this->entityView->getPlaceholders() );
+       private function addHtmlToParserOutput(
+               ParserOutput $parserOutput,
+               EntityRevision $entityRevision,
+               array $entityIds,
+               $editable
+       ) {
+               $entityView = $this->entityViewFactory->newEntityView(
+                       $this->languageFallbackChain,
+                       $this->languageCode,
+                       $entityRevision->getEntity()->getType()
+               );
+
+               $entityInfo = $this->getEntityInfoForView( $entityIds );
+
+               $html = $entityView->getHtml( $entityRevision, $entityInfo, 
$editable );
+               $parserOutput->setText( $html );
+               $parserOutput->setExtensionData( 'wikibase-view-chunks', 
$entityView->getPlaceholders() );
        }
 
-       private function addModules( ParserOutput $pout, $editable ) {
+       private function addModules( ParserOutput $parserOutput, $editable ) {
                // make css available for JavaScript-less browsers
-               $pout->addModuleStyles( array(
+               $parserOutput->addModuleStyles( array(
                        'wikibase.common',
                        'wikibase.toc',
                        'jquery.ui.core',
@@ -221,7 +280,7 @@
 
                if ( $editable ) {
                        // make sure required client sided resources will be 
loaded:
-                       $pout->addModules( 'wikibase.ui.entityViewInit' );
+                       $parserOutput->addModules( 'wikibase.ui.entityViewInit' 
);
                }
        }
 
diff --git a/repo/includes/EntityParserOutputGeneratorFactory.php 
b/repo/includes/EntityParserOutputGeneratorFactory.php
index e865e60..1efa6cc 100644
--- a/repo/includes/EntityParserOutputGeneratorFactory.php
+++ b/repo/includes/EntityParserOutputGeneratorFactory.php
@@ -3,27 +3,19 @@
 namespace Wikibase;
 
 use InvalidArgumentException;
-use Language;
 use ParserOptions;
 use ParserOutput;
 use RequestContext;
 use User;
-use ValueFormatters\FormatterOptions;
-use ValueFormatters\ValueFormatter;
 use Wikibase\DataModel\Entity\Entity;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\EntityIdParser;
-use Wikibase\DataModel\Entity\PropertyDataTypeLookup;
 use Wikibase\LanguageFallbackChainFactory;
-use Wikibase\Lib\OutputFormatSnakFormatterFactory;
 use Wikibase\Lib\Serializers\SerializationOptions;
-use Wikibase\Lib\SnakFormatter;
 use Wikibase\Lib\Store\EntityInfoBuilderFactory;
+use Wikibase\Lib\Store\EntityLookup;
 use Wikibase\Lib\Store\EntityTitleLookup;
-use Wikibase\Repo\View\ClaimsView;
-use Wikibase\Repo\View\FingerprintView;
-use Wikibase\Repo\View\SectionEditLinkGenerator;
-use Wikibase\Repo\View\SnakHtmlGenerator;
+use Wikibase\Repo\View\EntityViewFactory;
 use Wikibase\Repo\WikibaseRepo;
 
 /**
@@ -35,9 +27,9 @@
 class EntityParserOutputGeneratorFactory {
 
        /**
-        * @var OutputFormatSnakFormatterFactory
+        * @var EntityViewFactory
         */
-       private $snakFormatterFactory;
+       private $entityViewFactory;
 
        /**
         * @var EntityInfoBuilderFactory
@@ -55,82 +47,49 @@
        private $entityIdParser;
 
        /**
-        * @var PropertyDataTypeLookup
+        * @var ValuesFinder
         */
-       private $propertyDataTypeLookup;
+       private $valuesFinder;
 
        /**
         * @var LanguageFallbackChainFactory
         */
        private $languageFallbackChainFactory;
 
-       /**
-        * @var ReferencedEntitiesFinder
-        */
-       private $referencedEntitiesFinder;
-
-       /**
-        * @var SectionEditLinkGenerator
-        */
-       private $sectionEditLinkGenerator;
-
        public function __construct(
-               OutputFormatSnakFormatterFactory $snakFormatterFactory,
+               EntityViewFactory $entityViewFactory,
                EntityInfoBuilderFactory $entityInfoBuilderFactory,
                EntityTitleLookup $entityTitleLookup,
                EntityIdParser $entityIdParser,
-               PropertyDataTypeLookup $propertyDataTypeLookup,
-               LanguageFallbackChainFactory $languageFallbackChainFactory,
-               ReferencedEntitiesFinder $referencedEntitiesFinder
+               ValuesFinder $valuesFinder,
+               LanguageFallbackChainFactory $languageFallbackChainFactory
        ) {
-               $this->snakFormatterFactory = $snakFormatterFactory;
+               $this->entityViewFactory = $entityViewFactory;
                $this->entityInfoBuilderFactory = $entityInfoBuilderFactory;
                $this->entityTitleLookup = $entityTitleLookup;
                $this->entityIdParser = $entityIdParser;
-               $this->propertyDataTypeLookup = $propertyDataTypeLookup;
+               $this->valuesFinder = $valuesFinder;
                $this->languageFallbackChainFactory = 
$languageFallbackChainFactory;
-               $this->referencedEntitiesFinder = $referencedEntitiesFinder;
-               $this->sectionEditLinkGenerator = new 
SectionEditLinkGenerator();
        }
 
        /**
         * Creates an EntityParserOutputGenerator to create the ParserOutput 
for the entity
         *
-        * @param EntityRevision $entityRevision
         * @param ParserOptions|null $options
         *
         * @return EntityParserOutputGenerator
         */
-       public function getEntityParserOutputGenerator( $entityType, 
ParserOptions $options = null ) {
+       public function getEntityParserOutputGenerator( ParserOptions $options 
= null ) {
                $languageCode = $this->getLanguageCode( $options );
 
                return new EntityParserOutputGenerator(
-                       $this->newEntityView( $entityType, $languageCode ),
+                       $this->entityViewFactory,
                        $this->newParserOutputJsConfigBuilder( $languageCode ),
-                       $this->makeSerializationOptions( $languageCode ),
                        $this->entityTitleLookup,
-                       $this->propertyDataTypeLookup,
+                       $this->valuesFinder,
                        $this->entityInfoBuilderFactory,
+                       $this->getLanguageFallbackChain( $languageCode ),
                        $languageCode
-               );
-       }
-
-       /**
-        * @param string $languageCode
-        *
-        * @return SnakFormatter
-        */
-       private function getSnakFormatter( $languageCode ) {
-               $formatterOptions = new FormatterOptions();
-               $formatterOptions->setOption( ValueFormatter::OPT_LANG, 
$languageCode );
-
-               // @fixme don't get fallback chain twice and it's also probably 
not needed here.
-               $languageFallbackChain = $this->getLanguageFallbackChain( 
$languageCode );
-               $formatterOptions->setOption( 'languages', 
$languageFallbackChain );
-
-               return $this->snakFormatterFactory->getSnakFormatter(
-                       SnakFormatter::FORMAT_HTML_WIDGET,
-                       $formatterOptions
                );
        }
 
@@ -143,7 +102,7 @@
                return new ParserOutputJsConfigBuilder(
                        $this->entityIdParser,
                        $this->entityTitleLookup,
-                       $languageCode
+                       $this->makeSerializationOptions( $languageCode )
                );
        }
 
@@ -164,70 +123,6 @@
                }
 
                return $languageCode;
-       }
-
-       /**
-        * @param string $languageCode
-        *
-        * @return ClaimsView
-        */
-       private function newClaimsView( $languageCode ) {
-               // @fixme SnakFormatterFactory needs to be injected into 
ClaimsView,
-               // and also the entity info records via a TermLookup or such.
-               $snakHtmlGenerator = new SnakHtmlGenerator(
-                       $this->getSnakFormatter( $languageCode ),
-                       $this->entityTitleLookup
-               );
-
-               $claimHtmlGenerator = new ClaimHtmlGenerator(
-                       $snakHtmlGenerator,
-                       $this->entityTitleLookup
-               );
-
-               return new ClaimsView(
-                       $this->entityInfoBuilderFactory,
-                       $this->entityTitleLookup,
-                       $this->sectionEditLinkGenerator,
-                       $claimHtmlGenerator,
-                       $languageCode
-               );
-       }
-
-       /**
-        * @param string $languageCode
-        *
-        * @return FingerprintView
-        */
-       private function newFingerprintView( $languageCode ) {
-               return new FingerprintView(
-                       $this->sectionEditLinkGenerator,
-                       $languageCode
-               );
-       }
-
-       /**
-        * Creates an EntityView suitable for rendering the entity.
-        *
-        * @param EntityRevision $entityRevision
-        * @param string $languageCode
-        *
-        * @return EntityView
-        */
-       private function newEntityView( $entityType, $languageCode ) {
-               $fingerprintView = $this->newFingerprintView( $languageCode );
-               $claimsView = $this->newClaimsView( $languageCode );
-
-               // @fixme all that seems needed in EntityView is language code 
and dir.
-               $language = Language::factory( $languageCode );
-
-               // @fixme support more entity types
-               if ( $entityType === 'item' ) {
-                       return new ItemView( $fingerprintView, $claimsView, 
$language );
-               } elseif ( $entityType === 'property' ) {
-                       return new PropertyView( $fingerprintView, $claimsView, 
$language );
-               }
-
-               throw new InvalidArgumentException( 'No EntityView for entity 
type: ' . $entityType );
        }
 
        /**
diff --git a/repo/includes/EntityView.php b/repo/includes/EntityView.php
index 5fb3acf..4c50eda 100644
--- a/repo/includes/EntityView.php
+++ b/repo/includes/EntityView.php
@@ -85,7 +85,7 @@
         *
         * @return string HTML
         */
-       public function getHtml( EntityRevision $entityRevision, $editable = 
true ) {
+       public function getHtml( EntityRevision $entityRevision, array 
$entityInfo, $editable = true ) {
                $entity = $entityRevision->getEntity();
 
                //NOTE: even though $editable is unused at the moment, we will 
need it for the JS-less editing model.
@@ -97,7 +97,7 @@
                        $entityId,
                        $this->language->getCode(),
                        $this->language->getDir(),
-                       $this->getInnerHtml( $entityRevision, $editable )
+                       $this->getInnerHtml( $entityRevision, $entityInfo, 
$editable )
                );
 
                if ( $editable ) {
@@ -137,7 +137,9 @@
         * @throws InvalidArgumentException
         * @return string
         */
-       protected function getInnerHtml( EntityRevision $entityRevision, 
$editable = true ) {
+       protected function getInnerHtml( EntityRevision $entityRevision, array 
$entityInfo,
+               $editable = true
+       ) {
                wfProfileIn( __METHOD__ );
 
                $entity = $entityRevision->getEntity();
diff --git a/repo/includes/ItemView.php b/repo/includes/ItemView.php
index c9f8b9a..410247a 100644
--- a/repo/includes/ItemView.php
+++ b/repo/includes/ItemView.php
@@ -23,15 +23,22 @@
        /**
         * @see EntityView::getInnerHtml
         */
-       protected function getInnerHtml( EntityRevision $entityRevision, 
$editable = true ) {
+       protected function getInnerHtml( EntityRevision $entityRevision, array 
$entityInfo,
+               $editable = true
+       ) {
                $item = $entityRevision->getEntity();
 
                if ( !( $item instanceof Item ) ) {
                        throw new InvalidArgumentException( '$entityRevision 
must contain an Item.' );
                }
 
-               $html = parent::getInnerHtml( $entityRevision, $editable );
-               $html .= $this->claimsView->getHtml( $item->getClaims(), 
'wikibase-statements' );
+               $html = parent::getInnerHtml( $entityRevision, $entityInfo, 
$editable );
+               $html .= $this->claimsView->getHtml(
+                       $item->getClaims(),
+                       $entityInfo,
+                       'wikibase-statements'
+               );
+
                $html .= $this->getHtmlForSiteLinks( $item, $editable );
 
                return $html;
diff --git a/repo/includes/ParserOutputJsConfigBuilder.php 
b/repo/includes/ParserOutputJsConfigBuilder.php
index b7d8f3b..f48f6ad 100644
--- a/repo/includes/ParserOutputJsConfigBuilder.php
+++ b/repo/includes/ParserOutputJsConfigBuilder.php
@@ -26,48 +26,46 @@
        /**
         * @var EntityIdParser
         */
-       protected $entityIdParser;
+       private $entityIdParser;
 
        /**
         * @var EntityTitleLookup
         */
-       protected $entityTitleLookup;
+       private $entityTitleLookup;
 
        /**
-        * @var string
+        * @var SerializationOptions
         */
-       protected $langCode;
+       private $serializationOptions;
 
        /**
         * @var SerializerFactory
         */
-       protected $serializerFactory;
+       private $serializerFactory;
 
        /**
         * @param EntityIdParser $entityIdParser
         * @param EntityTitleLookup $entityTitleLookup
-        * @param string $langCode
+        * @param SerializationOptions $serializationOptions
         */
        public function __construct(
                EntityIdParser $entityIdParser,
                EntityTitleLookup $entityTitleLookup,
-               $langCode
+               SerializationOptions $serializationOptions
        ) {
                $this->entityIdParser = $entityIdParser;
                $this->entityTitleLookup = $entityTitleLookup;
-               $this->langCode = $langCode;
-
+               $this->serializationOptions = $serializationOptions;
                $this->serializerFactory = new SerializerFactory();
        }
 
        /**
         * @param Entity $entity
         * @param array $entityInfo
-        * @param SerializationOptions $options
         *
         * @return array
         */
-       public function build( Entity $entity, array $entityInfo, 
SerializationOptions $options ) {
+       public function build( Entity $entity, array $entityInfo ) {
                $entityId = $entity->getId();
 
                if ( !$entityId ) {
@@ -81,7 +79,7 @@
                $configVars = array(
                        'wbEntityId' => $entityId,
                        'wbUsedEntities' => FormatJson::encode( $revisionInfo ),
-                       'wbEntity' => FormatJson::encode( 
$this->getSerializedEntity( $entity, $options ) )
+                       'wbEntity' => FormatJson::encode( 
$this->getSerializedEntity( $entity ) )
                );
 
                return $configVars;
@@ -120,12 +118,15 @@
 
        /**
         * @param Entity $entity
-        * @param SerializationOptions $options
         *
         * @return string
         */
-       protected function getSerializedEntity( Entity $entity, 
SerializationOptions $options ) {
-               $serializer = $this->getEntitySerializer( $entity->getType(), 
$options );
+       protected function getSerializedEntity( Entity $entity ) {
+               $serializer = $this->getEntitySerializer(
+                       $entity->getType(),
+                       $this->serializationOptions
+               );
+
                return $serializer->getSerialized( $entity );
        }
 
diff --git a/repo/includes/PropertyView.php b/repo/includes/PropertyView.php
index 467700c..c259c7a 100644
--- a/repo/includes/PropertyView.php
+++ b/repo/includes/PropertyView.php
@@ -22,7 +22,9 @@
        /**
         * @see EntityView::getInnerHtml
         */
-       public function getInnerHtml( EntityRevision $entityRevision, $editable 
= true ) {
+       public function getInnerHtml( EntityRevision $entityRevision, array 
$entityInfo,
+               $editable = true
+       ) {
                wfProfileIn( __METHOD__ );
 
                $property = $entityRevision->getEntity();
@@ -31,11 +33,16 @@
                        throw new InvalidArgumentException( '$entityRevision 
must contain a Property.' );
                }
 
-               $html = parent::getInnerHtml( $entityRevision, $editable );
+               $html = parent::getInnerHtml( $entityRevision, $entityInfo, 
$editable );
                $html .= $this->getHtmlForDataType( $this->getDataType( 
$property ) );
 
                if ( defined( 'WB_EXPERIMENTAL_FEATURES' ) && 
WB_EXPERIMENTAL_FEATURES ) {
-                       $html .= $this->claimsView->getHtml( 
$property->getClaims(), 'wikibase-attributes' );
+                       // @fixme Property::getClaims no longer returns any 
statements for properties!
+                       $html .= $this->claimsView->getHtml(
+                               $property->getClaims(),
+                               $entityInfo,
+                               'wikibase-attributes'
+                       );
                }
 
                $footer = wfMessage( 'wikibase-property-footer' );
diff --git a/repo/includes/View/ClaimsView.php 
b/repo/includes/View/ClaimsView.php
index 9f577bb..6ba6369 100644
--- a/repo/includes/View/ClaimsView.php
+++ b/repo/includes/View/ClaimsView.php
@@ -23,11 +23,6 @@
 class ClaimsView {
 
        /**
-        * @var EntityInfoBuilderFactory
-        */
-       private $entityInfoBuilderFactory;
-
-       /**
         * @var EntityTitleLookup
         */
        private $entityTitleLookup;
@@ -48,20 +43,17 @@
        private $languageCode;
 
        /**
-        * @param EntityInfoBuilderFactory $entityInfoBuilderFactory
         * @param EnttiyTitleLookup $entityTitleLookup
         * @param SectionEditLinkGenerator $sectionEditLinkGenerator
         * @param ClaimHtmlGenerator $claimHtmlGenerator
         * @param string $languageCode
         */
        public function __construct(
-               EntityInfoBuilderFactory $entityInfoBuilderFactory,
                EntityTitleLookup $entityTitleLookup,
                SectionEditLinkGenerator $sectionEditLinkGenerator,
                ClaimHtmlGenerator $claimHtmlGenerator,
                $languageCode
        ) {
-               $this->entityInfoBuilderFactory = $entityInfoBuilderFactory;
                $this->entityTitleLookup = $entityTitleLookup;
                $this->sectionEditLinkGenerator = $sectionEditLinkGenerator;
                $this->claimHtmlGenerator = $claimHtmlGenerator;
@@ -74,13 +66,13 @@
         * @since 0.5
         *
         * @param Claim[] $claims the claims to render
+        * @param array $entityInfo
         * @param string $heading the message key of the heading
         * @return string
         */
-       public function getHtml( array $claims, $heading = 'wikibase-claims' ) {
+       public function getHtml( array $claims, array $entityInfo, $heading = 
'wikibase-claims' ) {
                // aggregate claims by properties
                $claimsByProperty = $this->groupClaimsByProperties( $claims );
-               $entityInfo = $this->getEntityInfo( $claims, 
$this->languageCode );
 
                $claimsHtml = '';
                foreach ( $claimsByProperty as $claims ) {
@@ -125,37 +117,6 @@
                        $claimsByProperty[$propertyId->getNumericId()][] = 
$claim;
                }
                return $claimsByProperty;
-       }
-
-       /**
-        * Fetches labels and descriptions for all entities used as properties 
in snaks in the given
-        * entity.
-        *
-        * @param Snak[] $claims
-        * @param string $languageCode the language code of the labels to fetch.
-        * @return array[] Entity info array that maps property IDs to labels 
and descriptions.
-        */
-       private function getEntityInfo( array $claims, $languageCode ) {
-               // TODO: Share cache with PropertyLabelResolver
-               // TODO: ... or share info with getBasicEntityInfo.
-
-               // TODO: Make a finder just for properties, so we don't have to 
filter.
-               $refFinder = new ReferencedEntitiesFinder();
-               $snaks = $this->getSnaksFromClaims( $claims );
-               $entityIds = $refFinder->findSnakLinks( $snaks );
-               $propertyIds = array_filter( $entityIds, function ( EntityId 
$id ) {
-                       return $id->getEntityType() === Property::ENTITY_TYPE;
-               } );
-
-               // NOTE: This is a bit hackish, it would be more appropriate to 
use a TermTable here.
-               $entityInfoBuilder = 
$this->entityInfoBuilderFactory->newEntityInfoBuilder( $propertyIds );
-               $entityInfoBuilder->removeMissing();
-               $entityInfoBuilder->collectTerms(
-                       array( 'label', 'description' ),
-                       array( $languageCode )
-               );
-
-               return $entityInfoBuilder->getEntityInfo();
        }
 
        /**
diff --git a/repo/includes/View/EntityViewFactory.php 
b/repo/includes/View/EntityViewFactory.php
new file mode 100644
index 0000000..0687734
--- /dev/null
+++ b/repo/includes/View/EntityViewFactory.php
@@ -0,0 +1,173 @@
+<?php
+
+namespace Wikibase\Repo\View;
+
+use InvalidArgumentException;
+use Language;
+use ValueFormatters\FormatterOptions;
+use ValueFormatters\ValueFormatter;
+use Wikibase\ClaimHtmlGenerator;
+use Wikibase\ItemView;
+use Wikibase\LanguageFallbackChain;
+use Wikibase\Lib\OutputFormatSnakFormatterFactory;
+use Wikibase\Lib\SnakFormatter;
+use Wikibase\Lib\Store\EntityInfoBuilderFactory;
+use Wikibase\Lib\Store\EntityLookup;
+use Wikibase\Lib\Store\EntityRetrievingTermLookup;
+use Wikibase\Lib\Store\EntityTitleLookup;
+use Wikibase\Lib\Store\LanguageLabelLookup;
+use Wikibase\Lib\WikibaseValueFormatterBuilders;
+use Wikibase\PropertyView;
+use Wikibase\Repo\View\ClaimsView;
+use Wikibase\Repo\View\FingerprintView;
+use Wikibase\Repo\View\SectionEditLinkGenerator;
+use Wikibase\Repo\View\SnakHtmlGenerator;
+
+/**
+ * @since 0.5
+ *
+ * @licence GNU GPL v2+
+ * @author Katie Filbert < [email protected] >
+ */
+class EntityViewFactory {
+
+       /**
+        * @var EntityTitleLookup
+        */
+       private $entityTitleLookup;
+
+       /**
+        * @var EntityLookup
+        */
+       private $entityLookup;
+
+       /**
+        * @var OutputFormatSnakFormatterFactory
+        */
+       private $snakFormatterFactory;
+
+       /**
+        * @var SectionEditLinkGenerator
+        */
+       private $sectionEditLinkGenerator;
+
+       public function __construct(
+               EntityTitleLookup $entityTitleLookup,
+               EntityLookup $entityLookup,
+               OutputFormatSnakFormatterFactory $snakFormatterFactory
+       ) {
+               $this->entityTitleLookup = $entityTitleLookup;
+               $this->entityLookup = $entityLookup;
+               $this->snakFormatterFactory = $snakFormatterFactory;
+               $this->sectionEditLinkGenerator = new 
SectionEditLinkGenerator();
+       }
+
+       /**
+        * Creates an EntityView suitable for rendering the entity.
+        *
+        * @param LanguageFallbackChain $fallbackChain
+        * @param string $languageCode
+        * @param string $entityType
+        *
+        * @return EntityView
+        */
+       public function newEntityView(
+               LanguageFallbackChain $fallbackChain,
+               $languageCode,
+               $entityType
+        ) {
+               $fingerprintView = $this->newFingerprintView( $languageCode );
+               $claimsView = $this->newClaimsView( $fallbackChain, 
$languageCode );
+
+               // @fixme all that seems needed in EntityView is language code 
and dir.
+               $language = Language::factory( $languageCode );
+
+               // @fixme support more entity types
+               if ( $entityType === 'item' ) {
+                       return new ItemView( $fingerprintView, $claimsView, 
$language );
+               } elseif ( $entityType === 'property' ) {
+                       return new PropertyView( $fingerprintView, $claimsView, 
$language );
+               }
+
+               throw new InvalidArgumentException( 'No EntityView for entity 
type: ' . $entityType );
+       }
+
+       /**
+        * @param LanguageFallbackChain $fallbackChain
+        * @param string $languageCode
+        *
+        * @return ClaimsView
+        */
+       private function newClaimsView(
+               LanguageFallbackChain $fallbackChain,
+               $languageCode
+       ) {
+               $snakHtmlGenerator = new SnakHtmlGenerator(
+                       $this->getSnakFormatter( $fallbackChain, $languageCode 
),
+                       $this->entityTitleLookup
+               );
+
+               $claimHtmlGenerator = new ClaimHtmlGenerator(
+                       $snakHtmlGenerator,
+                       $this->entityTitleLookup
+               );
+
+               return new ClaimsView(
+                       $this->entityTitleLookup,
+                       $this->sectionEditLinkGenerator,
+                       $claimHtmlGenerator,
+                       $languageCode
+               );
+       }
+
+       /**
+        * @param string $languageCode
+        *
+        * @return FingerprintView
+        */
+       private function newFingerprintView( $languageCode ) {
+               return new FingerprintView(
+                       $this->sectionEditLinkGenerator,
+                       $languageCode
+               );
+       }
+
+       /**
+        * @param LanguageFallbackChain $languageFallbackChain
+        * @param string $languageCode
+        *
+        * @return SnakFormatter
+        */
+       private function getSnakFormatter(
+               LanguageFallbackChain $languageFallbackChain,
+               $languageCode
+       ) {
+               $formatterOptions = new FormatterOptions();
+               $formatterOptions->setOption( ValueFormatter::OPT_LANG, 
$languageCode );
+               $formatterOptions->setOption( 'languages', 
$languageFallbackChain );
+
+               // @fixme use language fallback here
+               return $this->snakFormatterFactory->getSnakFormatter(
+                       SnakFormatter::FORMAT_HTML_WIDGET,
+                       $this->getValueFormatterBuilders( $languageCode ),
+                       $formatterOptions
+               );
+       }
+
+       /**
+        * @param string $languageCode
+        *
+        * @return WikibaseValueFormatterBuilders
+        */
+       private function getValueFormatterBuilders( $languageCode ) {
+               $termLookup = new EntityRetrievingTermLookup( 
$this->entityLookup );
+
+               return new WikibaseValueFormatterBuilders(
+                       $this->entityLookup,
+                       Language::factory( $languageCode ),
+                       new LanguageLabelLookup( $termLookup, $languageCode ),
+                       $this->entityTitleLookup
+               );
+       }
+
+}
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 654eee5..4ab4fd7 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -47,6 +47,8 @@
 use Wikibase\Lib\SnakFormatter;
 use Wikibase\Lib\Store\EntityContentDataCodec;
 use Wikibase\Lib\Store\EntityLookup;
+use Wikibase\Lib\Store\EntityRetrievingTermLookup;
+use Wikibase\Lib\Store\LanguageLabelLookup;
 use Wikibase\Lib\WikibaseDataTypeBuilders;
 use Wikibase\Lib\WikibaseSnakFormatterBuilders;
 use Wikibase\Lib\WikibaseValueFormatterBuilders;
@@ -63,6 +65,7 @@
 use Wikibase\Repo\Notifications\DatabaseChangeTransmitter;
 use Wikibase\Repo\Notifications\DummyChangeTransmitter;
 use Wikibase\Repo\Store\EntityPermissionChecker;
+use Wikibase\Repo\View\EntityViewFactory;
 use Wikibase\Settings;
 use Wikibase\SettingsArray;
 use Wikibase\SnakFactory;
@@ -75,6 +78,7 @@
 use Wikibase\Validators\SnakValidator;
 use Wikibase\Validators\TermValidatorFactory;
 use Wikibase\Validators\ValidatorErrorLocalizer;
+use Wikibase\ValuesFinder;
 
 /**
  * Top level factory for the WikibaseRepo extension.
@@ -480,9 +484,12 @@
        public function getValueFormatterBuilders() {
                global $wgContLang;
 
+               $termLookup = new EntityRetrievingTermLookup( 
$this->getEntityLookup() );
+
                return new WikibaseValueFormatterBuilders(
                        $this->getEntityLookup(),
                        $wgContLang,
+                       new LanguageLabelLookup( $termLookup, 
$wgContLang->getCode() ),
                        $this->getEntityTitleLookup()
                );
        }
@@ -491,15 +498,12 @@
         * @return OutputFormatSnakFormatterFactory
         */
        protected function newSnakFormatterFactory() {
-               $builders = new WikibaseSnakFormatterBuilders(
-                       $this->getValueFormatterBuilders(),
+               $snakFormatterBuilders = new WikibaseSnakFormatterBuilders(
                        $this->getPropertyDataTypeLookup(),
                        $this->getDataTypeFactory()
                );
 
-               $factory = new OutputFormatSnakFormatterFactory( 
$builders->getSnakFormatterBuildersForFormats() );
-
-               return $factory;
+               return new OutputFormatSnakFormatterFactory( 
$snakFormatterBuilders );
        }
 
        /**
@@ -579,29 +583,25 @@
 
                $valueFormatterBuilders = $this->getValueFormatterBuilders();
 
-               $snakFormatterBuilders = new WikibaseSnakFormatterBuilders(
-                       $valueFormatterBuilders,
-                       $this->getPropertyDataTypeLookup(),
-                       $this->getDataTypeFactory()
-               );
-
                $valueFormatterBuilders->setValueFormatter(
                        SnakFormatter::FORMAT_PLAIN,
                        'VT:wikibase-entityid',
                        $idFormatter
                );
 
-               $snakFormatterFactory = new OutputFormatSnakFormatterFactory(
-                       
$snakFormatterBuilders->getSnakFormatterBuildersForFormats()
+               $termLookup = new EntityRetrievingTermLookup( 
$this->getEntityLookup() );
+
+               $snakFormatterFactory = $this->getSnakFormatterFactory();
+               $snakFormatter = $snakFormatterFactory->getSnakFormatter(
+                       SnakFormatter::FORMAT_PLAIN,
+                       $valueFormatterBuilders,
+                       $options
                );
+
                $valueFormatterFactory = new OutputFormatValueFormatterFactory(
                        
$valueFormatterBuilders->getValueFormatterBuildersForFormats()
                );
 
-               $snakFormatter = $snakFormatterFactory->getSnakFormatter(
-                       SnakFormatter::FORMAT_PLAIN,
-                       $options
-               );
                $valueFormatter = $valueFormatterFactory->getValueFormatter(
                        SnakFormatter::FORMAT_PLAIN,
                        $options
@@ -616,16 +616,6 @@
                );
 
                return $formatter;
-       }
-
-       public function getParserOutputJsConfigBuilder( $langCode ) {
-               return new ParserOutputJsConfigBuilder(
-                       $this->getStore()->getEntityInfoBuilderFactory(),
-                       $this->getEntityIdParser(),
-                       $this->getEntityContentFactory(),
-                       new ReferencedEntitiesFinder(),
-                       $langCode
-               );
        }
 
        /**
@@ -949,14 +939,21 @@
         * @return EntityParserOutputGeneratorFactory
         */
        public function getEntityParserOutputGeneratorFactory() {
+               $entityTitleLookup = $this->getEntityContentFactory();
+
+               $entityViewFactory = new EntityViewFactory(
+                       $entityTitleLookup,
+                       $this->getEntityLookup(),
+                       $this->getSnakFormatterFactory()
+               );
+
                return new EntityParserOutputGeneratorFactory(
-                       $this->getSnakFormatterFactory(),
+                       $entityViewFactory,
                        $this->getStore()->getEntityInfoBuilderFactory(),
-                       $this->getEntityContentFactory(),
+                       $entityTitleLookup,
                        $this->getEntityIdParser(),
-                       $this->getPropertyDataTypeLookup(),
-                       $this->getLanguageFallbackChainFactory(),
-                       new ReferencedEntitiesFinder()
+                       new ValuesFinder( $this->getPropertyDataTypeLookup() ),
+                       $this->getLanguageFallbackChainFactory()
                );
        }
 
diff --git a/repo/includes/actions/EditEntityAction.php 
b/repo/includes/actions/EditEntityAction.php
index 33746a3..6ed14d5 100644
--- a/repo/includes/actions/EditEntityAction.php
+++ b/repo/includes/actions/EditEntityAction.php
@@ -63,7 +63,8 @@
 
                $langCode = $this->getContext()->getLanguage()->getCode();
 
-               //TODO: proper injection
+               // @todo: proper injection of all this stuff!
+               // and seems much, if not all, code here is duplicated in 
EntityContentDiffView
                $options = new FormatterOptions( array(
                        //TODO: fallback chain
                        ValueFormatter::OPT_LANG => $langCode
@@ -78,8 +79,19 @@
                $this->propertyNameFormatter = new EscapingValueFormatter( 
$labelFormatter, 'htmlspecialchars' );
 
                $formatterFactory = $wikibaseRepo->getSnakFormatterFactory();
-               $this->detailedSnakFormatter = 
$formatterFactory->getSnakFormatter( SnakFormatter::FORMAT_HTML_DIFF, $options 
);
-               $this->terseSnakFormatter = 
$formatterFactory->getSnakFormatter( SnakFormatter::FORMAT_HTML, $options );
+               $valueFormatterBuilders = 
$wikibaseRepo->getValueFormatterBuilders();
+
+               $this->detailedSnakFormatter = 
$formatterFactory->getSnakFormatter(
+                       SnakFormatter::FORMAT_HTML_DIFF,
+                       $valueFormatterBuilders,
+                       $options
+               );
+
+               $this->terseSnakFormatter = $formatterFactory->getSnakFormatter(
+                       SnakFormatter::FORMAT_HTML,
+                       $valueFormatterBuilders,
+                       $options
+               );
 
                $this->diffVisualizer = new EntityDiffVisualizer(
                        $this->getContext(),
diff --git a/repo/includes/content/EntityContent.php 
b/repo/includes/content/EntityContent.php
index 02c82dd..58a8767 100644
--- a/repo/includes/content/EntityContent.php
+++ b/repo/includes/content/EntityContent.php
@@ -26,18 +26,11 @@
 use ValueValidators\Result;
 use Wikibase\DataModel\Entity\Entity;
 use Wikibase\DataModel\Entity\EntityId;
-use Wikibase\Lib\Serializers\SerializationOptions;
-use Wikibase\Lib\SnakFormatter;
-use Wikibase\Lib\Store\EntityInfoBuilderFactory;
 use Wikibase\Lib\Store\EntityRedirect;
 use Wikibase\Lib\Store\EntityTitleLookup;
 use Wikibase\Repo\Content\EntityContentDiff;
 use Wikibase\Repo\Content\EntityHandler;
 use Wikibase\Repo\EntitySearchTextGenerator;
-use Wikibase\Repo\View\ClaimsView;
-use Wikibase\Repo\View\FingerprintView;
-use Wikibase\Repo\View\SectionEditLinkGenerator;
-use Wikibase\Repo\View\SnakHtmlGenerator;
 use Wikibase\Repo\WikibaseRepo;
 use Wikibase\Validators\EntityValidator;
 use WikiPage;
@@ -272,17 +265,14 @@
                $wikibaseRepo = WikibaseRepo::getDefaultInstance();
                $entityParserOutputGeneratorFactory = 
$wikibaseRepo->getEntityParserOutputGeneratorFactory();
 
-               $entityRevision = $this->getEntityRevision( $title, $revId );
-
                $outputGenerator = 
$entityParserOutputGeneratorFactory->getEntityParserOutputGenerator(
-                       $entityRevision->getEntity()->getType(),
                        $options
                );
 
                $editable = $options ? $options->getEditSection() : true;
 
                $output = $outputGenerator->getParserOutput(
-                       $entityRevision,
+                       $this->getEntityRevision( $title, $revId ),
                        $editable,
                        $generateHtml
                );
diff --git 
a/repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php 
b/repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php
index 13fa66a..8526cad 100644
--- a/repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php
+++ b/repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Wikibase;
+namespace Wikibase\Test;
 
 use Language;
 use ParserOptions;
@@ -17,47 +17,32 @@
  */
 class EntityParserOutputGeneratorFactoryTest extends \MediaWikiTestCase {
 
-       /**
-        * @dataProvider getEntityParserOutputGeneratorProvider
-        */
-       public function testGetEntityParserOutputGenerator( $entityType ) {
-               $wikibaseRepo = WikibaseRepo::getDefaultInstance();
-               $parserOutputGeneratorFactory = 
$wikibaseRepo->getEntityParserOutputGeneratorFactory();
+       public function testGetEntityParserOutputGenerator() {
+               $parserOutputGeneratorFactory = 
$this->getEntityParserOutputGeneratorFactory();
+
+               $testUser = new TestUser( 'Wikibase User' );
 
                $parserOutputGenerator = 
$parserOutputGeneratorFactory->getEntityParserOutputGenerator(
-                       $entityType,
-                       $this->getParserOptions()
+                       new ParserOptions( $testUser->getUser(), 
Language::factory( 'en' ) )
                );
 
-               $this->assertInstanceOf(
-                       'Wikibase\EntityParserOutputGenerator',
-                       $parserOutputGenerator
-               );
+               $this->assertInstanceOf( 
'Wikibase\EntityParserOutputGenerator', $parserOutputGenerator );
        }
 
-       public function getEntityParserOutputGeneratorProvider() {
-               return array(
-                       array( 'item' ),
-                       array( 'property' )
-               );
-       }
+       public function 
testGetEntityParserOutputGenerator_noParserOptionLanguage() {
+               $parserOutputGeneratorFactory = 
$this->getEntityParserOutputGeneratorFactory();
 
-       public function testGetEntityParserOutputGenerator_invalidType() {
-               $wikibaseRepo = WikibaseRepo::getDefaultInstance();
-               $parserOutputGeneratorFactory = 
$wikibaseRepo->getEntityParserOutputGeneratorFactory();
-
-               $this->setExpectedException( 'InvalidArgumentException' );
-
-               $parserOutputGeneratorFactory->getEntityParserOutputGenerator(
-                       'kittens',
-                       $this->getParserOptions()
-               );
-       }
-
-       private function getParserOptions() {
                $testUser = new TestUser( 'Wikibase User' );
-               $language = Language::factory( 'en' );
 
-               return new ParserOptions( $testUser->getUser(), $language );
+               $parserOutputGenerator = 
$parserOutputGeneratorFactory->getEntityParserOutputGenerator(
+                       new ParserOptions( $testUser->getUser() )
+               );
+
+               $this->assertInstanceOf( 
'Wikibase\EntityParserOutputGenerator', $parserOutputGenerator );
        }
+
+       private function getEntityParserOutputGeneratorFactory() {
+               return 
WikibaseRepo::getDefaultInstance()->getEntityParserOutputGeneratorFactory();
+       }
+
 }
diff --git a/repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php 
b/repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php
index 76fdcd8..699a667 100644
--- a/repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php
+++ b/repo/tests/phpunit/includes/EntityParserOutputGeneratorTest.php
@@ -12,7 +12,9 @@
 use Wikibase\DataModel\Statement\StatementList;
 use Wikibase\EntityParserOutputGenerator;
 use Wikibase\EntityRevision;
+use Wikibase\LanguageFallbackChain;
 use Wikibase\Lib\Store\Sql\SqlEntityInfoBuilderFactory;
+use Wikibase\ValuesFinder;
 
 /**
  * @covers Wikibase\EntityParserOutputGenerator
@@ -25,9 +27,9 @@
  */
 class EntityParserOutputGeneratorTest extends \PHPUnit_Framework_TestCase {
 
-       static $html = '<html>Nyan data!!!</html>';
-       static $placeholders = array( 'key' => 'value' );
-       static $configVars = array( 'foo' => 'bar' );
+       private static $html = '<html>Nyan data!!!</html>';
+       private static $placeholders = array( 'key' => 'value' );
+       private static $configVars = array( 'foo' => 'bar' );
 
        public function testGetParserOutput() {
                $entityParserOutputGenerator = 
$this->newEntityParserOutputGenerator();
@@ -48,12 +50,12 @@
 
        private function newEntityParserOutputGenerator() {
                return new EntityParserOutputGenerator(
-                       $this->getEntityViewMock(),
+                       $this->getEntityViewFactory(),
                        $this->getConfigBuilderMock(),
-                       $this->getMock( 
'Wikibase\Lib\Serializers\SerializationOptions' ),
                        $this->getEntityTitleLookupMock(),
-                       $this->getDataTypeLookup(),
+                       $this->getValuesFinder(),
                        new SqlEntityInfoBuilderFactory(),
+                       new LanguageFallbackChain( array() ),
                        'en'
                );
        }
@@ -73,20 +75,28 @@
                return $item;
        }
 
-       private function getEntityViewMock() {
+       private function getEntityViewFactory() {
+               $entityViewFactory = $this->getMockBuilder( 
'Wikibase\Repo\View\EntityViewFactory' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
                $entityView = $this->getMockBuilder( 'Wikibase\EntityView' )
                        ->disableOriginalConstructor()
                        ->getMock();
 
                $entityView->expects( $this->any() )
                        ->method( 'getHtml' )
-                       ->will( $this->returnValue( self::$html ) );
+                       ->will( $this->returnValue( '<html>Nyan data!!!</html>' 
) );
 
                $entityView->expects( $this->any() )
                        ->method( 'getPlaceholders' )
-                       ->will( $this->returnValue( self::$placeholders ) );
+                       ->will( $this->returnValue( array( 'key' => 'value' ) ) 
);
 
-               return $entityView;
+               $entityViewFactory->expects( $this->any() )
+                       ->method( 'newEntityView' )
+                       ->will( $this->returnValue( $entityView ) );
+
+               return $entityViewFactory;
        }
 
        private function getConfigBuilderMock() {
@@ -114,11 +124,13 @@
                return $entityTitleLookup;
        }
 
-       private function getDataTypeLookup() {
+       private function getValuesFinder() {
                $dataTypeLookup = new InMemoryDataTypeLookup();
+
                $dataTypeLookup->setDataTypeForProperty( new PropertyId( 'P42' 
), 'url' );
                $dataTypeLookup->setDataTypeForProperty( new PropertyId( 'P10' 
), 'commonsMedia' );
-               return $dataTypeLookup;
+
+               return new ValuesFinder( $dataTypeLookup );
        }
 
 }
diff --git a/repo/tests/phpunit/includes/ParserOutputJsConfigBuilderTest.php 
b/repo/tests/phpunit/includes/ParserOutputJsConfigBuilderTest.php
index 60acbfb..2c1bbff 100644
--- a/repo/tests/phpunit/includes/ParserOutputJsConfigBuilderTest.php
+++ b/repo/tests/phpunit/includes/ParserOutputJsConfigBuilderTest.php
@@ -40,13 +40,8 @@
         * @dataProvider buildProvider
         */
        public function testBuild( array $usedEntities, Entity $entity, array 
$entityInfo ) {
-               $langCode = 'en';
-               $langCodes = array( 'de', 'en', 'es', 'fr' );
-
-               $configBuilder = $this->getConfigBuilder( $langCode );
-               $options = $this->getSerializationOptions( $langCode, 
$langCodes );
-
-               $configVars = $configBuilder->build( $entity, $entityInfo, 
$options );
+               $configBuilder = $this->getConfigBuilder( 'en', array( 'de', 
'en', 'es', 'fr' ) );
+               $configVars = $configBuilder->build( $entity, $entityInfo );
 
                $this->assertInternalType( 'array', $configVars );
 
@@ -87,11 +82,12 @@
                );
        }
 
-       private function getConfigBuilder( $langCode ) {
+       private function getConfigBuilder( $languageCode, array $languageCodes 
) {
                $configBuilder = new ParserOutputJsConfigBuilder(
                        new BasicEntityIdParser(),
                        $this->getEntityTitleLookupMock(),
-                       $langCode
+                       $this->getSerializationOptions( $languageCode, 
$languageCodes ),
+                       $languageCode
                );
 
                return $configBuilder;
diff --git a/repo/tests/phpunit/includes/View/ClaimsViewTest.php 
b/repo/tests/phpunit/includes/View/ClaimsViewTest.php
index 87bbb3f..6322cee 100644
--- a/repo/tests/phpunit/includes/View/ClaimsViewTest.php
+++ b/repo/tests/phpunit/includes/View/ClaimsViewTest.php
@@ -80,7 +80,7 @@
        public function testGetHtml( array $claims ) {
                $claimsView = $this->newClaimsView();
 
-               $html = $claimsView->getHtml( $claims );
+               $html = $claimsView->getHtml( $claims, array() );
 
                foreach ( $claims as $claim ) {
                        $this->assertContains( $claim->getGuid(), $html );
@@ -91,13 +91,11 @@
         * @return ClaimsView
         */
        private function newClaimsView() {
-               $mockRepo = new MockRepository();
                $entityTitleLookup = $this->getEntityTitleLookupMock();
                $sectionEditLinkGenerator = new SectionEditLinkGenerator();
                $claimHtmlGenerator = $this->getClaimHtmlGeneratorMock();
 
                return new ClaimsView(
-                       $mockRepo,
                        $entityTitleLookup,
                        $sectionEditLinkGenerator,
                        $claimHtmlGenerator,
diff --git a/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php 
b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
new file mode 100644
index 0000000..49cfa05
--- /dev/null
+++ b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace Wikibase\Test;
+
+use Language;
+use ParserOptions;
+use TestUser;
+use Wikibase\LanguageFallbackChain;
+use Wikibase\Lib\SnakFormatter;
+use Wikibase\Repo\View\EntityViewFactory;
+
+/**
+ * @licence GNU GPL v2+
+ * @author Katie Filbert < [email protected] >
+ */
+class EntityViewFactoryTest extends \PHPUnit_Framework_TestCase {
+
+       /**
+        * @dataProvider newEntityViewProvider
+        */
+       public function testNewEntityView( $expectedClass, $entityType ) {
+               $entityViewFactory = $this->getEntityViewFactory();
+
+               $entityView = $entityViewFactory->newEntityView(
+                       new LanguageFallbackChain( array() ),
+                       'de',
+                       $entityType
+               );
+
+               $this->assertInstanceOf( $expectedClass, $entityView );
+       }
+
+       public function newEntityViewProvider() {
+               return array(
+                       array( 'Wikibase\ItemView', 'item' ),
+                       array( 'Wikibase\PropertyView', 'property' )
+               );
+       }
+
+       public function testNewEntityView_withInvalidType() {
+               $entityViewFactory = $this->getEntityViewFactory();
+
+               $this->setExpectedException( 'InvalidArgumentException' );
+
+               $entityViewFactory->newEntityView(
+                       new LanguageFallbackChain( array() ),
+                       'de',
+                       'kittens'
+               );
+       }
+
+       private function getEntityViewFactory() {
+               return new EntityViewFactory(
+                       $this->getEntityTitleLookup(),
+                       new MockRepository(),
+                       $this->getSnakFormatterFactory()
+               );
+       }
+
+       private function getEntityTitleLookup() {
+               $entityTitleLookup = $this->getMock( 
'Wikibase\Lib\Store\EntityTitleLookup' );
+
+               $entityTitleLookup->expects( $this->any() )
+                       ->method( 'getTitleForId' )
+                       ->will( $this->returnCallback( function( EntityId $id ) 
{
+                               $name = $id->getEntityType() . ':' . 
$id->getSerialization();
+                               return Title::makeTitle( NS_MAIN, $name );
+                       } ) );
+
+               return $entityTitleLookup;
+       }
+
+       private function getSnakFormatterFactory() {
+               $snakFormatter = $this->getMock( 'Wikibase\Lib\SnakFormatter' );
+
+               $snakFormatter->expects( $this->any() )
+                       ->method( 'getFormat' )
+                       ->will( $this->returnValue( SnakFormatter::FORMAT_HTML 
) );
+
+               $snakFormatterFactory = $this->getMockBuilder( 
'Wikibase\Lib\OutputFormatSnakFormatterFactory' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $snakFormatterFactory->expects( $this->any() )
+                       ->method( 'getSnakFormatter' )
+                       ->will( $this->returnValue( $snakFormatter ) );
+
+               return $snakFormatterFactory;
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/172590
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I31a18f05ec9d1723661f7ca526562faaa7c41bf6
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to