Jeroen De Dauw has submitted this change and it was merged.

Change subject: Replace Claims with StatementList in ChangeOpReference[Remove]
......................................................................


Replace Claims with StatementList in ChangeOpReference[Remove]

Change-Id: I98ce821988527f09c57af13d7ac861341c05ab67
---
M repo/includes/ChangeOp/ChangeOpReference.php
M repo/includes/ChangeOp/ChangeOpReferenceRemove.php
2 files changed, 39 insertions(+), 40 deletions(-)

Approvals:
  Jeroen De Dauw: Looks good to me, approved



diff --git a/repo/includes/ChangeOp/ChangeOpReference.php 
b/repo/includes/ChangeOp/ChangeOpReference.php
index eb38a09..01e02a2 100644
--- a/repo/includes/ChangeOp/ChangeOpReference.php
+++ b/repo/includes/ChangeOp/ChangeOpReference.php
@@ -4,12 +4,11 @@
 
 use InvalidArgumentException;
 use ValueValidators\Result;
-use Wikibase\DataModel\Claim\Claims;
 use Wikibase\DataModel\Entity\Entity;
 use Wikibase\DataModel\Reference;
 use Wikibase\DataModel\ReferenceList;
 use Wikibase\DataModel\Snak\Snak;
-use Wikibase\DataModel\Statement\Statement;
+use Wikibase\DataModel\Statement\StatementListHolder;
 use Wikibase\Summary;
 use Wikibase\Validators\SnakValidator;
 
@@ -28,7 +27,7 @@
         *
         * @var string
         */
-       protected $claimGuid;
+       protected $statementGuid;
 
        /**
         * @since 0.4
@@ -61,7 +60,7 @@
         *
         * @since 0.4
         *
-        * @param string $claimGuid
+        * @param string $statementGuid
         * @param Reference $reference
         * @param string $referenceHash (if empty '' a new reference will be 
created)
         * @param SnakValidator $snakValidator
@@ -70,14 +69,14 @@
         * @throws InvalidArgumentException
         */
        public function __construct(
-               $claimGuid,
+               $statementGuid,
                Reference $reference,
                $referenceHash,
                SnakValidator $snakValidator,
                $index = null
        ) {
-               if ( !is_string( $claimGuid ) || $claimGuid === '' ) {
-                       throw new InvalidArgumentException( '$claimGuid needs 
to be a string and must not be empty' );
+               if ( !is_string( $statementGuid ) || $statementGuid === '' ) {
+                       throw new InvalidArgumentException( '$statementGuid 
needs to be a string and must not be empty' );
                }
 
                if ( !is_string( $referenceHash ) ) {
@@ -92,7 +91,7 @@
                        throw new InvalidArgumentException( '$index must be an 
integer or null' );
                }
 
-               $this->claimGuid = $claimGuid;
+               $this->statementGuid = $statementGuid;
                $this->reference = $reference;
                $this->referenceHash = $referenceHash;
                $this->index = $index;
@@ -105,18 +104,18 @@
         * - the reference gets set to $reference when $referenceHash and 
$reference are set
         */
        public function apply( Entity $entity, Summary $summary = null ) {
-               $claims = new Claims( $entity->getClaims() );
-               $claim = $claims->getClaimWithGuid( $this->claimGuid );
-
-               if ( $claim === null ) {
-                       throw new ChangeOpException( "Entity does not have 
claim with GUID $this->claimGuid" );
+               if ( !( $entity instanceof StatementListHolder ) ) {
+                       throw new InvalidArgumentException( '$entity must be a 
StatementListHolder' );
                }
 
-               if ( !( $claim instanceof Statement ) ) {
-                       throw new ChangeOpException( 'The referenced claim is 
not a statement and thus cannot have references' );
+               $statements = $entity->getStatements();
+               $statement = $statements->getFirstStatementWithGuid( 
$this->statementGuid );
+
+               if ( $statement === null ) {
+                       throw new ChangeOpException( "Entity does not have a 
statement with GUID $this->statementGuid" );
                }
 
-               $references = $claim->getReferences();
+               $references = $statement->getReferences();
 
                if ( $this->referenceHash === '' ) {
                        $this->addReference( $references, $summary );
@@ -125,11 +124,11 @@
                }
 
                if ( $summary !== null ) {
-                       $summary->addAutoSummaryArgs( 
$this->getSnakSummaryArgs( $claim->getMainSnak() ) );
+                       $summary->addAutoSummaryArgs( 
$this->getSnakSummaryArgs( $statement->getMainSnak() ) );
                }
 
-               $claim->setReferences( $references );
-               $entity->setClaims( $claims );
+               $statement->setReferences( $references );
+               $entity->setStatements( $statements );
 
                return true;
        }
@@ -145,7 +144,7 @@
        protected function addReference( ReferenceList $references, Summary 
$summary = null ) {
                if ( $references->hasReference( $this->reference ) ) {
                        $hash = $this->reference->getHash();
-                       throw new ChangeOpException( "Claim has already a 
reference with hash $hash" );
+                       throw new ChangeOpException( "The statement has already 
a reference with hash $hash" );
                }
                $references->addReference( $this->reference, $this->index );
                $this->updateSummary( $summary, 'add' );
@@ -173,7 +172,7 @@
                }
 
                if ( $references->hasReference( $this->reference ) && 
$this->index === $currentIndex ) {
-                       throw new ChangeOpException( 'Claim has already a 
reference with hash '
+                       throw new ChangeOpException( 'The statement has already 
a reference with hash '
                        . $this->reference->getHash() . ' and index (' . 
$currentIndex . ') is not changed' );
                }
                $references->removeReferenceHash( $this->referenceHash );
diff --git a/repo/includes/ChangeOp/ChangeOpReferenceRemove.php 
b/repo/includes/ChangeOp/ChangeOpReferenceRemove.php
index 812729d..b990237 100644
--- a/repo/includes/ChangeOp/ChangeOpReferenceRemove.php
+++ b/repo/includes/ChangeOp/ChangeOpReferenceRemove.php
@@ -4,11 +4,10 @@
 
 use InvalidArgumentException;
 use ValueValidators\Result;
-use Wikibase\DataModel\Claim\Claims;
 use Wikibase\DataModel\Entity\Entity;
 use Wikibase\DataModel\ReferenceList;
 use Wikibase\DataModel\Snak\Snak;
-use Wikibase\DataModel\Statement\Statement;
+use Wikibase\DataModel\Statement\StatementListHolder;
 use Wikibase\Summary;
 
 /**
@@ -25,7 +24,7 @@
         *
         * @var string
         */
-       protected $claimGuid;
+       protected $statementGuid;
 
        /**
         * @since 0.5
@@ -39,21 +38,21 @@
         *
         * @since 0.5
         *
-        * @param string $claimGuid
+        * @param string $statementGuid
         * @param string $referenceHash
         *
         * @throws InvalidArgumentException
         */
-       public function __construct( $claimGuid, $referenceHash ) {
-               if ( !is_string( $claimGuid ) || $claimGuid === '' ) {
-                       throw new InvalidArgumentException( '$claimGuid needs 
to be a string and must not be empty' );
+       public function __construct( $statementGuid, $referenceHash ) {
+               if ( !is_string( $statementGuid ) || $statementGuid === '' ) {
+                       throw new InvalidArgumentException( '$statementGuid 
needs to be a string and must not be empty' );
                }
 
                if ( !is_string( $referenceHash ) || $referenceHash === '' ) {
                        throw new InvalidArgumentException( '$referenceHash 
needs to be a string and must not be empty' );
                }
 
-               $this->claimGuid = $claimGuid;
+               $this->statementGuid = $statementGuid;
                $this->referenceHash = $referenceHash;
        }
 
@@ -61,26 +60,27 @@
         * @see ChangeOp::apply()
         */
        public function apply( Entity $entity, Summary $summary = null ) {
-               $claims = new Claims( $entity->getClaims() );
-               $claim = $claims->getClaimWithGuid( $this->claimGuid );
-
-               if ( $claim === null ) {
-                       throw new ChangeOpException( "Entity does not have 
claim with GUID $this->claimGuid" );
+               if ( !( $entity instanceof StatementListHolder ) ) {
+                       throw new InvalidArgumentException( '$entity must be a 
StatementListHolder' );
                }
 
-               if ( !( $claim instanceof Statement ) ) {
-                       throw new ChangeOpException( 'The referenced claim is 
not a statement and thus cannot have references' );
+               $statements = $entity->getStatements();
+               $statement = $statements->getFirstStatementWithGuid( 
$this->statementGuid );
+
+               if ( $statement === null ) {
+                       throw new ChangeOpException( "Entity does not have 
claim with GUID $this->statementGuid" );
                }
 
-               $references = $claim->getReferences();
+               $references = $statement->getReferences();
                $this->removeReference( $references, $summary );
 
                if ( $summary !== null ) {
-                       $summary->addAutoSummaryArgs( 
$this->getSnakSummaryArgs( $claim->getMainSnak() ) );
+                       $summary->addAutoSummaryArgs( 
$this->getSnakSummaryArgs( $statement->getMainSnak() ) );
                }
 
-               $claim->setReferences( $references );
-               $entity->setClaims( $claims );
+               $statement->setReferences( $references );
+               $entity->setStatements( $statements );
+
                return true;
        }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I98ce821988527f09c57af13d7ac861341c05ab67
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <benestar.wikime...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to