Daniel Kinzler has uploaded a new change for review.
https://gerrit.wikimedia.org/r/49933
Change subject: Consolidate redundant code in the API.
......................................................................
Consolidate redundant code in the API.
This change pulls several methods used to manipulate claims
into the ApiModifyClaim base class.
Change-Id: If72901f66205c90b60cc1f7204fb28de3d648d75
---
M repo/includes/api/ApiCreateClaim.php
M repo/includes/api/ApiModifyClaim.php
M repo/includes/api/ApiSetClaimValue.php
M repo/includes/api/ApiSetReference.php
M repo/includes/api/RemoveQualifiers.php
M repo/includes/api/RemoveReferences.php
M repo/includes/api/SetClaim.php
M repo/includes/api/SetQualifier.php
M repo/includes/api/SetStatementRank.php
9 files changed, 178 insertions(+), 419 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/33/49933/1
diff --git a/repo/includes/api/ApiCreateClaim.php
b/repo/includes/api/ApiCreateClaim.php
index 9661965..f13b8c6 100644
--- a/repo/includes/api/ApiCreateClaim.php
+++ b/repo/includes/api/ApiCreateClaim.php
@@ -45,11 +45,12 @@
$this->checkParameterRequirements();
- $entityContent = $this->getEntityContent();
+ $params = $this->extractRequestParams();
+ $content = $this->getEntityContent( $params['entity'] );
- $claim = $this->addClaim( $entityContent->getEntity() );
+ $claim = $this->addClaim( $content->getEntity() );
- $this->saveChanges( $entityContent );
+ $this->saveChanges( $content );
$this->outputClaim( $claim );
@@ -93,22 +94,19 @@
/**
* @since 0.2
*
- * @return EntityContent
+ * @return Snak
+ * @throws MWException
*/
- protected function getEntityContent() {
+ protected function getSnakInstance() {
$params = $this->extractRequestParams();
- $baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
+ $factory = new SnakFactory();
- $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 ' . $params['entity'] . ' not
found', 'entity-not-found' );
- }
-
- return $entityContent;
+ return $factory->newSnak(
+ $this->getPropertyId(),
+ $params['snaktype'],
+ isset( $params['value'] ) ? \FormatJson::decode(
$params['value'], true ) : null
+ );
}
/**
diff --git a/repo/includes/api/ApiModifyClaim.php
b/repo/includes/api/ApiModifyClaim.php
index 54bad46..2ea7c9a 100644
--- a/repo/includes/api/ApiModifyClaim.php
+++ b/repo/includes/api/ApiModifyClaim.php
@@ -64,30 +64,57 @@
}
/**
+ * Loads the entity containing the Claim with the given GUID.
+ * If the baserevid parameter is specified, the specified revision of
the entity is loaded.
+ *
+ * @since 0.4
+ *
+ * @param $claimGuid string
+ *
+ * @return EntityContent
+ */
+ protected function getEntityContentForClaim( $claimGuid ) {
+ $entityId = Entity::getIdFromClaimGuid( $claimGuid );
+ $content = $this->getEntityContent( $entityId );
+
+ return $content;
+ }
+
+ /**
+ * Loads the specified entity.
+ * If the baserevid parameter is specified, the specified revision of
the entity is loaded.
+ *
+ * @since 0.4
+ *
+ * @param $entityId string|EntityId Entitiy ID as a string or object
+ *
+ * @return EntityContent
+ */
+ protected function getEntityContent( $entityId ) {
+ $params = $this->extractRequestParams();
+
+ if ( is_string( $entityId ) ) {
+ $entityId = EntityId::newFromPrefixedId( $entityId );
+ }
+
+ $entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
+
+ if ( $entityTitle === null ) {
+ $this->dieUsage( 'No such entity: ' . $entityId,
'entity-not-found' );
+ }
+
+ $baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
+
+ return $this->loadEntityContent( $entityTitle, $baseRevisionId
);
+ }
+
+ /**
* 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
- );
}
/**
diff --git a/repo/includes/api/ApiSetClaimValue.php
b/repo/includes/api/ApiSetClaimValue.php
index f592fd6..b4a4026 100644
--- a/repo/includes/api/ApiSetClaimValue.php
+++ b/repo/includes/api/ApiSetClaimValue.php
@@ -45,7 +45,8 @@
public function execute() {
wfProfileIn( __METHOD__ );
- $content = $this->getEntityContent();
+ $params = $this->extractRequestParams();
+ $content = $this->getEntityContentForClaim( $params['claim'] );
$params = $this->extractRequestParams();
@@ -61,26 +62,6 @@
$this->outputClaim( $claim );
wfProfileOut( __METHOD__ );
- }
-
- /**
- * @since 0.3
- *
- * @return EntityContent
- */
- protected function getEntityContent() {
- $params = $this->extractRequestParams();
-
- $entityId = EntityId::newFromPrefixedId(
Entity::getIdFromClaimGuid( $params['claim'] ) );
- $entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
-
- if ( $entityTitle === null ) {
- $this->dieUsage( 'No such entity',
'setclaimvalue-entity-not-found' );
- }
-
- $baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
-
- return $this->loadEntityContent( $entityTitle, $baseRevisionId
);
}
/**
diff --git a/repo/includes/api/ApiSetReference.php
b/repo/includes/api/ApiSetReference.php
index deede8c..5fd270d 100644
--- a/repo/includes/api/ApiSetReference.php
+++ b/repo/includes/api/ApiSetReference.php
@@ -29,7 +29,7 @@
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
-class ApiSetReference extends Api {
+class ApiSetReference extends ApiModifyClaim {
// TODO: automcomment
// TODO: example
@@ -44,8 +44,8 @@
public function execute() {
wfProfileIn( __METHOD__ );
- $content = $this->getEntityContent();
$params = $this->extractRequestParams();
+ $content = $this->getEntityContentForClaim(
$params['statement'] );
$reference = $this->updateReference(
$content->getEntity(),
@@ -59,26 +59,6 @@
$this->outputReference( $reference );
wfProfileOut( __METHOD__ );
- }
-
- /**
- * @since 0.3
- *
- * @return EntityContent
- */
- protected function getEntityContent() {
- $params = $this->extractRequestParams();
-
- $entityId = EntityId::newFromPrefixedId(
Entity::getIdFromClaimGuid( $params['statement'] ) );
- $entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
-
- if ( $entityTitle === null ) {
- $this->dieUsage( 'No such entity',
'setreference-entity-not-found' );
- }
-
- $baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
-
- return $this->loadEntityContent( $entityTitle, $baseRevisionId
);
}
/**
@@ -162,25 +142,22 @@
}
/**
- * @since 0.3
- *
- * @param EntityContent $content
+ * @see ApiAutocomment::getTextForComment()
*/
- protected function saveChanges( EntityContent $content ) {
- $summary = '/* wbsetreference */'; // TODO: automcomment
- $editEntity = $this->attemptSaveEntity( $content,
- $summary,
- EDIT_UPDATE );
+ public function getTextForComment( array $params, $plural = 1 ) {
+ return Autocomment::formatAutoComment(
+ $this->getModuleName(),
+ array( count( $params['reference'] ) )
+ );
+ }
- $revision = $editEntity->getNewRevision();
-
- if ( $revision ) {
- $this->getResult()->addValue(
- 'pageinfo',
- 'lastrevid',
- $revision->getId()
- );
- }
+ /**
+ * @see ApiAutocomment::getTextForSummary()
+ */
+ public function getTextForSummary( array $params ) {
+ return Autocomment::formatAutoSummary(
+ Autocomment::pickValuesFromParams( $params, 'reference'
)
+ );
}
/**
@@ -208,7 +185,7 @@
* @return array
*/
public function getAllowedParams() {
- return array(
+ return array_merge( parent::getAllowedParams(), array(
'statement' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
@@ -220,12 +197,7 @@
'reference' => array(
ApiBase::PARAM_TYPE => 'string',
),
- 'token' => null,
- 'baserevid' => array(
- ApiBase::PARAM_TYPE => 'integer',
- ),
- 'bot' => null,
- );
+ ) );
}
/**
@@ -236,18 +208,11 @@
* @return array
*/
public function getParamDescription() {
- return array(
+ return array_merge( parent::getParamDescription(), array(
'statement' => 'A GUID identifying the statement for
which a reference is being set',
'snaks' => 'The snaks to set the reference to. JSON
object with property ids pointing to arrays containing the snaks for that
property',
'reference' => 'A hash of the reference that should be
updated. Optional. When not provided, a new reference is created',
- '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".'
- ),
- );
+ ) );
}
/**
diff --git a/repo/includes/api/RemoveQualifiers.php
b/repo/includes/api/RemoveQualifiers.php
index 42b8f71..847e444 100644
--- a/repo/includes/api/RemoveQualifiers.php
+++ b/repo/includes/api/RemoveQualifiers.php
@@ -6,11 +6,11 @@
use MWException;
use Wikibase\EntityContent;
-use Wikibase\EntityId;
use Wikibase\Entity;
use Wikibase\EntityContentFactory;
use Wikibase\Claim;
use Wikibase\Settings;
+use Wikibase\Autocomment;
/**
* API module for removing qualifiers from a claim.
@@ -38,7 +38,7 @@
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
-class RemoveQualifiers extends \Wikibase\Api {
+class RemoveQualifiers extends \Wikibase\ApiModifyClaim {
// TODO: automcomment
// TODO: example
@@ -54,33 +54,14 @@
public function execute() {
wfProfileIn( __METHOD__ );
- $content = $this->getEntityContent();
+ $params = $this->extractRequestParams();
+ $content = $this->getEntityContentForClaim( $params['claim'] );
$this->doRemoveQualifiers( $content->getEntity() );
$this->saveChanges( $content );
wfProfileOut( __METHOD__ );
- }
-
- /**
- * @since 0.3
- *
- * @return EntityContent
- */
- protected function getEntityContent() {
- $params = $this->extractRequestParams();
-
- $entityId = EntityId::newFromPrefixedId(
Entity::getIdFromClaimGuid( $params['claim'] ) );
- $entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
-
- if ( $entityTitle === null ) {
- $this->dieUsage( 'No such entity',
'removequalifiers-entity-not-found' );
- }
-
- $baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
-
- return $this->loadEntityContent( $entityTitle, $baseRevisionId
);
}
/**
@@ -128,26 +109,22 @@
}
/**
- * @since 0.3
- *
- * @param EntityContent $content
+ * @see ApiAutocomment::getTextForComment()
*/
- protected function saveChanges( EntityContent $content ) {
- // collect information and create an EditEntity
- $summary = '/* wbremovequalifiers */'; //TODO: autosummary!
- $editEntity = $this->attemptSaveEntity( $content,
- $summary,
- EDIT_UPDATE );
+ public function getTextForComment( array $params, $plural = 1 ) {
+ return Autocomment::formatAutoComment(
+ $this->getModuleName(),
+ array( count( $params['qualifiers'] ) )
+ );
+ }
- $revision = $editEntity->getNewRevision();
-
- if ( $revision ) {
- $this->getResult()->addValue(
- 'pageinfo',
- 'lastrevid',
- $revision->getId()
- );
- }
+ /**
+ * @see ApiAutocomment::getTextForSummary()
+ */
+ public function getTextForSummary( array $params ) {
+ return Autocomment::formatAutoSummary(
+ Autocomment::pickValuesFromParams( $params,
'qualifiers' )
+ );
}
/**
@@ -158,7 +135,7 @@
* @return array
*/
public function getAllowedParams() {
- return array(
+ return array_merge( parent::getAllowedParams(), array(
'claim' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
@@ -168,12 +145,7 @@
ApiBase::PARAM_REQUIRED => true,
ApiBase::PARAM_ISMULTI => true,
),
- 'token' => null,
- 'baserevid' => array(
- ApiBase::PARAM_TYPE => 'integer',
- ),
- 'bot' => null,
- );
+ ) );
}
/**
@@ -184,18 +156,10 @@
* @return array
*/
public function getParamDescription() {
- return array(
+ return array_merge( parent::getParamDescription(), array(
'claim' => 'A GUID identifying the claim from which to
remove qualifiers',
'qualifiers' => 'Snak hashes of the querliers to
remove',
- '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".'
- ),
- );
+ ) );
}
/**
diff --git a/repo/includes/api/RemoveReferences.php
b/repo/includes/api/RemoveReferences.php
index 547d820..e7fc6c1 100644
--- a/repo/includes/api/RemoveReferences.php
+++ b/repo/includes/api/RemoveReferences.php
@@ -6,12 +6,12 @@
use MWException;
use Wikibase\EntityContent;
-use Wikibase\EntityId;
use Wikibase\Entity;
use Wikibase\EntityContentFactory;
use Wikibase\Statement;
use Wikibase\References;
use Wikibase\Settings;
+use Wikibase\Autocomment;
/**
* API module for removing one or more references of the same statement.
@@ -39,7 +39,7 @@
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
-class RemoveReferences extends \Wikibase\Api {
+class RemoveReferences extends \Wikibase\ApiModifyClaim {
public function __construct( $mainModule, $moduleName, $modulePrefix =
'' ) {
//NOTE: need to declare this constructor, so old PHP versions
don't use the
@@ -60,8 +60,8 @@
public function execute() {
wfProfileIn( __METHOD__ );
- $content = $this->getEntityContent();
$params = $this->extractRequestParams();
+ $content = $this->getEntityContentForClaim(
$params['statement'] );
$this->removeReferences(
$content->getEntity(),
@@ -72,26 +72,6 @@
$this->saveChanges( $content );
wfProfileOut( __METHOD__ );
- }
-
- /**
- * @since 0.3
- *
- * @return EntityContent
- */
- protected function getEntityContent() {
- $params = $this->extractRequestParams();
-
- $entityId = EntityId::newFromPrefixedId(
Entity::getIdFromClaimGuid( $params['statement'] ) );
- $entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
-
- if ( $entityTitle === null ) {
- $this->dieUsage( 'No such entity',
'removereferences-entity-not-found' );
- }
-
- $baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
-
- return $this->loadEntityContent( $entityTitle, $baseRevisionId
);
}
/**
@@ -140,26 +120,22 @@
}
/**
- * @since 0.3
- *
- * @param EntityContent $content
+ * @see ApiAutocomment::getTextForComment()
*/
- protected function saveChanges( EntityContent $content ) {
- // collect information and create an EditEntity
- $summary = '/* wbremovereferences */'; //TODO: autosummary
- $editEntity = $this->attemptSaveEntity( $content,
- $summary,
- EDIT_UPDATE );
+ public function getTextForComment( array $params, $plural = 1 ) {
+ return Autocomment::formatAutoComment(
+ $this->getModuleName(),
+ array( count( $params['references'] ) )
+ );
+ }
- $revision = $editEntity->getNewRevision();
-
- if ( $revision ) {
- $this->getResult()->addValue(
- 'pageinfo',
- 'lastrevid',
- $revision->getId()
- );
- }
+ /**
+ * @see ApiAutocomment::getTextForSummary()
+ */
+ public function getTextForSummary( array $params ) {
+ return Autocomment::formatAutoSummary(
+ Autocomment::pickValuesFromParams( $params,
'references' )
+ );
}
/**
@@ -170,7 +146,7 @@
* @return array
*/
public function getAllowedParams() {
- return array(
+ return array_merge( parent::getAllowedParams(), array(
'statement' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
@@ -180,12 +156,7 @@
ApiBase::PARAM_REQUIRED => true,
ApiBase::PARAM_ISMULTI => true,
),
- 'token' => null,
- 'baserevid' => array(
- ApiBase::PARAM_TYPE => 'integer',
- ),
- 'bot' => null,
- );
+ ) );
}
/**
@@ -196,17 +167,10 @@
* @return array
*/
public function getParamDescription() {
- return array(
+ return array_merge( parent::getParamDescription(), array(
'statement' => 'A GUID identifying the statement for
which a reference is being set',
'references' => 'The hashes of the references that
should be removed',
- '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".'
- ),
- );
+ ) );
}
/**
diff --git a/repo/includes/api/SetClaim.php b/repo/includes/api/SetClaim.php
index f220d02..604211a 100644
--- a/repo/includes/api/SetClaim.php
+++ b/repo/includes/api/SetClaim.php
@@ -10,6 +10,7 @@
use Wikibase\Claim;
use Wikibase\EntityId;
use Wikibase\EntityContentFactory;
+use Wikibase\Autocomment;
/**
* API module for creating or updating an entire Claim.
@@ -37,7 +38,7 @@
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
-class SetClaim extends \Wikibase\Api {
+class SetClaim extends \Wikibase\ApiModifyClaim {
// TODO: rights
@@ -123,65 +124,21 @@
}
/**
- * @since 0.4
- *
- * @param EntityId $entityId
- *
- * @return EntityContent
+ * @see ApiAutocomment::getTextForComment()
*/
- protected function getEntityContent( EntityId $entityId ) {
- $params = $this->extractRequestParams();
-
- $entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
-
- if ( $entityTitle === null ) {
- $this->dieUsage( 'No such entity',
'setclaim-entity-not-found' );
- }
-
- $baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
-
- return $this->loadEntityContent( $entityTitle, $baseRevisionId
);
+ public function getTextForComment( array $params, $plural = 1 ) {
+ return Autocomment::formatAutoComment(
+ $this->getModuleName(),
+ array( 1 )
+ );
}
/**
- * @since 0.4
- *
- * @param EntityContent $content
+ * @see ApiAutocomment::getTextForSummary()
*/
- protected function saveChanges( EntityContent $content ) {
- $params = $this->extractRequestParams();
-
- // collect information and create an EditEntity
- $summary = '/* wbsetclaim */'; // TODO: automcomment;
- $editEntity = $this->attemptSaveEntity( $content,
- $summary,
- EDIT_UPDATE );
-
- $revision = $editEntity->getNewRevision();
-
- if ( $revision ) {
- $this->getResult()->addValue(
- 'pageinfo',
- 'lastrevid',
- $revision->getId()
- );
- }
- }
-
- /**
- * @since 0.4
- *
- * @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 )
+ public function getTextForSummary( array $params ) {
+ return Autocomment::formatAutoSummary(
+ Autocomment::pickValuesFromParams( $params, 'claim' )
);
}
@@ -193,16 +150,12 @@
* @return array
*/
public function getAllowedParams() {
- return array(
+ return array_merge( parent::getAllowedParams(), array(
'claim' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
),
- 'token' => null,
- 'baserevid' => array(
- ApiBase::PARAM_TYPE => 'integer',
- ),
- );
+ ) );
}
/**
@@ -213,13 +166,9 @@
* @return array
*/
public function getParamDescription() {
- return array(
+ return array_merge( parent::getParamDescription(), array(
'claim' => 'Claim serialization',
- '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."
- ),
- );
+ ) );
}
/**
diff --git a/repo/includes/api/SetQualifier.php
b/repo/includes/api/SetQualifier.php
index d8e735d..703e920 100644
--- a/repo/includes/api/SetQualifier.php
+++ b/repo/includes/api/SetQualifier.php
@@ -6,13 +6,13 @@
use MWException;
use Wikibase\EntityContent;
-use Wikibase\EntityId;
use Wikibase\Entity;
use Wikibase\EntityContentFactory;
use Wikibase\Claim;
use Wikibase\Snaks;
use Wikibase\SnakFactory;
use Wikibase\Settings;
+use Wikibase\Autocomment;
/**
* API module for creating a qualifier or setting the value of an existing one.
@@ -40,7 +40,7 @@
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
-class SetQualifier extends \Wikibase\Api {
+class SetQualifier extends \Wikibase\ApiModifyClaim {
// TODO: automcomment
// TODO: example
@@ -59,7 +59,8 @@
$this->checkParameterRequirements();
- $content = $this->getEntityContent();
+ $params = $this->extractRequestParams();
+ $content = $this->getEntityContentForClaim( $params['claim'] );
$claim = $this->doSetQualifier(
$content->getEntity()
@@ -103,26 +104,6 @@
'setqualifier-value-required'
);
}
- }
-
- /**
- * @since 0.3
- *
- * @return EntityContent
- */
- protected function getEntityContent() {
- $params = $this->extractRequestParams();
-
- $entityId = EntityId::newFromPrefixedId(
Entity::getIdFromClaimGuid( $params['claim'] ) );
- $entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
-
- if ( $entityTitle === null ) {
- $this->dieUsage( 'No such entity',
'setqualifier-entity-not-found' );
- }
-
- $baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
-
- return $this->loadEntityContent( $entityTitle, $baseRevisionId
);
}
/**
@@ -249,42 +230,21 @@
}
/**
- * @since 0.3
- *
- * @param EntityContent $content
+ * @see ApiAutocomment::getTextForComment()
*/
- protected function saveChanges( EntityContent $content ) {
- // collect information and create an EditEntity
- $summary = '/* wbsetqualifier */'; // TODO: automcomment
- $editEntity = $this->attemptSaveEntity( $content,
- $summary,
- EDIT_UPDATE );
-
- $revision = $editEntity->getNewRevision();
-
- if ( $revision ) {
- $this->getResult()->addValue(
- 'pageinfo',
- 'lastrevid',
- $revision->getId()
- );
- }
+ public function getTextForComment( array $params, $plural = 1 ) {
+ return Autocomment::formatAutoComment(
+ $this->getModuleName(),
+ array( 1 )
+ );
}
/**
- * @since 0.3
- *
- * @param Claim $claim
+ * @see ApiAutocomment::getTextForSummary()
*/
- 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 )
+ public function getTextForSummary( array $params ) {
+ return Autocomment::formatAutoSummary(
+ Autocomment::pickValuesFromParams( $params, 'property' )
);
}
@@ -296,7 +256,7 @@
* @return array
*/
public function getAllowedParams() {
- return array(
+ return array_merge( parent::getAllowedParams(), array(
'claim' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
@@ -317,12 +277,7 @@
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => false,
),
- 'token' => null,
- 'baserevid' => array(
- ApiBase::PARAM_TYPE => 'integer',
- ),
- 'bot' => null,
- );
+ ) );
}
/**
@@ -333,7 +288,7 @@
* @return array
*/
public function getParamDescription() {
- return array(
+ return array_merge( parent::getParamDescription(), array(
'claim' => 'A GUID identifying the claim for which a
qualifier is being set',
'property' => array(
'Id of the snaks property.',
@@ -351,15 +306,7 @@
'The hash of the snak to modify.',
'Should only be provided for existing
qualifiers'
),
- '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".'
- ),
- );
+ ) );
}
/**
diff --git a/repo/includes/api/SetStatementRank.php
b/repo/includes/api/SetStatementRank.php
index be9cf9c..ffd1976 100644
--- a/repo/includes/api/SetStatementRank.php
+++ b/repo/includes/api/SetStatementRank.php
@@ -6,11 +6,11 @@
use MWException;
use Wikibase\EntityContent;
-use Wikibase\EntityId;
use Wikibase\Entity;
use Wikibase\EntityContentFactory;
use Wikibase\Statement;
use Wikibase\Settings;
+use Wikibase\Autocomment;
use Wikibase\Lib\Serializers\ClaimSerializer;
@@ -40,7 +40,7 @@
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
-class SetStatementRank extends \Wikibase\Api {
+class SetStatementRank extends \Wikibase\ApiModifyClaim {
// TODO: automcomment
// TODO: example
@@ -61,8 +61,8 @@
public function execute() {
wfProfileIn( __METHOD__ );
- $content = $this->getEntityContent();
$params = $this->extractRequestParams();
+ $content = $this->getEntityContentForClaim(
$params['statement'] );
$statement = $this->setStatementRank(
$content->getEntity(),
@@ -75,26 +75,6 @@
$this->outputStatement( $statement );
wfProfileOut( __METHOD__ );
- }
-
- /**
- * @since 0.3
- *
- * @return EntityContent
- */
- protected function getEntityContent() {
- $params = $this->extractRequestParams();
-
- $entityId = EntityId::newFromPrefixedId(
Entity::getIdFromClaimGuid( $params['statement'] ) );
- $entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
-
- if ( $entityTitle === null ) {
- $this->dieUsage( 'No such entity',
'setstatementrank-entity-not-found' );
- }
-
- $baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
-
- return $this->loadEntityContent( $entityTitle, $baseRevisionId
);
}
/**
@@ -130,26 +110,22 @@
}
/**
- * @since 0.3
- *
- * @param EntityContent $content
+ * @see ApiAutocomment::getTextForComment()
*/
- protected function saveChanges( EntityContent $content ) {
- // collect information and create an EditEntity
- $summary = '/* wbsetstatementrank */'; // TODO: automcomment
- $editEntity = $this->attemptSaveEntity( $content,
- $summary,
- EDIT_UPDATE );
+ public function getTextForComment( array $params, $plural = 1 ) {
+ return Autocomment::formatAutoComment(
+ $this->getModuleName(),
+ array( 1 )
+ );
+ }
- $revision = $editEntity->getNewRevision();
-
- if ( $revision ) {
- $this->getResult()->addValue(
- 'pageinfo',
- 'lastrevid',
- $revision->getId()
- );
- }
+ /**
+ * @see ApiAutocomment::getTextForSummary()
+ */
+ public function getTextForSummary( array $params ) {
+ return Autocomment::formatAutoSummary(
+ Autocomment::pickValuesFromParams( $params, 'statement'
)
+ );
}
/**
@@ -178,7 +154,7 @@
* @return array
*/
public function getAllowedParams() {
- return array(
+ return array_merge( parent::getAllowedParams(), array(
'statement' => array(
ApiBase::PARAM_TYPE => 'string',
ApiBase::PARAM_REQUIRED => true,
@@ -187,12 +163,7 @@
ApiBase::PARAM_TYPE =>
ClaimSerializer::getRanks(),
ApiBase::PARAM_REQUIRED => true,
),
- 'token' => null,
- 'baserevid' => array(
- ApiBase::PARAM_TYPE => 'integer',
- ),
- 'bot' => null,
- );
+ ) );
}
/**
@@ -203,17 +174,10 @@
* @return array
*/
public function getParamDescription() {
- return array(
+ 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',
- '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".'
- ),
- );
+ ) );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/49933
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If72901f66205c90b60cc1f7204fb28de3d648d75
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits