1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Wikibase\Repo\Maintenance; |
4
|
|
|
|
5
|
|
|
use MediaWiki\MediaWikiServices; |
6
|
|
|
use Serializers\Serializer; |
7
|
|
|
use Wikibase\DataModel\Services\Entity\EntityPrefetcher; |
8
|
|
|
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup; |
9
|
|
|
use Wikibase\Lib\Store\EntityRevisionLookup; |
10
|
|
|
use Wikibase\Repo\Dumpers\DumpGenerator; |
11
|
|
|
use Wikibase\Repo\Dumpers\JsonDumpGenerator; |
12
|
|
|
use Wikibase\Repo\Store\Sql\SqlEntityIdPagerFactory; |
13
|
|
|
use Wikibase\Repo\WikibaseRepo; |
14
|
|
|
|
15
|
|
|
require_once __DIR__ . '/DumpEntities.php'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @license GPL-2.0-or-later |
19
|
|
|
* @author Daniel Kinzler |
20
|
|
|
* @author Addshore |
21
|
|
|
*/ |
22
|
|
|
class DumpJson extends DumpEntities { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var EntityRevisionLookup |
26
|
|
|
*/ |
27
|
|
|
private $entityRevisionLookup; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Serializer |
31
|
|
|
*/ |
32
|
|
|
private $entitySerializer; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var EntityPrefetcher |
36
|
|
|
*/ |
37
|
|
|
private $entityPrefetcher; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var PropertyDataTypeLookup |
41
|
|
|
*/ |
42
|
|
|
private $propertyDatatypeLookup; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var bool |
46
|
|
|
*/ |
47
|
|
|
private $hasHadServicesSet = false; |
48
|
|
|
|
49
|
|
|
public function __construct() { |
50
|
|
|
parent::__construct(); |
51
|
|
|
|
52
|
|
|
$this->addOption( |
53
|
|
|
'snippet', |
54
|
|
|
'Output a JSON snippet without square brackets at the start and end. Allows output to' |
55
|
|
|
. ' be combined more freely.', |
56
|
|
|
false, |
57
|
|
|
false |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function setServices( |
62
|
|
|
SqlEntityIdPagerFactory $sqlEntityIdPagerFactory, |
63
|
|
|
array $existingEntityTypes, |
64
|
|
|
EntityPrefetcher $entityPrefetcher, |
65
|
|
|
PropertyDataTypeLookup $propertyDataTypeLookup, |
66
|
|
|
EntityRevisionLookup $entityRevisionLookup, |
67
|
|
|
Serializer $entitySerializer |
68
|
|
|
) { |
69
|
|
|
parent::setDumpEntitiesServices( |
|
|
|
|
70
|
|
|
$sqlEntityIdPagerFactory, |
71
|
|
|
$existingEntityTypes, |
72
|
|
|
[] |
73
|
|
|
); |
74
|
|
|
$this->entityPrefetcher = $entityPrefetcher; |
75
|
|
|
$this->propertyDatatypeLookup = $propertyDataTypeLookup; |
76
|
|
|
$this->entityRevisionLookup = $entityRevisionLookup; |
77
|
|
|
$this->entitySerializer = $entitySerializer; |
78
|
|
|
$this->hasHadServicesSet = true; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function execute() { |
82
|
|
|
if ( !$this->hasHadServicesSet ) { |
83
|
|
|
$wikibaseRepo = WikibaseRepo::getDefaultInstance(); |
84
|
|
|
$sqlEntityIdPagerFactory = new SqlEntityIdPagerFactory( |
85
|
|
|
$wikibaseRepo->getEntityNamespaceLookup(), |
86
|
|
|
$wikibaseRepo->getEntityIdLookup(), |
87
|
|
|
MediaWikiServices::getInstance()->getLinkCache() |
88
|
|
|
); |
89
|
|
|
$revisionLookup = $wikibaseRepo->getEntityRevisionLookup( |
90
|
|
|
$this->getEntityRevisionLookupCacheMode() |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$this->setServices( |
94
|
|
|
$sqlEntityIdPagerFactory, |
95
|
|
|
$wikibaseRepo->getEnabledEntityTypes(), |
96
|
|
|
$wikibaseRepo->getStore()->getEntityPrefetcher(), |
97
|
|
|
$wikibaseRepo->getPropertyDataTypeLookup(), |
98
|
|
|
$revisionLookup, |
99
|
|
|
$wikibaseRepo->getCompactEntitySerializer() |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
parent::execute(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Create concrete dumper instance |
107
|
|
|
* @param resource $output |
108
|
|
|
* @return DumpGenerator |
109
|
|
|
*/ |
110
|
|
|
protected function createDumper( $output ) { |
111
|
|
|
$dataTypeLookup = $this->propertyDatatypeLookup; |
112
|
|
|
|
113
|
|
|
$dumper = new JsonDumpGenerator( |
114
|
|
|
$output, |
115
|
|
|
$this->entityRevisionLookup, |
116
|
|
|
$this->entitySerializer, |
117
|
|
|
$this->entityPrefetcher, |
118
|
|
|
$dataTypeLookup |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$dumper->setUseSnippets( (bool)$this->getOption( 'snippet', false ) ); |
122
|
|
|
return $dumper; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
$maintClass = DumpJson::class; |
128
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN; |
129
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.