-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathdumpJson.php
159 lines (138 loc) · 3.92 KB
/
dumpJson.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
namespace Wikibase\Repo\Maintenance;
use MediaWiki\MediaWikiServices;
use Serializers\Serializer;
use Wikibase\DataModel\Entity\EntityIdParser;
use Wikibase\DataModel\Services\Entity\EntityPrefetcher;
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup;
use Wikibase\Lib\Store\EntityRevisionLookup;
use Wikibase\Repo\Dumpers\DumpGenerator;
use Wikibase\Repo\Dumpers\JsonDumpGenerator;
use Wikibase\Repo\Store\EntityTitleStoreLookup;
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 EntityTitleStoreLookup
*/
private $entityTitleStoreLookup;
/**
* @var Serializer
*/
private $entitySerializer;
/**
* @var EntityPrefetcher
*/
private $entityPrefetcher;
/**
* @var PropertyDataTypeLookup
*/
private $propertyDatatypeLookup;
/**
* @var bool
*/
private $hasHadServicesSet = false;
/**
* @var EntityIdParser
*/
private $entityIdParser;
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
);
$this->addOption(
'page-metadata',
'Entities should include page metadata.',
false,
false
);
}
public function setServices(
SqlEntityIdPagerFactory $sqlEntityIdPagerFactory,
array $existingEntityTypes,
EntityPrefetcher $entityPrefetcher,
PropertyDataTypeLookup $propertyDataTypeLookup,
EntityRevisionLookup $entityRevisionLookup,
Serializer $entitySerializer,
EntityIdParser $entityIdParser,
EntityTitleStoreLookup $entityTitleStoreLookup
) {
parent::setDumpEntitiesServices(
$sqlEntityIdPagerFactory,
$existingEntityTypes,
[]
);
$this->entityPrefetcher = $entityPrefetcher;
$this->propertyDatatypeLookup = $propertyDataTypeLookup;
$this->entityRevisionLookup = $entityRevisionLookup;
$this->entitySerializer = $entitySerializer;
$this->entityIdParser = $entityIdParser;
$this->entityTitleStoreLookup = $entityTitleStoreLookup;
$this->hasHadServicesSet = true;
}
public function execute() {
if ( !$this->hasHadServicesSet ) {
$mwServices = MediaWikiServices::getInstance();
$sqlEntityIdPagerFactory = new SqlEntityIdPagerFactory(
WikibaseRepo::getEntityNamespaceLookup( $mwServices ),
WikibaseRepo::getEntityIdLookup( $mwServices ),
WikibaseRepo::getRepoDomainDbFactory( $mwServices )->newRepoDb(),
$mwServices->getLinkCache()
);
$store = WikibaseRepo::getStore( $mwServices );
$revisionLookup = $store->getEntityRevisionLookup(
$this->getEntityRevisionLookupCacheMode()
);
$this->setServices(
$sqlEntityIdPagerFactory,
WikibaseRepo::getEnabledEntityTypes( $mwServices ),
$store->getEntityPrefetcher(),
WikibaseRepo::getPropertyDataTypeLookup(),
$revisionLookup,
WikibaseRepo::getCompactEntitySerializer( $mwServices ),
WikibaseRepo::getEntityIdParser( $mwServices ),
WikibaseRepo::getEntityTitleStoreLookup( $mwServices )
);
}
parent::execute();
}
/**
* Create concrete dumper instance
* @param resource $output
* @return DumpGenerator
*/
protected function createDumper( $output ) {
$dumper = new JsonDumpGenerator(
$output,
$this->entityRevisionLookup,
$this->entitySerializer,
$this->entityPrefetcher,
$this->propertyDatatypeLookup,
$this->entityIdParser,
$this->entityTitleStoreLookup
);
$dumper->setUseSnippets( (bool)$this->getOption( 'snippet', false ) );
$dumper->setAddPageMetadata( (bool)$this->getOption( 'page-metadata', false ) );
return $dumper;
}
protected function getDumpType(): string {
return "JSON";
}
}
$maintClass = DumpJson::class;
require_once RUN_MAINTENANCE_IF_MAIN;