@@ -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 ), |
|
| 172 | - $services->getStatsFactory()->withComponent( 'WikibaseQualityConstraints' ) |
|
| 171 | + ConstraintsServices::getSparqlHelper($services), |
|
| 172 | + $services->getStatsFactory()->withComponent('WikibaseQualityConstraints') |
|
| 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 | ]; |
@@ -81,26 +81,26 @@ discard block |
||
| 81 | 81 | * @return bool |
| 82 | 82 | * @throws OverflowException if $entitiesChecked exceeds the configured limit |
| 83 | 83 | */ |
| 84 | - private function isSubclassOf( EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0 ) { |
|
| 85 | - $maxEntities = $this->config->get( 'WBQualityConstraintsTypeCheckMaxEntities' ); |
|
| 84 | + private function isSubclassOf(EntityId $comparativeClass, array $classesToCheck, &$entitiesChecked = 0) { |
|
| 85 | + $maxEntities = $this->config->get('WBQualityConstraintsTypeCheckMaxEntities'); |
|
| 86 | 86 | if ( ++$entitiesChecked > $maxEntities ) { |
| 87 | - throw new OverflowException( 'Too many entities to check' ); |
|
| 87 | + throw new OverflowException('Too many entities to check'); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $item = $this->entityLookup->getEntity( $comparativeClass ); |
|
| 91 | - if ( !( $item instanceof StatementListProvider ) ) { |
|
| 90 | + $item = $this->entityLookup->getEntity($comparativeClass); |
|
| 91 | + if (!($item instanceof StatementListProvider)) { |
|
| 92 | 92 | return false; // lookup failed, probably because item doesn't exist |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - $subclassId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
| 95 | + $subclassId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
| 96 | 96 | $statements = $item->getStatements() |
| 97 | - ->getByPropertyId( new NumericPropertyId( $subclassId ) ) |
|
| 97 | + ->getByPropertyId(new NumericPropertyId($subclassId)) |
|
| 98 | 98 | ->getBestStatements(); |
| 99 | 99 | /** @var Statement $statement */ |
| 100 | - foreach ( $statements as $statement ) { |
|
| 100 | + foreach ($statements as $statement) { |
|
| 101 | 101 | $mainSnak = $statement->getMainSnak(); |
| 102 | 102 | |
| 103 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
| 103 | + if (!$this->hasCorrectType($mainSnak)) { |
|
| 104 | 104 | continue; |
| 105 | 105 | } |
| 106 | 106 | /** @var PropertyValueSnak $mainSnak */ |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | '@phan-var EntityIdValue $dataValue'; |
| 111 | 111 | $comparativeClass = $dataValue->getEntityId(); |
| 112 | 112 | |
| 113 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
| 113 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
| 114 | 114 | return true; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if ( $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ) ) { |
|
| 117 | + if ($this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked)) { |
|
| 118 | 118 | return true; |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -135,40 +135,40 @@ discard block |
||
| 135 | 135 | * @return CachedBool |
| 136 | 136 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
| 137 | 137 | */ |
| 138 | - public function isSubclassOfWithSparqlFallback( EntityId $comparativeClass, array $classesToCheck ) { |
|
| 139 | - $timing = $this->statsFactory->getTiming( 'isSubclassOf_duration_seconds' ) |
|
| 140 | - ->setLabel( 'result', 'success' ) |
|
| 141 | - ->setLabel( 'TypeCheckerImplementation', 'php' ) |
|
| 142 | - ->copyToStatsdAt( 'wikibase.quality.constraints.type.php.success.timing' ); |
|
| 138 | + public function isSubclassOfWithSparqlFallback(EntityId $comparativeClass, array $classesToCheck) { |
|
| 139 | + $timing = $this->statsFactory->getTiming('isSubclassOf_duration_seconds') |
|
| 140 | + ->setLabel('result', 'success') |
|
| 141 | + ->setLabel('TypeCheckerImplementation', 'php') |
|
| 142 | + ->copyToStatsdAt('wikibase.quality.constraints.type.php.success.timing'); |
|
| 143 | 143 | $timing->start(); |
| 144 | 144 | |
| 145 | 145 | try { |
| 146 | 146 | $entitiesChecked = 0; |
| 147 | - $isSubclass = $this->isSubclassOf( $comparativeClass, $classesToCheck, $entitiesChecked ); |
|
| 147 | + $isSubclass = $this->isSubclassOf($comparativeClass, $classesToCheck, $entitiesChecked); |
|
| 148 | 148 | $timing->stop(); |
| 149 | 149 | |
| 150 | 150 | // not really a timing, but works like one (we want percentiles etc.) |
| 151 | 151 | // TODO: probably a good candidate for T348796 |
| 152 | - $this->statsFactory->getTiming( 'isSubclassOf_entities_total' ) |
|
| 153 | - ->setLabel( 'TypeCheckerImplementation', 'php' ) |
|
| 154 | - ->setLabel( 'result', 'success' ) |
|
| 155 | - ->copyToStatsdAt( 'wikibase.quality.constraints.type.php.success.entities' ) |
|
| 156 | - ->observe( $entitiesChecked ); |
|
| 157 | - |
|
| 158 | - return new CachedBool( $isSubclass, Metadata::blank() ); |
|
| 159 | - } catch ( OverflowException $e ) { |
|
| 160 | - $timing->setLabel( 'result', 'overflow' ) |
|
| 161 | - ->copyToStatsdAt( 'wikibase.quality.constraints.type.php.overflow.timing' ) |
|
| 152 | + $this->statsFactory->getTiming('isSubclassOf_entities_total') |
|
| 153 | + ->setLabel('TypeCheckerImplementation', 'php') |
|
| 154 | + ->setLabel('result', 'success') |
|
| 155 | + ->copyToStatsdAt('wikibase.quality.constraints.type.php.success.entities') |
|
| 156 | + ->observe($entitiesChecked); |
|
| 157 | + |
|
| 158 | + return new CachedBool($isSubclass, Metadata::blank()); |
|
| 159 | + } catch (OverflowException $e) { |
|
| 160 | + $timing->setLabel('result', 'overflow') |
|
| 161 | + ->copyToStatsdAt('wikibase.quality.constraints.type.php.overflow.timing') |
|
| 162 | 162 | ->stop(); |
| 163 | 163 | |
| 164 | - if ( !( $this->sparqlHelper instanceof DummySparqlHelper ) ) { |
|
| 165 | - $this->statsFactory->getCounter( 'sparql_typeFallback_total' ) |
|
| 166 | - ->copyToStatsdAt( 'wikibase.quality.constraints.sparql.typeFallback' ) |
|
| 164 | + if (!($this->sparqlHelper instanceof DummySparqlHelper)) { |
|
| 165 | + $this->statsFactory->getCounter('sparql_typeFallback_total') |
|
| 166 | + ->copyToStatsdAt('wikibase.quality.constraints.sparql.typeFallback') |
|
| 167 | 167 | ->increment(); |
| 168 | 168 | |
| 169 | - $timing->setLabel( 'TypeCheckerImplementation', 'sparql' ) |
|
| 170 | - ->setLabel( 'result', 'success' ) |
|
| 171 | - ->copyToStatsdAt( 'wikibase.quality.constraints.type.sparql.success.timing' ) |
|
| 169 | + $timing->setLabel('TypeCheckerImplementation', 'sparql') |
|
| 170 | + ->setLabel('result', 'success') |
|
| 171 | + ->copyToStatsdAt('wikibase.quality.constraints.type.sparql.success.timing') |
|
| 172 | 172 | ->start(); |
| 173 | 173 | |
| 174 | 174 | $hasType = $this->sparqlHelper->hasType( |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | return $hasType; |
| 182 | 182 | } else { |
| 183 | - return new CachedBool( false, Metadata::blank() ); |
|
| 183 | + return new CachedBool(false, Metadata::blank()); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | } |
@@ -198,13 +198,13 @@ discard block |
||
| 198 | 198 | * @return CachedBool |
| 199 | 199 | * @throws SparqlHelperException if SPARQL is used and the query times out or some other error occurs |
| 200 | 200 | */ |
| 201 | - public function hasClassInRelation( StatementList $statements, array $relationIds, array $classesToCheck ) { |
|
| 201 | + public function hasClassInRelation(StatementList $statements, array $relationIds, array $classesToCheck) { |
|
| 202 | 202 | $metadatas = []; |
| 203 | 203 | |
| 204 | - foreach ( $this->getBestStatementsByPropertyIds( $statements, $relationIds ) as $statement ) { |
|
| 204 | + foreach ($this->getBestStatementsByPropertyIds($statements, $relationIds) as $statement) { |
|
| 205 | 205 | $mainSnak = $statement->getMainSnak(); |
| 206 | 206 | |
| 207 | - if ( !$this->hasCorrectType( $mainSnak ) ) { |
|
| 207 | + if (!$this->hasCorrectType($mainSnak)) { |
|
| 208 | 208 | continue; |
| 209 | 209 | } |
| 210 | 210 | /** @var PropertyValueSnak $mainSnak */ |
@@ -214,24 +214,24 @@ discard block |
||
| 214 | 214 | '@phan-var EntityIdValue $dataValue'; |
| 215 | 215 | $comparativeClass = $dataValue->getEntityId(); |
| 216 | 216 | |
| 217 | - if ( in_array( $comparativeClass->getSerialization(), $classesToCheck ) ) { |
|
| 217 | + if (in_array($comparativeClass->getSerialization(), $classesToCheck)) { |
|
| 218 | 218 | // discard $metadatas, we know this is fresh |
| 219 | - return new CachedBool( true, Metadata::blank() ); |
|
| 219 | + return new CachedBool(true, Metadata::blank()); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - $result = $this->isSubclassOfWithSparqlFallback( $comparativeClass, $classesToCheck ); |
|
| 222 | + $result = $this->isSubclassOfWithSparqlFallback($comparativeClass, $classesToCheck); |
|
| 223 | 223 | $metadatas[] = $result->getMetadata(); |
| 224 | - if ( $result->getBool() ) { |
|
| 224 | + if ($result->getBool()) { |
|
| 225 | 225 | return new CachedBool( |
| 226 | 226 | true, |
| 227 | - Metadata::merge( $metadatas ) |
|
| 227 | + Metadata::merge($metadatas) |
|
| 228 | 228 | ); |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | return new CachedBool( |
| 233 | 233 | false, |
| 234 | - Metadata::merge( $metadatas ) |
|
| 234 | + Metadata::merge($metadatas) |
|
| 235 | 235 | ); |
| 236 | 236 | } |
| 237 | 237 | |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * @return bool |
| 241 | 241 | * @phan-assert PropertyValueSnak $mainSnak |
| 242 | 242 | */ |
| 243 | - private function hasCorrectType( Snak $mainSnak ) { |
|
| 243 | + private function hasCorrectType(Snak $mainSnak) { |
|
| 244 | 244 | return $mainSnak instanceof PropertyValueSnak |
| 245 | 245 | && $mainSnak->getDataValue()->getType() === 'wikibase-entityid'; |
| 246 | 246 | } |
@@ -257,15 +257,15 @@ discard block |
||
| 257 | 257 | ) { |
| 258 | 258 | $statementArrays = []; |
| 259 | 259 | |
| 260 | - foreach ( $propertyIdSerializations as $propertyIdSerialization ) { |
|
| 261 | - $propertyId = new NumericPropertyId( $propertyIdSerialization ); |
|
| 260 | + foreach ($propertyIdSerializations as $propertyIdSerialization) { |
|
| 261 | + $propertyId = new NumericPropertyId($propertyIdSerialization); |
|
| 262 | 262 | $statementArrays[] = $statements |
| 263 | - ->getByPropertyId( $propertyId ) |
|
| 263 | + ->getByPropertyId($propertyId) |
|
| 264 | 264 | ->getBestStatements() |
| 265 | 265 | ->toArray(); |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - return call_user_func_array( 'array_merge', $statementArrays ); |
|
| 268 | + return call_user_func_array('array_merge', $statementArrays); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -285,8 +285,8 @@ discard block |
||
| 285 | 285 | $relation |
| 286 | 286 | ) { |
| 287 | 287 | $classes = array_map( |
| 288 | - static function ( $itemIdSerialization ) { |
|
| 289 | - return new ItemId( $itemIdSerialization ); |
|
| 288 | + static function($itemIdSerialization) { |
|
| 289 | + return new ItemId($itemIdSerialization); |
|
| 290 | 290 | }, |
| 291 | 291 | $classes |
| 292 | 292 | ); |
@@ -298,10 +298,10 @@ discard block |
||
| 298 | 298 | // wbqc-violation-message-valueType-instance |
| 299 | 299 | // wbqc-violation-message-valueType-subclass |
| 300 | 300 | // wbqc-violation-message-valueType-instanceOrSubclass |
| 301 | - return ( new ViolationMessage( 'wbqc-violation-message-' . $checker . '-' . $relation ) ) |
|
| 302 | - ->withEntityId( $propertyId, Role::CONSTRAINT_PROPERTY ) |
|
| 303 | - ->withEntityId( $entityId, Role::SUBJECT ) |
|
| 304 | - ->withEntityIdList( $classes, Role::OBJECT ); |
|
| 301 | + return (new ViolationMessage('wbqc-violation-message-'.$checker.'-'.$relation)) |
|
| 302 | + ->withEntityId($propertyId, Role::CONSTRAINT_PROPERTY) |
|
| 303 | + ->withEntityId($entityId, Role::SUBJECT) |
|
| 304 | + ->withEntityIdList($classes, Role::OBJECT); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | } |