Anja Jentzsch has submitted this change and it was merged.

Change subject: (bug 41163, 44165, 44166) autocomments for claims.
......................................................................


(bug 41163, 44165, 44166) autocomments for claims.

This adds autocomments when claims get added or removed, or
their main snak is changed.

Caveat: When removing or changing a claim, the claim ID (GUID) is shown in the
summary. That is not very helpful. To changes this, some refactoring is
needed - this is already in the pipeline.

Change-Id: I1c836d6f54d865f83d27b5853ff0d72532c9cd6a
---
M repo/Wikibase.i18n.php
M repo/Wikibase.php
M repo/includes/api/ApiCreateClaim.php
A repo/includes/api/ApiModifyClaim.php
M repo/includes/api/ApiRemoveClaims.php
M repo/includes/api/ApiSetClaimValue.php
6 files changed, 301 insertions(+), 367 deletions(-)

Approvals:
  Anja Jentzsch: Verified; Looks good to me, approved



diff --git a/repo/Wikibase.i18n.php b/repo/Wikibase.i18n.php
index c68f8e7..1e28c9f 100644
--- a/repo/Wikibase.i18n.php
+++ b/repo/Wikibase.i18n.php
@@ -258,9 +258,12 @@
        'wikibase-item-summary-wbsetsitelink-set' => 'Added site-specific [$2] 
link',
        'wikibase-item-summary-wbsetsitelink-remove' => 'Removed site-specific 
[$2] link',
        'wikibase-item-summary-wblinktitles-connect' => 'Connected [$2↔$3] 
{{PLURAL:$1|page|pages}}',
-       'wikibase-item-summary-wbcreateclaim-value' => 'Created {{PLURAL:$1|a 
value claim|value claims}}',
-       'wikibase-item-summary-wbcreateclaim-novalue' => 'Created {{PLURAL:$1|a 
novalue claim|novalue claims}}',
-       'wikibase-item-summary-wbcreateclaim-somevalue' => 'Created 
{{PLURAL:$1|a somevalue claim|somevalue claims}}',
+       'wikibase-item-summary-wbcreateclaim-value' => 'Created {{PLURAL:$1|a 
claim|claims}}', // legacy, used for old log entries!
+       'wikibase-item-summary-wbcreateclaim-novalue' => 'Created {{PLURAL:$1|a 
claim|claims}}', // legacy, used for old log entries!
+       'wikibase-item-summary-wbcreateclaim-somevalue' => 'Created 
{{PLURAL:$1|a claim|claims}}', // legacy, used for old log entries!
+       'wikibase-item-summary-wbcreateclaim' => 'Created {{PLURAL:$1|a 
claim|claims}}',
+       'wikibase-item-summary-wbsetclaimvalue' => 'Set {{PLURAL:$1|a claim 
value|claim values}}',
+       'wikibase-item-summary-wbremoveclaims' => 'Removed {{PLURAL:$1|a 
claim|claims}}',
        'wikibase-item-summary-special-create-item' => 'Created an [$2] item 
with {{PLURAL:$1|value|values}}',
 
        // property - summary and autocomment
@@ -672,9 +675,13 @@
 * $1 is the number of pages that were connected;
 * $2 is the site code for the from-page;
 * $3 is the site code for the to-page.',
-       'wikibase-item-summary-wbcreateclaim-value' => '{{wikibase summary 
messages|item-claims|Automatic edit summary when a claim is created and a value 
is used. The values can be of various types, including but not limited to 
defined properties.}}',
-       'wikibase-item-summary-wbcreateclaim-novalue' => "{{wikibase summary 
messages|item-claims|Automatic edit summary when ''no value'' is supplied to 
the claim. A ''no value'' means that there are no valid value to be set for 
this claim, or that there are no existing value.}}",
-       'wikibase-item-summary-wbcreateclaim-somevalue' => '{{wikibase summary 
messages|item-claims|Automatic edit summary when there should be a value but it 
is unknown. This is different from the case where there are no valid or 
existing value.}}',
+
+       'wikibase-item-summary-wbcreateclaim-value' => '{{wikibase summary 
messages|item-claims|Automatic edit summary when a claim is created and a value 
is used. The values can be of various types, including but not limited to 
defined properties. This is a LEGACY value, needed for old log entries!}}',
+       'wikibase-item-summary-wbcreateclaim-novalue' => "{{wikibase summary 
messages|item-claims|Automatic edit summary when ''no value'' is supplied to 
the claim. A ''no value'' means that there are no valid value to be set for 
this claim, or that there are no existing value. This is a LEGACY value, needed 
for old log entries!}}",
+       'wikibase-item-summary-wbcreateclaim-somevalue' => '{{wikibase summary 
messages|item-claims|Automatic edit summary when there should be a value but it 
is unknown. This is different from the case where there are no valid or 
existing value. This is a LEGACY value, needed for old log entries!}}',
+       'wikibase-item-summary-wbcreateclaim' => '{{wikibase summary 
messages|item-claims|Automatic edit summary when a claim is created.}}',
+       'wikibase-item-summary-wbsetclaimvalue' => '{{wikibase summary 
messages|item-claims|Automatic edit summary when the main value of one or more 
claim is changed.}}',
+       'wikibase-item-summary-wbremoveclaims' => '{{wikibase summary 
messages|item-claims|Automatic edit summary when one or more claim is 
removed.}}',
        'wikibase-item-summary-special-create-item' => '{{wikibase summary 
messages|item|Automatic edit summary when creating an item, and supplying one 
or more values. This page can take an additional sitelink, but this does not 
reflect in the autocomment.}}',
        'wikibase-property-summary-wbeditentity-create' => 'Automatic edit 
summary generated when creating a new property.',
        'wikibase-property-summary-wbeditentity-update' => 'Automatic edit 
summary generated when updating an existing property.',
diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index 9657c0d..bd04822 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -131,6 +131,7 @@
 $wgAutoloadClasses['Wikibase\ApiEditEntity']                   = $dir . 
'includes/api/ApiEditEntity.php';
 $wgAutoloadClasses['Wikibase\ApiGetEntities']                  = $dir . 
'includes/api/ApiGetEntities.php';
 $wgAutoloadClasses['Wikibase\ApiLinkTitles']                   = $dir . 
'includes/api/ApiLinkTitles.php';
+$wgAutoloadClasses['Wikibase\ApiModifyClaim']                  = $dir . 
'includes/api/ApiModifyClaim.php';
 $wgAutoloadClasses['Wikibase\ApiModifyEntity']                         = $dir 
. 'includes/api/ApiModifyEntity.php';
 $wgAutoloadClasses['Wikibase\ApiModifyLangAttribute']  = $dir . 
'includes/api/ApiModifyLangAttribute.php';
 $wgAutoloadClasses['Wikibase\ApiSearchEntities']               = $dir . 
'includes/api/ApiSearchEntities.php';
diff --git a/repo/includes/api/ApiCreateClaim.php 
b/repo/includes/api/ApiCreateClaim.php
index 3fdac60..9661965 100644
--- a/repo/includes/api/ApiCreateClaim.php
+++ b/repo/includes/api/ApiCreateClaim.php
@@ -28,8 +28,9 @@
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < jeroended...@gmail.com >
+ * @author Daniel Kinzler
  */
-class ApiCreateClaim extends Api implements ApiAutocomment {
+class ApiCreateClaim extends ApiModifyClaim {
 
        // TODO: automcomment
        // TODO: rights
@@ -90,40 +91,24 @@
        }
 
        /**
-        * @since 0.3
+        * @since 0.2
         *
-        * @param EntityContent $content
+        * @return EntityContent
         */
-       protected function saveChanges( EntityContent $content ) {
+       protected function getEntityContent() {
                $params = $this->extractRequestParams();
 
-               $user = $this->getUser();
-               $flags = 0;
                $baseRevisionId = isset( $params['baserevid'] ) ? intval( 
$params['baserevid'] ) : null;
-               $baseRevisionId = $baseRevisionId > 0 ? $baseRevisionId : false;
-               $flags |= ( $user->isAllowed( 'bot' ) && $params['bot'] ) ? 
EDIT_FORCE_BOT : 0;
-               $flags |= EDIT_UPDATE;
-               $editEntity = new EditEntity( $content, $user, $baseRevisionId, 
$this->getContext() );
 
-               $status = $editEntity->attemptSave(
-                       '', // TODO: autocomment
-                       $flags,
-                       isset( $params['token'] ) ? $params['token'] : ''
-               );
+               $entityId = EntityId::newFromPrefixedId( $params['entity'] );
+               $entityTitle = $entityId ? 
EntityContentFactory::singleton()->getTitleForId( $entityId ) : null;
+               $entityContent = $entityTitle === null ? null : 
$this->loadEntityContent( $entityTitle, $baseRevisionId );
 
-               if ( !$status->isOK() ) {
-                       $this->dieUsage( 'Failed to save the change', 
'createclaim-save-failed' );
+               if ( $entityContent === null ) {
+                       $this->dieUsage( 'Entity ' . $params['entity'] . ' not 
found', 'entity-not-found' );
                }
 
-               $statusValue = $status->getValue();
-
-               if ( isset( $statusValue['revision'] ) ) {
-                       $this->getResult()->addValue(
-                               'pageinfo',
-                               'lastrevid',
-                               (int)$statusValue['revision']->getId()
-                       );
-               }
+               return $entityContent;
        }
 
        /**
@@ -150,70 +135,6 @@
        }
 
        /**
-        * @since 0.2
-        *
-        * @return EntityContent
-        */
-       protected function getEntityContent() {
-               $params = $this->extractRequestParams();
-
-               $baseRevisionId = isset( $params['baserevid'] ) ? intval( 
$params['baserevid'] ) : null;
-
-               $entityId = EntityId::newFromPrefixedId( $params['entity'] );
-               $entityTitle = $entityId ? 
EntityContentFactory::singleton()->getTitleForId( $entityId ) : null;
-               $entityContent = $entityTitle === null ? null : 
$this->loadEntityContent( $entityTitle, $baseRevisionId );
-
-               if ( $entityContent === null ) {
-                       $this->dieUsage( 'Entity not found, snak not created', 
'entity-not-found' );
-               }
-
-               return $entityContent;
-       }
-
-       /**
-        * @since 0.2
-        *
-        * @return Snak
-        * @throws MWException
-        */
-       protected function getSnakInstance() {
-               $params = $this->extractRequestParams();
-
-               $factory = new SnakFactory();
-
-               $libRegistry = new LibRegistry( Settings::singleton() );
-               $parseResult = $libRegistry->getEntityIdParser()->parse( 
$params['property'] );
-
-               if ( !$parseResult->isValid() ) {
-                       throw new MWException( 
$parseResult->getError()->getText() );
-               }
-
-               return $factory->newSnak(
-                       $parseResult->getValue(),
-                       $params['snaktype'],
-                       isset( $params['value'] ) ? \FormatJson::decode( 
$params['value'], true ) : null
-               );
-       }
-
-       /**
-        * @since 0.3
-        *
-        * @param Claim $claim
-        */
-       protected function outputClaim( Claim $claim ) {
-               $serializerFactory = new 
\Wikibase\Lib\Serializers\SerializerFactory();
-
-               $serializer = $serializerFactory->newSerializerForObject( 
$claim );
-               $serializer->getOptions()->setIndexTags( 
$this->getResult()->getIsRawMode() );
-
-               $this->getResult()->addValue(
-                       null,
-                       'claim',
-                       $serializer->getSerialized( $claim )
-               );
-       }
-
-       /**
         * @see ApiBase::getAllowedParams
         *
         * @since 0.2
@@ -221,13 +142,9 @@
         * @return array
         */
        public function getAllowedParams() {
-               return array(
+               return array_merge( parent::getAllowedParams(), array(
                        'entity' => array(
                                ApiBase::PARAM_TYPE => 'string',
-                               ApiBase::PARAM_REQUIRED => true,
-                       ),
-                       'snaktype' => array(
-                               ApiBase::PARAM_TYPE => array( 'value', 
'novalue', 'somevalue' ),
                                ApiBase::PARAM_REQUIRED => true,
                        ),
                        'property' => array(
@@ -238,12 +155,11 @@
                                ApiBase::PARAM_TYPE => 'string',
                                ApiBase::PARAM_REQUIRED => false,
                        ),
-                       'token' => null,
-                       'baserevid' => array(
-                               ApiBase::PARAM_TYPE => 'integer',
+                       'snaktype' => array(
+                               ApiBase::PARAM_TYPE => array( 'value', 
'novalue', 'somevalue' ),
+                               ApiBase::PARAM_REQUIRED => true,
                        ),
-                       'bot' => null,
-               );
+               ) );
        }
 
        /**
@@ -254,19 +170,12 @@
         * @return array
         */
        public function getParamDescription() {
-               return array(
+               return array_merge( parent::getParamDescription(), array(
                        'entity' => 'Id of the entity you are adding the claim 
to',
                        'property' => 'Id of the snaks property',
                        'value' => 'Value of the snak when creating a claim 
with a snak that has a value',
                        'snaktype' => 'The type of the snak',
-                       'token' => 'An "edittoken" token previously obtained 
through the token module (prop=info).',
-                       'baserevid' => array( 'The numeric identifier for the 
revision to base the modification on.',
-                               "This is used for detecting conflicts during 
save."
-                       ),
-                       'bot' => array( 'Mark this edit as bot',
-                               'This URL flag will only be respected if the 
user belongs to the group "bot".'
-                       ),
-               );
+               ) );
        }
 
        /**
@@ -298,35 +207,13 @@
        }
 
        /**
-        * @see ApiBase::getHelpUrls
-        *
-        * @since 0.2
-        *
-        * @return string
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbcreateclaim';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.2
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
-       /**
         * @see  ApiAutocomment::getTextForComment()
         */
        public function getTextForComment( array $params, $plural = 1 ) {
                return Autocomment::formatAutoComment(
-                       'wbcreateclaim-' . $params['snaktype'],
+                       $this->getModuleName(),
                        array(
-                               /*plural */ (int)isset( $params['value'] ) + 
(int)isset( $params['property'] )
+                               /*plural */ 1
                        )
                );
        }
@@ -336,29 +223,7 @@
         */
        public function getTextForSummary( array $params ) {
                return Autocomment::formatAutoSummary(
-                       Autocomment::pickValuesFromParams( $params, 'property', 
'value' )
+                       Autocomment::pickValuesFromParams( $params, 'property' )
                );
        }
-
-       /**
-        * @see \ApiBase::needsToken()
-        */
-       public function needsToken() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithTokens' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::mustBePosted()
-        */
-       public function mustBePosted() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithPost' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::isWriteMode()
-        */
-       public function isWriteMode() {
-               return true;
-       }
-
 }
diff --git a/repo/includes/api/ApiModifyClaim.php 
b/repo/includes/api/ApiModifyClaim.php
new file mode 100644
index 0000000..1ed6fd5
--- /dev/null
+++ b/repo/includes/api/ApiModifyClaim.php
@@ -0,0 +1,221 @@
+<?php
+
+namespace Wikibase;
+use ApiBase, MWException;
+
+/**
+ * Base module for handling claims.
+ *
+ * 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
+ *
+ * @ingroup WikibaseRepo
+ * @ingroup API
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroended...@gmail.com >
+ * @author Daniel Kinzler
+ */
+abstract class ApiModifyClaim extends Api implements ApiAutocomment {
+
+       /**
+        * @since 0.4
+        *
+        * @param EntityContent $content The content to save
+        * @param int           $flags   Edit flags, e.g. EDIT_NEW
+        * @param string|null   $summary The summary to set. If null, the 
summary will be auto-generated.
+        *
+        * @return void
+        */
+       protected function saveChanges( EntityContent $content, $summary = null 
) {
+               $params = $this->extractRequestParams();
+
+               if ( $summary === null ) {
+                       $summary = Autocomment::buildApiSummary( $this, 
$params, $content );
+               }
+
+               $user = $this->getUser();
+               $baseRevisionId = isset( $params['baserevid'] ) ? intval( 
$params['baserevid'] ) : null;
+               $baseRevisionId = $baseRevisionId > 0 ? $baseRevisionId : false;
+
+               $flags = EDIT_UPDATE;
+               $flags |= ( $user->isAllowed( 'bot' ) && $params['bot'] ) ? 
EDIT_FORCE_BOT : 0;
+
+               $editEntity = new EditEntity( $content, $user, $baseRevisionId, 
$this->getContext() );
+
+               $status = $editEntity->attemptSave(
+                       $summary,
+                       $flags,
+                       isset( $params['token'] ) ? $params['token'] : ''
+               );
+
+               if ( !$status->isOK() ) {
+                       $this->dieUsage( $status->getHTML( 
'wikibase-api-save-failed' ), 'save-failed' );
+               }
+
+               $statusValue = $status->getValue();
+
+               if ( isset( $statusValue['revision'] ) ) {
+                       $this->getResult()->addValue(
+                               'pageinfo',
+                               'lastrevid',
+                               (int)$statusValue['revision']->getId()
+                       );
+               }
+       }
+
+       /**
+        * Checks if the required parameters are set and are valid and 
consistent.
+        *
+        * @since 0.2
+        */
+       protected function checkParameterRequirements() {
+               // noop
+       }
+
+       /**
+        * @since 0.2
+        *
+        * @return Snak
+        * @throws MWException
+        */
+       protected function getSnakInstance() {
+               $params = $this->extractRequestParams();
+
+               $factory = new SnakFactory();
+
+               return $factory->newSnak(
+                       $this->getPropertyId(),
+                       $params['snaktype'],
+                       isset( $params['value'] ) ? \FormatJson::decode( 
$params['value'], true ) : null
+               );
+       }
+
+       /**
+        * @return EntityId
+        */
+       protected function getPropertyId() {
+               $params = $this->extractRequestParams();
+
+               $libRegistry = new LibRegistry( Settings::singleton() );
+               $parseResult = $libRegistry->getEntityIdParser()->parse( 
$params['property'] );
+
+               if ( !$parseResult->isValid() ) {
+                       $this->dieUsage( $parseResult->getError()->getText(), 
'illegal-property-id' );
+               }
+
+               return $parseResult->getValue();
+       }
+
+       /**
+        * @since 0.3
+        *
+        * @param Claim $claim
+        */
+       protected function outputClaim( Claim $claim ) {
+               $serializerFactory = new 
\Wikibase\Lib\Serializers\SerializerFactory();
+
+               $serializer = $serializerFactory->newSerializerForObject( 
$claim );
+               $serializer->getOptions()->setIndexTags( 
$this->getResult()->getIsRawMode() );
+
+               $this->getResult()->addValue(
+                       null,
+                       'claim',
+                       $serializer->getSerialized( $claim )
+               );
+       }
+
+       /**
+        * @see ApiBase::getAllowedParams
+        *
+        * @since 0.2
+        *
+        * @return array
+        */
+       public function getAllowedParams() {
+               return array(
+                       'token' => null,
+                       'baserevid' => array(
+                               ApiBase::PARAM_TYPE => 'integer',
+                       ),
+                       'bot' => null,
+               );
+       }
+
+       /**
+        * @see ApiBase::getParamDescription
+        *
+        * @since 0.2
+        *
+        * @return array
+        */
+       public function getParamDescription() {
+               return array(
+                       'token' => 'An "edittoken" token previously obtained 
through the token module (prop=info).',
+                       'baserevid' => array( 'The numeric identifier for the 
revision to base the modification on.',
+                               "This is used for detecting conflicts during 
save."
+                       ),
+                       'bot' => array( 'Mark this edit as bot',
+                               'This URL flag will only be respected if the 
user belongs to the group "bot".'
+                       ),
+               );
+       }
+
+       /**
+        * @see ApiBase::getHelpUrls
+        *
+        * @since 0.2
+        *
+        * @return string
+        */
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/Extension:Wikibase/API#' 
. $this->getModuleName();
+       }
+
+       /**
+        * @see ApiBase::getVersion
+        *
+        * @since 0.2
+        *
+        * @return string
+        */
+       public function getVersion() {
+               return get_class( $this ) . '-' . WB_VERSION;
+       }
+
+       /**
+        * @see \ApiBase::needsToken()
+        */
+       public function needsToken() {
+               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithTokens' ) : true;
+       }
+
+       /**
+        * @see \ApiBase::mustBePosted()
+        */
+       public function mustBePosted() {
+               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithPost' ) : true;
+       }
+
+       /**
+        * @see \ApiBase::isWriteMode()
+        */
+       public function isWriteMode() {
+               return true;
+       }
+
+}
diff --git a/repo/includes/api/ApiRemoveClaims.php 
b/repo/includes/api/ApiRemoveClaims.php
index 270a880..2e9e8d6 100644
--- a/repo/includes/api/ApiRemoveClaims.php
+++ b/repo/includes/api/ApiRemoveClaims.php
@@ -28,10 +28,10 @@
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < jeroended...@gmail.com >
+ * @author Daniel Kinzler
  */
-class ApiRemoveClaims extends Api {
+class ApiRemoveClaims extends ApiModifyClaim {
 
-       // TODO: automcomment
        // TODO: example
        // TODO: rights
        // TODO: conflict detection
@@ -108,7 +108,6 @@
                        );
 
                        $entity->setClaims( $claims );
-
                        $this->saveChanges( $entityContent );
                }
 
@@ -192,82 +191,33 @@
        }
 
        /**
-        * @since 0.3
-        *
-        * @param EntityContent $content
-        */
-       protected function saveChanges( EntityContent $content ) {
-               $params = $this->extractRequestParams();
-
-               $user = $this->getUser();
-               $flags = 0;
-               $baseRevisionId = isset( $params['baserevid'] ) ? intval( 
$params['baserevid'] ) : null;
-               $baseRevisionId = $baseRevisionId > 0 ? $baseRevisionId : false;
-               $flags |= ( $user->isAllowed( 'bot' ) && $params['bot'] ) ? 
EDIT_FORCE_BOT : 0;
-               $flags |= EDIT_UPDATE;
-               $editEntity = new EditEntity( $content, $user, $baseRevisionId, 
$this->getContext() );
-
-               $status = $editEntity->attemptSave(
-                       '', // TODO: automcomment
-                       $flags,
-                       isset( $params['token'] ) ? $params['token'] : ''
-               );
-
-               if ( !$status->isGood() ) {
-                       $this->dieUsage( 'Failed to save the change', 
'save-failed' );
-               }
-
-               $statusValue = $status->getValue();
-
-               if ( isset( $statusValue['revision'] ) ) {
-                       $this->getResult()->addValue(
-                               'pageinfo',
-                               'lastrevid',
-                               (int)$statusValue['revision']->getId()
-                       );
-               }
-       }
-
-       /**
         * @see ApiBase::getAllowedParams
         *
-        * @since 0.3
+        * @since 0.2
         *
         * @return array
         */
        public function getAllowedParams() {
-               return array(
+               return array_merge( parent::getAllowedParams(), array(
                        'claim' => array(
                                ApiBase::PARAM_TYPE => 'string',
                                ApiBase::PARAM_ISMULTI => true,
                                ApiBase::PARAM_REQUIRED => true,
                        ),
-                       'token' => null,
-                       'baserevid' => array(
-                               ApiBase::PARAM_TYPE => 'integer',
-                       ),
-                       'bot' => null,
-               );
+               ) );
        }
 
        /**
         * @see ApiBase::getParamDescription
         *
-        * @since 0.3
+        * @since 0.2
         *
         * @return array
         */
        public function getParamDescription() {
-               return array(
+               return array_merge( parent::getParamDescription(), array(
                        'claim' => 'A GUID identifying the claim',
-                       'token' => 'An "edittoken" token previously obtained 
through the token module (prop=info).',
-                       'baserevid' => array( 'The numeric identifier for the 
revision to base the modification on.',
-                               "This is used for detecting conflicts during 
save."
-                       ),
-                       'bot' => array( 'Mark this edit as bot',
-                               'This URL flag will only be respected if the 
user belongs to the group "bot".'
-                       ),
-               );
+               ) );
        }
 
        /**
@@ -298,46 +248,25 @@
        }
 
        /**
-        * @see ApiBase::getHelpUrls
-        *
-        * @since 0.3
-        *
-        * @return string
+        * @see  ApiAutocomment::getTextForComment()
         */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbremoveclaims';
+       public function getTextForComment( array $params, $plural = 1 ) {
+               $guids = $params['claim'];
+
+               return Autocomment::formatAutoComment(
+                       $this->getModuleName(),
+                       array(
+                               /*plural */ count( $guids ),
+                       )
+               );
        }
 
        /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.3
-        *
-        * @return string
+        * @see  ApiAutocomment::getTextForSummary()
         */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
+       public function getTextForSummary( array $params ) {
+               return Autocomment::formatAutoSummary(
+                       Autocomment::pickValuesFromParams( $params, 'claim' )
+               );
        }
-
-       /**
-        * @see \ApiBase::needsToken()
-        */
-       public function needsToken() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithTokens' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::mustBePosted()
-        */
-       public function mustBePosted() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithPost' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::isWriteMode()
-        */
-       public function isWriteMode() {
-               return true;
-       }
-
 }
diff --git a/repo/includes/api/ApiSetClaimValue.php 
b/repo/includes/api/ApiSetClaimValue.php
index 0a95e03..f592fd6 100644
--- a/repo/includes/api/ApiSetClaimValue.php
+++ b/repo/includes/api/ApiSetClaimValue.php
@@ -28,8 +28,9 @@
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < jeroended...@gmail.com >
+ * @author Daniel Kinzler
  */
-class ApiSetClaimValue extends Api {
+class ApiSetClaimValue extends ApiModifyClaim {
 
        // TODO: example
        // TODO: rights
@@ -130,69 +131,14 @@
        }
 
        /**
-        * @since 0.3
-        *
-        * @param EntityContent $content
-        */
-       protected function saveChanges( EntityContent $content ) {
-               $params = $this->extractRequestParams();
-
-               $user = $this->getUser();
-               $flags = 0;
-               $baseRevisionId = isset( $params['baserevid'] ) ? intval( 
$params['baserevid'] ) : null;
-               $baseRevisionId = $baseRevisionId > 0 ? $baseRevisionId : false;
-               $flags |= ( $user->isAllowed( 'bot' ) && $params['bot'] ) ? 
EDIT_FORCE_BOT : 0;
-               $flags |= EDIT_UPDATE;
-               $editEntity = new EditEntity( $content, $user, $baseRevisionId, 
$this->getContext() );
-
-               $status = $editEntity->attemptSave(
-                       '', // TODO: automcomment
-                       $flags,
-                       isset( $params['token'] ) ? $params['token'] : ''
-               );
-
-               if ( !$status->isGood() ) {
-                       $this->dieUsage( 'Failed to save the change', 
'setclaimvalue-save-failed' );
-               }
-
-               $statusValue = $status->getValue();
-
-               if ( isset( $statusValue['revision'] ) ) {
-                       $this->getResult()->addValue(
-                               'pageinfo',
-                               'lastrevid',
-                               (int)$statusValue['revision']->getId()
-                       );
-               }
-       }
-
-       /**
-        * @since 0.3
-        *
-        * @param Claim $claim
-        */
-       protected function outputClaim( Claim $claim ) {
-               $serializerFactory = new 
\Wikibase\Lib\Serializers\SerializerFactory();
-               $serializer = $serializerFactory->newSerializerForObject( 
$claim );
-
-               $serializer->getOptions()->setIndexTags( 
$this->getResult()->getIsRawMode() );
-
-               $this->getResult()->addValue(
-                       null,
-                       'claim',
-                       $serializer->getSerialized( $claim )
-               );
-       }
-
-       /**
         * @see ApiBase::getAllowedParams
         *
-        * @since 0.3
+        * @since 0.2
         *
         * @return array
         */
        public function getAllowedParams() {
-               return array(
+               return array_merge( parent::getAllowedParams(), array(
                        'claim' => array(
                                ApiBase::PARAM_TYPE => 'string',
                                ApiBase::PARAM_REQUIRED => true,
@@ -205,35 +151,22 @@
                                ApiBase::PARAM_TYPE => array( 'value', 
'novalue', 'somevalue' ),
                                ApiBase::PARAM_REQUIRED => true,
                        ),
-                       'token' => null,
-                       'baserevid' => array(
-                               ApiBase::PARAM_TYPE => 'integer',
-                       ),
-                       'bot' => null,
-               );
+               ) );
        }
 
        /**
         * @see ApiBase::getParamDescription
         *
-        * @since 0.3
+        * @since 0.2
         *
         * @return array
         */
        public function getParamDescription() {
-               return array(
+               return array_merge( parent::getParamDescription(), array(
                        'claim' => 'A GUID identifying the claim',
                        'snaktype' => 'The type of the snak',
                        'value' => 'The value to set the datavalue of the the 
main snak of the claim to',
-                       'token' => 'An "edittoken" token previously obtained 
through the token module (prop=info).',
-                       'baserevid' => array( 'The numeric identifier for the 
revision to base the modification on.',
-                               "This is used for detecting conflicts during 
save."
-                       ),
-                       'bot' => array( 'Mark this edit as bot',
-                               'This URL flag will only be respected if the 
user belongs to the group "bot".'
-                       ),
-
-               );
+               ) );
        }
 
        /**
@@ -263,47 +196,25 @@
                );
        }
 
+
        /**
-        * @see ApiBase::getHelpUrls
-        *
-        * @since 0.3
-        *
-        * @return string
+        * @see  ApiAutocomment::getTextForComment()
         */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbsetclaimvalue';
+       public function getTextForComment( array $params, $plural = 1 ) {
+               return Autocomment::formatAutoComment(
+                       $this->getModuleName(),
+                       array(
+                               /*plural */ (int)isset( $params['claim'] )
+                       )
+               );
        }
 
        /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.3
-        *
-        * @return string
+        * @see  ApiAutocomment::getTextForSummary()
         */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
+       public function getTextForSummary( array $params ) {
+               return Autocomment::formatAutoSummary(
+                       Autocomment::pickValuesFromParams( $params, 'claim' )
+               );
        }
-
-       /**
-        * @see \ApiBase::needsToken()
-        */
-       public function needsToken() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithTokens' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::mustBePosted()
-        */
-       public function mustBePosted() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithPost' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::isWriteMode()
-        */
-       public function isWriteMode() {
-               return true;
-       }
-
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1c836d6f54d865f83d27b5853ff0d72532c9cd6a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: mw1.21-wmf10
Gerrit-Owner: Anja Jentzsch <anja.jentz...@wikimedia.de>
Gerrit-Reviewer: Anja Jentzsch <anja.jentz...@wikimedia.de>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>

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

Reply via email to