@@ -28,47 +28,47 @@ discard block |
||
28 | 28 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResultSerializer; |
29 | 29 | |
30 | 30 | return [ |
31 | - ConstraintsServices::EXPIRY_LOCK => function( MediaWikiServices $services ) { |
|
32 | - return new ExpiryLock( ObjectCache::getInstance( CACHE_ANYTHING ) ); |
|
31 | + ConstraintsServices::EXPIRY_LOCK => function(MediaWikiServices $services) { |
|
32 | + return new ExpiryLock(ObjectCache::getInstance(CACHE_ANYTHING)); |
|
33 | 33 | }, |
34 | 34 | |
35 | - ConstraintsServices::LOGGING_HELPER => function( MediaWikiServices $services ) { |
|
35 | + ConstraintsServices::LOGGING_HELPER => function(MediaWikiServices $services) { |
|
36 | 36 | return new LoggingHelper( |
37 | 37 | $services->getStatsdDataFactory(), |
38 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' ), |
|
38 | + LoggerFactory::getInstance('WikibaseQualityConstraints'), |
|
39 | 39 | $services->getMainConfig() |
40 | 40 | ); |
41 | 41 | }, |
42 | 42 | |
43 | - ConstraintsServices::CONSTRAINT_STORE => function( MediaWikiServices $services ) { |
|
43 | + ConstraintsServices::CONSTRAINT_STORE => function(MediaWikiServices $services) { |
|
44 | 44 | $wbRepo = WikibaseRepo::getDefaultInstance(); |
45 | 45 | $sourceDefinitions = $wbRepo->getEntitySourceDefinitions(); |
46 | - $propertySource = $sourceDefinitions->getSourceForEntityType( Property::ENTITY_TYPE ); |
|
46 | + $propertySource = $sourceDefinitions->getSourceForEntityType(Property::ENTITY_TYPE); |
|
47 | 47 | $dbName = $propertySource->getDatabaseName(); |
48 | 48 | |
49 | - if ( $propertySource->getSourceName() !== $wbRepo->getLocalEntitySource()->getSourceName() ) { |
|
50 | - throw new \RuntimeException( 'Can\'t get a ConstraintStore for a non local entity source.' ); |
|
49 | + if ($propertySource->getSourceName() !== $wbRepo->getLocalEntitySource()->getSourceName()) { |
|
50 | + throw new \RuntimeException('Can\'t get a ConstraintStore for a non local entity source.'); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | return new ConstraintRepositoryStore( |
54 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
54 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
55 | 55 | $dbName |
56 | 56 | ); |
57 | 57 | }, |
58 | 58 | |
59 | - ConstraintsServices::CONSTRAINT_LOOKUP => function( MediaWikiServices $services ) { |
|
59 | + ConstraintsServices::CONSTRAINT_LOOKUP => function(MediaWikiServices $services) { |
|
60 | 60 | $wbRepo = WikibaseRepo::getDefaultInstance(); |
61 | 61 | $sourceDefinitions = $wbRepo->getEntitySourceDefinitions(); |
62 | - $propertySource = $sourceDefinitions->getSourceForEntityType( Property::ENTITY_TYPE ); |
|
62 | + $propertySource = $sourceDefinitions->getSourceForEntityType(Property::ENTITY_TYPE); |
|
63 | 63 | $dbName = $propertySource->getDatabaseName(); |
64 | 64 | $rawLookup = new ConstraintRepositoryLookup( |
65 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
65 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
66 | 66 | $dbName |
67 | 67 | ); |
68 | - return new CachingConstraintLookup( $rawLookup ); |
|
68 | + return new CachingConstraintLookup($rawLookup); |
|
69 | 69 | }, |
70 | 70 | |
71 | - ConstraintsServices::CHECK_RESULT_SERIALIZER => function( MediaWikiServices $services ) { |
|
71 | + ConstraintsServices::CHECK_RESULT_SERIALIZER => function(MediaWikiServices $services) { |
|
72 | 72 | return new CheckResultSerializer( |
73 | 73 | new ConstraintSerializer( |
74 | 74 | false // constraint parameters are not exposed |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | ); |
80 | 80 | }, |
81 | 81 | |
82 | - ConstraintsServices::CHECK_RESULT_DESERIALIZER => function( MediaWikiServices $services ) { |
|
82 | + ConstraintsServices::CHECK_RESULT_DESERIALIZER => function(MediaWikiServices $services) { |
|
83 | 83 | // TODO in the future, get EntityIdParser and DataValueFactory from $services? |
84 | 84 | $repo = WikibaseRepo::getDefaultInstance(); |
85 | 85 | $entityIdParser = $repo->getEntityIdParser(); |
@@ -96,11 +96,11 @@ discard block |
||
96 | 96 | ); |
97 | 97 | }, |
98 | 98 | |
99 | - ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => function( MediaWikiServices $services ) { |
|
99 | + ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => function(MediaWikiServices $services) { |
|
100 | 100 | return new ViolationMessageSerializer(); |
101 | 101 | }, |
102 | 102 | |
103 | - ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => function( MediaWikiServices $services ) { |
|
103 | + ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => function(MediaWikiServices $services) { |
|
104 | 104 | // TODO in the future, get EntityIdParser and DataValueFactory from $services? |
105 | 105 | $repo = WikibaseRepo::getDefaultInstance(); |
106 | 106 | $entityIdParser = $repo->getEntityIdParser(); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | ); |
113 | 113 | }, |
114 | 114 | |
115 | - ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => function( MediaWikiServices $services ) { |
|
115 | + ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => function(MediaWikiServices $services) { |
|
116 | 116 | // TODO in the future, get DeserializerFactory and entity source definitions from $services? |
117 | 117 | $repo = WikibaseRepo::getDefaultInstance(); |
118 | 118 | $deserializerFactory = $repo->getBaseDataModelDeserializerFactory(); |
@@ -121,15 +121,15 @@ discard block |
||
121 | 121 | return new ConstraintParameterParser( |
122 | 122 | $services->getMainConfig(), |
123 | 123 | $deserializerFactory, |
124 | - $entitySourceDefinitions->getSourceForEntityType( 'item' )->getConceptBaseUri() |
|
124 | + $entitySourceDefinitions->getSourceForEntityType('item')->getConceptBaseUri() |
|
125 | 125 | ); |
126 | 126 | }, |
127 | 127 | |
128 | - ConstraintsServices::CONNECTION_CHECKER_HELPER => function( MediaWikiServices $services ) { |
|
128 | + ConstraintsServices::CONNECTION_CHECKER_HELPER => function(MediaWikiServices $services) { |
|
129 | 129 | return new ConnectionCheckerHelper(); |
130 | 130 | }, |
131 | 131 | |
132 | - ConstraintsServices::RANGE_CHECKER_HELPER => function( MediaWikiServices $services ) { |
|
132 | + ConstraintsServices::RANGE_CHECKER_HELPER => function(MediaWikiServices $services) { |
|
133 | 133 | // TODO in the future, get UnitConverter from $services? |
134 | 134 | $repo = WikibaseRepo::getDefaultInstance(); |
135 | 135 | $unitConverter = $repo->getUnitConverter(); |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | ); |
141 | 141 | }, |
142 | 142 | |
143 | - ConstraintsServices::SPARQL_HELPER => function( MediaWikiServices $services ) { |
|
144 | - $endpoint = $services->getMainConfig()->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
145 | - if ( $endpoint === '' ) { |
|
143 | + ConstraintsServices::SPARQL_HELPER => function(MediaWikiServices $services) { |
|
144 | + $endpoint = $services->getMainConfig()->get('WBQualityConstraintsSparqlEndpoint'); |
|
145 | + if ($endpoint === '') { |
|
146 | 146 | return new DummySparqlHelper(); |
147 | 147 | } |
148 | 148 | |
@@ -158,122 +158,122 @@ discard block |
||
158 | 158 | $entityIdParser, |
159 | 159 | $propertyDataTypeLookup, |
160 | 160 | $services->getMainWANObjectCache(), |
161 | - ConstraintsServices::getViolationMessageSerializer( $services ), |
|
162 | - ConstraintsServices::getViolationMessageDeserializer( $services ), |
|
161 | + ConstraintsServices::getViolationMessageSerializer($services), |
|
162 | + ConstraintsServices::getViolationMessageDeserializer($services), |
|
163 | 163 | $services->getStatsdDataFactory(), |
164 | - ConstraintsServices::getExpiryLock( $services ), |
|
164 | + ConstraintsServices::getExpiryLock($services), |
|
165 | 165 | ConstraintsServices::getLoggingHelper(), |
166 | - wfWikiID() . ' WikibaseQualityConstraints ' . Http::userAgent(), |
|
166 | + wfWikiID().' WikibaseQualityConstraints '.Http::userAgent(), |
|
167 | 167 | $services->getHttpRequestFactory() |
168 | 168 | ); |
169 | 169 | }, |
170 | 170 | |
171 | - ConstraintsServices::TYPE_CHECKER_HELPER => function( MediaWikiServices $services ) { |
|
171 | + ConstraintsServices::TYPE_CHECKER_HELPER => function(MediaWikiServices $services) { |
|
172 | 172 | return new TypeCheckerHelper( |
173 | - WikibaseServices::getEntityLookup( $services ), |
|
173 | + WikibaseServices::getEntityLookup($services), |
|
174 | 174 | $services->getMainConfig(), |
175 | - ConstraintsServices::getSparqlHelper( $services ), |
|
175 | + ConstraintsServices::getSparqlHelper($services), |
|
176 | 176 | $services->getStatsdDataFactory() |
177 | 177 | ); |
178 | 178 | }, |
179 | 179 | |
180 | - ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => function( MediaWikiServices $services ) { |
|
180 | + ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => function(MediaWikiServices $services) { |
|
181 | 181 | // TODO in the future, get StatementGuidParser from $services? |
182 | 182 | $repo = WikibaseRepo::getDefaultInstance(); |
183 | 183 | $statementGuidParser = $repo->getStatementGuidParser(); |
184 | 184 | |
185 | 185 | $config = $services->getMainConfig(); |
186 | 186 | $checkerMap = [ |
187 | - $config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
188 | - => ConstraintCheckerServices::getConflictsWithChecker( $services ), |
|
189 | - $config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
190 | - => ConstraintCheckerServices::getItemChecker( $services ), |
|
191 | - $config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
192 | - => ConstraintCheckerServices::getTargetRequiredClaimChecker( $services ), |
|
193 | - $config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
194 | - => ConstraintCheckerServices::getSymmetricChecker( $services ), |
|
195 | - $config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
196 | - => ConstraintCheckerServices::getInverseChecker( $services ), |
|
197 | - $config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
198 | - => ConstraintCheckerServices::getQualifierChecker( $services ), |
|
199 | - $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
200 | - => ConstraintCheckerServices::getQualifiersChecker( $services ), |
|
201 | - $config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
202 | - => ConstraintCheckerServices::getMandatoryQualifiersChecker( $services ), |
|
203 | - $config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
204 | - => ConstraintCheckerServices::getRangeChecker( $services ), |
|
205 | - $config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
206 | - => ConstraintCheckerServices::getDiffWithinRangeChecker( $services ), |
|
207 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
208 | - => ConstraintCheckerServices::getTypeChecker( $services ), |
|
209 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
210 | - => ConstraintCheckerServices::getValueTypeChecker( $services ), |
|
211 | - $config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
212 | - => ConstraintCheckerServices::getSingleValueChecker( $services ), |
|
213 | - $config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
214 | - => ConstraintCheckerServices::getMultiValueChecker( $services ), |
|
215 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
216 | - => ConstraintCheckerServices::getUniqueValueChecker( $services ), |
|
217 | - $config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
218 | - => ConstraintCheckerServices::getFormatChecker( $services ), |
|
219 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
220 | - => ConstraintCheckerServices::getCommonsLinkChecker( $services ), |
|
221 | - $config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
222 | - => ConstraintCheckerServices::getOneOfChecker( $services ), |
|
223 | - $config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
224 | - => ConstraintCheckerServices::getValueOnlyChecker( $services ), |
|
225 | - $config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
226 | - => ConstraintCheckerServices::getReferenceChecker( $services ), |
|
227 | - $config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
|
228 | - => ConstraintCheckerServices::getNoBoundsChecker( $services ), |
|
229 | - $config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
|
230 | - => ConstraintCheckerServices::getAllowedUnitsChecker( $services ), |
|
231 | - $config->get( 'WBQualityConstraintsSingleBestValueConstraintId' ) |
|
232 | - => ConstraintCheckerServices::getSingleBestValueChecker( $services ), |
|
233 | - $config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' ) |
|
234 | - => ConstraintCheckerServices::getEntityTypeChecker( $services ), |
|
235 | - $config->get( 'WBQualityConstraintsNoneOfConstraintId' ) |
|
236 | - => ConstraintCheckerServices::getNoneOfChecker( $services ), |
|
237 | - $config->get( 'WBQualityConstraintsIntegerConstraintId' ) |
|
238 | - => ConstraintCheckerServices::getIntegerChecker( $services ), |
|
239 | - $config->get( 'WBQualityConstraintsCitationNeededConstraintId' ) |
|
240 | - => ConstraintCheckerServices::getCitationNeededChecker( $services ), |
|
241 | - $config->get( 'WBQualityConstraintsPropertyScopeConstraintId' ) |
|
242 | - => ConstraintCheckerServices::getPropertyScopeChecker( $services ), |
|
243 | - $config->get( 'WBQualityConstraintsContemporaryConstraintId' ) |
|
244 | - => ConstraintCheckerServices::getContemporaryChecker( $services ), |
|
187 | + $config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
188 | + => ConstraintCheckerServices::getConflictsWithChecker($services), |
|
189 | + $config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
190 | + => ConstraintCheckerServices::getItemChecker($services), |
|
191 | + $config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
192 | + => ConstraintCheckerServices::getTargetRequiredClaimChecker($services), |
|
193 | + $config->get('WBQualityConstraintsSymmetricConstraintId') |
|
194 | + => ConstraintCheckerServices::getSymmetricChecker($services), |
|
195 | + $config->get('WBQualityConstraintsInverseConstraintId') |
|
196 | + => ConstraintCheckerServices::getInverseChecker($services), |
|
197 | + $config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
198 | + => ConstraintCheckerServices::getQualifierChecker($services), |
|
199 | + $config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
200 | + => ConstraintCheckerServices::getQualifiersChecker($services), |
|
201 | + $config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
202 | + => ConstraintCheckerServices::getMandatoryQualifiersChecker($services), |
|
203 | + $config->get('WBQualityConstraintsRangeConstraintId') |
|
204 | + => ConstraintCheckerServices::getRangeChecker($services), |
|
205 | + $config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
206 | + => ConstraintCheckerServices::getDiffWithinRangeChecker($services), |
|
207 | + $config->get('WBQualityConstraintsTypeConstraintId') |
|
208 | + => ConstraintCheckerServices::getTypeChecker($services), |
|
209 | + $config->get('WBQualityConstraintsValueTypeConstraintId') |
|
210 | + => ConstraintCheckerServices::getValueTypeChecker($services), |
|
211 | + $config->get('WBQualityConstraintsSingleValueConstraintId') |
|
212 | + => ConstraintCheckerServices::getSingleValueChecker($services), |
|
213 | + $config->get('WBQualityConstraintsMultiValueConstraintId') |
|
214 | + => ConstraintCheckerServices::getMultiValueChecker($services), |
|
215 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
216 | + => ConstraintCheckerServices::getUniqueValueChecker($services), |
|
217 | + $config->get('WBQualityConstraintsFormatConstraintId') |
|
218 | + => ConstraintCheckerServices::getFormatChecker($services), |
|
219 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
220 | + => ConstraintCheckerServices::getCommonsLinkChecker($services), |
|
221 | + $config->get('WBQualityConstraintsOneOfConstraintId') |
|
222 | + => ConstraintCheckerServices::getOneOfChecker($services), |
|
223 | + $config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
224 | + => ConstraintCheckerServices::getValueOnlyChecker($services), |
|
225 | + $config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
226 | + => ConstraintCheckerServices::getReferenceChecker($services), |
|
227 | + $config->get('WBQualityConstraintsNoBoundsConstraintId') |
|
228 | + => ConstraintCheckerServices::getNoBoundsChecker($services), |
|
229 | + $config->get('WBQualityConstraintsAllowedUnitsConstraintId') |
|
230 | + => ConstraintCheckerServices::getAllowedUnitsChecker($services), |
|
231 | + $config->get('WBQualityConstraintsSingleBestValueConstraintId') |
|
232 | + => ConstraintCheckerServices::getSingleBestValueChecker($services), |
|
233 | + $config->get('WBQualityConstraintsAllowedEntityTypesConstraintId') |
|
234 | + => ConstraintCheckerServices::getEntityTypeChecker($services), |
|
235 | + $config->get('WBQualityConstraintsNoneOfConstraintId') |
|
236 | + => ConstraintCheckerServices::getNoneOfChecker($services), |
|
237 | + $config->get('WBQualityConstraintsIntegerConstraintId') |
|
238 | + => ConstraintCheckerServices::getIntegerChecker($services), |
|
239 | + $config->get('WBQualityConstraintsCitationNeededConstraintId') |
|
240 | + => ConstraintCheckerServices::getCitationNeededChecker($services), |
|
241 | + $config->get('WBQualityConstraintsPropertyScopeConstraintId') |
|
242 | + => ConstraintCheckerServices::getPropertyScopeChecker($services), |
|
243 | + $config->get('WBQualityConstraintsContemporaryConstraintId') |
|
244 | + => ConstraintCheckerServices::getContemporaryChecker($services), |
|
245 | 245 | ]; |
246 | 246 | |
247 | 247 | return new DelegatingConstraintChecker( |
248 | - WikibaseServices::getEntityLookup( $services ), |
|
248 | + WikibaseServices::getEntityLookup($services), |
|
249 | 249 | $checkerMap, |
250 | - ConstraintsServices::getConstraintLookup( $services ), |
|
251 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
250 | + ConstraintsServices::getConstraintLookup($services), |
|
251 | + ConstraintsServices::getConstraintParameterParser($services), |
|
252 | 252 | $statementGuidParser, |
253 | - ConstraintsServices::getLoggingHelper( $services ), |
|
254 | - $config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
255 | - $config->get( 'WBQualityConstraintsCheckReferences' ), |
|
256 | - $config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
253 | + ConstraintsServices::getLoggingHelper($services), |
|
254 | + $config->get('WBQualityConstraintsCheckQualifiers'), |
|
255 | + $config->get('WBQualityConstraintsCheckReferences'), |
|
256 | + $config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
257 | 257 | ); |
258 | 258 | }, |
259 | 259 | |
260 | - ConstraintsServices::RESULTS_SOURCE => function( MediaWikiServices $services ) { |
|
260 | + ConstraintsServices::RESULTS_SOURCE => function(MediaWikiServices $services) { |
|
261 | 261 | $config = $services->getMainConfig(); |
262 | 262 | $resultsSource = new CheckingResultsSource( |
263 | - ConstraintsServices::getDelegatingConstraintChecker( $services ) |
|
263 | + ConstraintsServices::getDelegatingConstraintChecker($services) |
|
264 | 264 | ); |
265 | 265 | |
266 | 266 | $cacheCheckConstraintsResults = false; |
267 | 267 | |
268 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
268 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
269 | 269 | $cacheCheckConstraintsResults = true; |
270 | 270 | // check that we can use getLocalRepoWikiPageMetaDataAccessor() |
271 | 271 | // TODO we should always be able to cache constraint check results (T244726) |
272 | 272 | $repo = WikibaseRepo::getDefaultInstance(); |
273 | - foreach ( $repo->getEntitySourceDefinitions()->getSources() as $entitySource ) { |
|
274 | - if ( $entitySource->getSourceName() !== $repo->getLocalEntitySource()->getSourceName() ) { |
|
275 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' )->warning( |
|
276 | - 'Cannot cache constraint check results for non-local source: ' . |
|
273 | + foreach ($repo->getEntitySourceDefinitions()->getSources() as $entitySource) { |
|
274 | + if ($entitySource->getSourceName() !== $repo->getLocalEntitySource()->getSourceName()) { |
|
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,12 +282,12 @@ 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 | 292 | // TODO in the future, get EntityIdParser and WikiPageEntityMetaDataAccessor from $services? |
293 | 293 | $repo = WikibaseRepo::getDefaultInstance(); |
@@ -297,14 +297,14 @@ discard block |
||
297 | 297 | $resultsSource = new CachingResultsSource( |
298 | 298 | $resultsSource, |
299 | 299 | ResultsCache::getDefaultInstance(), |
300 | - ConstraintsServices::getCheckResultSerializer( $services ), |
|
301 | - ConstraintsServices::getCheckResultDeserializer( $services ), |
|
300 | + ConstraintsServices::getCheckResultSerializer($services), |
|
301 | + ConstraintsServices::getCheckResultDeserializer($services), |
|
302 | 302 | $wikiPageEntityMetaDataAccessor, |
303 | 303 | $entityIdParser, |
304 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
304 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
305 | 305 | $possiblyStaleConstraintTypes, |
306 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
307 | - ConstraintsServices::getLoggingHelper( $services ) |
|
306 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
307 | + ConstraintsServices::getLoggingHelper($services) |
|
308 | 308 | ); |
309 | 309 | } |
310 | 310 |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | |
32 | 32 | const BATCH_SIZE = 10; |
33 | 33 | |
34 | - public static function newFromGlobalState( Title $title, array $params ) { |
|
35 | - Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' ); |
|
34 | + public static function newFromGlobalState(Title $title, array $params) { |
|
35 | + Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]'); |
|
36 | 36 | $repo = WikibaseRepo::getDefaultInstance(); |
37 | 37 | return new UpdateConstraintsTableJob( |
38 | 38 | $title, |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $params['revisionId'] ?? null, |
42 | 42 | MediaWikiServices::getInstance()->getMainConfig(), |
43 | 43 | ConstraintsServices::getConstraintStore(), |
44 | - $repo->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ), |
|
44 | + $repo->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED), |
|
45 | 45 | $repo->getBaseDataModelSerializerFactory()->newSnakSerializer() |
46 | 46 | ); |
47 | 47 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | EntityRevisionLookup $entityRevisionLookup, |
97 | 97 | Serializer $snakSerializer |
98 | 98 | ) { |
99 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
99 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
100 | 100 | |
101 | 101 | $this->propertyId = $propertyId; |
102 | 102 | $this->revisionId = $revisionId; |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | $this->snakSerializer = $snakSerializer; |
107 | 107 | } |
108 | 108 | |
109 | - public function extractParametersFromQualifiers( SnakList $qualifiers ) { |
|
109 | + public function extractParametersFromQualifiers(SnakList $qualifiers) { |
|
110 | 110 | $parameters = []; |
111 | - foreach ( $qualifiers as $qualifier ) { |
|
111 | + foreach ($qualifiers as $qualifier) { |
|
112 | 112 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
113 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
113 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
114 | 114 | $parameters[$qualifierId][] = $paramSerialization; |
115 | 115 | } |
116 | 116 | return $parameters; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | '@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue'; |
128 | 128 | $entityId = $dataValue->getEntityId(); |
129 | 129 | $constraintTypeQid = $entityId->getSerialization(); |
130 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
130 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
131 | 131 | return new Constraint( |
132 | 132 | $constraintId, |
133 | 133 | $propertyId, |
@@ -142,17 +142,17 @@ discard block |
||
142 | 142 | PropertyId $propertyConstraintPropertyId |
143 | 143 | ) { |
144 | 144 | $constraintsStatements = $property->getStatements() |
145 | - ->getByPropertyId( $propertyConstraintPropertyId ) |
|
146 | - ->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] ); |
|
145 | + ->getByPropertyId($propertyConstraintPropertyId) |
|
146 | + ->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]); |
|
147 | 147 | $constraints = []; |
148 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
149 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
150 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
151 | - $constraintStore->insertBatch( $constraints ); |
|
148 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
149 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
150 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
151 | + $constraintStore->insertBatch($constraints); |
|
152 | 152 | $constraints = []; |
153 | 153 | } |
154 | 154 | } |
155 | - $constraintStore->insertBatch( $constraints ); |
|
155 | + $constraintStore->insertBatch($constraints); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -163,19 +163,19 @@ discard block |
||
163 | 163 | public function run() { |
164 | 164 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
165 | 165 | |
166 | - $propertyId = new PropertyId( $this->propertyId ); |
|
166 | + $propertyId = new PropertyId($this->propertyId); |
|
167 | 167 | $propertyRevision = $this->entityRevisionLookup->getEntityRevision( |
168 | 168 | $propertyId, |
169 | 169 | 0, // latest |
170 | 170 | EntityRevisionLookup::LATEST_FROM_REPLICA |
171 | 171 | ); |
172 | 172 | |
173 | - if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) { |
|
174 | - JobQueueGroup::singleton()->push( $this ); |
|
173 | + if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) { |
|
174 | + JobQueueGroup::singleton()->push($this); |
|
175 | 175 | return true; |
176 | 176 | } |
177 | 177 | |
178 | - $this->constraintStore->deleteForProperty( $propertyId ); |
|
178 | + $this->constraintStore->deleteForProperty($propertyId); |
|
179 | 179 | |
180 | 180 | /** @var Property $property */ |
181 | 181 | $property = $propertyRevision->getEntity(); |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $this->importConstraintsForProperty( |
184 | 184 | $property, |
185 | 185 | $this->constraintStore, |
186 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
186 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
187 | 187 | ); |
188 | 188 | |
189 | 189 | return true; |
@@ -38,90 +38,90 @@ |
||
38 | 38 | const RESULTS_SOURCE = 'WBQC_ResultsSource'; |
39 | 39 | const EXPIRY_LOCK = 'WBQC_ExpiryLock'; |
40 | 40 | |
41 | - private static function getService( ?MediaWikiServices $services, $name ) { |
|
42 | - if ( $services === null ) { |
|
41 | + private static function getService(?MediaWikiServices $services, $name) { |
|
42 | + if ($services === null) { |
|
43 | 43 | $services = MediaWikiServices::getInstance(); |
44 | 44 | } |
45 | - return $services->getService( $name ); |
|
45 | + return $services->getService($name); |
|
46 | 46 | } |
47 | 47 | |
48 | - public static function getLoggingHelper( MediaWikiServices $services = null ): LoggingHelper { |
|
49 | - return self::getService( $services, self::LOGGING_HELPER ); |
|
48 | + public static function getLoggingHelper(MediaWikiServices $services = null): LoggingHelper { |
|
49 | + return self::getService($services, self::LOGGING_HELPER); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | public static function getConstraintStore( |
53 | 53 | MediaWikiServices $services = null |
54 | 54 | ): ConstraintStore { |
55 | - return self::getService( $services, self::CONSTRAINT_STORE ); |
|
55 | + return self::getService($services, self::CONSTRAINT_STORE); |
|
56 | 56 | } |
57 | 57 | |
58 | - public static function getConstraintLookup( MediaWikiServices $services = null ): ConstraintLookup { |
|
59 | - return self::getService( $services, self::CONSTRAINT_LOOKUP ); |
|
58 | + public static function getConstraintLookup(MediaWikiServices $services = null): ConstraintLookup { |
|
59 | + return self::getService($services, self::CONSTRAINT_LOOKUP); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | public static function getCheckResultSerializer( |
63 | 63 | MediaWikiServices $services = null |
64 | 64 | ): CheckResultSerializer { |
65 | - return self::getService( $services, self::CHECK_RESULT_SERIALIZER ); |
|
65 | + return self::getService($services, self::CHECK_RESULT_SERIALIZER); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | public static function getCheckResultDeserializer( |
69 | 69 | MediaWikiServices $services = null |
70 | 70 | ): CheckResultDeserializer { |
71 | - return self::getService( $services, self::CHECK_RESULT_DESERIALIZER ); |
|
71 | + return self::getService($services, self::CHECK_RESULT_DESERIALIZER); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | public static function getViolationMessageSerializer( |
75 | 75 | MediaWikiServices $services = null |
76 | 76 | ): ViolationMessageSerializer { |
77 | - return self::getService( $services, self::VIOLATION_MESSAGE_SERIALIZER ); |
|
77 | + return self::getService($services, self::VIOLATION_MESSAGE_SERIALIZER); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | public static function getViolationMessageDeserializer( |
81 | 81 | MediaWikiServices $services = null |
82 | 82 | ): ViolationMessageDeserializer { |
83 | - return self::getService( $services, self::VIOLATION_MESSAGE_DESERIALIZER ); |
|
83 | + return self::getService($services, self::VIOLATION_MESSAGE_DESERIALIZER); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | public static function getConstraintParameterParser( |
87 | 87 | MediaWikiServices $services = null |
88 | 88 | ): ConstraintParameterParser { |
89 | - return self::getService( $services, self::CONSTRAINT_PARAMETER_PARSER ); |
|
89 | + return self::getService($services, self::CONSTRAINT_PARAMETER_PARSER); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | public static function getConnectionCheckerHelper( |
93 | 93 | MediaWikiServices $services = null |
94 | 94 | ): ConnectionCheckerHelper { |
95 | - return self::getService( $services, self::CONNECTION_CHECKER_HELPER ); |
|
95 | + return self::getService($services, self::CONNECTION_CHECKER_HELPER); |
|
96 | 96 | } |
97 | 97 | |
98 | - public static function getRangeCheckerHelper( MediaWikiServices $services = null ): RangeCheckerHelper { |
|
99 | - return self::getService( $services, self::RANGE_CHECKER_HELPER ); |
|
98 | + public static function getRangeCheckerHelper(MediaWikiServices $services = null): RangeCheckerHelper { |
|
99 | + return self::getService($services, self::RANGE_CHECKER_HELPER); |
|
100 | 100 | } |
101 | 101 | |
102 | - public static function getSparqlHelper( MediaWikiServices $services = null ): SparqlHelper { |
|
103 | - return self::getService( $services, self::SPARQL_HELPER ); |
|
102 | + public static function getSparqlHelper(MediaWikiServices $services = null): SparqlHelper { |
|
103 | + return self::getService($services, self::SPARQL_HELPER); |
|
104 | 104 | } |
105 | 105 | |
106 | - public static function getTypeCheckerHelper( MediaWikiServices $services = null ): TypeCheckerHelper { |
|
107 | - return self::getService( $services, self::TYPE_CHECKER_HELPER ); |
|
106 | + public static function getTypeCheckerHelper(MediaWikiServices $services = null): TypeCheckerHelper { |
|
107 | + return self::getService($services, self::TYPE_CHECKER_HELPER); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | public static function getDelegatingConstraintChecker( |
111 | 111 | MediaWikiServices $services = null |
112 | 112 | ): DelegatingConstraintChecker { |
113 | - return self::getService( $services, self::DELEGATING_CONSTRAINT_CHECKER ); |
|
113 | + return self::getService($services, self::DELEGATING_CONSTRAINT_CHECKER); |
|
114 | 114 | } |
115 | 115 | |
116 | - public static function getResultsSource( MediaWikiServices $services = null ): ResultsSource { |
|
117 | - return self::getService( $services, self::RESULTS_SOURCE ); |
|
116 | + public static function getResultsSource(MediaWikiServices $services = null): ResultsSource { |
|
117 | + return self::getService($services, self::RESULTS_SOURCE); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * @return ExpiryLock |
122 | 122 | */ |
123 | - public static function getExpiryLock( MediaWikiServices $services = null ) { |
|
124 | - return self::getService( $services, self::EXPIRY_LOCK ); |
|
123 | + public static function getExpiryLock(MediaWikiServices $services = null) { |
|
124 | + return self::getService($services, self::EXPIRY_LOCK); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * then using the main DBLoadBalancer service may be incorrect. |
26 | 26 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
27 | 27 | */ |
28 | - public function __construct( ILoadBalancer $lb, $dbName ) { |
|
28 | + public function __construct(ILoadBalancer $lb, $dbName) { |
|
29 | 29 | $this->lb = $lb; |
30 | 30 | $this->dbName = $dbName; |
31 | 31 | } |
@@ -35,16 +35,16 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return Constraint[] |
37 | 37 | */ |
38 | - public function queryConstraintsForProperty( PropertyId $propertyId ) { |
|
39 | - $dbr = $this->lb->getConnectionRef( ILoadBalancer::DB_REPLICA, [], $this->dbName ); |
|
38 | + public function queryConstraintsForProperty(PropertyId $propertyId) { |
|
39 | + $dbr = $this->lb->getConnectionRef(ILoadBalancer::DB_REPLICA, [], $this->dbName); |
|
40 | 40 | |
41 | 41 | $results = $dbr->select( |
42 | 42 | 'wbqc_constraints', |
43 | 43 | '*', |
44 | - [ 'pid' => $propertyId->getNumericId() ] |
|
44 | + ['pid' => $propertyId->getNumericId()] |
|
45 | 45 | ); |
46 | 46 | |
47 | - return $this->convertToConstraints( $results ); |
|
47 | + return $this->convertToConstraints($results); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -52,26 +52,26 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return Constraint[] |
54 | 54 | */ |
55 | - private function convertToConstraints( IResultWrapper $results ) { |
|
55 | + private function convertToConstraints(IResultWrapper $results) { |
|
56 | 56 | $constraints = []; |
57 | - $logger = LoggerFactory::getInstance( 'WikibaseQualityConstraints' ); |
|
58 | - foreach ( $results as $result ) { |
|
57 | + $logger = LoggerFactory::getInstance('WikibaseQualityConstraints'); |
|
58 | + foreach ($results as $result) { |
|
59 | 59 | $constraintTypeItemId = $result->constraint_type_qid; |
60 | - $constraintParameters = json_decode( $result->constraint_parameters, true ); |
|
60 | + $constraintParameters = json_decode($result->constraint_parameters, true); |
|
61 | 61 | |
62 | - if ( $constraintParameters === null ) { |
|
62 | + if ($constraintParameters === null) { |
|
63 | 63 | // T171295 |
64 | - $logger->warning( 'Constraint {constraintId} has invalid constraint parameters.', [ |
|
64 | + $logger->warning('Constraint {constraintId} has invalid constraint parameters.', [ |
|
65 | 65 | 'method' => __METHOD__, |
66 | 66 | 'constraintId' => $result->constraint_guid, |
67 | 67 | 'constraintParameters' => $result->constraint_parameters, |
68 | - ] ); |
|
69 | - $constraintParameters = [ '@error' => [ /* unknown */ ] ]; |
|
68 | + ]); |
|
69 | + $constraintParameters = ['@error' => [/* unknown */]]; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $constraints[] = new Constraint( |
73 | 73 | $result->constraint_guid, |
74 | - PropertyId::newFromNumber( $result->pid ), |
|
74 | + PropertyId::newFromNumber($result->pid), |
|
75 | 75 | $constraintTypeItemId, |
76 | 76 | $constraintParameters |
77 | 77 | ); |
@@ -24,16 +24,16 @@ discard block |
||
24 | 24 | * then using the main DBLoadBalancer service may be incorrect. |
25 | 25 | * @param string|false $dbName Database name ($domain for ILoadBalancer methods). |
26 | 26 | */ |
27 | - public function __construct( ILoadBalancer $lb, $dbName ) { |
|
27 | + public function __construct(ILoadBalancer $lb, $dbName) { |
|
28 | 28 | $this->lb = $lb; |
29 | 29 | $this->dbName = $dbName; |
30 | 30 | } |
31 | 31 | |
32 | - private function encodeConstraintParameters( array $constraintParameters ) { |
|
33 | - $json = json_encode( $constraintParameters, JSON_FORCE_OBJECT ); |
|
32 | + private function encodeConstraintParameters(array $constraintParameters) { |
|
33 | + $json = json_encode($constraintParameters, JSON_FORCE_OBJECT); |
|
34 | 34 | |
35 | - if ( strlen( $json ) > 50000 ) { |
|
36 | - $json = json_encode( [ '@error' => [ 'toolong' => true ] ] ); |
|
35 | + if (strlen($json) > 50000) { |
|
36 | + $json = json_encode(['@error' => ['toolong' => true]]); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | return $json; |
@@ -45,21 +45,21 @@ discard block |
||
45 | 45 | * @throws DBUnexpectedError |
46 | 46 | * @return bool |
47 | 47 | */ |
48 | - public function insertBatch( array $constraints ) { |
|
48 | + public function insertBatch(array $constraints) { |
|
49 | 49 | $accumulator = array_map( |
50 | - function ( Constraint $constraint ) { |
|
50 | + function(Constraint $constraint) { |
|
51 | 51 | return [ |
52 | 52 | 'constraint_guid' => $constraint->getConstraintId(), |
53 | 53 | 'pid' => $constraint->getPropertyId()->getNumericId(), |
54 | 54 | 'constraint_type_qid' => $constraint->getConstraintTypeItemId(), |
55 | - 'constraint_parameters' => $this->encodeConstraintParameters( $constraint->getConstraintParameters() ) |
|
55 | + 'constraint_parameters' => $this->encodeConstraintParameters($constraint->getConstraintParameters()) |
|
56 | 56 | ]; |
57 | 57 | }, |
58 | 58 | $constraints |
59 | 59 | ); |
60 | 60 | |
61 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_MASTER, [], $this->dbName ); |
|
62 | - return $dbw->insert( 'wbqc_constraints', $accumulator ); |
|
61 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_MASTER, [], $this->dbName); |
|
62 | + return $dbw->insert('wbqc_constraints', $accumulator); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @throws DBUnexpectedError |
71 | 71 | */ |
72 | - public function deleteForProperty( PropertyId $propertyId ) { |
|
73 | - $dbw = $this->lb->getConnection( ILoadBalancer::DB_MASTER, [], $this->dbName ); |
|
72 | + public function deleteForProperty(PropertyId $propertyId) { |
|
73 | + $dbw = $this->lb->getConnection(ILoadBalancer::DB_MASTER, [], $this->dbName); |
|
74 | 74 | $dbw->delete( |
75 | 75 | 'wbqc_constraints', |
76 | 76 | [ |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @return bool |
17 | 17 | * @throws DBUnexpectedError |
18 | 18 | */ |
19 | - public function insertBatch( array $constraints ); |
|
19 | + public function insertBatch(array $constraints); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Delete all constraints for the property ID. |
@@ -25,6 +25,6 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @throws DBUnexpectedError |
27 | 27 | */ |
28 | - public function deleteForProperty( PropertyId $propertyId ); |
|
28 | + public function deleteForProperty(PropertyId $propertyId); |
|
29 | 29 | |
30 | 30 | } |