Daniel Kinzler has submitted this change and it was merged. Change subject: Slightly overhaul SetAliases ......................................................................
Slightly overhaul SetAliases SetAliases was acting weird in case it was told to do more than just set, add or remove at once (while only add and remove together make sense and are valid after this change). This furthermore fixes an edit summary bug. Bug: 46743 Change-Id: Ic265625ed4987d4b7eed294ee8df303972834aa0 --- M repo/Wikibase.i18n.php M repo/includes/api/SetAliases.php 2 files changed, 51 insertions(+), 32 deletions(-) Approvals: Daniel Kinzler: Verified; Looks good to me, approved jenkins-bot: Checked diff --git a/repo/Wikibase.i18n.php b/repo/Wikibase.i18n.php index d0619f5..4936778 100644 --- a/repo/Wikibase.i18n.php +++ b/repo/Wikibase.i18n.php @@ -209,7 +209,7 @@ 'wikibase-entitydata-text' => 'This page provides a linked data interface to entity values. Please provide the entity ID in the URL, using subpage syntax.', // API errors - these messages should not be translated - 'wikibase-api-aliases-invalid-list' => 'Use either one of "set", "add" and "remove" parameters.', # Do not translate + 'wikibase-api-aliases-invalid-list' => 'Use either "set" or "add"/"remove" parameters.', # Do not translate 'wikibase-api-no-token' => 'No token given.', # Do not translate 'wikibase-api-no-data' => 'No data to operate upon.', # Do not translate 'wikibase-api-client-error' => 'The external client site failed.', # Do not translate diff --git a/repo/includes/api/SetAliases.php b/repo/includes/api/SetAliases.php index 52fe519..91bc26a 100644 --- a/repo/includes/api/SetAliases.php +++ b/repo/includes/api/SetAliases.php @@ -22,6 +22,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > * @author John Erling Blad < jeb...@gmail.com > + * @author Marius Hoch < h...@online.de > */ class SetAliases extends ModifyEntity { @@ -31,11 +32,11 @@ protected function getRequiredPermissions( Entity $entity, array $params ) { $permissions = parent::getRequiredPermissions( $entity, $params ); - if ( isset( $params['add'] ) || isset( $params['set'] ) ) { + if ( !empty( $params['add'] ) || isset( $params['set'] ) ) { // add and set has a common permission due to the special page SetAliases $permissions[] = 'alias-update'; } - if ( isset( $params['remove'] ) ) { + if ( !empty( $params['remove'] ) ) { $permissions[] = 'alias-remove'; } return $permissions; @@ -47,7 +48,7 @@ protected function validateParameters( array $params ) { parent::validateParameters( $params ); - if ( !( ( isset( $params['add'] ) || isset( $params['remove'] ) ) XOR isset( $params['set'] ) ) ) { + if ( !( ( !empty( $params['add'] ) || !empty( $params['remove'] ) ) xor isset( $params['set'] ) ) ) { $this->dieUsage( $this->msg( 'wikibase-api-aliases-invalid-list' )->text(), 'aliases-invalid-list' ); } } @@ -68,6 +69,7 @@ $summary = $this->createSummary( $params ); $summary->setLanguage( $params['language'] ); + // Set the list of aliases to a user given one OR add/ remove certain entries if ( isset( $params['set'] ) ) { $summary->setAction( 'set' ); $summary->addAutoSummaryArgs( $params['set'] ); @@ -78,30 +80,44 @@ $params['set'] ) ); - } - if ( isset( $params['remove'] ) ) { - $summary->setAction( 'remove' ); - $summary->addAutoSummaryArgs( $params['remove'] ); - $entityContent->getEntity()->removeAliases( - $params['language'], - array_map( - function( $str ) { return Utils::trimToNFC( $str ); }, - $params['remove'] - ) - ); - } + } else { - if ( isset( $params['add'] ) ) { - $summary->setAction( 'add' ); - $summary->addAutoSummaryArgs( $params['add'] ); - $entityContent->getEntity()->addAliases( - $params['language'], - array_map( - function( $str ) { return Utils::trimToNFC( $str ); }, - $params['add'] - ) - ); + if ( !empty( $params['add'] ) ) { + $entityContent->getEntity()->addAliases( + $params['language'], + array_map( + function( $str ) { return Utils::trimToNFC( $str ); }, + $params['add'] + ) + ); + } + + if ( !empty( $params['remove'] ) ) { + $entityContent->getEntity()->removeAliases( + $params['language'], + array_map( + function( $str ) { return Utils::trimToNFC( $str ); }, + $params['remove'] + ) + ); + } + + // Set the action to set in case we add and remove entries in a single edit. + if ( !empty( $params['add'] ) && !empty( $params['remove'] ) ) { + $summary->setAction( 'set' ); + // Get the full list of current aliases + $summary->addAutoSummaryArgs( + $entityContent->getEntity()->getAliases( $params['language'] ) + ); + } elseif ( !empty( $params['add'] ) ) { + $summary->setAction( 'add' ); + $summary->addAutoSummaryArgs( $params['add'] ); + } elseif ( !empty( $params['remove'] ) ) { + $summary->setAction( 'remove' ); + $summary->addAutoSummaryArgs( $params['remove'] ); + } + } $aliases = $entityContent->getEntity()->getAliases( $params['language'] ); @@ -162,9 +178,9 @@ parent::getParamDescriptionForSiteLink(), parent::getParamDescriptionForEntity(), array( - 'add' => 'List of aliases to add', - 'remove' => 'List of aliases to remove', - 'set' => 'A list of aliases that will replace the current list', + 'add' => 'List of aliases to add (can be combined with remove)', + 'remove' => 'List of aliases to remove (can be combined with add)', + 'set' => 'A list of aliases that will replace the current list (can not be combined with neither add nor remove)', 'language' => 'The language of which to set the aliases', ) ); @@ -185,13 +201,16 @@ protected function getExamples() { return array( 'api.php?action=wbsetaliases&language=en&id=q1&set=Foo|Bar' - => 'Set the English labels for the entity with id q1 to Foo and Bar', + => 'Set the English aliases for the entity with id q1 to Foo and Bar', 'api.php?action=wbsetaliases&language=en&id=q1&add=Foo|Bar' - => 'Add Foo and Bar to the list of English labels for the entity with id q1', + => 'Add Foo and Bar to the list of English aliases for the entity with id q1', 'api.php?action=wbsetaliases&language=en&id=q1&remove=Foo|Bar' - => 'Remove Foo and Bar from the list of English labels for the entity with id q1', + => 'Remove Foo and Bar from the list of English aliases for the entity with id q1', + + 'api.php?action=wbsetaliases&language=en&id=q1&remove=Foo&add=Bar' + => 'Remove Foo from the list of English aliases for the entity with id q1 while adding Bar to it', ); } -- To view, visit https://gerrit.wikimedia.org/r/59746 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic265625ed4987d4b7eed294ee8df303972834aa0 Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Hoo man <h...@online.de> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Hoo man <h...@online.de> Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits