@@ -18,10 +18,10 @@ discard block |
||
18 | 18 | use Wikibase\Repo\WikibaseRepo; |
19 | 19 | |
20 | 20 | // @codeCoverageIgnoreStart |
21 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
22 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
21 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
22 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
23 | 23 | |
24 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
24 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
25 | 25 | // @codeCoverageIgnoreEnd |
26 | 26 | |
27 | 27 | /** |
@@ -60,20 +60,20 @@ discard block |
||
60 | 60 | parent::__construct(); |
61 | 61 | |
62 | 62 | $this->addDescription( |
63 | - 'Import entities needed for constraint checks ' . |
|
63 | + 'Import entities needed for constraint checks '. |
|
64 | 64 | 'from Wikidata into the local repository.' |
65 | 65 | ); |
66 | 66 | $this->addOption( |
67 | 67 | 'config-format', |
68 | - 'The format in which the resulting configuration will be omitted: ' . |
|
69 | - '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' . |
|
68 | + 'The format in which the resulting configuration will be omitted: '. |
|
69 | + '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '. |
|
70 | 70 | 'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.' |
71 | 71 | ); |
72 | 72 | $this->addOption( |
73 | 73 | 'dry-run', |
74 | 74 | 'Don’t actually import entities, just print which ones would be imported.' |
75 | 75 | ); |
76 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
76 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | */ |
82 | 82 | private function setupServices() { |
83 | 83 | $services = MediaWikiServices::getInstance(); |
84 | - $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer( $services ); |
|
85 | - $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer( $services ); |
|
86 | - $this->entityStore = WikibaseRepo::getEntityStore( $services ); |
|
84 | + $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer($services); |
|
85 | + $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer($services); |
|
86 | + $this->entityStore = WikibaseRepo::getEntityStore($services); |
|
87 | 87 | $this->httpRequestFactory = $services->getHttpRequestFactory(); |
88 | - if ( !$this->getOption( 'dry-run', false ) ) { |
|
89 | - $this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' ); |
|
88 | + if (!$this->getOption('dry-run', false)) { |
|
89 | + $this->user = User::newSystemUser('WikibaseQualityConstraints importer'); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -95,21 +95,21 @@ discard block |
||
95 | 95 | |
96 | 96 | $configUpdates = []; |
97 | 97 | |
98 | - $extensionJsonFile = __DIR__ . '/../extension.json'; |
|
99 | - $extensionJsonText = file_get_contents( $extensionJsonFile ); |
|
100 | - $extensionJson = json_decode( $extensionJsonText, /* assoc = */ true ); |
|
98 | + $extensionJsonFile = __DIR__.'/../extension.json'; |
|
99 | + $extensionJsonText = file_get_contents($extensionJsonFile); |
|
100 | + $extensionJson = json_decode($extensionJsonText, /* assoc = */ true); |
|
101 | 101 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
102 | - $wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() ); |
|
102 | + $wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig()); |
|
103 | 103 | |
104 | - foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) { |
|
105 | - $localEntityId = $this->importEntityFromWikidata( $wikidataEntityId ); |
|
104 | + foreach ($wikidataEntityIds as $key => $wikidataEntityId) { |
|
105 | + $localEntityId = $this->importEntityFromWikidata($wikidataEntityId); |
|
106 | 106 | $configUpdates[$key] = [ |
107 | 107 | 'wikidata' => $wikidataEntityId, |
108 | 108 | 'local' => $localEntityId, |
109 | 109 | ]; |
110 | 110 | } |
111 | 111 | |
112 | - $this->outputConfigUpdates( $configUpdates ); |
|
112 | + $this->outputConfigUpdates($configUpdates); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -117,18 +117,18 @@ discard block |
||
117 | 117 | * @param Config $wikiConfig |
118 | 118 | * @return string[] |
119 | 119 | */ |
120 | - private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) { |
|
120 | + private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) { |
|
121 | 121 | $wikidataEntityIds = []; |
122 | 122 | |
123 | - foreach ( $extensionJsonConfig as $key => $value ) { |
|
124 | - if ( !preg_match( '/Id$/', $key ) ) { |
|
123 | + foreach ($extensionJsonConfig as $key => $value) { |
|
124 | + if (!preg_match('/Id$/', $key)) { |
|
125 | 125 | continue; |
126 | 126 | } |
127 | 127 | |
128 | 128 | $wikidataEntityId = $value['value']; |
129 | - $localEntityId = $wikiConfig->get( $key ); |
|
129 | + $localEntityId = $wikiConfig->get($key); |
|
130 | 130 | |
131 | - if ( $localEntityId === $wikidataEntityId ) { |
|
131 | + if ($localEntityId === $wikidataEntityId) { |
|
132 | 132 | $wikidataEntityIds[$key] = $wikidataEntityId; |
133 | 133 | } |
134 | 134 | } |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | * @param string $wikidataEntityId |
141 | 141 | * @return string local entity ID |
142 | 142 | */ |
143 | - private function importEntityFromWikidata( $wikidataEntityId ) { |
|
143 | + private function importEntityFromWikidata($wikidataEntityId) { |
|
144 | 144 | $wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json"; |
145 | - $wikidataEntitiesJson = $this->httpRequestFactory->get( $wikidataEntityUrl, [], __METHOD__ ); |
|
146 | - return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ); |
|
145 | + $wikidataEntitiesJson = $this->httpRequestFactory->get($wikidataEntityUrl, [], __METHOD__); |
|
146 | + return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,24 +151,24 @@ discard block |
||
151 | 151 | * @param string $wikidataEntitiesJson |
152 | 152 | * @return string local entity ID |
153 | 153 | */ |
154 | - private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) { |
|
154 | + private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) { |
|
155 | 155 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
156 | - $wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId]; |
|
157 | - $wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray ); |
|
156 | + $wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId]; |
|
157 | + $wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray); |
|
158 | 158 | |
159 | - $wikidataEntity->setId( null ); |
|
159 | + $wikidataEntity->setId(null); |
|
160 | 160 | |
161 | - if ( $wikidataEntity instanceof StatementListProvider ) { |
|
161 | + if ($wikidataEntity instanceof StatementListProvider) { |
|
162 | 162 | $wikidataEntity->getStatements()->clear(); |
163 | 163 | } |
164 | 164 | |
165 | - if ( $wikidataEntity instanceof Item ) { |
|
166 | - $wikidataEntity->setSiteLinkList( new SiteLinkList() ); |
|
165 | + if ($wikidataEntity instanceof Item) { |
|
166 | + $wikidataEntity->setSiteLinkList(new SiteLinkList()); |
|
167 | 167 | } |
168 | 168 | |
169 | - if ( $this->getOption( 'dry-run', false ) ) { |
|
170 | - $wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) ); |
|
171 | - $this->output( $wikidataEntityJson . "\n" ); |
|
169 | + if ($this->getOption('dry-run', false)) { |
|
170 | + $wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity)); |
|
171 | + $this->output($wikidataEntityJson."\n"); |
|
172 | 172 | return "-$wikidataEntityId"; |
173 | 173 | } |
174 | 174 | |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | )->getEntity(); |
182 | 182 | |
183 | 183 | return $localEntity->getId()->getSerialization(); |
184 | - } catch ( StorageException $storageException ) { |
|
185 | - return $this->storageExceptionToEntityId( $storageException ); |
|
184 | + } catch (StorageException $storageException) { |
|
185 | + return $this->storageExceptionToEntityId($storageException); |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
189 | - private function storageExceptionToEntityId( StorageException $storageException ) { |
|
189 | + private function storageExceptionToEntityId(StorageException $storageException) { |
|
190 | 190 | $message = $storageException->getMessage(); |
191 | 191 | // example messages: |
192 | 192 | // * Item [[Item:Q475|Q475]] already has label "as references" |
@@ -196,25 +196,25 @@ discard block |
||
196 | 196 | // * Property [[Property:P694|P694]] already has label "instance of" |
197 | 197 | // associated with language code en. |
198 | 198 | $pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/'; |
199 | - if ( preg_match( $pattern, $message, $matches ) ) { |
|
199 | + if (preg_match($pattern, $message, $matches)) { |
|
200 | 200 | return $matches[1]; |
201 | 201 | } else { |
202 | 202 | throw $storageException; |
203 | 203 | } |
204 | 204 | } |
205 | 205 | |
206 | - private function outputConfigUpdates( array $configUpdates ) { |
|
207 | - $configFormat = $this->getOption( 'config-format', 'globals' ); |
|
208 | - switch ( $configFormat ) { |
|
206 | + private function outputConfigUpdates(array $configUpdates) { |
|
207 | + $configFormat = $this->getOption('config-format', 'globals'); |
|
208 | + switch ($configFormat) { |
|
209 | 209 | case 'globals': |
210 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
210 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
211 | 211 | break; |
212 | 212 | case 'wgConf': |
213 | - $this->outputConfigUpdatesWgConf( $configUpdates ); |
|
213 | + $this->outputConfigUpdatesWgConf($configUpdates); |
|
214 | 214 | break; |
215 | 215 | default: |
216 | - $this->error( "Invalid config format \"$configFormat\", using \"globals\"" ); |
|
217 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
216 | + $this->error("Invalid config format \"$configFormat\", using \"globals\""); |
|
217 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
218 | 218 | break; |
219 | 219 | } |
220 | 220 | } |
@@ -222,22 +222,22 @@ discard block |
||
222 | 222 | /** |
223 | 223 | * @param array[] $configUpdates |
224 | 224 | */ |
225 | - private function outputConfigUpdatesGlobals( array $configUpdates ) { |
|
226 | - foreach ( $configUpdates as $key => $value ) { |
|
227 | - $localValueCode = var_export( $value['local'], true ); |
|
228 | - $this->output( "\$wg$key = $localValueCode;\n" ); |
|
225 | + private function outputConfigUpdatesGlobals(array $configUpdates) { |
|
226 | + foreach ($configUpdates as $key => $value) { |
|
227 | + $localValueCode = var_export($value['local'], true); |
|
228 | + $this->output("\$wg$key = $localValueCode;\n"); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
233 | 233 | * @param array[] $configUpdates |
234 | 234 | */ |
235 | - private function outputConfigUpdatesWgConf( array $configUpdates ) { |
|
236 | - $wikiIdCode = var_export( WikiMap::getCurrentWikiId(), true ); |
|
237 | - foreach ( $configUpdates as $key => $value ) { |
|
238 | - $keyCode = var_export( "wg$key", true ); |
|
239 | - $wikidataValueCode = var_export( $value['wikidata'], true ); |
|
240 | - $localValueCode = var_export( $value['local'], true ); |
|
235 | + private function outputConfigUpdatesWgConf(array $configUpdates) { |
|
236 | + $wikiIdCode = var_export(WikiMap::getCurrentWikiId(), true); |
|
237 | + foreach ($configUpdates as $key => $value) { |
|
238 | + $keyCode = var_export("wg$key", true); |
|
239 | + $wikidataValueCode = var_export($value['wikidata'], true); |
|
240 | + $localValueCode = var_export($value['local'], true); |
|
241 | 241 | $block = <<< EOF |
242 | 242 | $keyCode => [ |
243 | 243 | 'default' => $wikidataValueCode, |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | |
247 | 247 | |
248 | 248 | EOF; |
249 | - $this->output( $block ); |
|
249 | + $this->output($block); |
|
250 | 250 | } |
251 | 251 | } |
252 | 252 |
@@ -30,53 +30,53 @@ discard block |
||
30 | 30 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResultSerializer; |
31 | 31 | |
32 | 32 | return [ |
33 | - ConstraintsServices::EXPIRY_LOCK => static function ( MediaWikiServices $services ) { |
|
34 | - return new ExpiryLock( ObjectCache::getInstance( CACHE_ANYTHING ) ); |
|
33 | + ConstraintsServices::EXPIRY_LOCK => static function(MediaWikiServices $services) { |
|
34 | + return new ExpiryLock(ObjectCache::getInstance(CACHE_ANYTHING)); |
|
35 | 35 | }, |
36 | 36 | |
37 | - ConstraintsServices::LOGGING_HELPER => static function ( MediaWikiServices $services ) { |
|
37 | + ConstraintsServices::LOGGING_HELPER => static function(MediaWikiServices $services) { |
|
38 | 38 | return new LoggingHelper( |
39 | 39 | $services->getStatsdDataFactory(), |
40 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
40 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
41 | 41 | $services->getMainConfig() |
42 | 42 | ); |
43 | 43 | }, |
44 | 44 | |
45 | - ConstraintsServices::CONSTRAINT_STORE => static function ( MediaWikiServices $services ) { |
|
46 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
47 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
48 | - if ( $propertySource === null ) { |
|
49 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for properties not stored in a database.' ); |
|
45 | + ConstraintsServices::CONSTRAINT_STORE => static function(MediaWikiServices $services) { |
|
46 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
47 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
48 | + if ($propertySource === null) { |
|
49 | + throw new RuntimeException('Can\'t get a ConstraintStore for properties not stored in a database.'); |
|
50 | 50 | } |
51 | 51 | |
52 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
53 | - if ( $propertySource->getSourceName() !== $localEntitySourceName ) { |
|
54 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for a non local entity source.' ); |
|
52 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
53 | + if ($propertySource->getSourceName() !== $localEntitySourceName) { |
|
54 | + throw new RuntimeException('Can\'t get a ConstraintStore for a non local entity source.'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | $dbName = $propertySource->getDatabaseName(); |
58 | 58 | return new ConstraintRepositoryStore( |
59 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
59 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
60 | 60 | $dbName |
61 | 61 | ); |
62 | 62 | }, |
63 | 63 | |
64 | - ConstraintsServices::CONSTRAINT_LOOKUP => static function ( MediaWikiServices $services ) { |
|
65 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
66 | - $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType( Property::ENTITY_TYPE ); |
|
67 | - if ( $propertySource === null ) { |
|
68 | - throw new RuntimeException( 'Can\'t get a ConstraintStore for properties not stored in a database.' ); |
|
64 | + ConstraintsServices::CONSTRAINT_LOOKUP => static function(MediaWikiServices $services) { |
|
65 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
66 | + $propertySource = $sourceDefinitions->getDatabaseSourceForEntityType(Property::ENTITY_TYPE); |
|
67 | + if ($propertySource === null) { |
|
68 | + throw new RuntimeException('Can\'t get a ConstraintStore for properties not stored in a database.'); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $dbName = $propertySource->getDatabaseName(); |
72 | 72 | $rawLookup = new ConstraintRepositoryLookup( |
73 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
73 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
74 | 74 | $dbName |
75 | 75 | ); |
76 | - return new CachingConstraintLookup( $rawLookup ); |
|
76 | + return new CachingConstraintLookup($rawLookup); |
|
77 | 77 | }, |
78 | 78 | |
79 | - ConstraintsServices::CHECK_RESULT_SERIALIZER => static function ( MediaWikiServices $services ) { |
|
79 | + ConstraintsServices::CHECK_RESULT_SERIALIZER => static function(MediaWikiServices $services) { |
|
80 | 80 | return new CheckResultSerializer( |
81 | 81 | new ConstraintSerializer( |
82 | 82 | false // constraint parameters are not exposed |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | ); |
88 | 88 | }, |
89 | 89 | |
90 | - ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function ( MediaWikiServices $services ) { |
|
91 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
92 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
90 | + ConstraintsServices::CHECK_RESULT_DESERIALIZER => static function(MediaWikiServices $services) { |
|
91 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
92 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
93 | 93 | |
94 | 94 | return new CheckResultDeserializer( |
95 | 95 | new ConstraintDeserializer(), |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | ); |
103 | 103 | }, |
104 | 104 | |
105 | - ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function ( MediaWikiServices $services ) { |
|
105 | + ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => static function(MediaWikiServices $services) { |
|
106 | 106 | return new ViolationMessageSerializer(); |
107 | 107 | }, |
108 | 108 | |
109 | - ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function ( MediaWikiServices $services ) { |
|
110 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
111 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
109 | + ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => static function(MediaWikiServices $services) { |
|
110 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
111 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
112 | 112 | |
113 | 113 | return new ViolationMessageDeserializer( |
114 | 114 | $entityIdParser, |
@@ -116,37 +116,37 @@ discard block |
||
116 | 116 | ); |
117 | 117 | }, |
118 | 118 | |
119 | - ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function ( MediaWikiServices $services ) { |
|
120 | - $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory( $services ); |
|
121 | - $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
119 | + ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => static function(MediaWikiServices $services) { |
|
120 | + $deserializerFactory = WikibaseRepo::getBaseDataModelDeserializerFactory($services); |
|
121 | + $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
122 | 122 | |
123 | 123 | return new ConstraintParameterParser( |
124 | 124 | $services->getMainConfig(), |
125 | 125 | $deserializerFactory, |
126 | - $entitySourceDefinitions->getDatabaseSourceForEntityType( 'item' )->getConceptBaseUri() |
|
126 | + $entitySourceDefinitions->getDatabaseSourceForEntityType('item')->getConceptBaseUri() |
|
127 | 127 | ); |
128 | 128 | }, |
129 | 129 | |
130 | - ConstraintsServices::CONNECTION_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
130 | + ConstraintsServices::CONNECTION_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
131 | 131 | return new ConnectionCheckerHelper(); |
132 | 132 | }, |
133 | 133 | |
134 | - ConstraintsServices::RANGE_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
134 | + ConstraintsServices::RANGE_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
135 | 135 | return new RangeCheckerHelper( |
136 | 136 | $services->getMainConfig(), |
137 | - WikibaseRepo::getUnitConverter( $services ) |
|
137 | + WikibaseRepo::getUnitConverter($services) |
|
138 | 138 | ); |
139 | 139 | }, |
140 | 140 | |
141 | - ConstraintsServices::SPARQL_HELPER => static function ( MediaWikiServices $services ) { |
|
142 | - $endpoint = $services->getMainConfig()->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
143 | - if ( $endpoint === '' ) { |
|
141 | + ConstraintsServices::SPARQL_HELPER => static function(MediaWikiServices $services) { |
|
142 | + $endpoint = $services->getMainConfig()->get('WBQualityConstraintsSparqlEndpoint'); |
|
143 | + if ($endpoint === '') { |
|
144 | 144 | return new DummySparqlHelper(); |
145 | 145 | } |
146 | 146 | |
147 | - $rdfVocabulary = WikibaseRepo::getRdfVocabulary( $services ); |
|
148 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
149 | - $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup( $services ); |
|
147 | + $rdfVocabulary = WikibaseRepo::getRdfVocabulary($services); |
|
148 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
149 | + $propertyDataTypeLookup = WikibaseRepo::getPropertyDataTypeLookup($services); |
|
150 | 150 | |
151 | 151 | return new SparqlHelper( |
152 | 152 | $services->getMainConfig(), |
@@ -154,126 +154,126 @@ discard block |
||
154 | 154 | $entityIdParser, |
155 | 155 | $propertyDataTypeLookup, |
156 | 156 | $services->getMainWANObjectCache(), |
157 | - ConstraintsServices::getViolationMessageSerializer( $services ), |
|
158 | - ConstraintsServices::getViolationMessageDeserializer( $services ), |
|
157 | + ConstraintsServices::getViolationMessageSerializer($services), |
|
158 | + ConstraintsServices::getViolationMessageDeserializer($services), |
|
159 | 159 | $services->getStatsdDataFactory(), |
160 | - ConstraintsServices::getExpiryLock( $services ), |
|
161 | - ConstraintsServices::getLoggingHelper( $services ), |
|
162 | - WikiMap::getCurrentWikiId() . ' WikibaseQualityConstraints ' . $services->getHttpRequestFactory()->getUserAgent(), |
|
160 | + ConstraintsServices::getExpiryLock($services), |
|
161 | + ConstraintsServices::getLoggingHelper($services), |
|
162 | + WikiMap::getCurrentWikiId().' WikibaseQualityConstraints '.$services->getHttpRequestFactory()->getUserAgent(), |
|
163 | 163 | $services->getHttpRequestFactory() |
164 | 164 | ); |
165 | 165 | }, |
166 | 166 | |
167 | - ConstraintsServices::TYPE_CHECKER_HELPER => static function ( MediaWikiServices $services ) { |
|
167 | + ConstraintsServices::TYPE_CHECKER_HELPER => static function(MediaWikiServices $services) { |
|
168 | 168 | return new TypeCheckerHelper( |
169 | - WikibaseServices::getEntityLookup( $services ), |
|
169 | + WikibaseServices::getEntityLookup($services), |
|
170 | 170 | $services->getMainConfig(), |
171 | - ConstraintsServices::getSparqlHelper( $services ), |
|
171 | + ConstraintsServices::getSparqlHelper($services), |
|
172 | 172 | $services->getStatsdDataFactory() |
173 | 173 | ); |
174 | 174 | }, |
175 | 175 | |
176 | - ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function ( MediaWikiServices $services ) { |
|
177 | - $statementGuidParser = WikibaseRepo::getStatementGuidParser( $services ); |
|
176 | + ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => static function(MediaWikiServices $services) { |
|
177 | + $statementGuidParser = WikibaseRepo::getStatementGuidParser($services); |
|
178 | 178 | |
179 | 179 | $config = $services->getMainConfig(); |
180 | 180 | $checkerMap = [ |
181 | - $config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
182 | - => ConstraintCheckerServices::getConflictsWithChecker( $services ), |
|
183 | - $config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
184 | - => ConstraintCheckerServices::getItemChecker( $services ), |
|
185 | - $config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
186 | - => ConstraintCheckerServices::getTargetRequiredClaimChecker( $services ), |
|
187 | - $config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
188 | - => ConstraintCheckerServices::getSymmetricChecker( $services ), |
|
189 | - $config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
190 | - => ConstraintCheckerServices::getInverseChecker( $services ), |
|
191 | - $config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
192 | - => ConstraintCheckerServices::getQualifierChecker( $services ), |
|
193 | - $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
194 | - => ConstraintCheckerServices::getQualifiersChecker( $services ), |
|
195 | - $config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
196 | - => ConstraintCheckerServices::getMandatoryQualifiersChecker( $services ), |
|
197 | - $config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
198 | - => ConstraintCheckerServices::getRangeChecker( $services ), |
|
199 | - $config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
200 | - => ConstraintCheckerServices::getDiffWithinRangeChecker( $services ), |
|
201 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
202 | - => ConstraintCheckerServices::getTypeChecker( $services ), |
|
203 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
204 | - => ConstraintCheckerServices::getValueTypeChecker( $services ), |
|
205 | - $config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
206 | - => ConstraintCheckerServices::getSingleValueChecker( $services ), |
|
207 | - $config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
208 | - => ConstraintCheckerServices::getMultiValueChecker( $services ), |
|
209 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
210 | - => ConstraintCheckerServices::getUniqueValueChecker( $services ), |
|
211 | - $config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
212 | - => ConstraintCheckerServices::getFormatChecker( $services ), |
|
213 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
214 | - => ConstraintCheckerServices::getCommonsLinkChecker( $services ), |
|
215 | - $config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
216 | - => ConstraintCheckerServices::getOneOfChecker( $services ), |
|
217 | - $config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
218 | - => ConstraintCheckerServices::getValueOnlyChecker( $services ), |
|
219 | - $config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
220 | - => ConstraintCheckerServices::getReferenceChecker( $services ), |
|
221 | - $config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
|
222 | - => ConstraintCheckerServices::getNoBoundsChecker( $services ), |
|
223 | - $config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
|
224 | - => ConstraintCheckerServices::getAllowedUnitsChecker( $services ), |
|
225 | - $config->get( 'WBQualityConstraintsSingleBestValueConstraintId' ) |
|
226 | - => ConstraintCheckerServices::getSingleBestValueChecker( $services ), |
|
227 | - $config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' ) |
|
228 | - => ConstraintCheckerServices::getEntityTypeChecker( $services ), |
|
229 | - $config->get( 'WBQualityConstraintsNoneOfConstraintId' ) |
|
230 | - => ConstraintCheckerServices::getNoneOfChecker( $services ), |
|
231 | - $config->get( 'WBQualityConstraintsIntegerConstraintId' ) |
|
232 | - => ConstraintCheckerServices::getIntegerChecker( $services ), |
|
233 | - $config->get( 'WBQualityConstraintsCitationNeededConstraintId' ) |
|
234 | - => ConstraintCheckerServices::getCitationNeededChecker( $services ), |
|
235 | - $config->get( 'WBQualityConstraintsPropertyScopeConstraintId' ) |
|
236 | - => ConstraintCheckerServices::getPropertyScopeChecker( $services ), |
|
237 | - $config->get( 'WBQualityConstraintsContemporaryConstraintId' ) |
|
238 | - => ConstraintCheckerServices::getContemporaryChecker( $services ), |
|
239 | - $config->get( 'WBQualityConstraintsLexemeLanguageConstraintId' ) |
|
240 | - => ConstraintCheckerServices::getLexemeLanguageChecker( $services ), |
|
241 | - $config->get( 'WBQualityConstraintsLabelInLanguageConstraintId' ) |
|
242 | - => ConstraintCheckerServices::getLabelInLanguageChecker( $services ), |
|
181 | + $config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
182 | + => ConstraintCheckerServices::getConflictsWithChecker($services), |
|
183 | + $config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
184 | + => ConstraintCheckerServices::getItemChecker($services), |
|
185 | + $config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
186 | + => ConstraintCheckerServices::getTargetRequiredClaimChecker($services), |
|
187 | + $config->get('WBQualityConstraintsSymmetricConstraintId') |
|
188 | + => ConstraintCheckerServices::getSymmetricChecker($services), |
|
189 | + $config->get('WBQualityConstraintsInverseConstraintId') |
|
190 | + => ConstraintCheckerServices::getInverseChecker($services), |
|
191 | + $config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
192 | + => ConstraintCheckerServices::getQualifierChecker($services), |
|
193 | + $config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
194 | + => ConstraintCheckerServices::getQualifiersChecker($services), |
|
195 | + $config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
196 | + => ConstraintCheckerServices::getMandatoryQualifiersChecker($services), |
|
197 | + $config->get('WBQualityConstraintsRangeConstraintId') |
|
198 | + => ConstraintCheckerServices::getRangeChecker($services), |
|
199 | + $config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
200 | + => ConstraintCheckerServices::getDiffWithinRangeChecker($services), |
|
201 | + $config->get('WBQualityConstraintsTypeConstraintId') |
|
202 | + => ConstraintCheckerServices::getTypeChecker($services), |
|
203 | + $config->get('WBQualityConstraintsValueTypeConstraintId') |
|
204 | + => ConstraintCheckerServices::getValueTypeChecker($services), |
|
205 | + $config->get('WBQualityConstraintsSingleValueConstraintId') |
|
206 | + => ConstraintCheckerServices::getSingleValueChecker($services), |
|
207 | + $config->get('WBQualityConstraintsMultiValueConstraintId') |
|
208 | + => ConstraintCheckerServices::getMultiValueChecker($services), |
|
209 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
210 | + => ConstraintCheckerServices::getUniqueValueChecker($services), |
|
211 | + $config->get('WBQualityConstraintsFormatConstraintId') |
|
212 | + => ConstraintCheckerServices::getFormatChecker($services), |
|
213 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
214 | + => ConstraintCheckerServices::getCommonsLinkChecker($services), |
|
215 | + $config->get('WBQualityConstraintsOneOfConstraintId') |
|
216 | + => ConstraintCheckerServices::getOneOfChecker($services), |
|
217 | + $config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
218 | + => ConstraintCheckerServices::getValueOnlyChecker($services), |
|
219 | + $config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
220 | + => ConstraintCheckerServices::getReferenceChecker($services), |
|
221 | + $config->get('WBQualityConstraintsNoBoundsConstraintId') |
|
222 | + => ConstraintCheckerServices::getNoBoundsChecker($services), |
|
223 | + $config->get('WBQualityConstraintsAllowedUnitsConstraintId') |
|
224 | + => ConstraintCheckerServices::getAllowedUnitsChecker($services), |
|
225 | + $config->get('WBQualityConstraintsSingleBestValueConstraintId') |
|
226 | + => ConstraintCheckerServices::getSingleBestValueChecker($services), |
|
227 | + $config->get('WBQualityConstraintsAllowedEntityTypesConstraintId') |
|
228 | + => ConstraintCheckerServices::getEntityTypeChecker($services), |
|
229 | + $config->get('WBQualityConstraintsNoneOfConstraintId') |
|
230 | + => ConstraintCheckerServices::getNoneOfChecker($services), |
|
231 | + $config->get('WBQualityConstraintsIntegerConstraintId') |
|
232 | + => ConstraintCheckerServices::getIntegerChecker($services), |
|
233 | + $config->get('WBQualityConstraintsCitationNeededConstraintId') |
|
234 | + => ConstraintCheckerServices::getCitationNeededChecker($services), |
|
235 | + $config->get('WBQualityConstraintsPropertyScopeConstraintId') |
|
236 | + => ConstraintCheckerServices::getPropertyScopeChecker($services), |
|
237 | + $config->get('WBQualityConstraintsContemporaryConstraintId') |
|
238 | + => ConstraintCheckerServices::getContemporaryChecker($services), |
|
239 | + $config->get('WBQualityConstraintsLexemeLanguageConstraintId') |
|
240 | + => ConstraintCheckerServices::getLexemeLanguageChecker($services), |
|
241 | + $config->get('WBQualityConstraintsLabelInLanguageConstraintId') |
|
242 | + => ConstraintCheckerServices::getLabelInLanguageChecker($services), |
|
243 | 243 | ]; |
244 | 244 | |
245 | 245 | return new DelegatingConstraintChecker( |
246 | - WikibaseServices::getEntityLookup( $services ), |
|
246 | + WikibaseServices::getEntityLookup($services), |
|
247 | 247 | $checkerMap, |
248 | - ConstraintsServices::getConstraintLookup( $services ), |
|
249 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
248 | + ConstraintsServices::getConstraintLookup($services), |
|
249 | + ConstraintsServices::getConstraintParameterParser($services), |
|
250 | 250 | $statementGuidParser, |
251 | - ConstraintsServices::getLoggingHelper( $services ), |
|
252 | - $config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
253 | - $config->get( 'WBQualityConstraintsCheckReferences' ), |
|
254 | - $config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
251 | + ConstraintsServices::getLoggingHelper($services), |
|
252 | + $config->get('WBQualityConstraintsCheckQualifiers'), |
|
253 | + $config->get('WBQualityConstraintsCheckReferences'), |
|
254 | + $config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
255 | 255 | ); |
256 | 256 | }, |
257 | 257 | |
258 | - ConstraintsServices::RESULTS_SOURCE => static function ( MediaWikiServices $services ) { |
|
258 | + ConstraintsServices::RESULTS_SOURCE => static function(MediaWikiServices $services) { |
|
259 | 259 | $config = $services->getMainConfig(); |
260 | 260 | $resultsSource = new CheckingResultsSource( |
261 | - ConstraintsServices::getDelegatingConstraintChecker( $services ) |
|
261 | + ConstraintsServices::getDelegatingConstraintChecker($services) |
|
262 | 262 | ); |
263 | 263 | |
264 | 264 | $cacheCheckConstraintsResults = false; |
265 | 265 | |
266 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
266 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
267 | 267 | $cacheCheckConstraintsResults = true; |
268 | 268 | // check that we can use getLocalRepoWikiPageMetaDataAccessor() |
269 | 269 | // TODO we should always be able to cache constraint check results (T244726) |
270 | - $entitySources = WikibaseRepo::getEntitySourceDefinitions( $services )->getSources(); |
|
271 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
270 | + $entitySources = WikibaseRepo::getEntitySourceDefinitions($services)->getSources(); |
|
271 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
272 | 272 | |
273 | - foreach ( $entitySources as $entitySource ) { |
|
274 | - if ( $entitySource->getSourceName() !== $localEntitySourceName ) { |
|
275 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' )->warning( |
|
276 | - 'Cannot cache constraint check results for non-local source: ' . |
|
273 | + foreach ($entitySources as $entitySource) { |
|
274 | + if ($entitySource->getSourceName() !== $localEntitySourceName) { |
|
275 | + LoggerFactory::getInstance('WikibaseQualityConstraints')->warning( |
|
276 | + 'Cannot cache constraint check results for non-local source: '. |
|
277 | 277 | $entitySource->getSourceName() |
278 | 278 | ); |
279 | 279 | $cacheCheckConstraintsResults = false; |
@@ -282,40 +282,40 @@ discard block |
||
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
285 | - if ( $cacheCheckConstraintsResults ) { |
|
285 | + if ($cacheCheckConstraintsResults) { |
|
286 | 286 | $possiblyStaleConstraintTypes = [ |
287 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
288 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
289 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
290 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
287 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
288 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
289 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
290 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
291 | 291 | ]; |
292 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
292 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
293 | 293 | $wikiPageEntityMetaDataAccessor = WikibaseRepo::getLocalRepoWikiPageMetaDataAccessor( |
294 | 294 | $services ); |
295 | 295 | |
296 | 296 | $resultsSource = new CachingResultsSource( |
297 | 297 | $resultsSource, |
298 | 298 | ResultsCache::getDefaultInstance(), |
299 | - ConstraintsServices::getCheckResultSerializer( $services ), |
|
300 | - ConstraintsServices::getCheckResultDeserializer( $services ), |
|
299 | + ConstraintsServices::getCheckResultSerializer($services), |
|
300 | + ConstraintsServices::getCheckResultDeserializer($services), |
|
301 | 301 | $wikiPageEntityMetaDataAccessor, |
302 | 302 | $entityIdParser, |
303 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
303 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
304 | 304 | $possiblyStaleConstraintTypes, |
305 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
306 | - ConstraintsServices::getLoggingHelper( $services ) |
|
305 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
306 | + ConstraintsServices::getLoggingHelper($services) |
|
307 | 307 | ); |
308 | 308 | } |
309 | 309 | |
310 | 310 | return $resultsSource; |
311 | 311 | }, |
312 | 312 | |
313 | - ConstraintsServices::VIOLATION_MESSAGE_RENDERER_FACTORY => static function ( MediaWikiServices $services ) { |
|
313 | + ConstraintsServices::VIOLATION_MESSAGE_RENDERER_FACTORY => static function(MediaWikiServices $services) { |
|
314 | 314 | return new ViolationMessageRendererFactory( |
315 | 315 | $services->getMainConfig(), |
316 | 316 | $services->getLanguageNameUtils(), |
317 | - WikibaseRepo::getEntityIdHtmlLinkFormatterFactory( $services ), |
|
318 | - WikibaseRepo::getValueFormatterFactory( $services ) |
|
317 | + WikibaseRepo::getEntityIdHtmlLinkFormatterFactory($services), |
|
318 | + WikibaseRepo::getValueFormatterFactory($services) |
|
319 | 319 | ); |
320 | 320 | }, |
321 | 321 | ]; |