Thiemo Mättig (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/232751
Change subject: Fix all issues found while reviewing language code
canonicalization
......................................................................
Fix all issues found while reviewing language code canonicalization
This fixes all issues I found while reviewing patch set 10 of I92533ca.
Bug: T105430
Change-Id: Ia5cdb34cb081d7ccfb277abaf92bffd5b566c491
---
M repo/includes/Dumpers/RdfDumpGenerator.php
M repo/includes/LinkedData/EntityDataSerializationService.php
M repo/includes/rdf/RdfVocabulary.php
M repo/includes/rdf/SimpleValueRdfBuilder.php
M repo/includes/rdf/SiteLinksRdfBuilder.php
M repo/includes/specials/SpecialEntityData.php
M repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
M repo/tests/phpunit/includes/LinkedData/EntityDataRequestHandlerTest.php
M repo/tests/phpunit/includes/LinkedData/EntityDataSerializationServiceTest.php
M repo/tests/phpunit/includes/rdf/RdfBuilderTestData.php
M repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
11 files changed, 47 insertions(+), 54 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/51/232751/1
diff --git a/repo/includes/Dumpers/RdfDumpGenerator.php
b/repo/includes/Dumpers/RdfDumpGenerator.php
index ae241de..ab23dc2 100644
--- a/repo/includes/Dumpers/RdfDumpGenerator.php
+++ b/repo/includes/Dumpers/RdfDumpGenerator.php
@@ -159,21 +159,21 @@
* @param EntityRevisionLookup $entityRevisionLookup
* @param PropertyDataTypeLookup $propertyLookup
* @param EntityPrefetcher $entityPrefetcher
- * @param array $languageCodes
+ * @param string[] $canonicalLanguageCodes Mapping of non-standard to
canonical language codes.
*
* @return RdfDumpGenerator
* @throws MWException
*/
public static function createDumpGenerator(
- $format,
- $output,
- $baseUri,
- $dataUri,
- SiteList $sites,
- EntityRevisionLookup $entityRevisionLookup,
- PropertyDataTypeLookup $propertyLookup,
- EntityPrefetcher $entityPrefetcher,
- $languageCodes
+ $format,
+ $output,
+ $baseUri,
+ $dataUri,
+ SiteList $sites,
+ EntityRevisionLookup $entityRevisionLookup,
+ PropertyDataTypeLookup $propertyLookup,
+ EntityPrefetcher $entityPrefetcher,
+ array $canonicalLanguageCodes = array()
) {
$rdfWriter = self::getRdfWriter( $format );
if ( !$rdfWriter ) {
@@ -186,7 +186,7 @@
$rdfBuilder = new RdfBuilder(
$sites,
- new RdfVocabulary( $baseUri, $dataUri, $languageCodes ),
+ new RdfVocabulary( $baseUri, $dataUri,
$canonicalLanguageCodes ),
$propertyLookup,
$flavor,
$rdfWriter,
diff --git a/repo/includes/LinkedData/EntityDataSerializationService.php
b/repo/includes/LinkedData/EntityDataSerializationService.php
index 61b66e0..5e6eee7 100644
--- a/repo/includes/LinkedData/EntityDataSerializationService.php
+++ b/repo/includes/LinkedData/EntityDataSerializationService.php
@@ -111,9 +111,9 @@
private $siteStore;
/**
- * @var array
+ * @var string[] Mapping of non-standard to canonical language codes.
*/
- private $languageCodes;
+ private $canonicalLanguageCodes;
/**
* @param string $rdfBaseURI
@@ -121,10 +121,11 @@
* @param EntityLookup $entityLookup
* @param EntityTitleLookup $entityTitleLookup
* @param PropertyDataTypeLookup $propertyLookup
- * @param EntityDataFormatProvider $entityDataFormatProvider
* @param SiteList $sites
+ * @param EntityDataFormatProvider $entityDataFormatProvider
* @param SerializerFactory $serializerFactory
* @param SiteStore $siteStore
+ * @param string[] $canonicalLanguageCodes
*
* @since 0.4
*/
@@ -138,7 +139,7 @@
EntityDataFormatProvider $entityDataFormatProvider,
SerializerFactory $serializerFactory,
SiteStore $siteStore,
- $languageCodes
+ array $canonicalLanguageCodes = array()
) {
$this->rdfBaseURI = $rdfBaseURI;
$this->rdfDataURI = $rdfDataURI;
@@ -149,7 +150,7 @@
$this->sites = $sites;
$this->entityDataFormatProvider = $entityDataFormatProvider;
$this->siteStore = $siteStore;
- $this->languageCodes = $languageCodes;
+ $this->canonicalLanguageCodes = $canonicalLanguageCodes;
$this->rdfWriterFactory = new RdfWriterFactory();
}
@@ -422,7 +423,7 @@
$rdfBuilder = new RdfBuilder(
$this->sites,
- new RdfVocabulary( $this->rdfBaseURI,
$this->rdfDataURI, $this->languageCodes ),
+ new RdfVocabulary( $this->rdfBaseURI,
$this->rdfDataURI, $this->canonicalLanguageCodes ),
$this->propertyLookup,
$this->getFlavor( $flavorName ),
$rdfWriter,
diff --git a/repo/includes/rdf/RdfVocabulary.php
b/repo/includes/rdf/RdfVocabulary.php
index 082e57e..2ebf7d1 100644
--- a/repo/includes/rdf/RdfVocabulary.php
+++ b/repo/includes/rdf/RdfVocabulary.php
@@ -6,7 +6,6 @@
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Entity\Property;
use Wikibase\DataModel\Statement\Statement;
-use Wikibase\Repo\WikibaseRepo;
/**
* RDF vocabulary for use in mapping for wikibase data model.
@@ -84,9 +83,7 @@
);
/**
- * Map of qnames to namespace URIs
- *
- * @var array
+ * @var string[] Mapping of namespace names to URIs.
*/
private $namespaces = array();
@@ -94,30 +91,31 @@
* @var string
*/
private $baseUri;
+
/**
* @var string
*/
private $dataUri;
+
/**
- * List of non-standard language codes with standard equivalents
- * @var array
+ * @var string[] Mapping of non-standard to canonical language codes.
*/
private $canonicalLanguageCodes;
/**
- * Cached language resolutions
- * @var array
+ * @var string[]
*/
- private static $canonicalLanguageCache = array();
+ private static $canonicalLanguageCodeCache = array();
/**
* @param string $baseUri Base URI for entity concept URIs.
* @param string $dataUri Base URI for entity description URIs.
- * @param array $canonicalLanguageCodes Mapping from internal language
codes to canonical language codes
+ * @param string[] $canonicalLanguageCodes Mapping of non-standard to
canonical language codes.
*/
- public function __construct( $baseUri, $dataUri,
$canonicalLanguageCodes ) {
+ public function __construct( $baseUri, $dataUri, array
$canonicalLanguageCodes = array() ) {
$this->baseUri = $baseUri;
$this->dataUri = $dataUri;
+ $this->canonicalLanguageCodes = $canonicalLanguageCodes;
if ( substr( $this->baseUri, -7 ) === 'entity/' ) {
$topUri = substr( $this->baseUri, 0, -7 );
@@ -156,14 +154,12 @@
self::NS_GEO => self::GEO_URI,
self::NS_PROV => self::PROV_URI,
);
-
- $this->canonicalLanguageCodes = $canonicalLanguageCodes;
}
/**
* Returns a map of namespace names (prefixes) to URIs
*
- * @return array
+ * @return string[]
*/
public function getNamespaces() {
return $this->namespaces;
@@ -217,7 +213,7 @@
/**
* Get Wikibase value type name for ontology
*
- * @param DataValue $prop
+ * @param DataValue $val
*
* @return string
*/
@@ -237,24 +233,24 @@
}
/**
- * Return canonical language code from internal Wikibase one
- * @param string $langName
- * @return string
+ * @param string $languageCode Any non-standard or canonical language
code
+ *
+ * @return string Canonical language code
*/
- public function getCanonicalLanguage( $langName ) {
+ public function getCanonicalLanguageCode( $languageCode ) {
// First we check the case since most languages will be cached
very quickly
- if ( isset(self::$canonicalLanguageCache[$langName]) ) {
- return self::$canonicalLanguageCache[$langName];
+ if ( isset( self::$canonicalLanguageCodeCache[$languageCode] )
) {
+ return self::$canonicalLanguageCodeCache[$languageCode];
}
// Wikibase list goes first in case we want to override
// Like "simple" goes to en-x-simple not en
- if ( !empty($this->canonicalLanguageCodes[$langName]) ) {
- return $this->canonicalLanguageCodes[$langName];
+ if ( isset( $this->canonicalLanguageCodes[$languageCode] ) ) {
+ return $this->canonicalLanguageCodes[$languageCode];
}
- self::$canonicalLanguageCache[$langName] = wfBCP47( $langName );
- return self::$canonicalLanguageCache[$langName];
+ self::$canonicalLanguageCodeCache[$languageCode] = wfBCP47(
$languageCode );
+ return self::$canonicalLanguageCodeCache[$languageCode];
}
}
diff --git a/repo/includes/rdf/SimpleValueRdfBuilder.php
b/repo/includes/rdf/SimpleValueRdfBuilder.php
index 326ddb4..5de9ab7 100644
--- a/repo/includes/rdf/SimpleValueRdfBuilder.php
+++ b/repo/includes/rdf/SimpleValueRdfBuilder.php
@@ -263,7 +263,7 @@
MonolingualTextValue $value
) {
$writer->say( $propertyValueNamespace, $propertyValueLName
)->text( $value->getText(),
- $this->vocabulary->getCanonicalLanguage(
$value->getLanguageCode() ) );
+ $this->vocabulary->getCanonicalLanguageCode(
$value->getLanguageCode() ) );
}
/**
diff --git a/repo/includes/rdf/SiteLinksRdfBuilder.php
b/repo/includes/rdf/SiteLinksRdfBuilder.php
index 1ffb339..ab5ee80 100644
--- a/repo/includes/rdf/SiteLinksRdfBuilder.php
+++ b/repo/includes/rdf/SiteLinksRdfBuilder.php
@@ -95,7 +95,7 @@
->a( RdfVocabulary::NS_SCHEMA_ORG, 'Article' )
->say( RdfVocabulary::NS_SCHEMA_ORG, 'about'
)->is( RdfVocabulary::NS_ENTITY, $entityLName )
->say( RdfVocabulary::NS_SCHEMA_ORG,
'inLanguage' )->text(
-
$this->vocabulary->getCanonicalLanguage( $site->getLanguageCode() ) );
+
$this->vocabulary->getCanonicalLanguageCode( $site->getLanguageCode() ) );
foreach ( $siteLink->getBadges() as $badge ) {
$this->writer
diff --git a/repo/includes/specials/SpecialEntityData.php
b/repo/includes/specials/SpecialEntityData.php
index f460074..0e88f5e 100644
--- a/repo/includes/specials/SpecialEntityData.php
+++ b/repo/includes/specials/SpecialEntityData.php
@@ -89,7 +89,7 @@
$languageCodes = array_merge(
$GLOBALS['wgDummyLanguageCodes'],
- $this->wikibaseRepo->getSettings()->getSetting(
'canonicalLanguageCodes' )
+ $wikibaseRepo->getSettings()->getSetting(
'canonicalLanguageCodes' )
);
$serializationService = new EntityDataSerializationService(
diff --git a/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
b/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
index 23a5699..31fb8f1 100644
--- a/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
+++ b/repo/tests/phpunit/includes/Dumpers/RdfDumpGeneratorTest.php
@@ -109,8 +109,7 @@
$this->getSiteList(),
$entityRevisionLookup,
$propertyLookup,
- new NullEntityPrefetcher(),
- array('test' => 'en-x-test')
+ new NullEntityPrefetcher()
);
}
diff --git
a/repo/tests/phpunit/includes/LinkedData/EntityDataRequestHandlerTest.php
b/repo/tests/phpunit/includes/LinkedData/EntityDataRequestHandlerTest.php
index a13e0d5..7ae9819 100644
--- a/repo/tests/phpunit/includes/LinkedData/EntityDataRequestHandlerTest.php
+++ b/repo/tests/phpunit/includes/LinkedData/EntityDataRequestHandlerTest.php
@@ -102,8 +102,7 @@
new SiteList(),
$entityDataFormatProvider,
$serializerFactory,
- new MockSiteStore(),
- array('test' => 'en-x-test')
+ new MockSiteStore()
);
$entityDataFormatProvider->setFormatWhiteList(
diff --git
a/repo/tests/phpunit/includes/LinkedData/EntityDataSerializationServiceTest.php
b/repo/tests/phpunit/includes/LinkedData/EntityDataSerializationServiceTest.php
index a4ce310..18a70f0 100644
---
a/repo/tests/phpunit/includes/LinkedData/EntityDataSerializationServiceTest.php
+++
b/repo/tests/phpunit/includes/LinkedData/EntityDataSerializationServiceTest.php
@@ -111,8 +111,7 @@
new SiteList(),
new EntityDataFormatProvider(),
$serializerFactory,
- new MockSiteStore(),
- array("test" => "en-x-test")
+ new MockSiteStore()
);
return $service;
diff --git a/repo/tests/phpunit/includes/rdf/RdfBuilderTestData.php
b/repo/tests/phpunit/includes/rdf/RdfBuilderTestData.php
index 69db98e..35d92b9 100644
--- a/repo/tests/phpunit/includes/rdf/RdfBuilderTestData.php
+++ b/repo/tests/phpunit/includes/rdf/RdfBuilderTestData.php
@@ -134,7 +134,7 @@
* @return RdfVocabulary
*/
public function getVocabulary() {
- return new RdfVocabulary( self::URI_BASE, self::URI_DATA,
array("test" => "en-x-test") );
+ return new RdfVocabulary( self::URI_BASE, self::URI_DATA );
}
/**
diff --git a/repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
b/repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
index d1e8619..5f79dfd 100644
--- a/repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
+++ b/repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
@@ -80,8 +80,7 @@
new SiteList(),
$entityDataFormatProvider,
$serializerFactory,
- new MockSiteStore(),
- array('test' => 'en-x-test')
+ new MockSiteStore()
);
$maxAge = 60*60;
--
To view, visit https://gerrit.wikimedia.org/r/232751
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia5cdb34cb081d7ccfb277abaf92bffd5b566c491
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