Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/189734
Change subject: Simplify SpecialSetLabelDescriptionAliases ...................................................................... Simplify SpecialSetLabelDescriptionAliases ... to not use a Fingerprint object. The special page does work on a single language only. Change-Id: Ia555d3b5f7bb7efcac464cd3ef257e25fdbdff68 --- M repo/includes/specials/SpecialSetLabelDescriptionAliases.php 1 file changed, 47 insertions(+), 97 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/34/189734/1 diff --git a/repo/includes/specials/SpecialSetLabelDescriptionAliases.php b/repo/includes/specials/SpecialSetLabelDescriptionAliases.php index 1bc5be9..9646694 100644 --- a/repo/includes/specials/SpecialSetLabelDescriptionAliases.php +++ b/repo/includes/specials/SpecialSetLabelDescriptionAliases.php @@ -6,7 +6,6 @@ use InvalidArgumentException; use Language; use PermissionsError; -use OutOfBoundsException; use Wikibase\ChangeOp\ChangeOpException; use Wikibase\ChangeOp\FingerprintChangeOpFactory; use Wikibase\DataModel\Entity\Entity; @@ -26,6 +25,7 @@ * @licence GNU GPL v2+ * @author H. Snater < [email protected] > * @author Bene* < [email protected] > + * @author Thiemo Mättig */ class SpecialSetLabelDescriptionAliases extends SpecialModifyEntity { @@ -35,19 +35,25 @@ protected $fingerprintChangeOpFactory; /** - * The language label, description and aliases are set in. * @var string */ private $languageCode; /** - * @var Fingerprint + * @var string|null */ - private $labelDescriptionAliases; + private $label = null; /** - * @since 0.5 + * @var string|null */ + private $description = null; + + /** + * @var string[] + */ + private $aliases = array(); + public function __construct() { parent::__construct( 'SetLabelDescriptionAliases', 'edit' ); @@ -58,30 +64,22 @@ /** * @see SpecialModifyEntity::validateInput - * @since 0.5 * * @return bool */ protected function validateInput() { - $request = $this->getRequest(); - if ( !parent::validateInput() || !$this->isValidLanguageCode( $this->languageCode ) ) { return false; } - try{ + try { $this->checkTermChangePermissions( $this->entityRevision->getEntity() ); - } catch( PermissionsError $e ) { + } catch ( PermissionsError $e ) { $this->showErrorHTML( $this->msg( 'permissionserrors' ) . ': ' . $e->permission ); return false; } - if( $this->entityRevision ) { - $entity = $this->entityRevision->getEntity(); - return $entity instanceof FingerprintProvider; - } else { - return false; - } + return $this->entityRevision->getEntity() instanceof FingerprintProvider; } /** @@ -91,7 +89,7 @@ * @throws InvalidArgumentException */ private function checkTermChangePermissions( Entity $entity ) { - if( $entity instanceof Item ) { + if ( $entity instanceof Item ) { $type = 'item'; } else if ( $entity instanceof Property ) { $type = 'property'; @@ -106,7 +104,6 @@ /** * @see SpecialModifyEntity::getFormElements() - * @since 0.5 * * @param Entity $entity * @return string @@ -115,46 +112,28 @@ if ( $this->languageCode === null ) { $this->languageCode = $this->getLanguage()->getCode(); } - if ( $this->labelDescriptionAliases === null ) { - $this->labelDescriptionAliases = $entity instanceof FingerprintProvider - ? $entity->getFingerprint() - : new Fingerprint(); - } + + $fingerprint = $entity instanceof FingerprintProvider + ? $entity->getFingerprint() + : new Fingerprint(); $labelText = $this->getRequest()->getVal( 'label' ); - if( !$labelText ) { - try { - $labelText = $this->labelDescriptionAliases - ->getLabel( $this->languageCode ) - ->getText(); - } catch( OutOfBoundsException $e ) { - $labelText = ''; - } + if ( $labelText === null && $fingerprint->hasLabel( $this->languageCode ) ) { + $labelText = $fingerprint->getLabel( $this->languageCode )->getText(); } $labelInput = $this->getTextInput( 'label', $labelText ); $descriptionText = $this->getRequest()->getVal( 'description' ); - if( !$descriptionText ) { - try { - $descriptionText = $this->labelDescriptionAliases - ->getDescription( $this->languageCode ) - ->getText(); - } catch( OutOfBoundsException $e ) { - $descriptionText = ''; - } + if ( $descriptionText === null && $fingerprint->hasDescription( $this->languageCode ) ) { + $descriptionText = $fingerprint->getDescription( $this->languageCode )->getText(); } $descriptionInput = $this->getTextInput( 'description', $descriptionText ); $aliasesText = $this->getRequest()->getVal( 'aliases' ); - if( !$aliasesText ) { - try { - $aliasGroup = $this->labelDescriptionAliases->getAliasGroup( $this->languageCode ); - $aliasesText = implode( '|', $aliasGroup->getAliases() ); - } catch( OutOfBoundsException $e ) { - $aliasesText = ''; - } + if ( $aliasesText === null && $fingerprint->hasAliasGroup( $this->languageCode ) ) { + $aliasesText = implode( '|', $fingerprint->getAliasGroup( $this->languageCode )->getAliases() ); } $aliasesInput = $this->getTextInput( 'aliases', $aliasesText ); @@ -164,7 +143,7 @@ ); if ( $entity !== null && $this->languageCode !== null && $languageName !== '' ) { - return Html::rawElement( + $html = Html::rawElement( 'p', array(), $this->msg( @@ -174,10 +153,9 @@ )->parse() ) . Html::input( 'language', $this->languageCode, 'hidden' ) - . Html::input( 'id', $entity->getId()->getSerialization(), 'hidden' ) - . $labelInput . $descriptionInput . $aliasesInput; + . Html::input( 'id', $entity->getId()->getSerialization(), 'hidden' ); } else { - return Html::rawElement( + $html = Html::rawElement( 'p', array(), $this->msg( 'wikibase-setlabeldescriptionaliases-intro' )->parse() @@ -199,11 +177,14 @@ 'class' => 'wb-input', 'id' => 'wikibase-setlabeldescriptionaliases-language' ) - ) - . $this->getLabel( 'label' ) . $labelInput + ); + } + + $html .= $this->getLabel( 'label' ) . $labelInput . $this->getLabel( 'description' ) . $descriptionInput . $this->getLabel( 'aliases' ) . $aliasesInput; - } + + return $html; } /** @@ -251,7 +232,6 @@ /** * @see SpecialModifyEntity::prepareArguments() - * @since 0.5 * * @param string $subPage */ @@ -276,38 +256,9 @@ $this->showErrorHTML( $errorMessage ); } - $this->labelDescriptionAliases = null; - if( $this->entityRevision !== null ) { - $entity = $this->entityRevision->getEntity(); - if( $entity instanceof FingerprintProvider ) { - $this->labelDescriptionAliases = $entity->getFingerprint(); - } - } - - if( $this->labelDescriptionAliases === null ) { - $this->labelDescriptionAliases = new Fingerprint(); - } - - if( $request->getVal( 'label' ) && $this->languageCode ) { - $this->labelDescriptionAliases->setLabel( - $this->languageCode, - $request->getVal( 'label' ) - ); - } - - if( $request->getVal( 'description' ) && $this->languageCode ) { - $this->labelDescriptionAliases->setDescription( - $this->languageCode, - $request->getVal( 'description' ) - ); - } - - if( $request->getVal( 'aliases' ) && $this->languageCode ) { - $this->labelDescriptionAliases->setAliasGroup( - $this->languageCode, - explode( '|', $request->getVal( 'aliases' ) ) - ); - } + $this->label = $request->getVal( 'label' ); + $this->description = $request->getVal( 'description' ); + $this->aliases = explode( '|', $request->getVal( 'aliases' ) ); } /** @@ -330,26 +281,24 @@ * @return Summary[]|bool */ protected function modifyEntity( Entity $entity ) { - if( $this->labelDescriptionAliases === null ) { - return false; - } + $changeOps = array(); - $labelChangeOp = $this->fingerprintChangeOpFactory->newSetLabelOp( + $changeOps[] = $this->fingerprintChangeOpFactory->newSetLabelOp( $this->languageCode, - $this->labelDescriptionAliases->getLabel( $this->languageCode )->getText() + $this->label ); - $descriptionChangeOp = $this->fingerprintChangeOpFactory->newSetDescriptionOp( + $changeOps[] = $this->fingerprintChangeOpFactory->newSetDescriptionOp( $this->languageCode, - $this->labelDescriptionAliases->getDescription( $this->languageCode )->getText() + $this->description ); - $aliasesChangeOp = $this->fingerprintChangeOpFactory->newSetAliasesOp( + $changeOps[] = $this->fingerprintChangeOpFactory->newSetAliasesOp( $this->languageCode, - $this->labelDescriptionAliases->getAliasGroup( $this->languageCode )->getAliases() + $this->aliases ); $success = true; - foreach( array( $labelChangeOp, $descriptionChangeOp, $aliasesChangeOp ) as $changeOp ) { + foreach ( $changeOps as $changeOp ) { try { $this->applyChangeOp( $changeOp, $entity ); } catch ( ChangeOpException $e ) { @@ -358,10 +307,11 @@ } } - if( !$success ) { + if ( !$success ) { return false; } return $this->getSummary( 'wbeditentity' ); } + } -- To view, visit https://gerrit.wikimedia.org/r/189734 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia555d3b5f7bb7efcac464cd3ef257e25fdbdff68 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
