jenkins-bot has submitted this change and it was merged.

Change subject: grab a fresh ID before performing changeops
......................................................................


grab a fresh ID before performing changeops

This also refactors getRequiredPermissions
to take EntityContent instead of Entity

Change-Id: I8524e781909c7654bcbc7d3b92c0f7fe57dd3c95
---
M repo/includes/api/ApiWikibase.php
M repo/includes/api/EditEntity.php
M repo/includes/api/LinkTitles.php
M repo/includes/api/ModifyClaim.php
M repo/includes/api/ModifyEntity.php
M repo/includes/api/SetAliases.php
M repo/includes/api/SetDescription.php
M repo/includes/api/SetLabel.php
M repo/includes/api/SetSiteLink.php
M repo/includes/content/EntityContent.php
M repo/tests/phpunit/includes/api/EditEntityTest.php
M repo/tests/phpunit/includes/api/PermissionsTest.php
12 files changed, 49 insertions(+), 134 deletions(-)

Approvals:
  Tobias Gritschacher: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/includes/api/ApiWikibase.php 
b/repo/includes/api/ApiWikibase.php
index dc71066..8e74fc5 100644
--- a/repo/includes/api/ApiWikibase.php
+++ b/repo/includes/api/ApiWikibase.php
@@ -22,10 +22,6 @@
  *
  * @since 0.1
  *
- * @file
- * @ingroup WikibaseRepo
- * @ingroup API
- *
  * @licence GNU GPL v2+
  * @author John Erling Blad < [email protected] >
  * @author Tobias Gritschacher < [email protected] >
@@ -251,12 +247,12 @@
         * Returns the permissions that are required to perform the operation 
specified by
         * the parameters.
         *
-        * @param $entity \Wikibase\Entity the entity to check permissions for
+        * @param \Wikibase\EntityContent $entityContent the entityContent to 
check permissions for
         * @param $params array of arguments for the module, describing the 
operation to be performed
         *
         * @return \Status the check's result
         */
-       protected function getRequiredPermissions( Entity $entity, array 
$params ) {
+       protected function getRequiredPermissions( EntityContent 
$entityContent, array $params ) {
                $permissions = array( 'read' );
 
                //could directly check for each module here:
@@ -281,7 +277,7 @@
                        return Status::newGood();
                }
 
-               $permissions = $this->getRequiredPermissions( 
$entityContent->getEntity(), $params );
+               $permissions = $this->getRequiredPermissions( $entityContent, 
$params );
                $status = Status::newGood();
 
                foreach ( $permissions as $perm ) {
diff --git a/repo/includes/api/EditEntity.php b/repo/includes/api/EditEntity.php
index 321dbd8..028172c 100644
--- a/repo/includes/api/EditEntity.php
+++ b/repo/includes/api/EditEntity.php
@@ -11,7 +11,7 @@
 use Wikibase\ChangeOpSiteLink;
 use Wikibase\ChangeOpException;
 use ApiBase, User, Status, SiteList;
-use Wikibase\SiteLink;
+use Wikibase\Repo\WikibaseRepo;
 use Wikibase\Entity;
 use Wikibase\EntityContent;
 use Wikibase\Item;
@@ -23,10 +23,6 @@
  * Derived class for API modules modifying a single entity identified by id 
xor a combination of site and page title.
  *
  * @since 0.1
- *
- * @file ApiWikibaseModifyEntity.php
- * @ingroup WikibaseRepo
- * @ingroup API
  *
  * @licence GNU GPL v2+
  * @author John Erling Blad < [email protected] >
@@ -52,14 +48,18 @@
        }
 
        /**
-        * @see \Wikibase\Api\Api::getRequiredPermissions()
+        * @see \Wikibase\Api\ApiWikibase::getRequiredPermissions()
         */
-       protected function getRequiredPermissions( Entity $entity, array 
$params ) {
-               $permissions = parent::getRequiredPermissions( $entity, $params 
);
-
-               $type = $entity->getType();
-               $permissions[] = 'edit';
-               $permissions[] = $type . '-' . ( $entity->getId() === null ? 
'create' : 'override' );
+       protected function getRequiredPermissions( EntityContent 
$entityContent, array $params ) {
+               $permissions = parent::getRequiredPermissions( $entityContent, 
$params );
+               $type = $entityContent->getEntity()->getType();
+               $exists = $entityContent->getTitle()->exists();
+               if( !$exists ){
+                       $permissions[] = 'createpage';
+                       $permissions[] = $type . '-create';
+               } else {
+                       $permissions[] = $type . '-override';
+               }
                return $permissions;
        }
 
@@ -69,12 +69,15 @@
        protected function createEntity( array $params ) {
                $type = $params['new'];
                $this->flags |= EDIT_NEW;
-               $entityContentFactory = EntityContentFactory::singleton();
+               $entityContentFactory = 
WikibaseRepo::getDefaultInstance()->getEntityContentFactory();
                try {
-                       return $entityContentFactory->newFromType( $type );
+                       $entityContent = $entityContentFactory->newFromType( 
$type );
                } catch ( InvalidArgumentException $e ) {
                        $this->dieUsage( "No such entity type: '$type'", 
'no-such-entity-type' );
                }
+               /** @var $entityContent EntityContent */
+               $entityContent->grabFreshId();
+               return $entityContent;
        }
 
        /**
@@ -130,12 +133,12 @@
                }
 
                // if we create a new property, make sure we set the datatype
-               if ( $entityContent->isNew() && $entity->getType() === 
Property::ENTITY_TYPE ) {
-                       if ( !isset( $data['datatype'] ) ) {
-                               $this->dieUsage( 'No datatype given', 
'param-illegal' );
-                       } else {
-                               $entity->setDataTypeId( $data['datatype'] );
-                       }
+               if( !$entityContent->getTitle()->exists() && $entity->getType() 
=== Property::ENTITY_TYPE ){
+                               if ( !isset( $data['datatype'] ) ) {
+                                       $this->dieUsage( 'No datatype given', 
'param-illegal' );
+                               } else {
+                                       $entity->setDataTypeId( 
$data['datatype'] );
+                               }
                }
 
                if ( array_key_exists( 'labels', $data ) ) {
@@ -483,8 +486,8 @@
                                        'The entity will not be saved before it 
is filled with the "data", possibly with parts excluded.'
                                ),
                                'new' => array( "If set, a new entity will be 
created.",
-                                               "Set this to the type of the 
entity you want to create - currently 'item'|'property'.",
-                                               "It is not allowed to have this 
set when 'id' is also set."
+                                       "Set this to the type of the entity you 
want to create - currently 'item'|'property'.",
+                                       "It is not allowed to have this set 
when 'id' is also set."
                                ),
                        )
                );
diff --git a/repo/includes/api/LinkTitles.php b/repo/includes/api/LinkTitles.php
index dffe79b..397ea31 100644
--- a/repo/includes/api/LinkTitles.php
+++ b/repo/includes/api/LinkTitles.php
@@ -5,7 +5,7 @@
 use ApiBase, User, Status;
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\SimpleSiteLink;
-use Wikibase\Entity;
+use Wikibase\EntityContent;
 use Wikibase\EntityContentFactory;
 use Wikibase\Item;
 use Wikibase\ItemContent;
@@ -19,19 +19,15 @@
  *
  * @since 0.1
  *
- * @file
- * @ingroup WikibaseRepo
- * @ingroup API
- *
  * @licence GNU GPL v2+
  */
 class LinkTitles extends ApiWikibase {
 
        /**
-        * @see  \Wikibase\Api\ModifyEntity::getRequiredPermissions()
+        * @see  \Wikibase\Api\ApiWikiBase::getRequiredPermissions()
         */
-       protected function getRequiredPermissions( Entity $entity, array 
$params ) {
-               $permissions = parent::getRequiredPermissions( $entity, $params 
);
+       protected function getRequiredPermissions( EntityContent 
$entityContent, array $params ) {
+               $permissions = parent::getRequiredPermissions( $entityContent, 
$params );
 
                $permissions[] = 'linktitles-update';
                return $permissions;
diff --git a/repo/includes/api/ModifyClaim.php 
b/repo/includes/api/ModifyClaim.php
index 17a82e9..9745c38 100644
--- a/repo/includes/api/ModifyClaim.php
+++ b/repo/includes/api/ModifyClaim.php
@@ -18,9 +18,6 @@
  *
  * @since 0.4
  *
- * @ingroup WikibaseRepo
- * @ingroup API
- *
  * @licence GNU GPL v2+
  * @author Tobias Gritschacher < [email protected] >
  * @author Jeroen De Dauw < [email protected] >
@@ -117,10 +114,10 @@
        }
 
        /**
-        * @see  \Api::getRequiredPermissions()
+        * @see  \Wikibase\Api\ApiWikibase::getRequiredPermissions()
         */
-       protected function getRequiredPermissions( Entity $entity, array 
$params ) {
-               $permissions = parent::getRequiredPermissions( $entity, $params 
);
+       protected function getRequiredPermissions( EntityContent 
$entityContent, array $params ) {
+               $permissions = parent::getRequiredPermissions( $entityContent, 
$params );
 
                $permissions[] = 'edit';
                return $permissions;
diff --git a/repo/includes/api/ModifyEntity.php 
b/repo/includes/api/ModifyEntity.php
index cd881d8..ce17af9 100644
--- a/repo/includes/api/ModifyEntity.php
+++ b/repo/includes/api/ModifyEntity.php
@@ -20,10 +20,6 @@
  *
  * @since 0.1
  *
- * @file
- * @ingroup WikibaseRepo
- * @ingroup API
- *
  * @licence GNU GPL v2+
  * @author John Erling Blad < [email protected] >
  * @author Daniel Kinzler
@@ -52,10 +48,10 @@
        protected $flags;
 
        /**
-        * @see  \Api::getRequiredPermissions()
+        * @see  Wikibase\Api\ApiWikibase::getRequiredPermissions()
         */
-       protected function getRequiredPermissions( Entity $entity, array 
$params ) {
-               $permissions = parent::getRequiredPermissions( $entity, $params 
);
+       protected function getRequiredPermissions( EntityContent 
$entityContent, array $params ) {
+               $permissions = parent::getRequiredPermissions( $entityContent, 
$params );
 
                $permissions[] = 'edit';
                return $permissions;
diff --git a/repo/includes/api/SetAliases.php b/repo/includes/api/SetAliases.php
index b1da80a..76e7080 100644
--- a/repo/includes/api/SetAliases.php
+++ b/repo/includes/api/SetAliases.php
@@ -15,10 +15,6 @@
  *
  * @since 0.1
  *
- * @file
- * @ingroup WikibaseRepo
- * @ingroup API
- *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
  * @author John Erling Blad < [email protected] >
@@ -30,8 +26,8 @@
        /**
         * @see  \Wikibase\Api\ModifyEntity::getRequiredPermissions()
         */
-       protected function getRequiredPermissions( Entity $entity, array 
$params ) {
-               $permissions = parent::getRequiredPermissions( $entity, $params 
);
+       protected function getRequiredPermissions( EntityContent 
$entityContent, array $params ) {
+               $permissions = parent::getRequiredPermissions( $entityContent, 
$params );
 
                if ( !empty( $params['add'] ) || isset( $params['set'] ) ) {
                        // add and set has a common permission due to the 
special page SetAliases
diff --git a/repo/includes/api/SetDescription.php 
b/repo/includes/api/SetDescription.php
index 0438eb6..3b9da9a 100644
--- a/repo/includes/api/SetDescription.php
+++ b/repo/includes/api/SetDescription.php
@@ -14,10 +14,6 @@
  *
  * @since 0.1
  *
- * @file
- * @ingroup WikibaseRepo
- * @ingroup API
- *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
  * @author John Erling Blad < [email protected] >
@@ -28,8 +24,8 @@
        /**
         * @see  \Wikibase\Api\ModifyEntity::getRequiredPermissions()
         */
-       protected function getRequiredPermissions( Entity $entity, array 
$params ) {
-               $permissions = parent::getRequiredPermissions( $entity, $params 
);
+       protected function getRequiredPermissions( EntityContent 
$entityContent, array $params ) {
+               $permissions = parent::getRequiredPermissions( $entityContent, 
$params );
 
                $permissions[] = ( isset( $params['value'] ) && 0<strlen( 
$params['value'] ) )
                        ? 'description-update'
diff --git a/repo/includes/api/SetLabel.php b/repo/includes/api/SetLabel.php
index a434a42..2e113fa 100644
--- a/repo/includes/api/SetLabel.php
+++ b/repo/includes/api/SetLabel.php
@@ -14,10 +14,6 @@
  *
  * @since 0.1
  *
- * @file
- * @ingroup WikibaseRepo
- * @ingroup API
- *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
  * @author John Erling Blad < [email protected] >
@@ -28,8 +24,8 @@
        /**
         * @see \Wikibase\Api\ModifyEntity::getRequiredPermissions()
         */
-       protected function getRequiredPermissions( Entity $entity, array 
$params ) {
-               $permissions = parent::getRequiredPermissions( $entity, $params 
);
+       protected function getRequiredPermissions( EntityContent 
$entityContent, array $params ) {
+               $permissions = parent::getRequiredPermissions( $entityContent, 
$params );
 
                $permissions[] = ( isset( $params['value'] ) && 0 < strlen( 
$params['value'] ) )
                        ? 'label-update'
diff --git a/repo/includes/api/SetSiteLink.php 
b/repo/includes/api/SetSiteLink.php
index 4a60e15..f9dd159 100644
--- a/repo/includes/api/SetSiteLink.php
+++ b/repo/includes/api/SetSiteLink.php
@@ -15,10 +15,6 @@
  *
  * @since 0.1
  *
- * @file
- * @ingroup WikibaseRepo
- * @ingroup API
- *
  * @licence GNU GPL v2+
  * @author John Erling Blad < [email protected] >
  * @author Jeroen De Dauw < [email protected] >
@@ -30,8 +26,8 @@
        /**
         * @see  \Wikibase\Api\ModifyEntity::getRequiredPermissions()
         */
-       protected function getRequiredPermissions( Entity $entity, array 
$params ) {
-               $permissions = parent::getRequiredPermissions( $entity, $params 
);
+       protected function getRequiredPermissions( EntityContent 
$entityContent, array $params ) {
+               $permissions = parent::getRequiredPermissions( $entityContent, 
$params );
 
                $permissions[] = 'sitelink-' . ( strlen( $params['linktitle'] ) 
? 'update' : 'remove' );
                return $permissions;
diff --git a/repo/includes/content/EntityContent.php 
b/repo/includes/content/EntityContent.php
index 75f87e8..1d2769f 100644
--- a/repo/includes/content/EntityContent.php
+++ b/repo/includes/content/EntityContent.php
@@ -10,26 +10,7 @@
 /**
  * Abstract content object for articles representing Wikibase entities.
  *
- * 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.1
- *
- * @file
- * @ingroup WikibaseRepo
- * @ingroup Content
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
@@ -424,7 +405,7 @@
         *         generating a new ID.
         * @return int The new ID
         */
-       protected function grabFreshId() {
+       public function grabFreshId() {
                if ( !$this->isNew() ) {
                        throw new \MWException( "This entity already has an 
ID!" );
                }
@@ -483,7 +464,7 @@
                if ( ( $flags & EDIT_NEW ) == EDIT_NEW ) {
                        if ( $this->isNew() ) {
                                $this->grabFreshId();
-                       } else {
+                       } else if ( $this->getTitle()->exists() ) {
                                wfProfileOut( __METHOD__ );
                                return Status::newFatal( 'edit-already-exists' 
);
                        }
diff --git a/repo/tests/phpunit/includes/api/EditEntityTest.php 
b/repo/tests/phpunit/includes/api/EditEntityTest.php
index 281c724..e1ac907 100644
--- a/repo/tests/phpunit/includes/api/EditEntityTest.php
+++ b/repo/tests/phpunit/includes/api/EditEntityTest.php
@@ -5,26 +5,7 @@
 
 /**
  * Tests for the ApiWikibase class.
- *
- * This testset only checks the validity of the calls and correct handling of 
tokens and users.
- * Note that we creates an empty database and then starts manipulating 
testusers.
- *
- * 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
- *
- * @file
+
  * @since 0.1
  *
  * @ingroup WikibaseRepoTest
diff --git a/repo/tests/phpunit/includes/api/PermissionsTest.php 
b/repo/tests/phpunit/includes/api/PermissionsTest.php
index b8588e5..15a5811 100644
--- a/repo/tests/phpunit/includes/api/PermissionsTest.php
+++ b/repo/tests/phpunit/includes/api/PermissionsTest.php
@@ -10,26 +10,7 @@
  *
  * This file produce errors if run standalone.
  *
- * 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
- *
- * @file
  * @since 0.1
- *
- * @ingroup WikibaseRepoTest
- * @ingroup Test
  *
  * @licence GNU GPL v2+
  * @author Daniel Kinzler <[email protected]>

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I8524e781909c7654bcbc7d3b92c0f7fe57dd3c95
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to