Matěj Suchánek has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/345132 )
Change subject: Don't allow creating properties with arbitrary datatypes
......................................................................
Don't allow creating properties with arbitrary datatypes
Bug: T128724
Change-Id: I778a5ac96fe895968f9c8709fece3053e79da95b
---
M repo/includes/Api/EditEntity.php
M repo/tests/phpunit/includes/Api/EditEntityTest.php
2 files changed, 18 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/32/345132/2
diff --git a/repo/includes/Api/EditEntity.php b/repo/includes/Api/EditEntity.php
index f2827f2..e218e02 100644
--- a/repo/includes/Api/EditEntity.php
+++ b/repo/includes/Api/EditEntity.php
@@ -3,6 +3,7 @@
namespace Wikibase\Repo\Api;
use ApiMain;
+use DataTypes\DataTypeFactory;
use Deserializers\Deserializer;
use InvalidArgumentException;
use MWException;
@@ -68,6 +69,11 @@
private $statementDeserializer;
/**
+ * @var DataTypeFactory
+ */
+ private $dataTypeFactory;
+
+ /**
* @var EntityIdParser
*/
private $idParser;
@@ -100,6 +106,7 @@
$this->idParser = $wikibaseRepo->getEntityIdParser();
$this->entityFactory = $wikibaseRepo->getEntityFactory();
$this->statementDeserializer =
$wikibaseRepo->getExternalFormatStatementDeserializer();
+ $this->dataTypeFactory = $wikibaseRepo->getDataTypeFactory();
$changeOpFactoryProvider =
$wikibaseRepo->getChangeOpFactoryProvider();
$this->termChangeOpFactory =
$changeOpFactoryProvider->getFingerprintChangeOpFactory();
@@ -230,6 +237,8 @@
if ( !$exists && $entity instanceof Property ) {
if ( !isset( $data['datatype'] ) ) {
$this->errorReporter->dieError( 'No datatype
given', 'param-illegal' );
+ } elseif ( !in_array( $data['datatype'],
$this->dataTypeFactory->getTypeIds() ) ) {
+ $this->errorReporter->dieError( 'Invalid
datatype given', 'param-illegal' );
} else {
$entity->setDataTypeId( $data['datatype'] );
}
diff --git a/repo/tests/phpunit/includes/Api/EditEntityTest.php
b/repo/tests/phpunit/includes/Api/EditEntityTest.php
index 9b4d943..d845d56 100644
--- a/repo/tests/phpunit/includes/Api/EditEntityTest.php
+++ b/repo/tests/phpunit/includes/Api/EditEntityTest.php
@@ -849,6 +849,15 @@
'code' => 'not-supported',
'message' => 'The requested feature is
not supported by the given entity'
) ) ),
+ 'property with invalid datatype' => array(
+ 'p' => array(
+ 'new' => 'property',
+ 'data' => '{"datatype":"invalid"}',
+ ),
+ 'e' => array( 'exception' => array(
+ 'type' => ApiUsageException::class,
+ 'code' => 'param-illegal'
+ ) ) ),
'create mediainfo with automatic id' => array(
'p' => array( 'new' => 'mediainfo', 'data' =>
'{}' ),
'e' => array( 'exception' => array(
--
To view, visit https://gerrit.wikimedia.org/r/345132
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I778a5ac96fe895968f9c8709fece3053e79da95b
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits