Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
129 lines (109 sloc) 2.99 KB
<?php
namespace Wikibase;
use MediaWiki\MediaWikiServices;
use Serializers\Serializer;
use Wikibase\DataModel\Services\Entity\EntityPrefetcher;
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup;
use Wikibase\Dumpers\DumpGenerator;
use Wikibase\Dumpers\JsonDumpGenerator;
use Wikibase\Lib\Store\EntityRevisionLookup;
use Wikibase\Repo\Store\Sql\SqlEntityIdPagerFactory;
use Wikibase\Repo\WikibaseRepo;
require_once __DIR__ . '/DumpEntities.php';
/**
* @license GPL-2.0-or-later
* @author Daniel Kinzler
* @author Addshore
*/
class DumpJson extends DumpEntities {
/**
* @var EntityRevisionLookup
*/
private $entityRevisionLookup;
/**
* @var Serializer
*/
private $entitySerializer;
/**
* @var EntityPrefetcher
*/
private $entityPrefetcher;
/**
* @var PropertyDataTypeLookup
*/
private $propertyDatatypeLookup;
/**
* @var bool
*/
private $hasHadServicesSet = false;
public function __construct() {
parent::__construct();
$this->addOption(
'snippet',
'Output a JSON snippet without square brackets at the start and end. Allows output to'
. ' be combined more freely.',
false,
false
);
}
public function setServices(
SqlEntityIdPagerFactory $sqlEntityIdPagerFactory,
array $existingEntityTypes,
EntityPrefetcher $entityPrefetcher,
PropertyDataTypeLookup $propertyDataTypeLookup,
EntityRevisionLookup $entityRevisionLookup,
Serializer $entitySerializer
) {
parent::setDumpEntitiesServices(
$sqlEntityIdPagerFactory,
$existingEntityTypes,
[]
);
$this->entityPrefetcher = $entityPrefetcher;
$this->propertyDatatypeLookup = $propertyDataTypeLookup;
$this->entityRevisionLookup = $entityRevisionLookup;
$this->entitySerializer = $entitySerializer;
$this->hasHadServicesSet = true;
}
public function execute() {
if ( !$this->hasHadServicesSet ) {
$wikibaseRepo = WikibaseRepo::getDefaultInstance();
$sqlEntityIdPagerFactory = new SqlEntityIdPagerFactory(
$wikibaseRepo->getEntityNamespaceLookup(),
$wikibaseRepo->getEntityIdLookup(),
MediaWikiServices::getInstance()->getLinkCache()
);
$revisionLookup = $wikibaseRepo->getEntityRevisionLookup(
$this->getEntityRevisionLookupCacheMode()
);
$this->setServices(
$sqlEntityIdPagerFactory,
$wikibaseRepo->getEnabledEntityTypes(),
$wikibaseRepo->getStore()->getEntityPrefetcher(),
$wikibaseRepo->getPropertyDataTypeLookup(),
$revisionLookup,
$wikibaseRepo->getCompactEntitySerializer()
);
}
parent::execute();
}
/**
* Create concrete dumper instance
* @param resource $output
* @return DumpGenerator
*/
protected function createDumper( $output ) {
$dataTypeLookup = $this->propertyDatatypeLookup;
$dumper = new JsonDumpGenerator(
$output,
$this->entityRevisionLookup,
$this->entitySerializer,
$this->entityPrefetcher,
$dataTypeLookup
);
$dumper->setUseSnippets( (bool)$this->getOption( 'snippet', false ) );
return $dumper;
}
}
$maintClass = DumpJson::class;
require_once RUN_MAINTENANCE_IF_MAIN;
You can’t perform that action at this time.