From d89bcf2e0dc2bb856c88e2809be1cc00db1cfd04 Mon Sep 17 00:00:00 2001 From: Lucas Werkmeister Date: Fri, 24 Jan 2025 16:41:27 +0100 Subject: [PATCH] Add config option to fix s:, ref:, v: namespace prefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These should have used the node prefix (yielding wds:, wdref:, wdv: on Wikidata), but accidentally used the predicate prefix instead. Introduce a config option to fix that; as this changes the RDF output (remains to be decided whether that’s considered a significant or breaking change, but it certainly needs an announcement), put it behind a config option. Bug: T384344 Change-Id: I5e9da89e5096146898f9ac087a75942990868d5e Depends-On: I458d67dcfb0a755f31896cb8af6489fd97aeb731 --- repo/WikibaseRepo.ServiceWiring.php | 3 ++- repo/config/Wikibase.default.php | 9 ++++++++ repo/includes/Rdf/RdfVocabulary.php | 22 +++++++++++++------ .../unit/ServiceWiring/RdfVocabularyTest.php | 1 + 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/repo/WikibaseRepo.ServiceWiring.php b/repo/WikibaseRepo.ServiceWiring.php index 9cbe77e532..c87d30f65e 100644 --- a/repo/WikibaseRepo.ServiceWiring.php +++ b/repo/WikibaseRepo.ServiceWiring.php @@ -1697,7 +1697,8 @@ function ( $types, $localTypeName ) use ( $subEntityTypes ) { WikibaseRepo::getDataTypeDefinitions( $services )->getRdfTypeUris(), $repoSettings->getSetting( 'pagePropertiesRdf' ) ?: [], $repoSettings->getSetting( 'rdfDataRightsUrl' ), - $repoSettings->getSetting( 'tmpFixRdfSomevalueHash' ) + $repoSettings->getSetting( 'tmpFixRdfSomevalueHash' ), + $repoSettings->getSetting( 'tmpFixRdfNodeNamespacePrefix' ) ); }, diff --git a/repo/config/Wikibase.default.php b/repo/config/Wikibase.default.php index cc6c8d2f39..6e76d8f566 100644 --- a/repo/config/Wikibase.default.php +++ b/repo/config/Wikibase.default.php @@ -477,4 +477,13 @@ * @see https://phabricator.wikimedia.org/T384344 */ 'tmpFixRdfSomevalueHash' => false, + + /** + * Feature flag for the soft rollout of fixing the s:, ref: and v: prefixes (-> wds:, wdref:, wdv:). + * + * Added in https://phabricator.wikimedia.org/T384344, to be removed in Iadb3f55587 + * @var bool Whether to correctly use the rdfNodeNamespacePrefix (true) + * or incorrectly use the rdfPredicateNamespacePrefix (false) + */ + 'tmpFixRdfNodeNamespacePrefix' => false, ]; diff --git a/repo/includes/Rdf/RdfVocabulary.php b/repo/includes/Rdf/RdfVocabulary.php index 4c63ee68e1..2b166c2367 100644 --- a/repo/includes/Rdf/RdfVocabulary.php +++ b/repo/includes/Rdf/RdfVocabulary.php @@ -138,6 +138,8 @@ class RdfVocabulary { public bool $tmpFixRdfSomevalueHash; + private bool $tmpFixRdfNodeNamespacePrefix; + /** * @param string[] $conceptUris Associative array mapping repository names to base URIs for entity concept URIs. * @param string[] $dataUris Associative array mapping source/repository names to base URIs for entity description URIs. @@ -152,6 +154,7 @@ class RdfVocabulary { * All predicates will be prefixed with wikibase: * @param string $licenseUrl * @param bool $tmpFixRdfSomevalueHash Temporary feature flag. + * @param bool $tmpFixRdfNodeNamespacePrefix Temporary feature flag. */ public function __construct( array $conceptUris, @@ -163,7 +166,8 @@ public function __construct( array $dataTypeUris = [], array $pagePropertyDefs = [], string $licenseUrl = 'http://creativecommons.org/publicdomain/zero/1.0/', - bool $tmpFixRdfSomevalueHash = false + bool $tmpFixRdfSomevalueHash = false, + bool $tmpFixRdfNodeNamespacePrefix = false ) { Assert::parameterElementType( 'string', $conceptUris, '$conceptUris' ); Assert::parameterElementType( 'string', $dataUris, '$dataUris' ); @@ -178,6 +182,7 @@ public function __construct( $this->dataTypeUris = $dataTypeUris; $this->pagePropertyDefs = $pagePropertyDefs; $this->tmpFixRdfSomevalueHash = $tmpFixRdfSomevalueHash; + $this->tmpFixRdfNodeNamespacePrefix = $tmpFixRdfNodeNamespacePrefix; $this->namespaces = [ 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', @@ -215,13 +220,14 @@ public function __construct( foreach ( $conceptUris as $repositoryOrSourceName => $baseUri ) { $nodeNamespacePrefix = $rdfTurtleNodePrefixes[$repositoryOrSourceName]; $predicateNamespacePrefix = $rdfTurtlePredicatePrefixes[$repositoryOrSourceName]; + $buggyNodeNamespacePrefix = $tmpFixRdfNodeNamespacePrefix ? $nodeNamespacePrefix : $predicateNamespacePrefix; $this->entityNamespaceNames[$repositoryOrSourceName] = $nodeNamespacePrefix . self::NS_ENTITY; $this->dataNamespaceNames[$repositoryOrSourceName] = $predicateNamespacePrefix . self::NS_DATA; $this->statementNamespaceNames[$repositoryOrSourceName] = [ - self::NS_STATEMENT => $predicateNamespacePrefix . self::NS_STATEMENT, - self::NS_REFERENCE => $predicateNamespacePrefix . self::NS_REFERENCE, - self::NS_VALUE => $predicateNamespacePrefix . self::NS_VALUE, + self::NS_STATEMENT => $buggyNodeNamespacePrefix . self::NS_STATEMENT, + self::NS_REFERENCE => $buggyNodeNamespacePrefix . self::NS_REFERENCE, + self::NS_VALUE => $buggyNodeNamespacePrefix . self::NS_VALUE, ]; $this->propertyNamespaceNames[$repositoryOrSourceName] = array_combine( @@ -295,6 +301,8 @@ function ( $ns ) use ( $nodeNamespacePrefix ) { * @return string[] */ private function getConceptNamespaces( $nodeNamespacePrefix, $predicateNamespacePrefix, $baseUri, $dataUri ) { + $buggyNodeNamespacePrefix = $this->tmpFixRdfNodeNamespacePrefix ? $nodeNamespacePrefix : $predicateNamespacePrefix; + $topUri = $this->getConceptUriBase( $baseUri ); $propUri = $topUri . 'prop/'; @@ -302,9 +310,9 @@ private function getConceptNamespaces( $nodeNamespacePrefix, $predicateNamespace return [ $nodeNamespacePrefix . self::NS_ENTITY => $baseUri, $predicateNamespacePrefix . self::NS_DATA => $dataUri, - $predicateNamespacePrefix . self::NS_STATEMENT => $baseUri . 'statement/', - $predicateNamespacePrefix . self::NS_REFERENCE => $topUri . 'reference/', - $predicateNamespacePrefix . self::NS_VALUE => $topUri . 'value/', + $buggyNodeNamespacePrefix . self::NS_STATEMENT => $baseUri . 'statement/', + $buggyNodeNamespacePrefix . self::NS_REFERENCE => $topUri . 'reference/', + $buggyNodeNamespacePrefix . self::NS_VALUE => $topUri . 'value/', // predicates $nodeNamespacePrefix . self::NSP_DIRECT_CLAIM => $propUri . 'direct/', $nodeNamespacePrefix . self::NSP_DIRECT_CLAIM_NORM => $propUri . 'direct-normalized/', diff --git a/repo/tests/phpunit/unit/ServiceWiring/RdfVocabularyTest.php b/repo/tests/phpunit/unit/ServiceWiring/RdfVocabularyTest.php index 7739609de9..03fa3fa097 100644 --- a/repo/tests/phpunit/unit/ServiceWiring/RdfVocabularyTest.php +++ b/repo/tests/phpunit/unit/ServiceWiring/RdfVocabularyTest.php @@ -51,6 +51,7 @@ public function testConstruction(): void { 'pagePropertiesRdf' => $pagePropertyDefs, 'rdfDataRightsUrl' => 'https://license.test/cc0', 'tmpFixRdfSomevalueHash' => true, + 'tmpFixRdfNodeNamespacePrefix' => false, ] ) ); $this->mockService( 'WikibaseRepo.EntitySourceDefinitions', new EntitySourceDefinitions( [