Daniel Kinzler has uploaded a new change for review.
https://gerrit.wikimedia.org/r/138827
Change subject: Don't use services in EntityContent
......................................................................
Don't use services in EntityContent
Content objects shoudl ideally be value objects. This moves
any code that relies on services into the associated ContentHandler,
instead of having it in the Content object itself. This allows
such services to be injected when constructing the handler.
Note that the construction of EntityView objects is moved to
EntityHandler for now, but should be factoried into a separate
factory eventually.
Change-Id: I99753f806fa37bd21cc122a68dd47c4565484b25
---
M repo/Wikibase.hooks.php
M repo/includes/WikibaseRepo.php
M repo/includes/content/EntityContent.php
M repo/includes/content/EntityContentFactory.php
M repo/includes/content/EntityHandler.php
M repo/includes/content/ItemContent.php
M repo/includes/content/ItemHandler.php
M repo/includes/content/PropertyContent.php
M repo/includes/content/PropertyHandler.php
M repo/tests/phpunit/includes/content/EntityContentTest.php
M repo/tests/phpunit/includes/content/EntityHandlerTest.php
11 files changed, 269 insertions(+), 358 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/27/138827/1
diff --git a/repo/Wikibase.hooks.php b/repo/Wikibase.hooks.php
index 4c5274e..14432c5 100644
--- a/repo/Wikibase.hooks.php
+++ b/repo/Wikibase.hooks.php
@@ -1245,9 +1245,10 @@
$codec = $repo->getEntityContentDataCodec();
$entityPerPage = $repo->getStore()->newEntityPerPage();
$termIndex = $repo->getStore()->getTermIndex();
+ $errorLocalizer = $repo->getValidatorErrorLocalizer();
$siteLinkStore = $repo->getStore()->newSiteLinkCache();
- return new ItemHandler( $entityPerPage, $termIndex, $codec,
array( $validator ), $siteLinkStore );
+ return new ItemHandler( $entityPerPage, $termIndex, $codec,
array( $validator ), $errorLocalizer, $siteLinkStore );
}
private static function newPropertyHandler() {
@@ -1256,9 +1257,10 @@
$codec = $repo->getEntityContentDataCodec();
$entityPerPage = $repo->getStore()->newEntityPerPage();
$termIndex = $repo->getStore()->getTermIndex();
+ $errorLocalizer = $repo->getValidatorErrorLocalizer();
$propertyInfoStore = $repo->getStore()->getPropertyInfoStore();
- return new PropertyHandler( $entityPerPage, $termIndex, $codec,
array( $validator ), $propertyInfoStore );
+ return new PropertyHandler( $entityPerPage, $termIndex, $codec,
array( $validator ), $errorLocalizer, $propertyInfoStore );
}
/**
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index dc670fd..8db9b9b 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -6,6 +6,7 @@
use DataValues\DataValueFactory;
use SiteSQLStore;
use SiteStore;
+use StubObject;
use ValueFormatters\FormatterOptions;
use ValueFormatters\ValueFormatter;
use Wikibase\ChangeNotifier;
@@ -672,6 +673,7 @@
*/
protected function getMessageParameterFormatter() {
global $wgLang;
+ StubObject::unstub( $wgLang );
$formatterOptions = new FormatterOptions();
$valueFormatterBuilders = $this->getValueFormatterBuilders();
diff --git a/repo/includes/content/EntityContent.php
b/repo/includes/content/EntityContent.php
index e272add..a9b4581 100644
--- a/repo/includes/content/EntityContent.php
+++ b/repo/includes/content/EntityContent.php
@@ -4,27 +4,15 @@
use AbstractContent;
use Content;
-use Diff\DiffOp\Diff\Diff;
use DataUpdate;
-use IContextSource;
+use Diff\DiffOp\Diff\Diff;
use ParserOptions;
use ParserOutput;
-use RequestContext;
use Status;
use Title;
use User;
-use ValueFormatters\FormatterOptions;
-use ValueFormatters\ValueFormatter;
-use ValueValidators\Result;
-use Wikibase\DataModel\Entity\BasicEntityIdParser;
use Wikibase\Repo\Content\EntityContentDiff;
-use Wikibase\DataModel\Entity\EntityIdParser;
-use Wikibase\Lib\PropertyDataTypeLookup;
-use Wikibase\Lib\Serializers\SerializationOptions;
-use Wikibase\Lib\SnakFormatter;
use Wikibase\Repo\EntitySearchTextGenerator;
-use Wikibase\Repo\WikibaseRepo;
-use Wikibase\Validators\EntityValidator;
use WikiPage;
/**
@@ -37,7 +25,6 @@
* @author Daniel Kinzler
*/
abstract class EntityContent extends AbstractContent {
-
/**
* For use in the wb-status page property to indicate that the entity
has no special
@@ -77,27 +64,6 @@
}
/**
- * Returns the Title for the item or false if there is none.
- *
- * @since 0.1
- * @deprecated use EntityTitleLookup instead
- *
- * @deprecated since 0.5, use EntityTitleLookup:.getTitleForId instead.
- *
- * @return Title|bool
- */
- public function getTitle() {
- $id = $this->getEntity()->getId();
-
- if ( !$id ) {
- return false;
- }
-
- $lookup =
WikibaseRepo::getDefaultInstance()->getEntityTitleLookup();
- return $lookup->getTitleForId( $id );
- }
-
- /**
* Returns the entity contained by this entity content.
* Deriving classes typically have a more specific get method as
* for greater clarity and type hinting.
@@ -107,6 +73,18 @@
* @return Entity
*/
abstract public function getEntity();
+
+ /**
+ * Returns the ID of the entity represented by this EntityContent;
+ *
+ * @return null|EntityId
+ *
+ * @todo: Force an ID to be present; Entity objects without an ID may
sense, EntityContent
+ * objects with no entity ID don't.
+ */
+ public function getEntityId() {
+ return $this->getEntity()->getId();
+ }
/**
* @see Content::getDeletionUpdates
@@ -178,7 +156,9 @@
public function getParserOutput( Title $title, $revId = null,
ParserOptions $options = null,
$generateHtml = true
) {
- $entityView = $this->getEntityView( null, $options, null );
+ /* @var EntityHandler $handler */
+ $handler = $this->getContentHandler();
+ $entityView = $handler->getEntityView( null, $options, null );
$editable = !$options? true : $options->getEditSection();
if ( $revId === null || $revId === 0 ) {
@@ -199,105 +179,6 @@
return $output;
}
-
- /**
- * Creates an EntityView suitable for rendering the entity.
- *
- * @note: this uses global state to access the services needed for
- * displaying the entity.
- *
- * @since 0.5
- *
- * @param IContextSource|null $context
- * @param ParserOptions|null $options
- * @param LanguageFallbackChain|null $uiLanguageFallbackChain
- *
- * @return EntityView
- */
- public function getEntityView( IContextSource $context = null,
ParserOptions $options = null,
- LanguageFallbackChain $uiLanguageFallbackChain = null
- ) {
- //TODO: cache last used entity view
-
- if ( $context === null ) {
- $context = RequestContext::getMain();
- }
-
- // determine output language ----
- $langCode = $context->getLanguage()->getCode();
-
- if ( $options !== null ) {
- // NOTE: Parser Options language overrides context
language!
- $langCode = $options->getUserLang();
- }
-
- // make formatter options ----
- $formatterOptions = new FormatterOptions();
- $formatterOptions->setOption( ValueFormatter::OPT_LANG,
$langCode );
-
- // Force the context's language to be the one specified by the
parser options.
- if ( $context && $context->getLanguage()->getCode() !==
$langCode ) {
- $context = clone $context;
- $context->setLanguage( $langCode );
- }
-
- // apply language fallback chain ----
- if ( !$uiLanguageFallbackChain ) {
- $factory =
WikibaseRepo::getDefaultInstance()->getLanguageFallbackChainFactory();
- $uiLanguageFallbackChain =
$factory->newFromContextForPageView( $context );
- }
-
- $formatterOptions->setOption( 'languages',
$uiLanguageFallbackChain );
-
- // get all the necessary services ----
- $snakFormatter =
WikibaseRepo::getDefaultInstance()->getSnakFormatterFactory()
- ->getSnakFormatter( SnakFormatter::FORMAT_HTML_WIDGET,
$formatterOptions );
-
- $dataTypeLookup =
WikibaseRepo::getDefaultInstance()->getPropertyDataTypeLookup();
- $entityInfoBuilder =
WikibaseRepo::getDefaultInstance()->getStore()->getEntityInfoBuilder();
- $entityContentFactory =
WikibaseRepo::getDefaultInstance()->getEntityContentFactory();
- $idParser = new BasicEntityIdParser();
-
- $options = $this->makeSerializationOptions( $langCode,
$uiLanguageFallbackChain );
-
- // construct the instance ----
- $entityView = $this->newEntityView(
- $context,
- $snakFormatter,
- $dataTypeLookup,
- $entityInfoBuilder,
- $entityContentFactory,
- $idParser,
- $options
- );
-
- return $entityView;
- }
-
- /**
- * Instantiates an EntityView.
- *
- * @see getEntityView()
- *
- * @param IContextSource $context
- * @param SnakFormatter $snakFormatter
- * @param Lib\PropertyDataTypeLookup $dataTypeLookup
- * @param EntityInfoBuilder $entityInfoBuilder
- * @param EntityTitleLookup $entityTitleLookup
- * @param EntityIdParser $idParser
- * @param SerializationOptions $options
- *
- * @return EntityView
- */
- protected abstract function newEntityView(
- IContextSource $context,
- SnakFormatter $snakFormatter,
- PropertyDataTypeLookup $dataTypeLookup,
- EntityInfoBuilder $entityInfoBuilder,
- EntityTitleLookup $entityTitleLookup,
- EntityIdParser $idParser,
- SerializationOptions $options
- );
/**
* @return String a string representing the content in a way useful for
building a full text
@@ -499,13 +380,11 @@
* @return ItemContent
*/
public function copy() {
- $array = array();
+ /* @var EntityHandler $handler */
+ $handler = $this->getContentHandler();
- foreach ( $this->getEntity()->toArray() as $key => $value ) {
- $array[$key] = is_object( $value ) ? clone $value :
$value;
- }
-
- return static::newFromArray( $array );
+ $entity = $this->getEntity()->copy();
+ return $handler->makeEntityContent( $entity );
}
/**
@@ -528,49 +407,12 @@
return $status;
}
- $status = $this->applyOnSaveValidators();
+ /* @var EntityHandler $handler */
+ $handler = $this->getContentHandler();
+ $status = $handler->applyOnSaveValidators( $this );
wfProfileOut( __METHOD__ );
return $status;
- }
-
- /**
- * Apply all EntityValidators registered for on-save validation.
- */
- private function applyOnSaveValidators() {
- /* @var EntityHandler $handler */
- $handler = $this->getContentHandler();
- $validators = $handler->getOnSaveValidators();
-
- $entity = $this->getEntity();
- $result = Result::newSuccess();
-
- /* @var EntityValidator $validator */
- foreach ( $validators as $validator ) {
- $result = $validator->validateEntity( $entity );
-
- if ( !$result->isValid() ) {
- break;
- }
- }
-
- $localizer =
WikibaseRepo::getDefaultInstance()->getValidatorErrorLocalizer();
- return $localizer->getResultStatus( $result );
- }
-
- /**
- * @param string $langCode
- * @param LanguageFallbackChain $fallbackChain
- *
- * @return SerializationOptions
- */
- private function makeSerializationOptions( $langCode,
LanguageFallbackChain $fallbackChain ) {
- $langCodes = Utils::getLanguageCodes() + array( $langCode =>
$fallbackChain );
-
- $options = new SerializationOptions();
- $options->setLanguages( $langCodes );
-
- return $options;
}
/**
diff --git a/repo/includes/content/EntityContentFactory.php
b/repo/includes/content/EntityContentFactory.php
index a1a4459..797c330 100644
--- a/repo/includes/content/EntityContentFactory.php
+++ b/repo/includes/content/EntityContentFactory.php
@@ -106,7 +106,7 @@
*
* @since 0.5
*
- * @param int $type
+ * @param string $type
*
* @throws OutOfBoundsException if no content model is defined for the
given entity type.
* @return EntityHandler
@@ -121,7 +121,7 @@
*
* @since 0.5
*
- * @param int $type
+ * @param string $type
*
* @throws OutOfBoundsException if no content model is defined for the
given entity type.
* @return int
@@ -141,7 +141,7 @@
*
* @since 0.2
*
- * @param integer $revisionId
+ * @param int $revisionId
*
* @return EntityContent|null
*/
diff --git a/repo/includes/content/EntityHandler.php
b/repo/includes/content/EntityHandler.php
index 7ea23df..9b7fe25 100644
--- a/repo/includes/content/EntityHandler.php
+++ b/repo/includes/content/EntityHandler.php
@@ -14,10 +14,17 @@
use Revision;
use Title;
use User;
+use ValueFormatters\FormatterOptions;
+use ValueFormatters\ValueFormatter;
+use ValueValidators\Result;
use Wikibase\DataModel\Entity\BasicEntityIdParser;
+use Wikibase\Lib\Serializers\SerializationOptions;
+use Wikibase\Lib\SnakFormatter;
use Wikibase\Lib\Store\EntityContentDataCodec;
+use Wikibase\Repo\WikibaseRepo;
use Wikibase\Updates\DataUpdateClosure;
use Wikibase\Validators\EntityValidator;
+use Wikibase\Validators\ValidatorErrorLocalizer;
/**
* Base handler class for Wikibase\Entity content classes.
@@ -51,18 +58,25 @@
private $termIndex;
/**
+ * @var ValidatorErrorLocalizer
+ */
+ private $errorLocalizer;
+
+ /**
* @param string $modelId
* @param EntityPerPage $entityPerPage
* @param TermIndex $termIndex
* @param EntityContentDataCodec $contentCodec
* @param EntityValidator[] $preSaveValidators
+ * @param ValidatorErrorLocalizer $errorLocalizer
*/
public function __construct(
$modelId,
EntityPerPage $entityPerPage,
TermIndex $termIndex,
EntityContentDataCodec $contentCodec,
- array $preSaveValidators
+ array $preSaveValidators,
+ ValidatorErrorLocalizer $errorLocalizer
) {
$formats = $contentCodec->getSupportedFormats();
@@ -72,6 +86,7 @@
$this->preSaveValidators = $preSaveValidators;
$this->entityPerPage = $entityPerPage;
$this->termIndex = $termIndex;
+ $this->errorLocalizer = $errorLocalizer;
}
/**
@@ -95,13 +110,35 @@
}
/**
- * Returns a set of validators for enforcing hard constraints on the
content
- * before saving. For soft constraints, see the TermValidatorFactory.
+ * Returns the concrete EntityView implementation to use.
*
- * @return EntityValidator[]
+ * @since 0.5
+ *
+ * @return string The class name.
*/
- public function getOnSaveValidators() {
- return $this->preSaveValidators;
+ protected abstract function getEntityViewClass();
+
+ /**
+ * Apply all EntityValidators registered for on-save validation
+ *
+ * @param EntityContent $content
+ *
+ * @return \Status
+ */
+ public function applyOnSaveValidators( EntityContent $content ) {
+ $entity = $content->getEntity();
+ $result = Result::newSuccess();
+
+ /* @var EntityValidator $validator */
+ foreach ( $this->preSaveValidators as $validator ) {
+ $result = $validator->validateEntity( $entity );
+
+ if ( !$result->isValid() ) {
+ break;
+ }
+ }
+
+ return $this->errorLocalizer->getResultStatus( $result );
}
/**
@@ -517,4 +554,93 @@
return $updates;
}
+
+ /**
+ * Creates an EntityView suitable for rendering the entity.
+ *
+ * @note: this uses global state to access the services needed for
+ * displaying the entity.
+ *
+ * @since 0.5
+ *
+ * @param IContextSource|null $context
+ * @param ParserOptions|null $options
+ * @param LanguageFallbackChain|null $uiLanguageFallbackChain
+ *
+ * @return EntityView
+ *
+ * @todo Factor out into a EntityViewFactory class, and inject that!
+ */
+ public function getEntityView( IContextSource $context = null,
ParserOptions $options = null,
+ LanguageFallbackChain $uiLanguageFallbackChain = null
+ ) {
+ if ( $context === null ) {
+ $context = RequestContext::getMain();
+ }
+
+ // determine output language ----
+ $langCode = $context->getLanguage()->getCode();
+
+ if ( $options !== null ) {
+ // NOTE: Parser Options language overrides context
language!
+ $langCode = $options->getUserLang();
+ }
+
+ // make formatter options ----
+ $formatterOptions = new FormatterOptions();
+ $formatterOptions->setOption( ValueFormatter::OPT_LANG,
$langCode );
+
+ // Force the context's language to be the one specified by the
parser options.
+ if ( $context && $context->getLanguage()->getCode() !==
$langCode ) {
+ $context = clone $context;
+ $context->setLanguage( $langCode );
+ }
+
+ // apply language fallback chain ----
+ if ( !$uiLanguageFallbackChain ) {
+ $factory =
WikibaseRepo::getDefaultInstance()->getLanguageFallbackChainFactory();
+ $uiLanguageFallbackChain =
$factory->newFromContextForPageView( $context );
+ }
+
+ $formatterOptions->setOption( 'languages',
$uiLanguageFallbackChain );
+
+ // get all the necessary services ----
+ $snakFormatter =
WikibaseRepo::getDefaultInstance()->getSnakFormatterFactory()
+ ->getSnakFormatter( SnakFormatter::FORMAT_HTML_WIDGET,
$formatterOptions );
+
+ $dataTypeLookup =
WikibaseRepo::getDefaultInstance()->getPropertyDataTypeLookup();
+ $entityInfoBuilder =
WikibaseRepo::getDefaultInstance()->getStore()->getEntityInfoBuilder();
+ $entityContentFactory =
WikibaseRepo::getDefaultInstance()->getEntityContentFactory();
+ $entityTitleLookup =
WikibaseRepo::getDefaultInstance()->getEntityContentFactory();
+ $idParser = new BasicEntityIdParser();
+
+ $langCodes = Utils::getLanguageCodes() + array( $langCode =>
$uiLanguageFallbackChain );
+
+ $options = new SerializationOptions();
+ $options->setLanguages( $langCodes );
+
+ $configBuilder = new ParserOutputJsConfigBuilder(
+ $entityInfoBuilder,
+ $idParser,
+ $entityContentFactory,
+ new ReferencedEntitiesFinder(),
+ $context->getLanguage()->getCode()
+ );
+
+ // construct the instance ----
+ $viewClass = $this->getEntityViewClass();
+
+ $entityView = new $viewClass(
+ $context,
+ $snakFormatter,
+ $dataTypeLookup,
+ $entityInfoBuilder,
+ $entityTitleLookup,
+ $options,
+ $configBuilder
+ );
+
+ return $entityView;
+ }
+
}
diff --git a/repo/includes/content/ItemContent.php
b/repo/includes/content/ItemContent.php
index d784d26..b542cd1 100644
--- a/repo/includes/content/ItemContent.php
+++ b/repo/includes/content/ItemContent.php
@@ -2,11 +2,6 @@
namespace Wikibase;
-use IContextSource;
-use Wikibase\DataModel\Entity\EntityIdParser;
-use Wikibase\Lib\PropertyDataTypeLookup;
-use Wikibase\Lib\Serializers\SerializationOptions;
-use Wikibase\Lib\SnakFormatter;
use Wikibase\Repo\ItemSearchTextGenerator;
/**
@@ -118,49 +113,6 @@
}
/**
- * Instantiates an EntityView.
- *
- * @see getEntityView()
- *
- * @param IContextSource $context
- * @param SnakFormatter $snakFormatter
- * @param PropertyDataTypeLookup $dataTypeLookup
- * @param EntityInfoBuilder $entityInfoBuilder
- * @param EntityTitleLookup $entityTitleLookup
- * @param EntityIdParser $idParser
- * @param SerializationOptions $options
- *
- * @return EntityView
- */
- protected function newEntityView(
- IContextSource $context,
- SnakFormatter $snakFormatter,
- PropertyDataTypeLookup $dataTypeLookup,
- EntityInfoBuilder $entityInfoBuilder,
- EntityTitleLookup $entityTitleLookup,
- EntityIdParser $idParser,
- SerializationOptions $options
- ) {
- $configBuilder = new ParserOutputJsConfigBuilder(
- $entityInfoBuilder,
- $idParser,
- $entityTitleLookup,
- new ReferencedEntitiesFinder(),
- $context->getLanguage()->getCode()
- );
-
- return new ItemView(
- $context,
- $snakFormatter,
- $dataTypeLookup,
- $entityInfoBuilder,
- $entityTitleLookup,
- $options,
- $configBuilder
- );
- }
-
- /**
* @see EntityContent::getEntityPageProperties
*
* Records the number of sitelinks in the 'wb-sitelinks' key.
@@ -173,7 +125,7 @@
return array_merge(
parent::getEntityPageProperties(),
array(
- 'wb-sitelinks' =>
$item->getSiteLinkList()->count(),
+ 'wb-sitelinks' => count( $item->getSiteLinks()
),
)
);
}
diff --git a/repo/includes/content/ItemHandler.php
b/repo/includes/content/ItemHandler.php
index 149179d..da2d2a5 100644
--- a/repo/includes/content/ItemHandler.php
+++ b/repo/includes/content/ItemHandler.php
@@ -8,6 +8,7 @@
use Wikibase\Lib\Store\SiteLinkCache;
use Wikibase\Updates\DataUpdateClosure;
use Wikibase\Validators\EntityValidator;
+use Wikibase\Validators\ValidatorErrorLocalizer;
/**
* Content handler for Wikibase items.
@@ -25,6 +26,34 @@
private $siteLinkStore;
/**
+ * @param EntityPerPage $entityPerPage
+ * @param TermIndex $termIndex
+ * @param EntityContentDataCodec $contentCodec
+ * @param EntityValidator[] $preSaveValidators
+ * @param ValidatorErrorLocalizer $errorLocalizer
+ * @param SiteLinkCache $siteLinkStore
+ */
+ public function __construct(
+ EntityPerPage $entityPerPage,
+ TermIndex $termIndex,
+ EntityContentDataCodec $contentCodec,
+ array $preSaveValidators,
+ ValidatorErrorLocalizer $errorLocalizer,
+ SiteLinkCache $siteLinkStore
+ ) {
+ parent::__construct(
+ CONTENT_MODEL_WIKIBASE_ITEM,
+ $entityPerPage,
+ $termIndex,
+ $contentCodec,
+ $preSaveValidators,
+ $errorLocalizer
+ );
+
+ $this->siteLinkStore = $siteLinkStore;
+ }
+
+ /**
* @see EntityHandler::getContentClass
*
* @since 0.3
@@ -36,28 +65,14 @@
}
/**
- * @param EntityPerPage $entityPerPage
- * @param TermIndex $termIndex
- * @param EntityContentDataCodec $contentCodec
- * @param EntityValidator[] $preSaveValidators
- * @param SiteLinkCache $siteLinkStore
+ * @see EntityHandler::getEntityViewClass
+ *
+ * @since 0.5
+ *
+ * @return string The class name.
*/
- public function __construct(
- EntityPerPage $entityPerPage,
- TermIndex $termIndex,
- EntityContentDataCodec $contentCodec,
- array $preSaveValidators,
- SiteLinkCache $siteLinkStore
- ) {
- parent::__construct(
- CONTENT_MODEL_WIKIBASE_ITEM,
- $entityPerPage,
- $termIndex,
- $contentCodec,
- $preSaveValidators
- );
-
- $this->siteLinkStore = $siteLinkStore;
+ protected function getEntityViewClass() {
+ return '\Wikibase\ItemView';
}
/**
@@ -142,4 +157,5 @@
parent::getEntityModificationUpdates( $content, $title )
);
}
+
}
diff --git a/repo/includes/content/PropertyContent.php
b/repo/includes/content/PropertyContent.php
index 34a7ef9..fb14a84 100644
--- a/repo/includes/content/PropertyContent.php
+++ b/repo/includes/content/PropertyContent.php
@@ -2,12 +2,6 @@
namespace Wikibase;
-use IContextSource;
-use Wikibase\DataModel\Entity\EntityIdParser;
-use Wikibase\Lib\PropertyDataTypeLookup;
-use Wikibase\Lib\Serializers\SerializationOptions;
-use Wikibase\Lib\SnakFormatter;
-
/**
* Content object for articles representing Wikibase properties.
*
@@ -111,46 +105,4 @@
return $this->property;
}
- /**
- * Instantiates an EntityView.
- *
- * @see getEntityView()
- *
- * @param IContextSource $context
- * @param SnakFormatter $snakFormatter
- * @param PropertyDataTypeLookup $dataTypeLookup
- * @param EntityInfoBuilder $entityInfoBuilder
- * @param EntityTitleLookup $entityTitleLookup
- * @param EntityIdParser $idParser
- * @param SerializationOptions $options
- *
- * @return EntityView
- */
- protected function newEntityView(
- IContextSource $context,
- SnakFormatter $snakFormatter,
- PropertyDataTypeLookup $dataTypeLookup,
- EntityInfoBuilder $entityInfoBuilder,
- EntityTitleLookup $entityTitleLookup,
- EntityIdParser $idParser,
- SerializationOptions $options
- ) {
- $configBuilder = new ParserOutputJsConfigBuilder(
- $entityInfoBuilder,
- $idParser,
- $entityTitleLookup,
- new ReferencedEntitiesFinder(),
- $context->getLanguage()->getCode()
- );
-
- return new PropertyView(
- $context,
- $snakFormatter,
- $dataTypeLookup,
- $entityInfoBuilder,
- $entityTitleLookup,
- $options,
- $configBuilder
- );
- }
}
diff --git a/repo/includes/content/PropertyHandler.php
b/repo/includes/content/PropertyHandler.php
index e697721..8400e32 100644
--- a/repo/includes/content/PropertyHandler.php
+++ b/repo/includes/content/PropertyHandler.php
@@ -7,6 +7,7 @@
use Wikibase\Lib\Store\EntityContentDataCodec;
use Wikibase\Updates\DataUpdateClosure;
use Wikibase\Validators\EntityValidator;
+use Wikibase\Validators\ValidatorErrorLocalizer;
/**
* Content handler for Wikibase items.
@@ -36,10 +37,22 @@
}
/**
+ * @see EntityHandler::getEntityViewClass
+ *
+ * @since 0.5
+ *
+ * @return string The class name.
+ */
+ protected function getEntityViewClass() {
+ return '\Wikibase\PropertyView';
+ }
+
+ /**
* @param EntityPerPage $entityPerPage
* @param TermIndex $termIndex
* @param EntityContentDataCodec $contentCodec
* @param EntityValidator[] $preSaveValidators
+ * @param ValidatorErrorLocalizer $errorLocalizer
* @param PropertyInfoStore $infoStore
*/
public function __construct(
@@ -47,6 +60,7 @@
TermIndex $termIndex,
EntityContentDataCodec $contentCodec,
$preSaveValidators,
+ ValidatorErrorLocalizer $errorLocalizer,
PropertyInfoStore $infoStore
) {
parent::__construct(
@@ -54,7 +68,8 @@
$entityPerPage,
$termIndex,
$contentCodec,
- $preSaveValidators
+ $preSaveValidators,
+ $errorLocalizer
);
$this->infoStore = $infoStore;
diff --git a/repo/tests/phpunit/includes/content/EntityContentTest.php
b/repo/tests/phpunit/includes/content/EntityContentTest.php
index bdb4568..68891dc 100644
--- a/repo/tests/phpunit/includes/content/EntityContentTest.php
+++ b/repo/tests/phpunit/includes/content/EntityContentTest.php
@@ -254,53 +254,6 @@
$this->assertArrayEquals( array_keys( $pageProps ), array_keys(
$actual ) );
}
- public function dataGetEntityView() {
- $context = new RequestContext();
- $context->setLanguage( 'de' );
-
- $options = new ParserOptions();
- $options->setUserLang( 'nl' );
-
- $fallbackChain = new LanguageFallbackChain( array(
- LanguageWithConversion::factory(
$context->getLanguage() )
- ) );
-
- return array(
- array( $context, null, null ),
- array( null, $options, null ),
- array( $context, $options, null ),
-
- array( $context, null, $fallbackChain ),
- array( null, $options, $fallbackChain ),
- array( $context, $options, $fallbackChain ),
- );
- }
-
- /**
- * @dataProvider dataGetEntityView
- *
- * @param IContextSource $context
- * @param ParserOptions $parserOptions
- * @param LanguageFallbackChain $fallbackChain
- */
- public function testGetEntityView(
- IContextSource $context = null,
- ParserOptions $parserOptions = null,
- LanguageFallbackChain $fallbackChain = null
- ) {
- $content = $this->newEmpty();
- $view = $content->getEntityView( $context, $parserOptions,
$fallbackChain );
-
- $this->assertInstanceOf( 'Wikibase\EntityView', $view );
-
- if ( $parserOptions ) {
- // NOTE: the view must be using the language from the
parser options.
- $this->assertEquals( $view->getLanguage()->getCode(),
$parserOptions->getUserLang() );
- } elseif ( $content ) {
- $this->assertEquals( $view->getLanguage()->getCode(),
$context->getLanguage()->getCode() );
- }
- }
-
public function diffProvider() {
$empty = $this->newEmpty();
diff --git a/repo/tests/phpunit/includes/content/EntityHandlerTest.php
b/repo/tests/phpunit/includes/content/EntityHandlerTest.php
index 1ec9b2f..8399318 100644
--- a/repo/tests/phpunit/includes/content/EntityHandlerTest.php
+++ b/repo/tests/phpunit/includes/content/EntityHandlerTest.php
@@ -3,13 +3,18 @@
namespace Wikibase\Test;
use ContentHandler;
+use IContextSource;
use Language;
+use ParserOptions;
+use RequestContext;
use Revision;
use Title;
use Wikibase\Entity;
use Wikibase\EntityContent;
use Wikibase\EntityFactory;
use Wikibase\EntityHandler;
+use Wikibase\LanguageFallbackChain;
+use Wikibase\LanguageWithConversion;
use Wikibase\Repo\WikibaseRepo;
/**
@@ -277,4 +282,50 @@
$this->assertEquals( $this->getModelId(), $content->getModel()
);
}
+
+ public function dataGetEntityView() {
+ $context = new RequestContext();
+ $context->setLanguage( 'de' );
+
+ $options = new ParserOptions();
+ $options->setUserLang( 'nl' );
+
+ $fallbackChain = new LanguageFallbackChain( array(
+ LanguageWithConversion::factory(
$context->getLanguage() )
+ ) );
+
+ return array(
+ array( $context, null, null ),
+ array( null, $options, null ),
+ array( $context, $options, null ),
+
+ array( $context, null, $fallbackChain ),
+ array( null, $options, $fallbackChain ),
+ array( $context, $options, $fallbackChain ),
+ );
+ }
+
+ /**
+ * @dataProvider dataGetEntityView
+ *
+ * @param IContextSource $context
+ * @param ParserOptions $parserOptions
+ * @param LanguageFallbackChain $fallbackChain
+ */
+ public function testGetEntityView(
+ IContextSource $context = null,
+ ParserOptions $parserOptions = null,
+ LanguageFallbackChain $fallbackChain = null
+ ) {
+ $handler = $this->getHandler();
+ $view = $handler->getEntityView( $context, $parserOptions,
$fallbackChain );
+
+ $this->assertInstanceOf( 'Wikibase\EntityView', $view );
+
+ if ( $parserOptions ) {
+ // NOTE: the view must be using the language from the
parser options.
+ $this->assertEquals( $view->getLanguage()->getCode(),
$parserOptions->getUserLang() );
+ }
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/138827
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I99753f806fa37bd21cc122a68dd47c4565484b25
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