Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/191592
Change subject: New auto-summary message for SpecialSetLabelDescriptionAliases
......................................................................
New auto-summary message for SpecialSetLabelDescriptionAliases
Again, this is only one step, more patches are coming.
Change-Id: I66f06792386adddf48e342a7a623e38033bc28ae
---
M repo/i18n/en.json
M repo/includes/specials/SpecialSetLabelDescriptionAliases.php
2 files changed, 78 insertions(+), 40 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/92/191592/1
diff --git a/repo/i18n/en.json b/repo/i18n/en.json
index ebe9c1e..33e549a 100644
--- a/repo/i18n/en.json
+++ b/repo/i18n/en.json
@@ -343,6 +343,7 @@
"wikibase-item-summary-wbsetaliases-add-remove": "Added and removed
[$2] {{PLURAL:$1|alias|aliases}}",
"wikibase-item-summary-wbsetaliases-add": "Added [$2]
{{PLURAL:$1|alias|aliases}}",
"wikibase-item-summary-wbsetaliases-remove": "Removed [$2]
{{PLURAL:$1|alias|aliases}}",
+ "wikibase-item-summary-wbsetlabeldescriptionaliases": "Changed [$2]
label, description and aliases",
"wikibase-item-summary-wbsetsitelink-add": "Added link to [$2]",
"wikibase-item-summary-wbsetsitelink-add-both": "Added link with badges
to [$2]",
"wikibase-item-summary-wbsetsitelink-set": "Changed link to [$2]",
diff --git a/repo/includes/specials/SpecialSetLabelDescriptionAliases.php
b/repo/includes/specials/SpecialSetLabelDescriptionAliases.php
index 55e3439..6e32b4d 100644
--- a/repo/includes/specials/SpecialSetLabelDescriptionAliases.php
+++ b/repo/includes/specials/SpecialSetLabelDescriptionAliases.php
@@ -4,6 +4,7 @@
use Html;
use Language;
+use Wikibase\ChangeOp\ChangeOp;
use Wikibase\ChangeOp\ChangeOpException;
use Wikibase\ChangeOp\FingerprintChangeOpFactory;
use Wikibase\DataModel\Entity\Entity;
@@ -244,7 +245,7 @@
}
/**
- * @param string $languageCode
+ * @param string|null $languageCode
*
* @return bool
*/
@@ -257,52 +258,25 @@
*
* @param Entity $entity
*
- * @return Summary[]|bool
+ * @return Summary|bool
*/
protected function modifyEntity( Entity $entity ) {
- $fingerprint = $entity->getFingerprint();
- $changeOpFactory = $this->changeOpFactory;
- $changeOps = array();
+ $changeOps = $this->getChangeOps( $entity->getFingerprint() );
- if ( $this->label !== '' ) {
- $changeOps[] = $changeOpFactory->newSetLabelOp(
- $this->languageCode,
- $this->label
- );
- } elseif ( $fingerprint->hasLabel( $this->languageCode ) ) {
- $changeOps[] = $changeOpFactory->newRemoveLabelOp(
- $this->languageCode
- );
+ if ( empty( $changeOps ) ) {
+ // FIXME: Localize!
+ $this->showErrorHTML( 'Nothing changed.' );
+ return false;
}
- if ( $this->description !== '' ) {
- $changeOps[] = $changeOpFactory->newSetDescriptionOp(
- $this->languageCode,
- $this->description
- );
- } elseif ( $fingerprint->hasDescription( $this->languageCode )
) {
- $changeOps[] = $changeOpFactory->newRemoveDescriptionOp(
- $this->languageCode
- );
- }
-
- if ( !empty( $this->aliases ) ) {
- $changeOps[] = $changeOpFactory->newSetAliasesOp(
- $this->languageCode,
- $this->aliases
- );
- } elseif ( $fingerprint->hasAliasGroup( $this->languageCode ) )
{
- $changeOps[] = $changeOpFactory->newRemoveAliasesOp(
- $this->languageCode,
- $fingerprint->getAliasGroup(
$this->languageCode )->getAliases()
- );
- }
-
+ $summary = false;
$success = true;
- foreach ( $changeOps as $changeOp ) {
+ foreach ( $changeOps as $module => $changeOp ) {
+ $summary = $this->getSummary( $module );
+
try {
- $this->applyChangeOp( $changeOp, $entity );
+ $this->applyChangeOp( $changeOp, $entity,
$summary );
} catch ( ChangeOpException $ex ) {
$this->showErrorHTML( $ex->getMessage() );
$success = false;
@@ -313,7 +287,70 @@
return false;
}
- return $this->getSummary( 'wbeditentity' );
+ if ( count( $changeOps ) > 1 ) {
+ $summary =
$this->getSummaryForLabelDescriptionAliases();
+ }
+
+ return $summary;
+ }
+
+ /**
+ * @param Fingerprint $fingerprint
+ *
+ * @return ChangeOp[]
+ */
+ private function getChangeOps( Fingerprint $fingerprint ) {
+ $changeOpFactory = $this->changeOpFactory;
+ $changeOps = array();
+
+ if ( $this->label !== '' ) {
+ $changeOps['wbsetlabel'] =
$changeOpFactory->newSetLabelOp(
+ $this->languageCode,
+ $this->label
+ );
+ } elseif ( $fingerprint->hasLabel( $this->languageCode ) ) {
+ $changeOps['wbsetlabel'] =
$changeOpFactory->newRemoveLabelOp(
+ $this->languageCode
+ );
+ }
+
+ if ( $this->description !== '' ) {
+ $changeOps['wbsetdescription'] =
$changeOpFactory->newSetDescriptionOp(
+ $this->languageCode,
+ $this->description
+ );
+ } elseif ( $fingerprint->hasDescription( $this->languageCode )
) {
+ $changeOps['wbsetdescription'] =
$changeOpFactory->newRemoveDescriptionOp(
+ $this->languageCode
+ );
+ }
+
+ if ( !empty( $this->aliases ) ) {
+ $changeOps['wbsetaliases'] =
$changeOpFactory->newSetAliasesOp(
+ $this->languageCode,
+ $this->aliases
+ );
+ } elseif ( $fingerprint->hasAliasGroup( $this->languageCode ) )
{
+ $changeOps['wbsetaliases'] =
$changeOpFactory->newRemoveAliasesOp(
+ $this->languageCode,
+ $fingerprint->getAliasGroup(
$this->languageCode )->getAliases()
+ );
+ }
+
+ return $changeOps;
+ }
+
+ /**
+ * @return Summary
+ */
+ private function getSummaryForLabelDescriptionAliases() {
+ // FIXME: Use the existing messages if only 1 of the 3 fields
changed.
+ // FIXME: Introduce more specific messages if only 2 of the 3
fields changed.
+ $summary = $this->getSummary( 'wbsetlabeldescriptionaliases' );
+ $summary->addAutoSummaryArgs( $this->label, $this->description,
$this->aliases );
+
+ $summary->setLanguage( $this->languageCode );
+ return $summary;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/191592
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I66f06792386adddf48e342a7a623e38033bc28ae
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits