Addshore has uploaded a new change for review. https://gerrit.wikimedia.org/r/218661
Change subject: Rename Wikibase\Term to Wikibase\TermIndexEntry ...................................................................... Rename Wikibase\Term to Wikibase\TermIndexEntry This avoids confusion with Term in DataModel. The two are very different. Change-Id: I0a1df9767b60fe44d78fb6739c929c1e0ed94cde --- M client/includes/api/PageTerms.php M client/tests/phpunit/includes/api/PageTermsTest.php R lib/includes/TermIndexEntry.php M lib/includes/store/BufferingTermLookup.php M lib/includes/store/EntityTermLookupBase.php M lib/includes/store/LabelConflictFinder.php M lib/includes/store/TermIndex.php M lib/includes/store/TermPropertyLabelResolver.php M lib/includes/store/sql/TermSqlIndex.php R lib/tests/phpunit/TermIndexEntryTest.php M lib/tests/phpunit/store/BufferingTermLookupTest.php M lib/tests/phpunit/store/EntityTermLookupTest.php M lib/tests/phpunit/store/LanguageFallbackLabelDescriptionLookupTest.php M lib/tests/phpunit/store/LanguageLabelDescriptionLookupTest.php M lib/tests/phpunit/store/MockTermIndex.php M lib/tests/phpunit/store/TermIndexTest.php M lib/tests/phpunit/store/TermPropertyLabelResolverTest.php M repo/includes/Hooks/LabelPrefetchHookHandlers.php M repo/includes/LabelDescriptionDuplicateDetector.php M repo/includes/api/SearchEntities.php M repo/includes/specials/SpecialEntitiesWithoutPageFactory.php M repo/includes/specials/SpecialItemDisambiguation.php M repo/tests/phpunit/includes/LabelDescriptionDuplicateDetectorTest.php M repo/tests/phpunit/includes/api/SearchEntitiesTest.php M repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutPageTest.php M repo/tests/phpunit/includes/store/sql/TermSearchKeyBuilderTest.php M repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php 27 files changed, 235 insertions(+), 230 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/61/218661/1 diff --git a/client/includes/api/PageTerms.php b/client/includes/api/PageTerms.php index 0702691..7844bb7 100644 --- a/client/includes/api/PageTerms.php +++ b/client/includes/api/PageTerms.php @@ -10,7 +10,7 @@ use Title; use Wikibase\DataModel\Entity\EntityId; use Wikibase\Store\EntityIdLookup; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\TermIndex; /** @@ -102,7 +102,7 @@ * @param string[]|null $termTypes * @param string[]|null $languageCodes * - * @return Term[] + * @return TermIndexEntry[] */ private function getTermsOfEntities( array $entityIds, array $termTypes = null, array $languageCodes = null ) { $entityIdGroups = $this->splitPageEntityMapByType( $entityIds ); @@ -158,7 +158,7 @@ /** * @param int[] $entityToPageMap - * @param Term[] $terms + * @param TermIndexEntry[] $terms * * @return array[][] An associative array, mapping pageId + entity type to a list of strings. */ @@ -178,7 +178,7 @@ $termsPerPage[$pageId][$type][] = $text; } else { // $text should never be null, but let's be vigilant. - wfWarn( __METHOD__ . ': Encountered null text in Term object!' ); + wfWarn( __METHOD__ . ': Encountered null text in TermIndexEntry object!' ); } } @@ -239,8 +239,12 @@ ApiBase::PARAM_TYPE => 'integer', ), 'terms' => array( - // XXX Ought to get this list from Wikibase\Term, its setType() also hardcodes it. - ApiBase::PARAM_TYPE => array( Term::TYPE_ALIAS, Term::TYPE_DESCRIPTION, Term::TYPE_LABEL ), + // XXX Ought to get this list from Wikibase\TermIndexEntry, its setType() also hardcodes it. + ApiBase::PARAM_TYPE => array( + TermIndexEntry::TYPE_ALIAS, + TermIndexEntry::TYPE_DESCRIPTION, + TermIndexEntry::TYPE_LABEL + ), ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_HELP_MSG => 'apihelp-query+pageterms-param-terms', ), diff --git a/client/tests/phpunit/includes/api/PageTermsTest.php b/client/tests/phpunit/includes/api/PageTermsTest.php index 8a9ce6f..1fbf442 100644 --- a/client/tests/phpunit/includes/api/PageTermsTest.php +++ b/client/tests/phpunit/includes/api/PageTermsTest.php @@ -13,7 +13,7 @@ use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\Entity\PropertyId; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\TermIndex; /** @@ -144,7 +144,7 @@ * @param string[]|null $termTypes * @param string[]|null $languageCodes * - * @return Term[] + * @return TermIndexEntry[] */ public function getTermsOfEntities( array $termObjectsByEntityId, array $entityIds, array $termTypes = null, array $languageCodes = null ) { $result = array(); @@ -156,7 +156,7 @@ continue; } - /** @var Term $term */ + /** @var TermIndexEntry $term */ foreach ( $termObjectsByEntityId[$key] as $term ) { if ( ( is_array( $termTypes ) && !in_array( $term->getType(), $termTypes ) ) || ( is_array( $languageCodes ) && !in_array( $term->getLanguage(), $languageCodes ) ) @@ -175,14 +175,14 @@ * @param EntityId $entityId * @param array[] $termGroups * - * @return Term[] + * @return TermIndexEntry[] */ private function makeTermsFromGroups( EntityId $entityId, $termGroups ) { $terms = array(); foreach ( $termGroups as $type => $group ) { foreach ( $group as $lang => $text ) { - $terms[] = new Term( array( + $terms[] = new TermIndexEntry( array( 'termType' => $type, 'termLanguage' => $lang, 'termText' => $text, diff --git a/lib/includes/Term.php b/lib/includes/TermIndexEntry.php similarity index 94% rename from lib/includes/Term.php rename to lib/includes/TermIndexEntry.php index 53e2bdf..88facdb 100644 --- a/lib/includes/Term.php +++ b/lib/includes/TermIndexEntry.php @@ -7,15 +7,15 @@ use Wikibase\DataModel\LegacyIdInterpreter; /** - * Object representing a term. - * Terms can be incomplete. + * Object representing a term index entry. + * Term index entries can be incomplete. * * @since 0.2 * * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class Term { +class TermIndexEntry { /** * Term type enum. @@ -201,12 +201,12 @@ * Imposes an canonical but arbitrary order on Term objects. * Useful for sorting lists of terms for comparison. * - * @param Term $a - * @param Term $b + * @param TermIndexEntry $a + * @param TermIndexEntry $b * * @return int Returns 1 if $a is greater than $b, -1 if $b is greater than $a, and 0 otherwise. */ - public static function compare( Term $a, Term $b ) { + public static function compare( TermIndexEntry $a, TermIndexEntry $b ) { foreach ( self::$fieldNames as $n ) { $exists = array_key_exists( $n, $a->fields ); diff --git a/lib/includes/store/BufferingTermLookup.php b/lib/includes/store/BufferingTermLookup.php index ddec43d..3622c40 100644 --- a/lib/includes/store/BufferingTermLookup.php +++ b/lib/includes/store/BufferingTermLookup.php @@ -6,7 +6,7 @@ use Wikibase\DataModel\Entity\EntityId; use Wikibase\Lib\Store\EntityTermLookupBase; use Wikibase\Lib\Store\StorageException; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\TermIndex; /** @@ -175,7 +175,7 @@ } /** - * @param Term[] $terms + * @param TermIndexEntry[] $terms * * @return string[] The buffer keys to which the terms were assigned. */ diff --git a/lib/includes/store/EntityTermLookupBase.php b/lib/includes/store/EntityTermLookupBase.php index c5f3740..1d7f6cb 100644 --- a/lib/includes/store/EntityTermLookupBase.php +++ b/lib/includes/store/EntityTermLookupBase.php @@ -4,7 +4,7 @@ use OutOfBoundsException; use Wikibase\DataModel\Entity\EntityId; -use Wikibase\Term; +use Wikibase\TermIndexEntry; /** * @since 0.5 @@ -87,7 +87,7 @@ abstract protected function getTermsOfType( EntityId $entityId, $termType, array $languageCodes ); /** - * @param Term[] $wikibaseTerms + * @param TermIndexEntry[] $wikibaseTerms * * @return string[] strings keyed by language code */ diff --git a/lib/includes/store/LabelConflictFinder.php b/lib/includes/store/LabelConflictFinder.php index cc2357b..fb6b300 100644 --- a/lib/includes/store/LabelConflictFinder.php +++ b/lib/includes/store/LabelConflictFinder.php @@ -2,7 +2,7 @@ namespace Wikibase\Lib\Store; -use Wikibase\Term; +use Wikibase\TermIndexEntry; /** * Service interface for detecting label conflicts. @@ -24,7 +24,7 @@ * @param string $entityType The entity type to consider for conflicts. * @param string[] $labels The labels to look for, with language codes as keys. * - * @return Term[] + * @return TermIndexEntry[] */ public function getLabelConflicts( $entityType, array $labels ); @@ -42,7 +42,7 @@ * @param string[] $labels The labels to look for, with language codes as keys. * @param string[] $descriptions The descriptions to consider (if desired), with language codes as keys. * - * @return Term[] + * @return TermIndexEntry[] */ public function getLabelWithDescriptionConflicts( $entityType, array $labels, array $descriptions ); diff --git a/lib/includes/store/TermIndex.php b/lib/includes/store/TermIndex.php index f7de790..f2735dc 100644 --- a/lib/includes/store/TermIndex.php +++ b/lib/includes/store/TermIndex.php @@ -46,7 +46,7 @@ * @param string[]|null $languageCodes The desired languages, given as language codes. * If null, all languages are returned. * - * @return Term[] + * @return TermIndexEntry[] */ public function getTermsOfEntity( EntityId $entityId, @@ -66,7 +66,7 @@ * @param string[]|null $languageCodes The desired languages, given as language codes. * If null, all languages are returned. * - * @return Term[] + * @return TermIndexEntry[] */ public function getTermsOfEntities( array $entityIds, @@ -88,7 +88,7 @@ * * @since 0.2 * - * @param Term[] $terms + * @param TermIndexEntry[] $terms * @param string|null $termType * @param string|null $entityType * @param array $options @@ -97,7 +97,7 @@ * - prefixSearch: boolean, default false * - LIMIT: int, defaults to none * - * @return Term[] + * @return TermIndexEntry[] */ public function getMatchingTerms( array $terms, @@ -116,7 +116,7 @@ * * @since 0.4 * - * @param Term[] $terms + * @param TermIndexEntry[] $terms * @param string|null $entityType * @param array $options * Accepted options are: diff --git a/lib/includes/store/TermPropertyLabelResolver.php b/lib/includes/store/TermPropertyLabelResolver.php index ca69813..e74c168 100644 --- a/lib/includes/store/TermPropertyLabelResolver.php +++ b/lib/includes/store/TermPropertyLabelResolver.php @@ -121,7 +121,7 @@ } protected function loadProperties() { - $termTemplate = new Term( array( + $termTemplate = new TermIndexEntry( array( 'termType' => 'label', 'termLanguage' => $this->languageCode, 'entityType' => Property::ENTITY_TYPE diff --git a/lib/includes/store/sql/TermSqlIndex.php b/lib/includes/store/sql/TermSqlIndex.php index 16bfe90..828ad76 100644 --- a/lib/includes/store/sql/TermSqlIndex.php +++ b/lib/includes/store/sql/TermSqlIndex.php @@ -95,8 +95,8 @@ $newTerms = $this->getEntityTerms( $entity ); $oldTerms = $this->getTermsOfEntity( $entity->getId() ); - $termsToInsert = array_udiff( $newTerms, $oldTerms, 'Wikibase\Term::compare' ); - $termsToDelete = array_udiff( $oldTerms, $newTerms, 'Wikibase\Term::compare' ); + $termsToInsert = array_udiff( $newTerms, $oldTerms, 'Wikibase\TermIndexEntry::compare' ); + $termsToDelete = array_udiff( $oldTerms, $newTerms, 'Wikibase\TermIndexEntry::compare' ); if ( !$termsToInsert && !$termsToDelete ) { wfDebugLog( __CLASS__, __FUNCTION__ . ': terms did not change, returning.' ); @@ -130,7 +130,7 @@ * @since 0.5 * * @param EntityDocument $entity - * @param Term[] $terms + * @param TermIndexEntry[] $terms * @param DatabaseBase $dbw * * @return bool Success indicator @@ -173,7 +173,7 @@ /** * @param EntityDocument $entity * - * @return Term[] + * @return TermIndexEntry[] */ public function getEntityTerms( EntityDocument $entity ) { // FIXME: OCP violation. No support for new types of entities can be registered @@ -201,26 +201,26 @@ * @param Fingerprint $fingerprint * @param array $extraFields * - * @return Term[] + * @return TermIndexEntry[] */ private function getFingerprintTerms( Fingerprint $fingerprint, array $extraFields = array() ) { $terms = array(); foreach ( $fingerprint->getDescriptions()->toTextArray() as $languageCode => $description ) { - $term = new Term( $extraFields ); + $term = new TermIndexEntry( $extraFields ); $term->setLanguage( $languageCode ); - $term->setType( Term::TYPE_DESCRIPTION ); + $term->setType( TermIndexEntry::TYPE_DESCRIPTION ); $term->setText( $description ); $terms[] = $term; } foreach ( $fingerprint->getLabels()->toTextArray() as $languageCode => $label ) { - $term = new Term( $extraFields ); + $term = new TermIndexEntry( $extraFields ); $term->setLanguage( $languageCode ); - $term->setType( Term::TYPE_LABEL ); + $term->setType( TermIndexEntry::TYPE_LABEL ); $term->setText( $label ); $terms[] = $term; @@ -229,10 +229,10 @@ /** @var AliasGroup $aliasGroup */ foreach ( $fingerprint->getAliasGroups() as $aliasGroup ) { foreach ( $aliasGroup->getAliases() as $alias ) { - $term = new Term( $extraFields ); + $term = new TermIndexEntry( $extraFields ); $term->setLanguage( $aliasGroup->getLanguageCode() ); - $term->setType( Term::TYPE_ALIAS ); + $term->setType( TermIndexEntry::TYPE_ALIAS ); $term->setText( $alias ); $terms[] = $term; @@ -251,7 +251,7 @@ * @since 0.5 * * @param EntityId $entityId - * @param Term[] $terms + * @param TermIndexEntry[] $terms * @param DatabaseBase $dbw * * @return bool Success indicator @@ -323,11 +323,11 @@ /** * Returns an array with the database table fields for the provided term. * - * @param Term $term + * @param TermIndexEntry $term * * @return string[] */ - private function getTermFields( Term $term ) { + private function getTermFields( TermIndexEntry $term ) { $fields = array( 'term_language' => $term->getLanguage(), 'term_type' => $term->getType(), @@ -378,7 +378,7 @@ * @param string[]|null $termTypes * @param string[]|null $languageCodes * - * @return Term[] + * @return TermIndexEntry[] */ public function getTermsOfEntity( EntityId $entityId, @@ -402,7 +402,7 @@ * @param string[]|null $languageCodes * * @throws MWException - * @return Term[] + * @return TermIndexEntry[] */ public function getTermsOfEntities( array $entityIds, @@ -418,7 +418,7 @@ * @param string[]|null $languageCodes * * @throws MWException - * @return Term[] + * @return TermIndexEntry[] */ private function fetchTerms( array $entityIds, @@ -502,12 +502,12 @@ * * @since 0.2 * - * @param Term[] $terms + * @param TermIndexEntry[] $terms * @param string|null $termType * @param string|null $entityType * @param array $options * - * @return Term[] + * @return TermIndexEntry[] */ public function getMatchingTerms( array $terms, @@ -552,7 +552,7 @@ * * @since 0.4 * - * @param Term[] $terms + * @param TermIndexEntry[] $terms * @param string|null $entityType * @param array $options There is an implicit LIMIT of 5000 items in this implementation * @@ -659,7 +659,7 @@ /** * @param DatabaseBase $db - * @param Term[] $terms + * @param TermIndexEntry[] $terms * @param string|null $termType * @param string|null $entityType * @param array $options @@ -685,7 +685,7 @@ /** * @param DatabaseBase $db - * @param Term $term + * @param TermIndexEntry $term * @param string|null $termType * @param string|null $entityType * @param array $options @@ -694,7 +694,7 @@ */ private function termMatchConditions( DatabaseBase $db, - Term $term, + TermIndexEntry $term, $termType = null, $entityType = null, array $options = array() @@ -761,7 +761,7 @@ * * @param Iterator|array $obtainedTerms PHP fails for not having a common iterator/array thing :<0 * - * @return Term[] + * @return TermIndexEntry[] */ private function buildTermResult( $obtainedTerms ) { $matchingTerms = array(); @@ -782,7 +782,7 @@ $matchingTerm[$this->termFieldMap[$key]] = $value; } - $matchingTerms[] = new Term( $matchingTerm ); + $matchingTerms[] = new TermIndexEntry( $matchingTerm ); } return $matchingTerms; @@ -814,7 +814,7 @@ * @param string[] $labels * * @throws InvalidArgumentException - * @return Term[] + * @return TermIndexEntry[] */ public function getLabelConflicts( $entityType, array $labels ) { if ( !is_string( $entityType ) ) { @@ -825,11 +825,11 @@ return array(); } - $templates = $this->makeQueryTerms( $labels, Term::TYPE_LABEL ); + $templates = $this->makeQueryTerms( $labels, TermIndexEntry::TYPE_LABEL ); $labelConflicts = $this->getMatchingTerms( $templates, - Term::TYPE_LABEL, + TermIndexEntry::TYPE_LABEL, $entityType, array( 'LIMIT' => $this->maxConflicts, @@ -853,7 +853,7 @@ * @param string[] $descriptions * * @throws InvalidArgumentException - * @return Term[] + * @return TermIndexEntry[] */ public function getLabelWithDescriptionConflicts( $entityType, @@ -878,8 +878,8 @@ $where = array(); $where['L.term_entity_type'] = $entityType; - $where['L.term_type'] = Term::TYPE_LABEL; - $where['D.term_type'] = Term::TYPE_DESCRIPTION; + $where['L.term_type'] = TermIndexEntry::TYPE_LABEL; + $where['D.term_type'] = TermIndexEntry::TYPE_DESCRIPTION; $where[] = 'D.term_entity_id=' . 'L.term_entity_id'; $where[] = 'D.term_entity_type=' . 'L.term_entity_type'; @@ -925,7 +925,7 @@ * @param string $type * * @throws InvalidArgumentException - * @return Term[] + * @return TermIndexEntry[] */ private function makeQueryTerms( $textsByLanguage, $type ) { $terms = array(); @@ -938,7 +938,7 @@ throw new InvalidArgumentException( '$textsByLanguage must contain string values only' ); } - $terms[] = new Term( array( + $terms[] = new TermIndexEntry( array( 'termText' => $text, 'termLanguage' => $lang, 'termType' => $type, diff --git a/lib/tests/phpunit/TermTest.php b/lib/tests/phpunit/TermIndexEntryTest.php similarity index 80% rename from lib/tests/phpunit/TermTest.php rename to lib/tests/phpunit/TermIndexEntryTest.php index 48b6f61..7946320 100644 --- a/lib/tests/phpunit/TermTest.php +++ b/lib/tests/phpunit/TermIndexEntryTest.php @@ -3,10 +3,10 @@ namespace Wikibase\Test; use Wikibase\DataModel\LegacyIdInterpreter; -use Wikibase\Term; +use Wikibase\TermIndexEntry; /** - * @covers Wikibase\Term + * @covers Wikibase\TermIndexEntry * * @group Wikibase * @group WikibaseTerm @@ -15,7 +15,7 @@ * @licence GNU GPL v2+ * @author Daniel Kinzler <daniel.kinz...@wikimedia.de> */ -class TermTest extends \MediaWikiTestCase { +class TermIndexEntryTest extends \MediaWikiTestCase { public function provideContructor() { return array( @@ -23,14 +23,14 @@ array( 'entityType' => 'item', 'entityId' => 23, - 'termType' => Term::TYPE_LABEL, + 'termType' => TermIndexEntry::TYPE_LABEL, 'termLanguage' => 'en', 'termText' => 'foo', ) ), array( // #1 array( - 'termType' => Term::TYPE_LABEL, + 'termType' => TermIndexEntry::TYPE_LABEL, 'termLanguage' => 'en', 'termText' => 'foo', ) @@ -48,7 +48,7 @@ * @dataProvider provideContructor */ public function testConstructor( $fields ) { - $term = new Term( $fields ); + $term = new TermIndexEntry( $fields ); $entityId = null; if ( isset( $fields['entityType'] ) && isset( $fields['entityId'] ) ) { @@ -64,7 +64,7 @@ } public function testClone() { - $term = new Term( array( + $term = new TermIndexEntry( array( 'termText' => 'Foo' ) ); @@ -82,15 +82,15 @@ $tests = array(); $tests[] = array( // #0 - new Term(), - new Term(), + new TermIndexEntry(), + new TermIndexEntry(), true ); - $term = new Term( array( + $term = new TermIndexEntry( array( 'entityType' => 'item', 'entityId' => 23, - 'termType' => Term::TYPE_LABEL, + 'termType' => TermIndexEntry::TYPE_LABEL, 'termLanguage' => 'en', 'termText' => 'foo', ) ); @@ -110,10 +110,10 @@ false ); - $other = new Term( array( + $other = new TermIndexEntry( array( 'entityType' => 'property', 'entityId' => 11, - 'termType' => Term::TYPE_LABEL, + 'termType' => TermIndexEntry::TYPE_LABEL, 'termLanguage' => 'en', 'termText' => 'foo', ) ); @@ -123,10 +123,10 @@ false ); - $other = new Term( array( + $other = new TermIndexEntry( array( 'entityType' => 'property', 'entityId' => 23, - 'termType' => Term::TYPE_LABEL, + 'termType' => TermIndexEntry::TYPE_LABEL, 'termLanguage' => 'en', 'termText' => 'foo', ) ); @@ -145,7 +145,7 @@ ); $other = clone $term; - $other->setType( Term::TYPE_DESCRIPTION ); + $other->setType( TermIndexEntry::TYPE_DESCRIPTION ); $tests[] = array( // #6 $term, $other, @@ -159,9 +159,9 @@ * @dataProvider provideCompare * @depends testClone */ - public function testCompare( Term $a, Term $b, $equal ) { - $ab = Term::compare( $a, $b ); - $ba = Term::compare( $b, $a ); + public function testCompare( TermIndexEntry $a, TermIndexEntry $b, $equal ) { + $ab = TermIndexEntry::compare( $a, $b ); + $ba = TermIndexEntry::compare( $b, $a ); if ( $equal ) { $this->assertEquals( 0, $ab, "Comparison of equal terms is expected to return 0" ); diff --git a/lib/tests/phpunit/store/BufferingTermLookupTest.php b/lib/tests/phpunit/store/BufferingTermLookupTest.php index f2abac0..ae7ab06 100644 --- a/lib/tests/phpunit/store/BufferingTermLookupTest.php +++ b/lib/tests/phpunit/store/BufferingTermLookupTest.php @@ -5,7 +5,7 @@ use Wikibase\DataModel\Entity\EntityId; use Wikibase\DataModel\Entity\ItemId; use Wikibase\Store\BufferingTermLookup; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\TermIndex; /** @@ -54,9 +54,9 @@ */ private function getRestrictedTermIndex( $getTermsOfEntityCalls, $getTermsOfEntitiesCalls ) { $terms = array( - 'en' => new Term( array( 'termType' => 'label', 'termLanguage' => 'en', 'termText' => 'Vienna', 'entityType' => 'item', 'entityId' => 123 ) ), - 'de' => new Term( array( 'termType' => 'label', 'termLanguage' => 'de', 'termText' => 'Wien', 'entityType' => 'item', 'entityId' => 123 ) ), - 'fr' => new Term( array( 'termType' => 'label', 'termLanguage' => 'fr', 'termText' => 'Vienne', 'entityType' => 'item', 'entityId' => 123 ) ), + 'en' => new TermIndexEntry( array( 'termType' => 'label', 'termLanguage' => 'en', 'termText' => 'Vienna', 'entityType' => 'item', 'entityId' => 123 ) ), + 'de' => new TermIndexEntry( array( 'termType' => 'label', 'termLanguage' => 'de', 'termText' => 'Wien', 'entityType' => 'item', 'entityId' => 123 ) ), + 'fr' => new TermIndexEntry( array( 'termType' => 'label', 'termLanguage' => 'fr', 'termText' => 'Vienne', 'entityType' => 'item', 'entityId' => 123 ) ), ); $termIndex = $this->getMock( 'Wikibase\TermIndex' ); diff --git a/lib/tests/phpunit/store/EntityTermLookupTest.php b/lib/tests/phpunit/store/EntityTermLookupTest.php index 6aaa835..2b47f64 100644 --- a/lib/tests/phpunit/store/EntityTermLookupTest.php +++ b/lib/tests/phpunit/store/EntityTermLookupTest.php @@ -128,28 +128,28 @@ protected function getTermIndex() { $terms = array( - new \Wikibase\Term( array( + new \Wikibase\TermIndexEntry( array( 'entityId' => 116, 'entityType' => 'item', 'termType' => 'label', 'termLanguage' => 'en', 'termText' => 'New York City' ) ), - new \Wikibase\Term( array( + new \Wikibase\TermIndexEntry( array( 'entityId' => 116, 'entityType' => 'item', 'termType' => 'label', 'termLanguage' => 'es', 'termText' => 'Nueva York' ) ), - new \Wikibase\Term( array( + new \Wikibase\TermIndexEntry( array( 'entityId' => 116, 'entityType' => 'item', 'termType' => 'description', 'termLanguage' => 'en', 'termText' => 'largest city in New York and the United States of America' ) ), - new \Wikibase\Term( array( + new \Wikibase\TermIndexEntry( array( 'entityId' => 116, 'entityType' => 'item', 'termType' => 'description', diff --git a/lib/tests/phpunit/store/LanguageFallbackLabelDescriptionLookupTest.php b/lib/tests/phpunit/store/LanguageFallbackLabelDescriptionLookupTest.php index 034579b..132acc2 100644 --- a/lib/tests/phpunit/store/LanguageFallbackLabelDescriptionLookupTest.php +++ b/lib/tests/phpunit/store/LanguageFallbackLabelDescriptionLookupTest.php @@ -3,7 +3,7 @@ namespace Wikibase\Test; use MediaWikiTestCase; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\Term\TermFallback; use Wikibase\Lib\Store\EntityTermLookup; @@ -128,42 +128,42 @@ private function getTermIndex() { $terms = array( - new Term( array( + new TermIndexEntry( array( 'entityId' => 116, 'entityType' => 'item', 'termType' => 'label', 'termLanguage' => 'en', 'termText' => 'New York City' ) ), - new Term( array( + new TermIndexEntry( array( 'entityId' => 116, 'entityType' => 'item', 'termType' => 'label', 'termLanguage' => 'es', 'termText' => 'New York City' ) ), - new Term( array( + new TermIndexEntry( array( 'entityId' => 116, 'entityType' => 'item', 'termType' => 'description', 'termLanguage' => 'en', 'termText' => 'Big Apple' ) ), - new Term( array( + new TermIndexEntry( array( 'entityId' => 117, 'entityType' => 'item', 'termType' => 'label', 'termLanguage' => 'en', 'termText' => 'Berlin' ) ), - new Term( array( + new TermIndexEntry( array( 'entityId' => 118, 'entityType' => 'item', 'termType' => 'label', 'termLanguage' => 'zh-cn', 'termText' => '测试' ) ), - new Term( array( + new TermIndexEntry( array( 'entityId' => 118, 'entityType' => 'item', 'termType' => 'description', diff --git a/lib/tests/phpunit/store/LanguageLabelDescriptionLookupTest.php b/lib/tests/phpunit/store/LanguageLabelDescriptionLookupTest.php index 604b1fd..960e99c 100644 --- a/lib/tests/phpunit/store/LanguageLabelDescriptionLookupTest.php +++ b/lib/tests/phpunit/store/LanguageLabelDescriptionLookupTest.php @@ -3,7 +3,7 @@ namespace Wikibase\Test; use MediaWikiTestCase; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\DataModel\Entity\ItemId; use Wikibase\Lib\Store\EntityTermLookup; use Wikibase\Lib\Store\LanguageLabelDescriptionLookup; @@ -81,35 +81,35 @@ private function getTermIndex() { $terms = array( - new Term( array( + new TermIndexEntry( array( 'entityId' => 116, 'entityType' => 'item', 'termType' => 'label', 'termLanguage' => 'en', 'termText' => 'New York City' ) ), - new Term( array( + new TermIndexEntry( array( 'entityId' => 116, 'entityType' => 'item', 'termType' => 'label', 'termLanguage' => 'es', 'termText' => 'New York City' ) ), - new Term( array( + new TermIndexEntry( array( 'entityId' => 116, 'entityType' => 'item', 'termType' => 'description', 'termLanguage' => 'en', 'termText' => 'Big Apple' ) ), - new Term( array( + new TermIndexEntry( array( 'entityId' => 117, 'entityType' => 'item', 'termType' => 'label', 'termLanguage' => 'en', 'termText' => 'Berlin' ) ), - new Term( array( + new TermIndexEntry( array( 'entityId' => 118, 'entityType' => 'item', 'termType' => 'label', diff --git a/lib/tests/phpunit/store/MockTermIndex.php b/lib/tests/phpunit/store/MockTermIndex.php index 310f587..f12ede4 100644 --- a/lib/tests/phpunit/store/MockTermIndex.php +++ b/lib/tests/phpunit/store/MockTermIndex.php @@ -7,7 +7,7 @@ use Wikibase\DataModel\Entity\EntityDocument; use Wikibase\DataModel\Entity\EntityId; use Wikibase\Lib\Store\LabelConflictFinder; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\TermIndex; /** @@ -28,12 +28,12 @@ class MockTermIndex implements TermIndex, LabelConflictFinder { /** - * @var Term[] + * @var TermIndexEntry[] */ protected $terms; /** - * @param Term[] $terms + * @param TermIndexEntry[] $terms */ public function __construct( array $terms ) { $this->terms = $terms; @@ -57,11 +57,11 @@ return array(); } - $templates = $this->makeTemplateTerms( $labels, Term::TYPE_LABEL ); + $templates = $this->makeTemplateTerms( $labels, TermIndexEntry::TYPE_LABEL ); $conflicts = $this->getMatchingTerms( $templates, - Term::TYPE_LABEL, + TermIndexEntry::TYPE_LABEL, $entityType ); @@ -98,11 +98,11 @@ return array(); } - $templates = $this->makeTemplateTerms( $descriptions, Term::TYPE_DESCRIPTION ); + $templates = $this->makeTemplateTerms( $descriptions, TermIndexEntry::TYPE_DESCRIPTION ); $descriptionConflicts = $this->getMatchingTerms( $templates, - Term::TYPE_DESCRIPTION, + TermIndexEntry::TYPE_DESCRIPTION, $entityType ); @@ -115,7 +115,7 @@ * @param string[] $textsByLanguage A list of texts, or a list of lists of texts (keyed by language on the top level) * @param string $type * - * @return Term[] + * @return TermIndexEntry[] */ private function makeTemplateTerms( $textsByLanguage, $type ) { $terms = array(); @@ -124,7 +124,7 @@ $texts = (array)$texts; foreach ( $texts as $text ) { - $terms[] = new Term( array( + $terms[] = new TermIndexEntry( array( 'termText' => $text, 'termLanguage' => $lang, 'termType' => $type, @@ -194,7 +194,7 @@ * @param string[]|null $termTypes * @param string[]|null $languageCodes * - * @return Term[] + * @return TermIndexEntry[] */ public function getTermsOfEntity( EntityId $entityId, @@ -232,7 +232,7 @@ * @param string[]|null $termTypes * @param string[]|null $languageCodes * - * @return Term[] + * @return TermIndexEntry[] */ public function getTermsOfEntities( array $entityIds, @@ -270,12 +270,12 @@ * language of the first Term in $terms. $The termType and $entityType parameters are used, * but the termType and entityType fields of the Terms in $terms are ignored. * - * @param Term[] $terms + * @param TermIndexEntry[] $terms * @param string|null $termType * @param string|null $entityType * @param array $options * - * @return Term[] + * @return TermIndexEntry[] */ public function getMatchingTerms( array $terms, @@ -305,7 +305,7 @@ } /** - * @param Term[] $terms + * @param TermIndexEntry[] $terms * @param string|null $entityType * @param array $options * @@ -343,9 +343,9 @@ /** * Rekeys a list of Terms based on EntityId and language. * - * @param Term[] $conflicts + * @param TermIndexEntry[] $conflicts * - * @return Term[] + * @return TermIndexEntry[] */ private function rekeyConflicts( array $conflicts ) { $rekeyed = array(); @@ -363,10 +363,10 @@ /** * Intersects two lists of Terms based on EntityId and language. * - * @param Term[] $base - * @param Term[] $filter + * @param TermIndexEntry[] $base + * @param TermIndexEntry[] $filter * - * @return Term[] + * @return TermIndexEntry[] */ private function intersectConflicts( array $base, array $filter ) { $base = $this->rekeyConflicts( $base ); @@ -376,13 +376,13 @@ } /** - * @param Term $term - * @param Term[] $templates + * @param TermIndexEntry $term + * @param TermIndexEntry[] $templates * @param array $options * * @return bool */ - private function termMatchesTemplates( Term $term, array $templates, array $options = array() ) { + private function termMatchesTemplates( TermIndexEntry $term, array $templates, array $options = array() ) { foreach ( $templates as $template ) { if ( $template->getType() !== null && $template->getType() != $term->getType() ) { continue; diff --git a/lib/tests/phpunit/store/TermIndexTest.php b/lib/tests/phpunit/store/TermIndexTest.php index ce31541..b74b629 100644 --- a/lib/tests/phpunit/store/TermIndexTest.php +++ b/lib/tests/phpunit/store/TermIndexTest.php @@ -7,7 +7,7 @@ use Wikibase\DataModel\Entity\Property; use Wikibase\DataModel\Entity\PropertyId; use Wikibase\Settings; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\TermIndex; /** @@ -46,9 +46,9 @@ $item1->setDescription( 'en', 'foo bar baz' ); $lookup->saveTermsOfEntity( $item1 ); - $foobar = new Term( array( 'termType' => Term::TYPE_LABEL, 'termText' => 'foobar' ) ); - $bazNl= new Term( array( 'termType' => Term::TYPE_LABEL, 'termText' => 'baz', 'termLanguage' => 'nl' ) ); - $froggerNl = new Term( array( 'termType' => Term::TYPE_LABEL, 'termText' => 'o_O', 'termLanguage' => 'nl' ) ); + $foobar = new TermIndexEntry( array( 'termType' => TermIndexEntry::TYPE_LABEL, 'termText' => 'foobar' ) ); + $bazNl= new TermIndexEntry( array( 'termType' => TermIndexEntry::TYPE_LABEL, 'termText' => 'baz', 'termLanguage' => 'nl' ) ); + $froggerNl = new TermIndexEntry( array( 'termType' => TermIndexEntry::TYPE_LABEL, 'termText' => 'o_O', 'termLanguage' => 'nl' ) ); $ids = $lookup->getMatchingIDs( array( $foobar ), Item::ENTITY_TYPE ); $this->assertInternalType( 'array', $ids ); @@ -83,14 +83,14 @@ $lookup->saveTermsOfEntity( $item1 ); $terms = array( - $id0 => new Term( array( + $id0 => new TermIndexEntry( array( 'termLanguage' => 'en', 'termText' => 'getmatchingterms-0', ) ), - $id1 => new Term( array( + $id1 => new TermIndexEntry( array( 'termText' => 'getmatchingterms-1', ) ), - new Term( array( + new TermIndexEntry( array( 'termText' => 'getmatchingterms-2', ) ), ); @@ -101,8 +101,8 @@ $this->assertCount( 2, $actual ); /** - * @var Term $term - * @var Term $expected + * @var TermIndexEntry $term + * @var TermIndexEntry $expected */ foreach ( $actual as $term ) { $id = $term->getEntityId()->getSerialization(); @@ -134,24 +134,24 @@ $id1 = $item1->getId()->getSerialization(); $lookup->saveTermsOfEntity( $item1 ); - /** @var Term[] $terms */ + /** @var TermIndexEntry[] $terms */ $terms = array( - $id0 => new Term( array( + $id0 => new TermIndexEntry( array( 'termLanguage' => 'en', 'termText' => 'preF', ) ), - $id1 => new Term( array( + $id1 => new TermIndexEntry( array( 'termText' => 'post', ) ), ); - /** @var Term[] $expectedTerms */ + /** @var TermIndexEntry[] $expectedTerms */ $expectedTerms = array( - $id0 => new Term( array( + $id0 => new TermIndexEntry( array( 'termLanguage' => 'en', 'termText' => 'prefix', ) ), - $id1 => new Term( array( + $id1 => new TermIndexEntry( array( 'termText' => 'postfix', ) ) ); @@ -170,8 +170,8 @@ $this->assertEquals( count( $expectedTerms ), count( $actual ) ); /** - * @var Term $term - * @var Term $expected + * @var TermIndexEntry $term + * @var TermIndexEntry $expected */ foreach ( $actual as $term ) { $id = $term->getEntityId()->getSerialization(); @@ -205,7 +205,7 @@ $this->assertNotTermExists( $lookup, 'testDeleteTermsForEntity' ); - $abc = new Term( array( 'termType' => Term::TYPE_LABEL, 'termText' => 'abc' ) ); + $abc = new TermIndexEntry( array( 'termType' => TermIndexEntry::TYPE_LABEL, 'termText' => 'abc' ) ); $ids = $lookup->getMatchingIDs( array( $abc ), Item::ENTITY_TYPE ); $this->assertNotContains( $id, $ids ); @@ -226,21 +226,21 @@ $this->assertTermExists( $lookup, 'testDeleteTermsForEntity', - Term::TYPE_DESCRIPTION, + TermIndexEntry::TYPE_DESCRIPTION, 'en', Item::ENTITY_TYPE ); $this->assertTermExists( $lookup, 'ghi', - Term::TYPE_LABEL, + TermIndexEntry::TYPE_LABEL, 'nl', Item::ENTITY_TYPE ); $this->assertTermExists( $lookup, 'o', - Term::TYPE_ALIAS, + TermIndexEntry::TYPE_ALIAS, 'fr', Item::ENTITY_TYPE ); @@ -251,21 +251,21 @@ $this->assertTermExists( $lookup, 'testDeleteTermsForEntity', - Term::TYPE_DESCRIPTION, + TermIndexEntry::TYPE_DESCRIPTION, 'en', Item::ENTITY_TYPE ); $this->assertTermExists( $lookup, 'ghi', - Term::TYPE_LABEL, + TermIndexEntry::TYPE_LABEL, 'nl', Item::ENTITY_TYPE ); $this->assertTermExists( $lookup, 'o', - Term::TYPE_ALIAS, + TermIndexEntry::TYPE_ALIAS, 'fr', Item::ENTITY_TYPE ); @@ -277,21 +277,21 @@ $this->assertTermExists( $lookup, 'testDeleteTermsForEntity', - Term::TYPE_DESCRIPTION, + TermIndexEntry::TYPE_DESCRIPTION, 'en', Item::ENTITY_TYPE ); $this->assertTermExists( $lookup, 'xyz', - Term::TYPE_LABEL, + TermIndexEntry::TYPE_LABEL, 'nl', Item::ENTITY_TYPE ); $this->assertTermExists( $lookup, 'o', - Term::TYPE_ALIAS, + TermIndexEntry::TYPE_ALIAS, 'fr', Item::ENTITY_TYPE ); @@ -329,8 +329,8 @@ $expectedTerms = $lookup->getEntityTerms( $item ); $actualTerms = $lookup->getTermsOfEntity( $item->getId() ); - $missingTerms = array_udiff( $expectedTerms, $actualTerms, 'Wikibase\Term::compare' ); - $extraTerms = array_udiff( $actualTerms, $expectedTerms, 'Wikibase\Term::compare' ); + $missingTerms = array_udiff( $expectedTerms, $actualTerms, 'Wikibase\TermIndexEntry::compare' ); + $extraTerms = array_udiff( $actualTerms, $expectedTerms, 'Wikibase\TermIndexEntry::compare' ); $this->assertEmpty( $missingTerms, 'Missing terms' ); $this->assertEmpty( $extraTerms, 'Extra terms' ); @@ -489,7 +489,7 @@ } private function getEntityIdStrings( array $terms ) { - return array_map( function( Term $term ) { + return array_map( function( TermIndexEntry $term ) { $id = $term->getEntityId(); return $id->getSerialization(); }, $terms ); @@ -532,15 +532,15 @@ $term_keys[] = $t->getType() . '/' . $t->getLanguage() . '/' . $t->getText(); } - $k = Term::TYPE_LABEL . '/en/abc'; + $k = TermIndexEntry::TYPE_LABEL . '/en/abc'; $this->assertContains( $k, $term_keys, "expected to find $k in terms for item" ); - $k = Term::TYPE_DESCRIPTION . '/en/testGetTermsOfEntity'; + $k = TermIndexEntry::TYPE_DESCRIPTION . '/en/testGetTermsOfEntity'; $this->assertContains( $k, $term_keys, "expected to find $k in terms for item" ); - $k = Term::TYPE_ALIAS . '/fr/_'; + $k = TermIndexEntry::TYPE_ALIAS . '/fr/_'; $this->assertContains( $k, $term_keys, "expected to find $k in terms for item" ); } @@ -569,7 +569,7 @@ $itemIds = array( $item1->getId(), $item2->getId() ); - $labelTerms = $lookup->getTermsOfEntities( $itemIds, array( Term::TYPE_LABEL ) ); + $labelTerms = $lookup->getTermsOfEntities( $itemIds, array( TermIndexEntry::TYPE_LABEL ) ); $this->assertEquals( 6, count( $labelTerms ), "expected 3 labels" ); $englishTerms = $lookup->getTermsOfEntities( $itemIds, null, array( 'en' ) ); @@ -578,10 +578,10 @@ $englishTerms = $lookup->getTermsOfEntities( array( $item1->getId() ), null, array( 'en' ) ); $this->assertEquals( 2, count( $englishTerms ), "expected 2 English terms" ); - $germanLabelTerms = $lookup->getTermsOfEntities( $itemIds, array( Term::TYPE_LABEL ), array( 'de' ) ); + $germanLabelTerms = $lookup->getTermsOfEntities( $itemIds, array( TermIndexEntry::TYPE_LABEL ), array( 'de' ) ); $this->assertEquals( 2, count( $germanLabelTerms ), "expected 1 German label" ); - $noTerms = $lookup->getTermsOfEntities( $itemIds, array( Term::TYPE_LABEL ), array() ); + $noTerms = $lookup->getTermsOfEntities( $itemIds, array( TermIndexEntry::TYPE_LABEL ), array() ); $this->assertEmpty( $noTerms, "expected no labels" ); $noTerms = $lookup->getTermsOfEntities( $itemIds, array(), array( 'de' ) ); @@ -596,19 +596,19 @@ $term_keys[] = $t->getType() . '/' . $t->getLanguage() . '/' . $t->getText(); } - $k = Term::TYPE_LABEL . '/en/abc'; + $k = TermIndexEntry::TYPE_LABEL . '/en/abc'; $this->assertContains( $k, $term_keys, "expected to find $k in terms for item" ); - $k = Term::TYPE_LABEL . '/en/xyz'; + $k = TermIndexEntry::TYPE_LABEL . '/en/xyz'; $this->assertContains( $k, $term_keys, "expected to find $k in terms for item" ); - $k = Term::TYPE_DESCRIPTION . '/en/another description'; + $k = TermIndexEntry::TYPE_DESCRIPTION . '/en/another description'; $this->assertContains( $k, $term_keys, "expected to find $k in terms for item" ); - $k = Term::TYPE_ALIAS . '/fr/x'; + $k = TermIndexEntry::TYPE_ALIAS . '/fr/x'; $this->assertContains( $k, $term_keys, "expected to find $k in terms for item" ); } @@ -629,7 +629,7 @@ $termFields['termLanguage'] = $language; } - $matches = $termIndex->getMatchingTerms( array( new Term( $termFields ) ), $termType, $entityType ); + $matches = $termIndex->getMatchingTerms( array( new TermIndexEntry( $termFields ) ), $termType, $entityType ); return !empty( $matches ); } diff --git a/lib/tests/phpunit/store/TermPropertyLabelResolverTest.php b/lib/tests/phpunit/store/TermPropertyLabelResolverTest.php index 74e5304..91207bb 100644 --- a/lib/tests/phpunit/store/TermPropertyLabelResolverTest.php +++ b/lib/tests/phpunit/store/TermPropertyLabelResolverTest.php @@ -7,7 +7,7 @@ use Wikibase\DataModel\Entity\Property; use Wikibase\DataModel\Entity\PropertyId; use Wikibase\PropertyLabelResolver; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\TermPropertyLabelResolver; /** @@ -24,7 +24,7 @@ /** * @param string $lang - * @param Term[] $terms + * @param TermIndexEntry[] $terms * * @return PropertyLabelResolver */ @@ -58,28 +58,28 @@ public function provideGetPropertyIdsForLabels() { $terms = array( // de - new Term( array( + new TermIndexEntry( array( 'termType' => 'label', 'termLanguage' => 'de', 'entityId' => 1, 'entityType' => Property::ENTITY_TYPE, 'termText' => 'Eins', ) ), - new Term( array( + new TermIndexEntry( array( 'termType' => 'label', 'termLanguage' => 'de', 'entityId' => 2, 'entityType' => Property::ENTITY_TYPE, 'termText' => 'Zwei', ) ), - new Term( array( + new TermIndexEntry( array( 'termType' => 'label', 'termLanguage' => 'de', 'entityId' => 3, 'entityType' => Property::ENTITY_TYPE, 'termText' => 'Drei', ) ), - new Term( array( + new TermIndexEntry( array( 'termType' => 'label', 'termLanguage' => 'de', 'entityId' => 4, @@ -88,28 +88,28 @@ ) ), // en - new Term( array( + new TermIndexEntry( array( 'termType' => 'label', 'termLanguage' => 'en', 'entityId' => 1, 'entityType' => Property::ENTITY_TYPE, 'termText' => 'One', ) ), - new Term( array( + new TermIndexEntry( array( 'termType' => 'label', 'termLanguage' => 'en', 'entityId' => 2, 'entityType' => Item::ENTITY_TYPE, // not a property 'termText' => 'Two', ) ), - new Term( array( + new TermIndexEntry( array( 'termType' => 'alias', // not a label 'termLanguage' => 'en', 'entityId' => 3, 'entityType' => Property::ENTITY_TYPE, 'termText' => 'Three', ) ), - new Term( array( + new TermIndexEntry( array( 'termType' => 'description', // not a label 'termLanguage' => 'en', 'entityId' => 4, diff --git a/repo/includes/Hooks/LabelPrefetchHookHandlers.php b/repo/includes/Hooks/LabelPrefetchHookHandlers.php index 154d255..e6b483e 100644 --- a/repo/includes/Hooks/LabelPrefetchHookHandlers.php +++ b/repo/includes/Hooks/LabelPrefetchHookHandlers.php @@ -11,7 +11,7 @@ use Wikibase\Repo\WikibaseRepo; use Wikibase\Store\EntityIdLookup; use Wikibase\Store\TermBuffer; -use Wikibase\Term; +use Wikibase\TermIndexEntry; /** * Hook handlers for triggering prefetching of labels. @@ -64,7 +64,7 @@ $idLookup = WikibaseRepo::getDefaultInstance()->getEntityIdLookup(); $titleFactory = new TitleFactory(); - $termTypes = array( Term::TYPE_LABEL, Term::TYPE_DESCRIPTION ); + $termTypes = array( TermIndexEntry::TYPE_LABEL, TermIndexEntry::TYPE_DESCRIPTION ); // NOTE: keep in sync with fallback chain construction in LinkBeginHookHandler::newFromGlobalState $context = RequestContext::getMain(); diff --git a/repo/includes/LabelDescriptionDuplicateDetector.php b/repo/includes/LabelDescriptionDuplicateDetector.php index 12eecb7..128abe3 100644 --- a/repo/includes/LabelDescriptionDuplicateDetector.php +++ b/repo/includes/LabelDescriptionDuplicateDetector.php @@ -100,7 +100,7 @@ /** * @param string $message Plain text message (English) * @param string $errorCode Error code (for later localization) - * @param Term[] $terms The conflicting terms. + * @param TermIndexEntry[] $terms The conflicting terms. * * @return UniquenessViolation[] */ @@ -124,15 +124,15 @@ } /** - * @param Term[] $terms + * @param TermIndexEntry[] $terms * @param EntityId $entityId * - * @return Term[] + * @return TermIndexEntry[] */ private function filterSelfConflicts( array $terms, EntityId $entityId ) { return array_filter( $terms, - function ( Term $term ) use ( $entityId ) { + function ( TermIndexEntry $term ) use ( $entityId ) { return !$entityId->equals( $term->getEntityId() ); } ); diff --git a/repo/includes/api/SearchEntities.php b/repo/includes/api/SearchEntities.php index 0ad634b..3571902 100644 --- a/repo/includes/api/SearchEntities.php +++ b/repo/includes/api/SearchEntities.php @@ -12,7 +12,7 @@ use Wikibase\LanguageFallbackChainFactory; use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Repo\WikibaseRepo; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\TermIndex; /** @@ -122,20 +122,20 @@ * @param int $limit * @param bool $prefixSearch * - * @return Term[] + * @return TermIndexEntry[] */ private function searchEntities( $term, $entityType, array $languages, $limit, $prefixSearch ) { $termTemplates = array(); foreach ( $languages as $language ) { - $termTemplates[] = new Term( array( - 'termType' => Term::TYPE_LABEL, + $termTemplates[] = new TermIndexEntry( array( + 'termType' => TermIndexEntry::TYPE_LABEL, 'termLanguage' => $language, 'termText' => $term ) ); - $termTemplates[] = new Term( array( - 'termType' => Term::TYPE_ALIAS, + $termTemplates[] = new TermIndexEntry( array( + 'termType' => TermIndexEntry::TYPE_ALIAS, 'termLanguage' => $language, 'termText' => $term ) ); @@ -299,7 +299,7 @@ ); } - $termTypes = array( Term::TYPE_LABEL, Term::TYPE_DESCRIPTION, Term::TYPE_ALIAS ); + $termTypes = array( TermIndexEntry::TYPE_LABEL, TermIndexEntry::TYPE_DESCRIPTION, TermIndexEntry::TYPE_ALIAS ); // Find all the remaining terms for the given entities $terms = $this->termIndex->getTermsOfEntities( @@ -332,15 +332,15 @@ $entry = $entries[$key]; switch ( $type ) { - case Term::TYPE_LABEL: + case TermIndexEntry::TYPE_LABEL: $entry['label'] = $term->getText(); $bestLangPerSlot[$key][$type] = $currentLang; break; - case Term::TYPE_DESCRIPTION: + case TermIndexEntry::TYPE_DESCRIPTION: $entry['description'] = $term->getText(); $bestLangPerSlot[$key][$type] = $currentLang; break; - case Term::TYPE_ALIAS: + case TermIndexEntry::TYPE_ALIAS: // Only include matching aliases if ( preg_match( $termPattern, $term->getText() ) ) { if ( !isset( $entry['aliases'] ) ) { diff --git a/repo/includes/specials/SpecialEntitiesWithoutPageFactory.php b/repo/includes/specials/SpecialEntitiesWithoutPageFactory.php index c479a41..0af4d4b 100644 --- a/repo/includes/specials/SpecialEntitiesWithoutPageFactory.php +++ b/repo/includes/specials/SpecialEntitiesWithoutPageFactory.php @@ -6,7 +6,7 @@ use Wikibase\Lib\ContentLanguages; use Wikibase\Repo\Store\EntityPerPage; use Wikibase\Repo\WikibaseRepo; -use Wikibase\Term; +use Wikibase\TermIndexEntry; /** * Factory to create special pages. @@ -69,7 +69,7 @@ public function createSpecialEntitiesWithoutLabel() { return new SpecialEntitiesWithoutPage( 'EntitiesWithoutLabel', - Term::TYPE_LABEL, + TermIndexEntry::TYPE_LABEL, 'wikibase-entitieswithoutlabel-legend', $this->entityPerPage, $this->entityFactory, @@ -85,7 +85,7 @@ public function createSpecialEntitiesWithoutDescription() { return new SpecialEntitiesWithoutPage( 'EntitiesWithoutDescription', - Term::TYPE_DESCRIPTION, + TermIndexEntry::TYPE_DESCRIPTION, 'wikibase-entitieswithoutdescription-legend', $this->entityPerPage, $this->entityFactory, diff --git a/repo/includes/specials/SpecialItemDisambiguation.php b/repo/includes/specials/SpecialItemDisambiguation.php index 9efa689..272eab3 100644 --- a/repo/includes/specials/SpecialItemDisambiguation.php +++ b/repo/includes/specials/SpecialItemDisambiguation.php @@ -13,7 +13,7 @@ use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Lib\Store\LanguageLabelDescriptionLookup; use Wikibase\Repo\WikibaseRepo; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\TermIndex; /** @@ -280,8 +280,8 @@ private function findLabelUsage( $languageCode, $label ) { //@todo: optionally $protoTerms = array( - new Term( array( - 'termType' => Term::TYPE_LABEL, + new TermIndexEntry( array( + 'termType' => TermIndexEntry::TYPE_LABEL, 'termLanguage' => $languageCode, 'termText' => $label ) ), diff --git a/repo/tests/phpunit/includes/LabelDescriptionDuplicateDetectorTest.php b/repo/tests/phpunit/includes/LabelDescriptionDuplicateDetectorTest.php index 408ba29..193151b 100644 --- a/repo/tests/phpunit/includes/LabelDescriptionDuplicateDetectorTest.php +++ b/repo/tests/phpunit/includes/LabelDescriptionDuplicateDetectorTest.php @@ -8,7 +8,7 @@ use Wikibase\DataModel\Entity\ItemId; use Wikibase\DataModel\Entity\Property; use Wikibase\LabelDescriptionDuplicateDetector; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\Validators\UniquenessViolation; /** @@ -25,24 +25,24 @@ private function getWorld() { $world = array(); - $world[] = new Term( array( - 'termType' => Term::TYPE_LABEL, + $world[] = new TermIndexEntry( array( + 'termType' => TermIndexEntry::TYPE_LABEL, 'termLanguage' => 'en', 'entityId' => 42, 'entityType' => Item::ENTITY_TYPE, 'termText' => 'item label', ) ); - $world[] = new Term( array( - 'termType' => Term::TYPE_DESCRIPTION, + $world[] = new TermIndexEntry( array( + 'termType' => TermIndexEntry::TYPE_DESCRIPTION, 'termLanguage' => 'en', 'entityId' => 42, 'entityType' => Item::ENTITY_TYPE, 'termText' => 'item description', ) ); - $world[] = new Term( array( - 'termType' => Term::TYPE_LABEL, + $world[] = new TermIndexEntry( array( + 'termType' => TermIndexEntry::TYPE_LABEL, 'termLanguage' => 'en', 'entityId' => 17, 'entityType' => Property::ENTITY_TYPE, diff --git a/repo/tests/phpunit/includes/api/SearchEntitiesTest.php b/repo/tests/phpunit/includes/api/SearchEntitiesTest.php index e19abcf..593950e 100644 --- a/repo/tests/phpunit/includes/api/SearchEntitiesTest.php +++ b/repo/tests/phpunit/includes/api/SearchEntitiesTest.php @@ -11,7 +11,7 @@ use Wikibase\Lib\ContentLanguages; use Wikibase\Lib\Store\EntityTitleLookup; use Wikibase\Repo\WikibaseRepo; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\TermIndex; use Wikibase\Api\SearchEntities; use Wikibase\DataModel\Entity\BasicEntityIdParser; @@ -176,16 +176,16 @@ $id = $idParser->parse( $entity['id'] ); foreach ( $entity['labels'] as $row ) { - $termObjects[] = $this->newTermFromDataRow( $id, Term::TYPE_LABEL, $row ); + $termObjects[] = $this->newTermFromDataRow( $id, TermIndexEntry::TYPE_LABEL, $row ); } foreach ( $entity['descriptions'] as $row ) { - $termObjects[] = $this->newTermFromDataRow( $id, Term::TYPE_DESCRIPTION, $row ); + $termObjects[] = $this->newTermFromDataRow( $id, TermIndexEntry::TYPE_DESCRIPTION, $row ); } foreach ( $entity['aliases'] as $rows ) { foreach ( $rows as $row ) { - $termObjects[] = $this->newTermFromDataRow( $id, Term::TYPE_ALIAS, $row ); + $termObjects[] = $this->newTermFromDataRow( $id, TermIndexEntry::TYPE_ALIAS, $row ); } } } @@ -196,7 +196,7 @@ } private function newTermFromDataRow( EntityId $entityId, $type, $row ) { - return new Term( array( + return new TermIndexEntry( array( 'termType' => $type, 'termLanguage' => $row['language'], 'termText' => $row['value'], diff --git a/repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutPageTest.php b/repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutPageTest.php index e9bea72..5ab432c 100644 --- a/repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutPageTest.php +++ b/repo/tests/phpunit/includes/specials/SpecialEntitiesWithoutPageTest.php @@ -4,7 +4,7 @@ use Wikibase\Repo\Specials\SpecialEntitiesWithoutPage; use Wikibase\Repo\WikibaseRepo; -use Wikibase\Term; +use Wikibase\TermIndexEntry; /** * @covers Wikibase\Repo\Specials\SpecialEntitiesWithoutPage @@ -38,7 +38,7 @@ return new SpecialEntitiesWithoutPage( 'EntitiesWithoutLabel', - Term::TYPE_LABEL, + TermIndexEntry::TYPE_LABEL, 'wikibase-entitieswithoutlabel-legend', $wikibaseRepo->getStore()->newEntityPerPage(), $wikibaseRepo->getEntityFactory(), diff --git a/repo/tests/phpunit/includes/store/sql/TermSearchKeyBuilderTest.php b/repo/tests/phpunit/includes/store/sql/TermSearchKeyBuilderTest.php index 5aaeadb..0fc80cd 100644 --- a/repo/tests/phpunit/includes/store/sql/TermSearchKeyBuilderTest.php +++ b/repo/tests/phpunit/includes/store/sql/TermSearchKeyBuilderTest.php @@ -5,7 +5,7 @@ use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\ItemId; use Wikibase\Repo\WikibaseRepo; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\TermSearchKeyBuilder; use Wikibase\TermSqlIndex; @@ -65,7 +65,7 @@ $builder->rebuildSearchKey(); // remove search key - $term = new Term(); + $term = new TermIndexEntry(); $term->setLanguage( $languageCode ); $term->setText( $searchText ); @@ -73,7 +73,7 @@ 'caseSensitive' => false, ); - $obtainedTerms = $termCache->getMatchingTerms( array( $term ), Term::TYPE_LABEL, Item::ENTITY_TYPE, $options ); + $obtainedTerms = $termCache->getMatchingTerms( array( $term ), TermIndexEntry::TYPE_LABEL, Item::ENTITY_TYPE, $options ); $this->assertEquals( $matches ? 1 : 0, count( $obtainedTerms ) ); diff --git a/repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php b/repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php index f0f1aad..ad95f07 100644 --- a/repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php +++ b/repo/tests/phpunit/includes/store/sql/TermSqlIndexTest.php @@ -9,7 +9,7 @@ use Wikibase\DataModel\Term\Fingerprint; use Wikibase\DataModel\Term\TermList; use Wikibase\StringNormalizer; -use Wikibase\Term; +use Wikibase\TermIndexEntry; use Wikibase\TermSqlIndex; /** @@ -65,7 +65,7 @@ $termIndex->saveTermsOfEntity( $item ); - $term = new Term(); + $term = new TermIndexEntry(); $term->setLanguage( $languageCode ); $term->setText( $searchText ); @@ -73,7 +73,7 @@ 'caseSensitive' => false, ); - $obtainedTerms = $termIndex->getMatchingTerms( array( $term ), Term::TYPE_LABEL, Item::ENTITY_TYPE, $options ); + $obtainedTerms = $termIndex->getMatchingTerms( array( $term ), TermIndexEntry::TYPE_LABEL, Item::ENTITY_TYPE, $options ); $this->assertEquals( $matches ? 1 : 0, count( $obtainedTerms ) ); @@ -116,8 +116,8 @@ new AliasGroupList() ); - $labelFooEn = new Term( array( 'termLanguage' => 'en', 'termType' => Term::TYPE_LABEL, 'termText' => 'Foo' ) ); - $descriptionBarEn = new Term( array( 'termLanguage' => 'en', 'termType' => Term::TYPE_DESCRIPTION, 'termText' => 'Bar' ) ); + $labelFooEn = new TermIndexEntry( array( 'termLanguage' => 'en', 'termType' => TermIndexEntry::TYPE_LABEL, 'termText' => 'Foo' ) ); + $descriptionBarEn = new TermIndexEntry( array( 'termLanguage' => 'en', 'termType' => TermIndexEntry::TYPE_DESCRIPTION, 'termText' => 'Bar' ) ); return array( 'no options' => array( @@ -137,10 +137,11 @@ /** * @dataProvider getMatchingTermsOptionsProvider - * @param Fingerprint $fingerprint - * @param Term[] $queryTerms + * +*@param Fingerprint $fingerprint + * @param TermIndexEntry[] $queryTerms * @param array $options - * @param Term[] $expected + * @param TermIndexEntry[] $expected */ public function testGetMatchingTerms_options( Fingerprint $fingerprint, array $queryTerms, array $options, array $expected ) { $termIndex = $this->getTermIndex(); @@ -200,7 +201,7 @@ $termIndex->saveTermsOfEntity( $item3 ); - $term = new Term(); + $term = new TermIndexEntry(); $term->setLanguage( $languageCode ); $term->setText( $searchText ); @@ -230,7 +231,7 @@ $termIndex->saveTermsOfEntity( $item1 ); - $term = new Term(); + $term = new TermIndexEntry(); $term->setLanguage( $languageCode ); $term->setText( $termText ); @@ -251,7 +252,7 @@ $termIndex->saveTermsOfEntity( $item1 ); - $term = new Term(); + $term = new TermIndexEntry(); $term->setLanguage( $languageCode ); $term->setText( substr( $termText, 0, -1 ) ); //last character stripped @@ -277,7 +278,7 @@ $termIndex->saveTermsOfEntity( $item1 ); - $term = new Term(); + $term = new TermIndexEntry(); $term->setLanguage( $languageCode ); $term->setText( '%' . $termText ); //must be used as a character and no LIKE placeholder @@ -363,21 +364,21 @@ $item->setFingerprint( $fingerprint ); $expectedTerms = array( - new Term( array( + new TermIndexEntry( array( 'entityId' => 999, 'entityType' => 'item', 'termText' => 'es un gato!', 'termLanguage' => 'es', 'termType' => 'description' ) ), - new Term( array( + new TermIndexEntry( array( 'entityId' => 999, 'entityType' => 'item', 'termText' => 'kittens!!!:)', 'termLanguage' => 'en', 'termType' => 'label' ) ), - new Term( array( + new TermIndexEntry( array( 'entityId' => 999, 'entityType' => 'item', 'termText' => 'kitten-alias', -- To view, visit https://gerrit.wikimedia.org/r/218661 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0a1df9767b60fe44d78fb6739c929c1e0ed94cde Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits