Addshore has uploaded a new change for review. https://gerrit.wikimedia.org/r/227200
Change subject: Fix wbgetclaims props parameter ...................................................................... Fix wbgetclaims props parameter Bug: T106899 Change-Id: I934e7eb6a18ab24d84f43fcde144189079654323 --- M repo/includes/api/GetClaims.php M repo/includes/api/ResultBuilder.php M repo/tests/phpunit/includes/api/ResultBuilderTest.php 3 files changed, 60 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/00/227200/1 diff --git a/repo/includes/api/GetClaims.php b/repo/includes/api/GetClaims.php index d87331c..fe63dff 100644 --- a/repo/includes/api/GetClaims.php +++ b/repo/includes/api/GetClaims.php @@ -114,7 +114,7 @@ } $claims = $this->getClaims( $entity, $guid ); - $this->resultBuilder->addClaims( $claims, null ); + $this->resultBuilder->addClaims( $claims, null, $params['props'] ); } private function validateParameters( array $params ) { @@ -254,6 +254,7 @@ 'references', ), self::PARAM_DFLT => 'references', + self::PARAM_ISMULTI => true, ), 'ungroupedlist' => array( self::PARAM_TYPE => 'boolean', diff --git a/repo/includes/api/ResultBuilder.php b/repo/includes/api/ResultBuilder.php index ed788ea..b301b4f 100644 --- a/repo/includes/api/ResultBuilder.php +++ b/repo/includes/api/ResultBuilder.php @@ -582,12 +582,24 @@ * * @param Claim[] $claims the labels to set in the result * @param array|string $path where the data is located + * @param array|string $props a list of fields to include, or "all" */ - public function addClaims( array $claims, $path ) { + public function addClaims( array $claims, $path, $props = 'all' ) { $claimsSerializer = $this->libSerializerFactory->newClaimsSerializer( $this->getOptions() ); $values = $claimsSerializer->getSerialized( new Claims( $claims ) ); + if ( is_array( $props ) && !in_array( 'references', $props ) ) { + $values = $this->modifier->modifyUsingCallback( + $values, + '*/*', + function ( $array ) { + unset( $array['references'] ); + return $array; + } + ); + } + // HACK: comply with ApiResult::setIndexedTagName $tag = isset( $values['_element'] ) ? $values['_element'] : 'claim'; $this->setList( $path, 'claims', $values, $tag ); diff --git a/repo/tests/phpunit/includes/api/ResultBuilderTest.php b/repo/tests/phpunit/includes/api/ResultBuilderTest.php index 274e5b2..94d33d2 100644 --- a/repo/tests/phpunit/includes/api/ResultBuilderTest.php +++ b/repo/tests/phpunit/includes/api/ResultBuilderTest.php @@ -1011,6 +1011,51 @@ $this->assertEquals( $expected, $data ); } + public function testAddClaimsNoProps() { + $result = $this->getDefaultResult(); + $path = array( 'entities', 'Q1' ); + + $statement = new Statement( + new PropertySomeValueSnak( new PropertyId( 'P12' ) ), + null, + new Referencelist( array( + new Reference( array( + new PropertyValueSnak( new PropertyId( 'P12' ), new StringValue( 'refSnakVal' ) ), + ) ), + ) ), + 'fooguidbar' + ); + + $expected = array( + 'entities' => array( + 'Q1' => array( + 'claims' => array( + 'P12' => array( + array( + 'id' => 'fooguidbar', + 'mainsnak' => array( + 'snaktype' => 'somevalue', + 'property' => 'P12', + ), + 'type' => 'statement', + 'rank' => 'normal', + ), + ), + ), + ), + ), + ); + + $props = array(); + + $resultBuilder = $this->getResultBuilder( $result ); + $resultBuilder->addClaims( array( $statement ), $path, $props ); + + $data = $result->getResultData(); + $this->removeElementsWithKeysRecursively( $data, array( '_type' ) ); + $this->assertEquals( $expected, $data ); + } + /** * @dataProvider statementSerializationProvider */ -- To view, visit https://gerrit.wikimedia.org/r/227200 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I934e7eb6a18ab24d84f43fcde144189079654323 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits