Smalyshev has uploaded a new change for review.
https://gerrit.wikimedia.org/r/216894
Change subject: T100463: add wdata to redirects
......................................................................
T100463: add wdata to redirects
Change-Id: If32318d6e8f90f7ff38e3568e74e2b5d46034a3c
---
M lib/includes/store/EntityRedirect.php
A lib/includes/store/UnresolvedRedirectRevisionException.php
M lib/includes/store/sql/WikiPageEntityRevisionLookup.php
M repo/includes/Dumpers/RdfDumpGenerator.php
M repo/includes/LinkedData/EntityDataRequestHandler.php
M repo/includes/LinkedData/EntityDataSerializationService.php
M repo/includes/rdf/RdfBuilder.php
7 files changed, 129 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/94/216894/1
diff --git a/lib/includes/store/EntityRedirect.php
b/lib/includes/store/EntityRedirect.php
index a00d2f9..b5fe2b7 100644
--- a/lib/includes/store/EntityRedirect.php
+++ b/lib/includes/store/EntityRedirect.php
@@ -26,18 +26,30 @@
private $targetId;
/**
+ * @var int
+ */
+ private $revisionId;
+
+ /**
+ * @var string
+ */
+ private $mwTimestamp;
+
+ /**
* @param EntityId $entityId
* @param EntityId $targetId
*
* @throws InvalidArgumentException
*/
- public function __construct( EntityId $entityId, EntityId $targetId ) {
+ public function __construct( EntityId $entityId, EntityId $targetId,
$revisionId = 0, $mwTimestamp = '' ) {
if ( $entityId->getEntityType() !== $targetId->getEntityType()
) {
throw new InvalidArgumentException( '$entityId and
$targetId must refer to the same kind of entity.' );
}
$this->entityId = $entityId;
$this->targetId = $targetId;
+ $this->revisionId = $revisionId;
+ $this->mwTimestamp = $mwTimestamp;
}
/**
@@ -55,6 +67,24 @@
}
/**
+ * @see Revision::getId
+ *
+ * @return int
+ */
+ public function getRevisionId() {
+ return $this->revisionId;
+ }
+
+ /**
+ * @see Revision::getTimestamp
+ *
+ * @return string in MediaWiki format or an empty string
+ */
+ public function getTimestamp() {
+ return $this->mwTimestamp;
+ }
+
+ /**
* @param EntityRedirect $that
*
* @return bool
@@ -67,7 +97,10 @@
return is_object( $that )
&& get_class( $that ) === get_called_class()
&& $this->entityId->equals( $that->entityId )
- && $this->targetId->equals( $that->targetId );
+ && $this->targetId->equals( $that->targetId )
+ && $this->revisionId == $that->revisionId
+ && $this->mwTimestamp == $that->mwTimestamp
+ ;
}
}
diff --git a/lib/includes/store/UnresolvedRedirectRevisionException.php
b/lib/includes/store/UnresolvedRedirectRevisionException.php
new file mode 100644
index 0000000..8c69f3f
--- /dev/null
+++ b/lib/includes/store/UnresolvedRedirectRevisionException.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Wikibase\Lib\Store;
+
+use Exception;
+use Wikibase\DataModel\Entity\EntityId;
+
+/**
+ * Exception indicating that an attempt was made to access a redirected
EntityId
+ * without resolving the redirect first.
+ * Includes revision information for the redirect data.
+ *
+ * @license GPL 2+
+ * @author Daniel Kinzler
+ */
+class UnresolvedRedirectRevisionException extends UnresolvedRedirectException {
+
+ /**
+ * @var int
+ */
+ private $revisionId;
+
+ /**
+ * @var string
+ */
+ private $mwTimestamp;
+
+ /**
+ * @param EntityId $redirectTargetId The ID of the target Entity of the
redirect
+ * @param int $revisionId Revision ID or 0 for none
+ * @param string $mwTimestamp in MediaWiki format or an empty string
for none
+ * @param string|null $message
+ * @param int $code
+ * @param Exception|null $previous
+ */
+ public function __construct( EntityId $redirectTargetId, $revisionId =
0, $mwTimestamp = '',
+ $message = null, $code = 0, Exception $previous = null
) {
+ parent::__construct( $redirectTargetId, $message, $code,
$previous );
+
+ $this->revisionId = $revisionId;
+ $this->mwTimestamp = $mwTimestamp;
+ }
+
+ /**
+ * @see Revision::getId
+ *
+ * @return int
+ */
+ public function getRevisionId() {
+ return $this->revisionId;
+ }
+
+ /**
+ * @see Revision::getTimestamp
+ *
+ * @return string in MediaWiki format or an empty string
+ */
+ public function getTimestamp() {
+ return $this->mwTimestamp;
+ }
+}
diff --git a/lib/includes/store/sql/WikiPageEntityRevisionLookup.php
b/lib/includes/store/sql/WikiPageEntityRevisionLookup.php
index b60a1fd..a74140a 100644
--- a/lib/includes/store/sql/WikiPageEntityRevisionLookup.php
+++ b/lib/includes/store/sql/WikiPageEntityRevisionLookup.php
@@ -85,7 +85,7 @@
if ( $redirect !== null ) {
// TODO: Optionally follow redirects. Doesn't
make sense if a revision ID is given.
- throw new UnresolvedRedirectException(
$redirect->getTargetId() );
+ throw new UnresolvedRedirectRevisionException(
$redirect->getTargetId(), (int)$row->rev_id, $row->rev_timestamp );
}
if ( $entityRevision === null ) {
diff --git a/repo/includes/Dumpers/RdfDumpGenerator.php
b/repo/includes/Dumpers/RdfDumpGenerator.php
index efaf6b9..96a4c7e 100644
--- a/repo/includes/Dumpers/RdfDumpGenerator.php
+++ b/repo/includes/Dumpers/RdfDumpGenerator.php
@@ -19,6 +19,7 @@
use Wikibase\Rdf\RdfProducer;
use Wikibase\Rdf\RdfVocabulary;
use Wikimedia\Purtle\RdfWriterFactory;
+use Wikibase\Lib\Store\UnresolvedRedirectRevisionException;
/**
* RdfDumpGenerator generates an RDF dump of a given set of entities, excluding
@@ -114,7 +115,12 @@
} catch ( MWContentSerializationException $ex ) {
throw new StorageException( 'Deserialization error for
' . $entityId->getSerialization() );
- } catch ( UnresolvedRedirectException $e ) {
+ } catch ( UnresolvedRedirectRevisionException $e ) {
+ $this->rdfBuilder->addEntityRevisionInfo(
+ $entityId,
+ $e->getRevisionId(),
+ $e->getTimestamp()
+ );
$this->rdfBuilder->addEntityRedirect(
$entityId,
$e->getRedirectTargetId()
diff --git a/repo/includes/LinkedData/EntityDataRequestHandler.php
b/repo/includes/LinkedData/EntityDataRequestHandler.php
index 99e1bbc..7fc1a15 100644
--- a/repo/includes/LinkedData/EntityDataRequestHandler.php
+++ b/repo/includes/LinkedData/EntityDataRequestHandler.php
@@ -18,6 +18,7 @@
use Wikibase\Lib\Store\EntityTitleLookup;
use Wikibase\Lib\Store\StorageException;
use Wikibase\Lib\Store\UnresolvedRedirectException;
+use Wikibase\Lib\Store\UnresolvedRedirectRevisionException;
/**
* Request handler implementing a linked data interface for Wikibase entities.
@@ -353,7 +354,11 @@
throw new HttpError( 404, wfMessage(
'wikibase-entitydata-not-found' )->params( $prefixedId ) );
}
} catch ( UnresolvedRedirectException $ex ) {
- $entityRedirect = new EntityRedirect( $id,
$ex->getRedirectTargetId() );
+ if($ex instanceof UnresolvedRedirectRevisionException )
{
+ $entityRedirect = new EntityRedirect( $id,
$ex->getRedirectTargetId(), $ex->getRevisionId(), $ex->getTimestamp() );
+ } else {
+ $entityRedirect = new EntityRedirect( $id,
$ex->getRedirectTargetId() );
+ }
if ( is_string( $revision ) ) {
// If no specific revision is requested,
resolve the redirect.
diff --git a/repo/includes/LinkedData/EntityDataSerializationService.php
b/repo/includes/LinkedData/EntityDataSerializationService.php
index fc51657..59ca21a 100644
--- a/repo/includes/LinkedData/EntityDataSerializationService.php
+++ b/repo/includes/LinkedData/EntityDataSerializationService.php
@@ -433,11 +433,17 @@
if ( $followedRedirect ) {
$rdfBuilder->addEntityRedirect(
$followedRedirect->getEntityId(), $followedRedirect->getTargetId() );
+ $rdfBuilder->addEntityRevisionInfo(
+ $followedRedirect->getEntityId(),
+ $followedRedirect->getRevisionId(),
+ $followedRedirect->getTimestamp()
+ );
}
if ( $followedRedirect && $flavor === 'dump' ) {
// For redirects, don't output the target entity data
if the "dump" flavor is requested.
// @todo: In this case, avoid loading the Entity all
together.
+ // However we want to output the revisions for redirects
} else {
$rdfBuilder->addEntityRevisionInfo(
$entityRevision->getEntity()->getId(),
diff --git a/repo/includes/rdf/RdfBuilder.php b/repo/includes/rdf/RdfBuilder.php
index bd3ccbd..9760deb 100644
--- a/repo/includes/rdf/RdfBuilder.php
+++ b/repo/includes/rdf/RdfBuilder.php
@@ -278,9 +278,20 @@
*/
public function addEntityRevisionInfo( EntityId $entityId, $revision,
$timestamp ) {
$timestamp = wfTimestamp( TS_ISO_8601, $timestamp );
+ $entityLName = $this->vocabulary->getEntityLName( $entityId );
$this->writer->about( RdfVocabulary::NS_DATA, $entityId )
- ->say( RdfVocabulary::NS_SCHEMA_ORG, 'version'
)->value( $revision, 'xsd', 'integer' )
+ ->a( RdfVocabulary::NS_SCHEMA_ORG, "Dataset" )
+ ->say( RdfVocabulary::NS_SCHEMA_ORG, 'about' )->is(
RdfVocabulary::NS_ENTITY, $entityLName );
+
+ if ( $this->shouldProduce( RdfProducer::PRODUCE_VERSION_INFO )
) {
+ // Dumps don't need version/license info for each
entity, since it is included in the dump header
+ $this->writer
+ ->say( RdfVocabulary::NS_CC, 'license' )->is(
RdfVocabulary::LICENSE )
+ ->say( RdfVocabulary::NS_SCHEMA_ORG,
'softwareVersion' )->value( RdfVocabulary::FORMAT_VERSION );
+ }
+
+ $this->writer->say( RdfVocabulary::NS_SCHEMA_ORG, 'version'
)->value( $revision, 'xsd', 'integer' )
->say( RdfVocabulary::NS_SCHEMA_ORG, 'dateModified'
)->value( $timestamp, 'xsd', 'dateTime' );
}
@@ -347,23 +358,9 @@
* @todo: extract into MetaDataRdfBuilder
*
* @param EntityDocument $entity
- * @param bool $produceData Should we also produce Dataset node?
*/
- private function addEntityMetaData( EntityDocument $entity,
$produceData = true ) {
+ private function addEntityMetaData( EntityDocument $entity ) {
$entityLName = $this->vocabulary->getEntityLName(
$entity->getId() );
-
- if ( $produceData ) {
- $this->writer->about( RdfVocabulary::NS_DATA,
$entity->getId() )
- ->a( RdfVocabulary::NS_SCHEMA_ORG, "Dataset" )
- ->say( RdfVocabulary::NS_SCHEMA_ORG, 'about'
)->is( RdfVocabulary::NS_ENTITY, $entityLName );
-
- if ( $this->shouldProduce(
RdfProducer::PRODUCE_VERSION_INFO ) ) {
- // Dumps don't need version/license info for
each entity, since it is included in the dump header
- $this->writer
- ->say( RdfVocabulary::NS_CC, 'license'
)->is( RdfVocabulary::LICENSE )
- ->say( RdfVocabulary::NS_SCHEMA_ORG,
'softwareVersion' )->value( RdfVocabulary::FORMAT_VERSION );
- }
- }
$this->writer->about( RdfVocabulary::NS_ENTITY, $entityLName )
->a( RdfVocabulary::NS_ONTOLOGY,
$this->vocabulary->getEntityTypeName( $entity->getType() ) );
--
To view, visit https://gerrit.wikimedia.org/r/216894
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If32318d6e8f90f7ff38e3568e74e2b5d46034a3c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits