Addshore has uploaded a new change for review. https://gerrit.wikimedia.org/r/230754
Change subject: Use other IdFormatters from DataModelServices ...................................................................... Use other IdFormatters from DataModelServices Change-Id: Ibdbb0a6e171c3d9174e0789043d650ab32851482 --- D lib/includes/formatters/EntityIdLabelFormatter.php D lib/includes/formatters/EscapingEntityIdFormatter.php D lib/includes/formatters/PlainEntityIdFormatter.php M lib/tests/phpunit/formatters/EntityIdLabelFormatterTest.php D lib/tests/phpunit/formatters/EscapingEntityIdFormatterTest.php D lib/tests/phpunit/formatters/PlainEntityIdFormatterTest.php M lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php M repo/includes/Diff/EntityContentDiffView.php M repo/includes/EntityIdLabelFormatterFactory.php M repo/includes/actions/EditEntityAction.php D repo/tests/phpunit/includes/EntityIdLabelFormatterFactoryTest.php M repo/tests/phpunit/includes/specials/SpecialWikibaseRepoPageTestBase.php 12 files changed, 9 insertions(+), 293 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/54/230754/1 diff --git a/lib/includes/formatters/EntityIdLabelFormatter.php b/lib/includes/formatters/EntityIdLabelFormatter.php deleted file mode 100644 index edda2b2..0000000 --- a/lib/includes/formatters/EntityIdLabelFormatter.php +++ /dev/null @@ -1,69 +0,0 @@ -<?php - -namespace Wikibase\Lib; - -use OutOfBoundsException; -use Wikibase\DataModel\Entity\EntityId; -use Wikibase\DataModel\Services\EntityId\EntityIdFormatter; -use Wikibase\DataModel\Term\Term; -use Wikibase\Lib\Store\LabelDescriptionLookup; - -/** - * @since 0.4 - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - * @author Katie Filbert < [email protected] > - * @author Daniel Kinzler - */ -class EntityIdLabelFormatter implements EntityIdFormatter { - - /** - * @var LabelDescriptionLookup - */ - private $labelDescriptionLookup; - - /** - * @since 0.4 - * - * @param LabelDescriptionLookup $labelDescriptionLookup - */ - public function __construct( LabelDescriptionLookup $labelDescriptionLookup ) { - $this->labelDescriptionLookup = $labelDescriptionLookup; - } - - /** - * @see EntityIdFormatter::formatEntityId - * - * @param EntityId $entityId - * - * @return string - */ - public function formatEntityId( EntityId $entityId ) { - $term = $this->lookupEntityLabel( $entityId ); - if ( $term !== null ) { - return $term->getText(); - } - - // @fixme check if the entity is deleted and format differently? - return $entityId->getSerialization(); - } - - /** - * Lookup a label for an entity - * - * @since 0.4 - * - * @param EntityId $entityId - * - * @return Term|null Null if no label was found in the language or language fallback chain. - */ - protected function lookupEntityLabel( EntityId $entityId ) { - try { - return $this->labelDescriptionLookup->getLabel( $entityId ); - } catch ( OutOfBoundsException $e ) { - return null; - } - } - -} diff --git a/lib/includes/formatters/EscapingEntityIdFormatter.php b/lib/includes/formatters/EscapingEntityIdFormatter.php deleted file mode 100644 index 9681bc7..0000000 --- a/lib/includes/formatters/EscapingEntityIdFormatter.php +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -namespace Wikibase\Lib; - -use InvalidArgumentException; -use Wikibase\DataModel\Entity\EntityId; -use Wikibase\DataModel\Services\EntityId\EntityIdFormatter; - -/** - * EscapingEntityIdFormatter wraps another EntityIdFormatter and - * applies a transformation (escaping) to that formatter's output. - * - * @license GPL 2+ - * @author Daniel Kinzler - */ -class EscapingEntityIdFormatter implements EntityIdFormatter { - - /** - * @var EntityIdFormatter - */ - private $formatter; - - /** - * @var callable - */ - private $escapeCallback; - - /** - * @param EntityIdFormatter $formatter - * @param callable $escapeCallback A callable taking plain text and returning escaped HTML - * @throws InvalidArgumentException - */ - public function __construct( EntityIdFormatter $formatter, $escapeCallback ) { - if ( !is_callable( $escapeCallback ) ) { - throw new InvalidArgumentException( '$escapeCallback must be callable' ); - } - - $this->formatter = $formatter; - $this->escapeCallback = $escapeCallback; - } - - /** - * Format an EntityId - * - * @param EntityId $value - * @return string - */ - public function formatEntityId( EntityId $value ) { - $text = $this->formatter->formatEntityId( $value ); - $escaped = call_user_func( $this->escapeCallback, $text ); - return $escaped; - } - -} diff --git a/lib/includes/formatters/PlainEntityIdFormatter.php b/lib/includes/formatters/PlainEntityIdFormatter.php deleted file mode 100644 index b3a6008..0000000 --- a/lib/includes/formatters/PlainEntityIdFormatter.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -namespace Wikibase\Lib; - -use Wikibase\DataModel\Entity\EntityId; -use Wikibase\DataModel\Services\EntityId\EntityIdFormatter; - -/** - * @since 0.4 - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - * @author Thiemo Mättig - */ -class PlainEntityIdFormatter implements EntityIdFormatter { - - /** - * @since 0.5 - * - * @param EntityId $entityId - * - * @return string - */ - public function formatEntityId( EntityId $entityId ) { - return $entityId->getSerialization(); - } - -} diff --git a/lib/tests/phpunit/formatters/EntityIdLabelFormatterTest.php b/lib/tests/phpunit/formatters/EntityIdLabelFormatterTest.php index ec1c518..92c4f96 100644 --- a/lib/tests/phpunit/formatters/EntityIdLabelFormatterTest.php +++ b/lib/tests/phpunit/formatters/EntityIdLabelFormatterTest.php @@ -7,11 +7,11 @@ use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\Entity\PropertyId; +use Wikibase\DataModel\Services\EntityId\EntityIdLabelFormatter; use Wikibase\DataModel\Term\Term; -use Wikibase\Lib\EntityIdLabelFormatter; /** - * @covers Wikibase\Lib\EntityIdLabelFormatter + * @covers Wikibase\DataModel\Services\EntityId\EntityIdLabelFormatter * * @group ValueFormatters * @group DataValueExtensions diff --git a/lib/tests/phpunit/formatters/EscapingEntityIdFormatterTest.php b/lib/tests/phpunit/formatters/EscapingEntityIdFormatterTest.php deleted file mode 100644 index b0164c5..0000000 --- a/lib/tests/phpunit/formatters/EscapingEntityIdFormatterTest.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php - -namespace Wikibase\Lib\Test; - -use PHPUnit_Framework_TestCase; -use Wikibase\DataModel\Entity\ItemId; -use Wikibase\Lib\EscapingEntityIdFormatter; - -/** - * @covers Wikibase\Lib\EscapingEntityIdFormatter - * - * @group ValueFormatters - * @group DataValueExtensions - * @group WikibaseLib - * @group Wikibase - * - * @licence GNU GPL v2+ - * @author Daniel Kinzler - */ -class EscapingEntityIdFormatterTest extends PHPUnit_Framework_TestCase { - - public function testFormat() { - $entityIdFormatter = $this->getMock( 'Wikibase\DataModel\Services\EntityId\EntityIdFormatter' ); - $entityIdFormatter->expects( $this->once() ) - ->method( 'formatEntityId' ) - ->will( $this->returnValue( 'Q1 is &%$;§ > Q2' ) ); - - $formatter = new EscapingEntityIdFormatter( $entityIdFormatter, 'htmlspecialchars' ); - $value = new ItemId( 'Q1' ); - - $this->assertEquals( 'Q1 is &%$;§ > Q2', $formatter->formatEntityId( $value ) ); - } - -} diff --git a/lib/tests/phpunit/formatters/PlainEntityIdFormatterTest.php b/lib/tests/phpunit/formatters/PlainEntityIdFormatterTest.php deleted file mode 100644 index ab56c48..0000000 --- a/lib/tests/phpunit/formatters/PlainEntityIdFormatterTest.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -namespace Wikibase\Test; - -use PHPUnit_Framework_TestCase; -use Wikibase\DataModel\Entity\EntityId; -use Wikibase\DataModel\Entity\ItemId; -use Wikibase\DataModel\Entity\PropertyId; -use Wikibase\Lib\PlainEntityIdFormatter; - -/** - * @covers Wikibase\Lib\PlainEntityIdFormatter - * - * @group ValueFormatters - * @group DataValueExtensions - * @group WikibaseLib - * @group Wikibase - * @group EntityIdFormatterTest - * - * @licence GNU GPL v2+ - * @author Jeroen De Dauw < [email protected] > - */ -class PlainEntityIdFormatterTest extends PHPUnit_Framework_TestCase { - - protected function newEntityIdFormatter() { - return new PlainEntityIdFormatter(); - } - - /** - * @return array - */ - public function validProvider() { - $argLists = array(); - - $argLists[] = array( new ItemId( 'q42' ), 'Q42' ); - $argLists[] = array( new ItemId( 'q9001' ), 'Q9001' ); - $argLists[] = array( new ItemId( 'q1' ), 'Q1' ); - - $argLists[] = array( new PropertyId( 'p42' ), 'P42' ); - $argLists[] = array( new PropertyId( 'p9001' ), 'P9001' ); - $argLists[] = array( new PropertyId( 'p1' ), 'P1' ); - - return $argLists; - } - - /** - * @dataProvider validProvider - * - * @param EntityId $entityId - * @param string $expectedString - */ - public function testParseWithValidArguments( EntityId $entityId, $expectedString ) { - $formatter = $this->newEntityIdFormatter(); - - $formattingResult = $formatter->formatEntityId( $entityId ); - - $this->assertInternalType( 'string', $formattingResult ); - $this->assertEquals( $expectedString, $formattingResult ); - } - -} diff --git a/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php b/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php index 61f75e2..bb573cb 100644 --- a/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php +++ b/lib/tests/phpunit/formatters/WikibaseValueFormatterBuildersTest.php @@ -18,13 +18,13 @@ use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\Entity\PropertyId; use Wikibase\DataModel\Services\EntityId\BasicEntityIdParser; +use Wikibase\DataModel\Services\EntityId\PlainEntityIdFormatter; use Wikibase\DataModel\Term\Term; use Wikibase\LanguageFallbackChain; use Wikibase\LanguageFallbackChainFactory; use Wikibase\Lib\EntityIdValueFormatter; use Wikibase\Lib\FormatterLabelDescriptionLookupFactory; use Wikibase\Lib\OutputFormatValueFormatterFactory; -use Wikibase\Lib\PlainEntityIdFormatter; use Wikibase\Lib\SnakFormatter; use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Lib\WikibaseValueFormatterBuilders; diff --git a/repo/includes/Diff/EntityContentDiffView.php b/repo/includes/Diff/EntityContentDiffView.php index c78a662..2768647 100644 --- a/repo/includes/Diff/EntityContentDiffView.php +++ b/repo/includes/Diff/EntityContentDiffView.php @@ -17,10 +17,10 @@ use ValueFormatters\FormatterOptions; use ValueFormatters\ValueFormatter; use Wikibase\DataModel\Services\EntityId\EntityIdFormatter; +use Wikibase\DataModel\Services\EntityId\EntityIdLabelFormatter; +use Wikibase\DataModel\Services\EntityId\EscapingEntityIdFormatter; use Wikibase\EntityContent; use Wikibase\Lib\EntityIdHtmlLinkFormatter; -use Wikibase\Lib\EntityIdLabelFormatter; -use Wikibase\Lib\EscapingEntityIdFormatter; use Wikibase\Lib\LanguageNameLookup; use Wikibase\Lib\SnakFormatter; use Wikibase\Lib\Store\EntityRetrievingTermLookup; diff --git a/repo/includes/EntityIdLabelFormatterFactory.php b/repo/includes/EntityIdLabelFormatterFactory.php index bec89ad..99bd374 100644 --- a/repo/includes/EntityIdLabelFormatterFactory.php +++ b/repo/includes/EntityIdLabelFormatterFactory.php @@ -2,7 +2,7 @@ namespace Wikibase\Repo; -use Wikibase\Lib\EntityIdLabelFormatter; +use Wikibase\DataModel\Services\EntityId\EntityIdLabelFormatter; use Wikibase\Lib\SnakFormatter; use Wikibase\Lib\Store\LabelDescriptionLookup; use Wikibase\View\EntityIdFormatterFactory; diff --git a/repo/includes/actions/EditEntityAction.php b/repo/includes/actions/EditEntityAction.php index 595d849..3c9d028 100644 --- a/repo/includes/actions/EditEntityAction.php +++ b/repo/includes/actions/EditEntityAction.php @@ -14,9 +14,9 @@ use ValueFormatters\FormatterOptions; use ValueFormatters\ValueFormatter; use WebRequest; +use Wikibase\DataModel\Services\EntityId\EntityIdLabelFormatter; +use Wikibase\DataModel\Services\EntityId\EscapingEntityIdFormatter; use Wikibase\Lib\EntityIdHtmlLinkFormatter; -use Wikibase\Lib\EntityIdLabelFormatter; -use Wikibase\Lib\EscapingEntityIdFormatter; use Wikibase\Lib\LanguageNameLookup; use Wikibase\Lib\SnakFormatter; use Wikibase\Lib\Store\EntityRetrievingTermLookup; diff --git a/repo/tests/phpunit/includes/EntityIdLabelFormatterFactoryTest.php b/repo/tests/phpunit/includes/EntityIdLabelFormatterFactoryTest.php deleted file mode 100644 index 8760503..0000000 --- a/repo/tests/phpunit/includes/EntityIdLabelFormatterFactoryTest.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php - -namespace Wikibase\Repo\Test; - -use PHPUnit_Framework_TestCase; -use Wikibase\Lib\SnakFormatter; -use Wikibase\Repo\EntityIdLabelFormatterFactory; - -/** - * @covers Wikibase\Repo\EntityIdLabelFormatterFactory - * - * @group ValueFormatters - * @group WikibaseLib - * @group Wikibase - * - * @licence GNU GPL v2+ - * @author Daniel Kinzler - */ -class EntityIdLabelFormatterFactoryTest extends PHPUnit_Framework_TestCase { - - private function getFormatterFactory() { - return new EntityIdLabelFormatterFactory(); - } - - public function testGetFormat() { - $factory = $this->getFormatterFactory(); - - $this->assertEquals( SnakFormatter::FORMAT_PLAIN, $factory->getOutputFormat() ); - } - - public function testGetEntityIdFormatter() { - $factory = $this->getFormatterFactory(); - - $formatter = $factory->getEntityIdFormater( $this->getMock( 'Wikibase\Lib\Store\LabelDescriptionLookup' ) ); - $this->assertInstanceOf( 'Wikibase\DataModel\Services\EntityId\EntityIdFormatter', $formatter ); - } - -} diff --git a/repo/tests/phpunit/includes/specials/SpecialWikibaseRepoPageTestBase.php b/repo/tests/phpunit/includes/specials/SpecialWikibaseRepoPageTestBase.php index e762d6e..cecf13c 100644 --- a/repo/tests/phpunit/includes/specials/SpecialWikibaseRepoPageTestBase.php +++ b/repo/tests/phpunit/includes/specials/SpecialWikibaseRepoPageTestBase.php @@ -13,9 +13,9 @@ use Wikibase\DataModel\Services\EntityId\BasicEntityIdParser; use Wikibase\DataModel\Services\EntityId\EntityIdFormatter; use Wikibase\DataModel\Services\EntityId\EntityIdParser; +use Wikibase\DataModel\Services\EntityId\PlainEntityIdFormatter; use Wikibase\DataModel\Snak\PropertyValueSnak; use Wikibase\DataModel\Snak\Snak; -use Wikibase\Lib\PlainEntityIdFormatter; use Wikibase\Lib\SnakFormatter; use Wikibase\Lib\Store\EntityRevisionLookup; use Wikibase\Lib\Store\EntityStore; -- To view, visit https://gerrit.wikimedia.org/r/230754 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibdbb0a6e171c3d9174e0789043d650ab32851482 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Addshore <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
