jenkins-bot has submitted this change and it was merged. Change subject: Remove the SetStatementRank API module as we are not going to use it ......................................................................
Remove the SetStatementRank API module as we are not going to use it Change-Id: I6a5755f59a202b2bf3da8611ef5d6e17309b854c --- M repo/config/Wikibase.experimental.php D repo/includes/api/SetStatementRank.php D repo/tests/phpunit/includes/api/SetStatementRankTest.php 3 files changed, 1 insertion(+), 433 deletions(-) Approvals: Addshore: Looks good to me, approved jenkins-bot: Verified diff --git a/repo/config/Wikibase.experimental.php b/repo/config/Wikibase.experimental.php index 05aec07..71e1a5f 100644 --- a/repo/config/Wikibase.experimental.php +++ b/repo/config/Wikibase.experimental.php @@ -6,26 +6,7 @@ * This file is NOT an entry point the Wikibase extension. Use Wikibase.php. * It should furthermore not be included from outside the extension. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * http://www.gnu.org/copyleft/gpl.html - * * @since 0.4 - * - * @file - * @ingroup WikibaseRepo - * * @licence GNU GPL v2+ */ @@ -34,13 +15,7 @@ } call_user_func( function() { - global $wgAutoloadClasses, $wgAPIModules, $wgHooks; - - $dir = __DIR__ . '/../'; - - $wgAutoloadClasses['Wikibase\Api\SetStatementRank'] = $dir . 'includes/api/SetStatementRank.php'; - - $wgAPIModules['wbsetstatementrank'] = 'Wikibase\Api\SetStatementRank'; + global $wgHooks; /** * Hook to add PHPUnit test cases. @@ -55,7 +30,6 @@ $wgHooks['UnitTestsList'][] = function( array &$files ) { // @codeCoverageIgnoreStart $testFiles = array( - 'api/SetStatementRank', ); foreach ( $testFiles as $file ) { diff --git a/repo/includes/api/SetStatementRank.php b/repo/includes/api/SetStatementRank.php deleted file mode 100644 index 0458d1f..0000000 --- a/repo/includes/api/SetStatementRank.php +++ /dev/null @@ -1,168 +0,0 @@ -<?php - -namespace Wikibase\Api; - -use ApiBase; -use Wikibase\Claim; -use Wikibase\Repo\WikibaseRepo; -use Wikibase\ChangeOp\ChangeOpStatementRank; -use Wikibase\ChangeOp\ChangeOpException; -use Wikibase\Statement; -use Wikibase\Lib\Serializers\ClaimSerializer; - -/** - * API module for setting the rank of a statement - * - * @since 0.3 - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - * @author Tobias Gritschacher < [email protected] > - */ -class SetStatementRank extends ModifyClaim { - - /** - * @see \ApiBase::execute - * - * @since 0.3 - */ - public function execute() { - wfProfileIn( __METHOD__ ); - - $params = $this->extractRequestParams(); - $this->validateParameters( $params ); - - $entityId = $this->claimGuidParser->parse( $params['statement'] )->getEntityId(); - $entityTitle = $this->claimModificationHelper->getEntityTitle( $entityId ); - $baseRevisionId = isset( $params['baserevid'] ) ? intval( $params['baserevid'] ) : null; - $entityContent = $this->loadEntityContent( $entityTitle, $baseRevisionId ); - $entity = $entityContent->getEntity(); - $summary = $this->claimModificationHelper->createSummary( $params, $this ); - - $claim = $this->claimModificationHelper->getClaimFromEntity( $params['statement'], $entity ); - - if ( ! ( $claim instanceof Statement ) ) { - $this->dieUsage( 'The referenced claim is not a statement and thus cannot have a rank', 'not-statement' ); - } - - $changeOp = $this->getChangeOp(); - - try { - $changeOp->apply( $entity, $summary ); - } catch ( ChangeOpException $e ) { - $this->dieUsage( $e->getMessage(), 'failed-save' ); - } - - $this->saveChanges( $entityContent, $summary ); - - $this->claimModificationHelper->addClaimToApiResult( $claim, 'statement' ); - - wfProfileOut( __METHOD__ ); - } - - /** - * Check the provided parameters - * - * @since 0.4 - */ - protected function validateParameters( array $params ) { - if ( !( $this->claimModificationHelper->validateClaimGuid( $params['statement'] ) ) ) { - $this->dieUsage( 'Invalid claim guid' , 'invalid-guid' ); - } - } - - /** - * @since 0.4 - * - * @return ChangeOpStatementRank - */ - protected function getChangeOp() { - $params = $this->extractRequestParams(); - - $claimGuid = $params['statement']; - - $rank = ClaimSerializer::unserializeRank( $params['rank'] ); - $changeOp = new ChangeOpStatementRank( $claimGuid, $rank ); - - return $changeOp; - } - - /** - * @see \ApiBase::getAllowedParams - * - * @since 0.3 - * - * @return array - */ - public function getAllowedParams() { - return array_merge( - array( - 'statement' => array( - ApiBase::PARAM_TYPE => 'string', - ApiBase::PARAM_REQUIRED => true, - ), - 'rank' => array( - ApiBase::PARAM_TYPE => ClaimSerializer::getRanks(), - ApiBase::PARAM_REQUIRED => true, - ), - ), - parent::getAllowedParams() - ); - } - - /** - * @see ApiBase::getPossibleErrors() - */ - public function getPossibleErrors() { - return array_merge( - parent::getPossibleErrors(), - $this->claimModificationHelper->getPossibleErrors(), - array( - array( 'code' => 'not-statement', 'info' => $this->msg( 'wikibase-api-not-statement' )->text() ), - ) - ); - } - - /** - * @see \ApiBase::getParamDescription - * - * @since 0.3 - * - * @return array - */ - public function getParamDescription() { - return array_merge( - parent::getParamDescription(), - array( - 'statement' => 'A GUID identifying the statement for which to set the rank', - 'rank' => 'The new value to set for the rank', - ) - ); - } - - /** - * @see \ApiBase::getDescription - * - * @since 0.3 - * - * @return string - */ - public function getDescription() { - return array( - 'API module for setting the rank of a Wikibase statement.' - ); - } - - /** - * @see \ApiBase::getExamples - * - * @since 0.3 - * - * @return array - */ - protected function getExamples() { - return array( - 'api.php?action=wbsetstatementrank&format=json&statement=Q2$4554c0f4-47b2-1cd9-2db9-aa270064c9f3&rank=normal&token=foobar' => 'Set the rank for the given statement to normal', - ); - } -} diff --git a/repo/tests/phpunit/includes/api/SetStatementRankTest.php b/repo/tests/phpunit/includes/api/SetStatementRankTest.php deleted file mode 100644 index 478aa47..0000000 --- a/repo/tests/phpunit/includes/api/SetStatementRankTest.php +++ /dev/null @@ -1,238 +0,0 @@ -<?php - -namespace Wikibase\Test\Api; - -use DataValues\StringValue; -use Wikibase\Item; -use Wikibase\ItemContent; -use Wikibase\Lib\ClaimGuidGenerator; -use Wikibase\PropertyNoValueSnak; -use Wikibase\PropertySomeValueSnak; -use Wikibase\PropertyValueSnak; -use Wikibase\Reference; -use Wikibase\Repo\WikibaseRepo; -use Wikibase\Snak; -use Wikibase\SnakList; -use Wikibase\Statement; -use Wikibase\Lib\Serializers\ClaimSerializer; - -/** - * @covers Wikibase\Api\SetStatementRank - * - * @since 0.3 - * - * @group API - * @group Database - * @group Wikibase - * @group WikibaseAPI - * @group WikibaseRepo - * @group SetStatementRankTest - * - * @group medium - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - * @author Katie Filbert < [email protected] > - */ -class SetStatementRankTest extends WikibaseApiTestCase { - - /** - * @return Snak[] - */ - protected function snakProvider() { - $snaks = array(); - - $snaks[] = new PropertyNoValueSnak( 42 ); - $snaks[] = new PropertySomeValueSnak( 9001 ); - $snaks[] = new PropertyValueSnak( 7201010, new StringValue( 'o_O' ) ); - - return $snaks; - } - - /** - * @return Statement[] - */ - protected function statementProvider() { - $statements = array(); - - $mainSnak = new PropertyNoValueSnak( 42 ); - $statement = new Statement( $mainSnak ); - $statements[] = $statement; - - foreach ( $this->snakProvider() as $snak ) { - $statement = clone $statement; - $snaks = new SnakList( array( $snak ) ); - $statement->getReferences()->addReference( new Reference( $snaks ) ); - $statements[] = $statement; - } - - $statement = clone $statement; - $snaks = new SnakList( $this->snakProvider() ); - $statement->getReferences()->addReference( new Reference( $snaks ) ); - $statements[] = $statement; - - $ranks = array( - Statement::RANK_DEPRECATED, - Statement::RANK_NORMAL, - Statement::RANK_PREFERRED - ); - - /** - * @var Statement[] $statements - */ - foreach ( $statements as &$statement ) { - $statement->setRank( $ranks[array_rand( $ranks )] ); - } - - return $statements; - } - - public function testRequests() { - //TODO REMOVE ONCE ENABLED - if ( !defined( 'WB_EXPERIMENTAL_FEATURES' ) || !WB_EXPERIMENTAL_FEATURES ) { - $this->markTestSkipped( 'WB_EXPERIMENTAL_FEATURES are not enabled so this module is not enabled..' ); - } - - $ranks = ClaimSerializer::getRanks(); - - foreach ( $this->statementProvider() as $statement ) { - $item = Item::newEmpty(); - $content = new ItemContent( $item ); - $content->save( '', null, EDIT_NEW ); - - $guidGenerator = new ClaimGuidGenerator( $item->getId() ); - $statement->setGuid( $guidGenerator->newGuid() ); - $item->addClaim( $statement ); - - $content->save( '' ); - - while ( true ) { - $rank = $ranks[array_rand( $ranks )]; - - if ( ClaimSerializer::unserializeRank( $rank ) !== $statement->getRank() ) { - break; - } - } - - $this->makeValidRequest( - $item, - $statement->getGuid(), - $rank - ); - - $this->makeInvalidRequest( - $statement->getGuid(), - '~=[,,_,,]:3' - ); - } - - $this->makeInvalidRequest( - '~=[,,_,,]:3', - reset( $ranks ) - ); - } - - protected function makeValidRequest( Item $item, $statementGuid, $statementRank ) { - $this->assertInternalType( 'string', $statementGuid ); - $this->assertInternalType( 'string', $statementRank ); - - $params = array( - 'action' => 'wbsetstatementrank', - 'statement' => $statementGuid, - 'rank' => $statementRank, - ); - - list( $resultArray, ) = $this->doApiRequestWithToken( $params ); - - $this->assertInternalType( 'array', $resultArray, 'top level element is an array' ); - $this->assertArrayHasKey( 'pageinfo', $resultArray, 'top level element has a pageinfo key' ); - $this->assertArrayHasKey( 'statement', $resultArray, 'top level element has a statement key' ); - - $statement = $resultArray['statement']; - $this->assertArrayHasKey( 'rank', $statement, 'statement element has a rank key' ); - - $this->assertEquals( $statementRank, $statement['rank'] ); - - $itemContent = WikibaseRepo::getDefaultInstance()->getEntityContentFactory()->getFromId( $item->getId() ); - - $this->assertInstanceOf( '\Wikibase\ItemContent', $itemContent ); - - $freshItem = $itemContent->getEntity(); - - $claims = new \Wikibase\Claims( $freshItem->getClaims() ); - - $this->assertTrue( $claims->hasClaimWithGuid( $statementGuid ) ); - - /** - * @var Statement $claim - */ - $claim = $claims->getClaimWithGuid( $statementGuid ); - - $this->assertEquals( - ClaimSerializer::unserializeRank( $statementRank ), - $claim->getRank() - ); - } - - protected function makeInvalidRequest( $statementGuid, $statementRank, $expectedError = null ) { - $params = array( - 'action' => 'wbsetstatementrank', - 'statement' => $statementGuid, - 'rank' => $statementRank, - ); - - try { - $this->doApiRequestWithToken( $params ); - $this->fail( 'Invalid request should raise an exception' ); - } - catch ( \Exception $e ) { - if ( $e instanceof \UsageException ) { - if ( $expectedError === null ) { - $this->assertTrue( true, 'Invalid request raised error' ); - } - else { - $this->assertEquals( $expectedError, $e->getCodeString(), 'Invalid request raised correct error' ); - } - } - elseif ( $e instanceof \MWException ) { - $this->assertTrue( true, 'Invalid request raised error' ); - } - else { - throw $e; - } - } - } - - /** - * @dataProvider invalidClaimProvider - */ - public function testInvalidClaimGuid( $claimGuid ) { - //TODO REMOVE ONCE ENABLED - if ( !defined( 'WB_EXPERIMENTAL_FEATURES' ) || !WB_EXPERIMENTAL_FEATURES ) { - $this->markTestSkipped( 'WB_EXPERIMENTAL_FEATURES are not enabled so this module is not enabled..' ); - } - - $ranks = ClaimSerializer::getRanks(); - - $params = array( - 'action' => 'wbsetstatementrank', - 'statement' => $claimGuid, - 'rank' => $ranks[0], - ); - - try { - $this->doApiRequestWithToken( $params ); - $this->fail( 'Invalid claim guid did not throw an error' ); - } catch ( \UsageException $e ) { - $this->assertEquals( 'invalid-guid', $e->getCodeString(), 'Invalid claim guid raised correct error' ); - } - } - - public function invalidClaimProvider() { - return array( - array( 'xyz' ), - array( 'x$y$z' ) - ); - } - -} -- To view, visit https://gerrit.wikimedia.org/r/89476 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I6a5755f59a202b2bf3da8611ef5d6e17309b854c Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <[email protected]> Gerrit-Reviewer: Addshore <[email protected]> Gerrit-Reviewer: Daniel Kinzler <[email protected]> Gerrit-Reviewer: Lydia Pintscher <[email protected]> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
