Daniel Kinzler has uploaded a new change for review.

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

Change subject: Handle DVs that mismatch a prop's expected type
......................................................................

Handle DVs that mismatch a prop's expected type

If a Snak contains a DataValue of a type different from
the value type expected by the peroperty's data type,
don't fail, but handle gracefully.

Bug: 63299
Change-Id: I41b489ff5b5ea474861922a8c50b214e67851319
---
M client/includes/WikibaseClient.php
M lib/includes/formatters/PropertyValueSnakFormatter.php
M lib/includes/formatters/WikibaseSnakFormatterBuilders.php
M lib/tests/phpunit/formatters/PropertyValueSnakFormatterTest.php
M lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/EntityViewTest.php
7 files changed, 267 insertions(+), 77 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/86/133286/1

diff --git a/client/includes/WikibaseClient.php 
b/client/includes/WikibaseClient.php
index db4db48..157c503 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -487,7 +487,8 @@
 
                $builders = new WikibaseSnakFormatterBuilders(
                        $valueFormatterBuilders,
-                       $this->getPropertyDataTypeLookup()
+                       $this->getPropertyDataTypeLookup(),
+                       $this->getDataTypeFactory()
                );
 
                $factory = new OutputFormatSnakFormatterFactory( 
$builders->getSnakFormatterBuildersForFormats() );
diff --git a/lib/includes/formatters/PropertyValueSnakFormatter.php 
b/lib/includes/formatters/PropertyValueSnakFormatter.php
index 53089d0..d2bf46d 100644
--- a/lib/includes/formatters/PropertyValueSnakFormatter.php
+++ b/lib/includes/formatters/PropertyValueSnakFormatter.php
@@ -1,7 +1,11 @@
 <?php
 namespace Wikibase\Lib;
+use DataTypes\DataTypeFactory;
 use DataValues\DataValue;
+use DataValues\UnDeserializableValue;
+use Html;
 use InvalidArgumentException;
+use Message;
 use Wikibase\PropertyValueSnak;
 use Wikibase\Snak;
 
@@ -30,14 +34,25 @@
        private $typeLookup;
 
        /**
+        * @var DataTypeFactory
+        */
+       private $dataTypeFactory;
+
+       /**
         * @param string $format The name of this formatter's output format.
         *        Use the FORMAT_XXX constants defined in 
OutputFormatSnakFormatterFactory.
         * @param DispatchingValueFormatter $valueFormatter
         * @param PropertyDataTypeLookup $typeLookup
+        * @param DataTypeFactory $dataTypeFactory
         *
         * @throws \InvalidArgumentException
         */
-       public function __construct( $format, DispatchingValueFormatter 
$valueFormatter, PropertyDataTypeLookup $typeLookup) {
+       public function __construct(
+               $format,
+               DispatchingValueFormatter $valueFormatter,
+               PropertyDataTypeLookup $typeLookup,
+               DataTypeFactory $dataTypeFactory
+       ) {
                if ( !is_string( $format ) ) {
                        throw new InvalidArgumentException( '$format must be a 
string' );
                }
@@ -45,6 +60,7 @@
                $this->format = $format;
                $this->valueFormatter = $valueFormatter;
                $this->typeLookup = $typeLookup;
+               $this->dataTypeFactory = $dataTypeFactory;
        }
 
        /**
@@ -61,17 +77,94 @@
                        throw new InvalidArgumentException( "Not a 
PropertyValueSnak: " . get_class( $snak ) );
                }
 
+               $value = $snak->getDataValue();
+               $warning = null;
+
                try {
                        /* @var PropertyValueSnak $snak */
                        $propertyType = 
$this->typeLookup->getDataTypeIdForProperty( $snak->getPropertyId() );
+                       $expectedDataValueType = 
$this->getDataValueTypeForPropertyDataType( $propertyType );
+
+                       // Check that the value actually has the expected type.
+                       if ( $expectedDataValueType !== null
+                               && $expectedDataValueType !== $value->getType() 
) {
+
+                               // Warn, but only if the value isn't "bad"; no 
point to complain again in that case.
+                               if ( $value->getType() === 
UnDeserializableValue::getType() ) {
+                                       wfWarn( __METHOD__ . ': Encountered 
undeserializable value '
+                                               . 
$snak->getPropertyId()->getPrefixedId() );
+
+                                       // NOTE: don't set a warning here, 
that's handled by UnDeserializableValueFormatter
+                               } else {
+                                       wfWarn( __METHOD__ . ': Mismatching 
value type: Peroperty '
+                                               . $snak->getPropertyId() . ' 
expects a '
+                                               . $expectedDataValueType . ', 
but snak contains a '
+                                               . $value->getType() );
+
+                                       $warning = wfMessage( 
'wikibase-snakview-variation-datavaluetypemismatch-details',
+                                               $value->getType(),
+                                               $expectedDataValueType );
+                               }
+
+                               // Don't use property data type based 
formatting, since our value
+                               // has a type not compatible to that data type.
+                               $propertyType = null;
+                       }
                } catch ( PropertyNotFoundException $ex ) {
                        // If the property has been removed, we should still be 
able to render the snak value, so don't fail here.
-                       wfDebugLog( __CLASS__, __FUNCTION__ . ': Can\'t look up 
data type for property ' . $snak->getPropertyId()->getPrefixedId() );
+                       wfWarn( __METHOD__ . ': Can\'t look up data type for 
property '
+                               . $snak->getPropertyId()->getPrefixedId() );
+
+                       $warning = wfMessage( 
'wikibase-snakformat-propertynotfound' );
                        $propertyType = null;
                }
 
-               $text = $this->formatValue( $snak->getDataValue(), 
$propertyType );
+               $text = $this->formatValue( $value, $propertyType );
+
+               if ( $warning ) {
+                       $text .= ' ' . $this->formatWarning( $warning );
+               }
+
                return $text;
+       }
+
+       /**
+        * @param Message $warning
+        *
+        * @return string
+        */
+       private function formatWarning( Message $warning ) {
+               $attributes = array( 'class' => 'error' );
+
+               //NOTE: format identifiers are MIME types, so we can just check 
the prefix.
+               if ( strpos( $this->format, SnakFormatter::FORMAT_HTML ) === 0 
) {
+                       $text = '(' . $warning->parse() . ')';
+                       $text = Html::rawElement( 'span', $attributes, $text );
+
+               } elseif ( $this->format === SnakFormatter::FORMAT_WIKI ) {
+                       $text = '(' . $warning->text() . ')';
+                       $text = Html::rawElement( 'span', $attributes, $text );
+
+               } elseif ( $this->format === SnakFormatter::FORMAT_PLAIN ) {
+                       $text = $warning->text();
+
+               } else {
+                       $text = '';
+               }
+
+               return $text;
+       }
+
+       /**
+        * Returns the expected value type for the given property data type
+        *
+        * @param string $dataTypeId A property data type id
+        *
+        * @return string A value type
+        */
+       private function getDataValueTypeForPropertyDataType( $dataTypeId ) {
+               $dataType = $this->dataTypeFactory->getType( $dataTypeId );
+               return $dataType->getDataValueType();
        }
 
        /**
@@ -112,4 +205,5 @@
        public function canFormatSnak( Snak $snak ) {
                return $snak->getType() === 'value';
        }
+
 }
diff --git a/lib/includes/formatters/WikibaseSnakFormatterBuilders.php 
b/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
index caa6d29..73ce536 100644
--- a/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
+++ b/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Lib;
 
+use DataTypes\DataTypeFactory;
 use ValueFormatters\FormatterOptions;
 use ValueFormatters\ValueFormatter;
 
@@ -20,24 +21,32 @@
        /**
         * @var WikibaseValueFormatterBuilders
         */
-       protected $valueFormatterBuilders;
+       private $valueFormatterBuilders;
 
        /**
         * @var PropertyDataTypeLookup
         */
-       protected $propertyDataTypeLookup;
+       private $propertyDataTypeLookup;
+
+       /**
+        * @var DataTypeFactory
+        */
+       private $dataTypeFactory;
 
        /**
         * @param WikibaseValueFormatterBuilders $valueFormatterBuilders
-                       'VT:bad' => 
'Wikibase\Lib\UnDeserializableValueFormatter'
+       'VT:bad' => 'Wikibase\Lib\UnDeserializableValueFormatter'
         * @param PropertyDataTypeLookup $propertyDataTypeLookup
+        * @param DataTypeFactory $dataTypeFactory
         */
        public function __construct(
                WikibaseValueFormatterBuilders $valueFormatterBuilders,
-               PropertyDataTypeLookup $propertyDataTypeLookup
+               PropertyDataTypeLookup $propertyDataTypeLookup,
+               DataTypeFactory $dataTypeFactory
        ) {
                $this->valueFormatterBuilders = $valueFormatterBuilders;
                $this->propertyDataTypeLookup = $propertyDataTypeLookup;
+               $this->dataTypeFactory = $dataTypeFactory;
        }
 
        /**
@@ -76,7 +85,12 @@
 
                $factory = new OutputFormatValueFormatterFactory( 
$this->valueFormatterBuilders->getValueFormatterBuildersForFormats() );
                $valueFormatter = 
$this->valueFormatterBuilders->buildDispatchingValueFormatter( $factory, 
$format, $options );
-               $valueSnakFormatter = new PropertyValueSnakFormatter( $format, 
$valueFormatter, $this->propertyDataTypeLookup );
+               $valueSnakFormatter = new PropertyValueSnakFormatter(
+                       $format,
+                       $valueFormatter,
+                       $this->propertyDataTypeLookup,
+                       $this->dataTypeFactory
+               );
 
                $formatters = array(
                        'novalue' => $noValueSnakFormatter,
diff --git a/lib/tests/phpunit/formatters/PropertyValueSnakFormatterTest.php 
b/lib/tests/phpunit/formatters/PropertyValueSnakFormatterTest.php
index b4775af..7df800f 100644
--- a/lib/tests/phpunit/formatters/PropertyValueSnakFormatterTest.php
+++ b/lib/tests/phpunit/formatters/PropertyValueSnakFormatterTest.php
@@ -2,13 +2,18 @@
 
 namespace Wikibase\Lib\Test;
 
+use DataTypes\DataType;
 use DataValues\StringValue;
+use DataValues\UnDeserializableValue;
+use ValueFormatters\FormatterOptions;
 use Wikibase\DataModel\Entity\PropertyId;
+use Wikibase\DataModel\Snak\PropertySomeValueSnak;
+use Wikibase\DataModel\Snak\PropertyValueSnak;
 use Wikibase\Lib\DispatchingValueFormatter;
+use Wikibase\Lib\PropertyNotFoundException;
 use Wikibase\Lib\PropertyValueSnakFormatter;
 use Wikibase\Lib\SnakFormatter;
-use Wikibase\PropertySomeValueSnak;
-use Wikibase\PropertyValueSnak;
+use Wikibase\Lib\UnDeserializableValueFormatter;
 
 /**
  * @covers Wikibase\Lib\PropertyValueSnakFormatter
@@ -32,12 +37,7 @@
        public function testConstructorErrors( $format, $error ) {
                $this->setExpectedException( $error );
 
-               $typeLookup = $this->getMock( 
'Wikibase\Lib\PropertyDataTypeLookup' );
-               $typeLookup->expects( $this->never() )->method( 
'getDataTypeIdForProperty' );
-
-               $valueFormatter = new DispatchingValueFormatter( array() );
-
-               new PropertyValueSnakFormatter( $format, $valueFormatter, 
$typeLookup );
+               $this->getDummyPropertyValueSnakFormatter( $format );
        }
 
        public function constructorErrorsProvider() {
@@ -53,74 +53,138 @@
         * @dataProvider formatSnakProvider
         * @covers PropertyValueSnakFormatter::formatSnak()
         */
-       public function testFormatSnak( $snak, $type, $formatters, $expected ) {
+       public function testFormatSnak( $snak, $dataType, $valueType, 
$targetFormat, $formatters, $expected ) {
+               if ( $dataType !== '' ) {
+                       $getDataTypeIdForPropertyResult = $this->returnValue( 
$dataType );
+               } else {
+                       $getDataTypeIdForPropertyResult = $this->throwException(
+                               new PropertyNotFoundException( new PropertyId( 
'P666' ) ) );
+               }
+
                $typeLookup = $this->getMock( 
'Wikibase\Lib\PropertyDataTypeLookup' );
                $typeLookup->expects( $this->atLeastOnce() )
                        ->method( 'getDataTypeIdForProperty' )
-                       ->will( $this->returnValue( $type ) );
+                       ->will( $getDataTypeIdForPropertyResult );
+
+               $typeFactory = $this->getMock( 'DataTypes\DataTypeFactory' );
+               $typeFactory->expects( $this->any() )
+                       ->method( 'getType' )
+                       ->will( $this->returnValue( new DataType( $dataType, 
$valueType, array() ) ) );
 
                $formatter = new PropertyValueSnakFormatter(
-                       SnakFormatter::FORMAT_PLAIN,
+                       $targetFormat,
                        new DispatchingValueFormatter( $formatters ),
-                       $typeLookup
+                       $typeLookup,
+                       $typeFactory
                );
 
-               $this->assertEquals( $expected, $formatter->formatSnak( $snak ) 
);
+               // NOTE: we want to suppress warnings here, so we can test that 
mismatching DataValues
+               // are still processed correctly after causing a warning.
+               wfSuppressWarnings();
+               $actual = $formatter->formatSnak( $snak );
+               wfRestoreWarnings();
+
+               $this->assertRegExp( $expected, $actual );
+       }
+
+       private function getMockFormatter( $value ) {
+               $formatter = $this->getMock( 'ValueFormatters\ValueFormatter' );
+               $formatter->expects( $this->any() )
+                       ->method( 'format' )
+                       ->will( $this->returnValue( $value ) );
+
+               return $formatter;
        }
 
        public function formatSnakProvider() {
-               $stringFormatter = $this->getMock( 
'ValueFormatters\ValueFormatter' );
-               $stringFormatter->expects( $this->any() )
-                       ->method( 'format' )
-                       ->will( $this->returnValue( 'VT:string' ) );
-
-               $mediaFormatter = $this->getMock( 
'ValueFormatters\ValueFormatter' );
-               $mediaFormatter->expects( $this->any() )
-                       ->method( 'format' )
-                       ->will( $this->returnValue( 'PT:commonsMedia' ) );
-
                $formatters = array(
-                       'VT:string' => $stringFormatter,
-                       'PT:commonsMedia' => $mediaFormatter,
+                       'VT:bad' => new UnDeserializableValueFormatter( new 
FormatterOptions() ),
+                       'VT:string' => $this->getMockFormatter( 'VT:string' ),
+                       'PT:commonsMedia' => $this->getMockFormatter( 
'PT:commonsMedia' )
                );
 
                return array(
                        'match PT' => array(
                                new PropertyValueSnak( 17, new StringValue( 
'Foo.jpg' ) ),
                                'commonsMedia',
+                               'string',
+                               SnakFormatter::FORMAT_PLAIN,
                                $formatters,
-                               'PT:commonsMedia'
+                               '/^PT:commonsMedia$/'
                        ),
 
                        'match VT' => array(
                                new PropertyValueSnak( 33, new StringValue( 
'something' ) ),
                                'someStuff',
+                               'string',
+                               SnakFormatter::FORMAT_WIKI,
                                $formatters,
-                               'VT:string'
+                               '/^VT:string$/'
+                       ),
+
+                       //NOTE: will fail unless warnings are suppressed
+                       'UnDeserializableValue' => array(
+                               new PropertyValueSnak( 7,
+                                       new UnDeserializableValue( 'cookie', 
'globecoordinate', 'cannot understand!' )
+                               ),
+                               'globe-coordinate',
+                               'bad',
+                               SnakFormatter::FORMAT_HTML,
+                               $formatters,
+                               // message key: wikibase-undeserializable-value
+                               '/value is invalid/'
+                       ),
+
+                       //NOTE: will fail unless warnings are suppressed
+                       'VT mismatching PT' => array(
+                               new PropertyValueSnak( 7, new StringValue( 
'dummy' ) ),
+                               'url',
+                               'iri', // url expects an iri, but will get a 
string
+                               SnakFormatter::FORMAT_WIKI,
+                               $formatters,
+                               // message key: 
wikibase-snakview-variation-datavaluetypemismatch-details
+                               '@^VT:string <span class="error">\(.*does not 
match.*\)</span>$@'
+                       ),
+
+                       //NOTE: will fail unless warnings are suppressed
+                       'property not found' => array(
+                               new PropertyValueSnak( 7, new StringValue( 
'dummy' ) ),
+                               '', // triggers an exception from the mock 
PropertyDataTypeLookup
+                               'xxx', // should not be used
+                               SnakFormatter::FORMAT_HTML,
+                               $formatters,
+                               // message key: 
wikibase-snakformat-propertynotfound
+                               '@^VT:string <span class="error">\(.*not 
found.*\)</span>$@'
                        ),
                );
+       }
+
+       private function getDummyPropertyValueSnakFormatter( $format = 'test' ) 
{
+               $typeLookup = $this->getMock( 
'Wikibase\Lib\PropertyDataTypeLookup' );
+               $typeLookup->expects( $this->never() )->method( 
'getDataTypeIdForProperty' );
+
+               $typeFactory = $this->getMock( 'DataTypes\DataTypeFactory' );
+               $typeFactory->expects( $this->never() )->method( 'getType' );
+
+               $valueFormatter = new DispatchingValueFormatter( array() );
+
+               $formatter = new PropertyValueSnakFormatter( $format, 
$valueFormatter, $typeLookup, $typeFactory );
+               return $formatter;
        }
 
        /**
         * @covers PropertyValueSnakFormatter::getFormat()
         */
        public function testGetFormat() {
-               $typeLookup = $this->getMock( 
'Wikibase\Lib\PropertyDataTypeLookup' );
-               $typeLookup->expects( $this->never() )->method( 
'getDataTypeIdForProperty' );
-
-               $formatter = new PropertyValueSnakFormatter( 'test', new 
DispatchingValueFormatter( array() ), $typeLookup );
+               $formatter = $this->getDummyPropertyValueSnakFormatter();
                $this->assertEquals( 'test', $formatter->getFormat() );
        }
-
 
        /**
         * @covers MessageSnakFormatter::canFormatSnak()
         */
        public function testCanFormatSnak() {
-               $typeLookup = $this->getMock( 
'Wikibase\Lib\PropertyDataTypeLookup' );
-               $typeLookup->expects( $this->never() )->method( 
'getDataTypeIdForProperty' );
-
-               $formatter = new PropertyValueSnakFormatter( 'test', new 
DispatchingValueFormatter( array() ), $typeLookup );
+               $formatter = $this->getDummyPropertyValueSnakFormatter();
 
                $snak = new PropertyValueSnak( new PropertyId( "P23" ), new 
StringValue( 'test' ) );
                $this->assertTrue( $formatter->canFormatSnak( $snak ), 
$snak->getType() );
diff --git a/lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php 
b/lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php
index e8d1c62..6bb022a 100644
--- a/lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php
+++ b/lib/tests/phpunit/formatters/WikibaseSnakFormatterBuildersTest.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Lib\Test;
 
+use DataTypes\DataType;
 use DataValues\StringValue;
 use DataValues\UnDeserializableValue;
 use Language;
@@ -43,6 +44,20 @@
                        ->method( 'getDataTypeIdForProperty' )
                        ->will( $this->returnValue( $propertyType ) );
 
+               $typeMap = array(
+                       'url' => 'string',
+                       'string' => 'string',
+                       'wikibase-item' => 'wikibase-entityid',
+                       'globecoordinate' => 'globecoordinate',
+               );
+
+               $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() );
+                       } ) );
+
                $entity = EntityFactory::singleton()->newEmpty( 
$entityId->getEntityType() );
                $entity->setId( $entityId );
                $entity->setLabel( 'en', 'Label for ' . 
$entityId->getPrefixedId() );
@@ -55,7 +70,7 @@
                $lang = Language::factory( 'en' );
 
                $valueFormatterBuilders = new WikibaseValueFormatterBuilders( 
$entityLookup, $lang );
-               return new WikibaseSnakFormatterBuilders( 
$valueFormatterBuilders, $typeLookup );
+               return new WikibaseSnakFormatterBuilders( 
$valueFormatterBuilders, $typeLookup, $typeFactory );
        }
 
        /**
@@ -146,15 +161,6 @@
                                'url',
                                new PropertyValueSnak( 7, new StringValue( 
'http://acme.com/' ) ),
                                '<a rel="nofollow" class="external free" 
href="http://acme.com/";>http://acme.com/</a>'
-                       ),
-                       'bad value' => array(
-                               SnakFormatter::FORMAT_PLAIN,
-                               $options,
-                               'globecoordinate',
-                               new PropertyValueSnak( 7,
-                                       new UnDeserializableValue( 'cookie', 
'globecoordinate', 'cannot understand!' )
-                               ),
-                               $badValueMsg
                        )
                );
        }
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 099acc3..e243774 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -431,7 +431,7 @@
        /**
         * @return WikibaseValueFormatterBuilders
         */
-       protected function getValueFormatterBuilders() {
+       public function getValueFormatterBuilders() {
                global $wgContLang;
 
                return new WikibaseValueFormatterBuilders(
@@ -447,7 +447,8 @@
        protected function newSnakFormatterFactory() {
                $builders = new WikibaseSnakFormatterBuilders(
                        $this->getValueFormatterBuilders(),
-                       $this->getPropertyDataTypeLookup()
+                       $this->getPropertyDataTypeLookup(),
+                       $this->getDataTypeFactory()
                );
 
                $factory = new OutputFormatSnakFormatterFactory( 
$builders->getSnakFormatterBuildersForFormats() );
@@ -517,7 +518,8 @@
 
                $snakFormatterBuilders = new WikibaseSnakFormatterBuilders(
                        $valueFormatterBuilders,
-                       $this->getPropertyDataTypeLookup()
+                       $this->getPropertyDataTypeLookup(),
+                       $this->getDataTypeFactory()
                );
 
                $valueFormatterBuilders->setValueFormatter(
diff --git a/repo/tests/phpunit/includes/EntityViewTest.php 
b/repo/tests/phpunit/includes/EntityViewTest.php
index cc50c2d..ef8f35f 100644
--- a/repo/tests/phpunit/includes/EntityViewTest.php
+++ b/repo/tests/phpunit/includes/EntityViewTest.php
@@ -2,44 +2,41 @@
 
 namespace Wikibase\Test;
 
+use DataValues\StringValue;
 use IContextSource;
 use InvalidArgumentException;
 use Language;
 use MediaWikiTestCase;
-use OutputPage;
 use RequestContext;
 use Title;
-use DataValues\StringValue;
 use ValueFormatters\FormatterOptions;
-use Wikibase\Claim;
-use Wikibase\CopyrightMessageBuilder;
+use Wikibase\DataModel\Claim\Claim;
 use Wikibase\DataModel\Entity\BasicEntityIdParser;
+use Wikibase\DataModel\Entity\Entity;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\EntityIdValue;
+use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\DataModel\Entity\Property;
 use Wikibase\DataModel\Entity\PropertyId;
-use Wikibase\Entity;
+use Wikibase\DataModel\Snak\PropertyNoValueSnak;
+use Wikibase\DataModel\Snak\PropertySomeValueSnak;
+use Wikibase\DataModel\Snak\PropertyValueSnak;
+use Wikibase\DataModel\Snak\Snak;
 use Wikibase\EntityInfoBuilder;
 use Wikibase\EntityRevision;
-use Wikibase\EntityRevisionLookup;
 use Wikibase\EntityTitleLookup;
 use Wikibase\EntityView;
-use Wikibase\Item;
 use Wikibase\LanguageFallbackChain;
-use Wikibase\LanguageFallbackChainFactory;
 use Wikibase\Lib\ClaimGuidGenerator;
-use Wikibase\Lib\InMemoryDataTypeLookup;
-use Wikibase\Lib\Serializers\SerializerFactory;
+use Wikibase\Lib\OutputFormatSnakFormatterFactory;
+use Wikibase\Lib\PropertyDataTypeLookup;
 use Wikibase\Lib\Serializers\SerializationOptions;
 use Wikibase\Lib\SnakFormatter;
+use Wikibase\Lib\WikibaseSnakFormatterBuilders;
 use Wikibase\ParserOutputJsConfigBuilder;
-use Wikibase\Property;
-use Wikibase\PropertyNoValueSnak;
-use Wikibase\PropertySomeValueSnak;
-use Wikibase\PropertyValueSnak;
 use Wikibase\ReferencedEntitiesFinder;
 use Wikibase\Repo\WikibaseRepo;
-use Wikibase\Snak;
 use Wikibase\Utils;
 
 /**
@@ -112,7 +109,7 @@
         */
        protected function newEntityView( $entityType, EntityInfoBuilder 
$entityInfoBuilder = null,
                EntityTitleLookup $entityTitleLookup = null, IContextSource 
$context = null,
-               LanguageFallbackChain $languageFallbackChain = null
+               LanguageFallbackChain $languageFallbackChain = null, 
PropertyDataTypeLookup $dataTypeLookup = null
        ) {
                if ( !is_string( $entityType ) ) {
                        throw new InvalidArgumentException( '$entityType must 
be a string!' );
@@ -140,11 +137,23 @@
                        $entityTitleLookup = $this->getEntityTitleLookupMock();
                }
 
-               $idParser = $this->newEntityIdParser();
+               if ( !$dataTypeLookup ) {
+                       $dataTypeLookup = $mockRepo;
+               }
 
+               $appContext = WikibaseRepo::getDefaultInstance();
+
+               $idParser = $this->newEntityIdParser();
                $formatterOptions = new FormatterOptions();
-               $snakFormatter = 
WikibaseRepo::getDefaultInstance()->getSnakFormatterFactory()
-                       ->getSnakFormatter( SnakFormatter::FORMAT_HTML_WIDGET, 
$formatterOptions );
+
+               $builders = new WikibaseSnakFormatterBuilders(
+                       $appContext->getValueFormatterBuilders(),
+                       $dataTypeLookup,
+                       $appContext->getDataTypeFactory()
+               );
+
+               $factory = new OutputFormatSnakFormatterFactory( 
$builders->getSnakFormatterBuildersForFormats() );
+               $snakFormatter = $factory->getSnakFormatter( 
SnakFormatter::FORMAT_HTML_WIDGET, $formatterOptions );
 
                $configBuilder = new ParserOutputJsConfigBuilder(
                        $entityInfoBuilder,

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I41b489ff5b5ea474861922a8c50b214e67851319
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>

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

Reply via email to