Bene has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/276741

Change subject: Add support for specific interfaces in 
SpecialSetLabelDescriptionAliases
......................................................................

Add support for specific interfaces in SpecialSetLabelDescriptionAliases

Special:SetLabelDescriptionAliases now also supports entities that only
have labels and descriptions for example, and only shows the relevant
forms for those entities.

Change-Id: Ie7a1271f0ee3347e57e12046ef9edfd049d21167
---
M repo/includes/Specials/SpecialSetLabelDescriptionAliases.php
1 file changed, 107 insertions(+), 45 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/41/276741/1

diff --git a/repo/includes/Specials/SpecialSetLabelDescriptionAliases.php 
b/repo/includes/Specials/SpecialSetLabelDescriptionAliases.php
index 0892aef..838d3f6 100644
--- a/repo/includes/Specials/SpecialSetLabelDescriptionAliases.php
+++ b/repo/includes/Specials/SpecialSetLabelDescriptionAliases.php
@@ -3,7 +3,6 @@
 namespace Wikibase\Repo\Specials;
 
 use Html;
-use InvalidArgumentException;
 use Language;
 use SiteStore;
 use Wikibase\ChangeOp\ChangeOp;
@@ -11,8 +10,12 @@
 use Wikibase\ChangeOp\ChangeOps;
 use Wikibase\ChangeOp\FingerprintChangeOpFactory;
 use Wikibase\DataModel\Entity\EntityDocument;
-use Wikibase\DataModel\Term\Fingerprint;
-use Wikibase\DataModel\Term\FingerprintProvider;
+use Wikibase\DataModel\Term\AliasesProvider;
+use Wikibase\DataModel\Term\AliasGroupList;
+use Wikibase\DataModel\Term\DescriptionsProvider;
+use Wikibase\DataModel\Term\LabelsProvider;
+use Wikibase\DataModel\Term\Term;
+use Wikibase\DataModel\Term\TermList;
 use Wikibase\EditEntityFactory;
 use Wikibase\Lib\ContentLanguages;
 use Wikibase\Lib\Store\EntityRevisionLookup;
@@ -114,9 +117,20 @@
         * @return bool
         */
        protected function validateInput() {
-               return parent::validateInput()
-                       && $this->entityRevision->getEntity() instanceof 
FingerprintProvider
-                       && $this->isValidLanguageCode( $this->languageCode )
+               if ( !parent::validateInput() ) {
+                       return false;
+               }
+
+               $entity = $this->entityRevision->getEntity();
+
+               if ( !( $entity instanceof LabelsProvider )
+                       && !( $entity instanceof DescriptionsProvider )
+                       && !( $entity instanceof AliasesProvider )
+               ) {
+                       return false;
+               }
+
+               return $this->isValidLanguageCode( $this->languageCode )
                        && $this->wasPostedWithLabelDescriptionOrAliases()
                        && $this->isAllowedToChangeTerms( 
$this->entityRevision->getEntity() );
        }
@@ -175,12 +189,19 @@
                                . Html::hidden(
                                        'language',
                                        $this->languageCode
-                               )
-                               . $this->getLabeledInputField( 'label', 
$this->label )
-                               . Html::element( 'br' )
-                               . $this->getLabeledInputField( 'description', 
$this->description )
-                               . Html::element( 'br' )
-                               . $this->getLabeledInputField( 'aliases', 
implode( '|', $this->aliases ) );
+                               );
+
+                       if ( $entity instanceof LabelsProvider ) {
+                               $html .= $this->getLabeledInputField( 'label', 
$this->label );
+                       }
+
+                       if ( $entity instanceof DescriptionsProvider ) {
+                               $html .= $this->getLabeledInputField( 
'description', $this->description );
+                       }
+
+                       if ( $entity instanceof AliasesProvider ) {
+                               $html .= $this->getLabeledInputField( 
'aliases', implode( '|', $this->aliases ) );
+                       }
                } else {
                        $intro = $this->msg( 
'wikibase-setlabeldescriptionaliases-intro' );
                        $fieldId = 
'wikibase-setlabeldescriptionaliases-language';
@@ -246,7 +267,8 @@
                                'id' => $fieldId,
                                'placeholder' => $value,
                        )
-               );
+               )
+               . Html::element( 'br' );
        }
 
        /**
@@ -273,8 +295,16 @@
                if ( $this->languageCode !== null && $this->entityRevision !== 
null ) {
                        $entity = $this->entityRevision->getEntity();
 
-                       if ( $entity instanceof FingerprintProvider ) {
-                               $this->setFingerprintFields( 
$entity->getFingerprint() );
+                       if ( $entity instanceof LabelsProvider ) {
+                               $this->setLabelsFields( $entity->getLabels() );
+                       }
+
+                       if ( $entity instanceof DescriptionsProvider ) {
+                               $this->setDescriptionsFields( 
$entity->getDescriptions() );
+                       }
+
+                       if ( $entity instanceof AliasesProvider ) {
+                               $this->setAliasesFields( 
$entity->getAliasGroups() );
                        }
                }
        }
@@ -302,23 +332,27 @@
                }
        }
 
-       private function setFingerprintFields( Fingerprint $fingerprint ) {
+       private function setLabelsFields( TermList $labels ) {
                if ( !$this->getRequest()->getCheck( 'label' )
-                       && $fingerprint->hasLabel( $this->languageCode )
+                       && $labels->hasTermForLanguage( $this->languageCode )
                ) {
-                       $this->label = $fingerprint->getLabel( 
$this->languageCode )->getText();
+                       $this->label = $labels->getByLanguage( 
$this->languageCode )->getText();
                }
+       }
 
+       private function setDescriptionsFields( TermList $descriptions ) {
                if ( !$this->getRequest()->getCheck( 'description' )
-                       && $fingerprint->hasDescription( $this->languageCode )
+                       && $descriptions->hasTermForLanguage( 
$this->languageCode )
                ) {
-                       $this->description = $fingerprint->getDescription( 
$this->languageCode )->getText();
+                       $this->description = $descriptions->getByLanguage( 
$this->languageCode )->getText();
                }
+       }
 
+       private function setAliasesFields( AliasGroupList $labels ) {
                if ( !$this->getRequest()->getCheck( 'aliases' )
-                       && $fingerprint->hasAliasGroup( $this->languageCode )
+                       && $labels->hasGroupForLanguage( $this->languageCode )
                ) {
-                       $this->aliases = $fingerprint->getAliasGroup( 
$this->languageCode )->getAliases();
+                       $this->aliases = $labels->getByLanguage( 
$this->languageCode )->getAliases();
                }
        }
 
@@ -336,15 +370,22 @@
         *
         * @param EntityDocument $entity
         *
-        * @throws InvalidArgumentException
         * @return Summary|bool
         */
        protected function modifyEntity( EntityDocument $entity ) {
-               if ( !( $entity instanceof FingerprintProvider ) ) {
-                       throw new InvalidArgumentException( '$entity must be a 
FingerprintProvider' );
+               $changeOps = array();
+
+               if ( $entity instanceof LabelsProvider ) {
+                       $changeOps += $this->getLabelsChangeOps( 
$entity->getLabels() );
                }
 
-               $changeOps = $this->getChangeOps( $entity->getFingerprint() );
+               if ( $entity instanceof DescriptionsProvider ) {
+                       $changeOps += $this->getDescriptionsChangeOps( 
$entity->getDescriptions() );
+               }
+
+               if ( $entity instanceof AliasesProvider ) {
+                       $changeOps += $this->getAliasesChangeOps( 
$entity->getAliasGroups() );
+               }
 
                if ( empty( $changeOps ) ) {
                        return false;
@@ -382,57 +423,78 @@
        }
 
        /**
-        * @param Fingerprint $fingerprint
+        * @param TermList $labels
         *
         * @return ChangeOp[]
         */
-       private function getChangeOps( Fingerprint $fingerprint ) {
-               $changeOpFactory = $this->changeOpFactory;
+       private function getLabelsChangeOps( TermList $labels ) {
                $changeOps = array();
 
                if ( $this->label !== '' ) {
-                       if ( !$fingerprint->hasLabel( $this->languageCode )
-                               || $fingerprint->getLabel( $this->languageCode 
)->getText() !== $this->label
+                       if ( !$labels->hasTermForLanguage( $this->languageCode )
+                               || $labels->getByLanguage( $this->languageCode 
)->getText() !== $this->label
                        ) {
-                               $changeOps['wbsetlabel'] = 
$changeOpFactory->newSetLabelOp(
+                               $changeOps['wbsetlabel'] = 
$this->changeOpFactory->newSetLabelOp(
                                        $this->languageCode,
                                        $this->label
                                );
                        }
-               } elseif ( $fingerprint->hasLabel( $this->languageCode ) ) {
-                       $changeOps['wbsetlabel'] = 
$changeOpFactory->newRemoveLabelOp(
+               } elseif ( $labels->hasTermForLanguage( $this->languageCode ) ) 
{
+                       $changeOps['wbsetlabel'] = 
$this->changeOpFactory->newRemoveLabelOp(
                                $this->languageCode
                        );
                }
 
+               return $changeOps;
+       }
+
+       /**
+        * @param TermList $descriptions
+        *
+        * @return ChangeOp[]
+        */
+       private function getDescriptionsChangeOps( TermList $descriptions ) {
+               $changeOps = array();
+
                if ( $this->description !== '' ) {
-                       if ( !$fingerprint->hasDescription( $this->languageCode 
)
-                               || $fingerprint->getDescription( 
$this->languageCode )->getText() !== $this->description
+                       if ( !$descriptions->hasTermForLanguage( 
$this->languageCode )
+                               || $descriptions->getByLanguage( 
$this->languageCode )->getText() !== $this->description
                        ) {
-                               $changeOps['wbsetdescription'] = 
$changeOpFactory->newSetDescriptionOp(
+                               $changeOps['wbsetdescription'] = 
$this->changeOpFactory->newSetDescriptionOp(
                                        $this->languageCode,
                                        $this->description
                                );
                        }
-               } elseif ( $fingerprint->hasDescription( $this->languageCode ) 
) {
-                       $changeOps['wbsetdescription'] = 
$changeOpFactory->newRemoveDescriptionOp(
+               } elseif ( $descriptions->hasTermForLanguage( 
$this->languageCode ) ) {
+                       $changeOps['wbsetdescription'] = 
$this->changeOpFactory->newRemoveDescriptionOp(
                                $this->languageCode
                        );
                }
 
+               return $changeOps;
+       }
+
+       /**
+        * @param AliasGroupList $aliases
+        *
+        * @return ChangeOp[]
+        */
+       private function getAliasesChangeOps( AliasGroupList $aliases ) {
+               $changeOps = array();
+
                if ( !empty( $this->aliases ) ) {
-                       if ( !$fingerprint->hasAliasGroup( $this->languageCode )
-                               || $fingerprint->getAliasGroup( 
$this->languageCode )->getAliases() !== $this->aliases
+                       if ( !$aliases->hasGroupForLanguage( 
$this->languageCode )
+                               || $aliases->getByLanguage( $this->languageCode 
)->getAliases() !== $this->aliases
                        ) {
-                               $changeOps['wbsetaliases'] = 
$changeOpFactory->newSetAliasesOp(
+                               $changeOps['wbsetaliases'] = 
$this->changeOpFactory->newSetAliasesOp(
                                        $this->languageCode,
                                        $this->aliases
                                );
                        }
-               } elseif ( $fingerprint->hasAliasGroup( $this->languageCode ) ) 
{
-                       $changeOps['wbsetaliases'] = 
$changeOpFactory->newRemoveAliasesOp(
+               } elseif ( $aliases->hasGroupForLanguage( $this->languageCode ) 
) {
+                       $changeOps['wbsetaliases'] = 
$this->changeOpFactory->newRemoveAliasesOp(
                                $this->languageCode,
-                               $fingerprint->getAliasGroup( 
$this->languageCode )->getAliases()
+                               $aliases->getByLanguage( $this->languageCode 
)->getAliases()
                        );
                }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie7a1271f0ee3347e57e12046ef9edfd049d21167
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <[email protected]>

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

Reply via email to