@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param WANObjectCache $cache |
37 | 37 | * @param string $formatVersion The version of the API response format. |
38 | 38 | */ |
39 | - public function __construct( WANObjectCache $cache, $formatVersion ) { |
|
39 | + public function __construct(WANObjectCache $cache, $formatVersion) { |
|
40 | 40 | $this->cache = $cache; |
41 | 41 | $this->formatVersion = $formatVersion; |
42 | 42 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | * @param EntityId $entityId |
46 | 46 | * @return string cache key |
47 | 47 | */ |
48 | - public function makeKey( EntityId $entityId ) { |
|
48 | + public function makeKey(EntityId $entityId) { |
|
49 | 49 | return $this->cache->makeKey( |
50 | 50 | 'WikibaseQualityConstraints', // extension |
51 | 51 | 'checkConstraints', // action |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param mixed|null &$info |
62 | 62 | * @return mixed |
63 | 63 | */ |
64 | - public function get( EntityId $key, &$curTTL = null, array $checkKeys = [], &$info = null ) { |
|
65 | - return $this->cache->get( $this->makeKey( $key ), $curTTL, $checkKeys, $info ); |
|
64 | + public function get(EntityId $key, &$curTTL = null, array $checkKeys = [], &$info = null) { |
|
65 | + return $this->cache->get($this->makeKey($key), $curTTL, $checkKeys, $info); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -72,16 +72,16 @@ discard block |
||
72 | 72 | * @param array $opts |
73 | 73 | * @return bool |
74 | 74 | */ |
75 | - public function set( EntityId $key, $value, $ttl = 0, array $opts = [] ) { |
|
76 | - return $this->cache->set( $this->makeKey( $key ), $value, $ttl, $opts ); |
|
75 | + public function set(EntityId $key, $value, $ttl = 0, array $opts = []) { |
|
76 | + return $this->cache->set($this->makeKey($key), $value, $ttl, $opts); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * @param EntityId $key |
81 | 81 | * @return bool |
82 | 82 | */ |
83 | - public function delete( EntityId $key ) { |
|
84 | - return $this->cache->delete( $this->makeKey( $key ) ); |
|
83 | + public function delete(EntityId $key) { |
|
84 | + return $this->cache->delete($this->makeKey($key)); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | } |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | DelegatingConstraintChecker $delegatingConstraintChecker |
79 | 79 | ): self { |
80 | 80 | $repo = WikibaseRepo::getDefaultInstance(); |
81 | - $helperFactory = $repo->getApiHelperFactory( RequestContext::getMain() ); |
|
81 | + $helperFactory = $repo->getApiHelperFactory(RequestContext::getMain()); |
|
82 | 82 | $language = $repo->getUserLanguage(); |
83 | 83 | |
84 | 84 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
85 | 85 | $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory |
86 | - ->getEntityIdFormatter( $language ); |
|
86 | + ->getEntityIdFormatter($language); |
|
87 | 87 | $formatterOptions = new FormatterOptions(); |
88 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
88 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
89 | 89 | $dataValueFormatter = $valueFormatterFactory |
90 | - ->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
90 | + ->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
91 | 91 | $violationMessageRenderer = new MultilingualTextViolationMessageRenderer( |
92 | 92 | $entityIdHtmlLinkFormatter, |
93 | 93 | $dataValueFormatter, |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | StatementGuidParser $statementGuidParser, |
124 | 124 | IBufferingStatsdDataFactory $dataFactory |
125 | 125 | ) { |
126 | - parent::__construct( $main, $name ); |
|
126 | + parent::__construct($main, $name); |
|
127 | 127 | |
128 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
128 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
129 | 129 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
130 | 130 | $this->violationMessageRenderer = $violationMessageRenderer; |
131 | 131 | $this->statementGuidParser = $statementGuidParser; |
@@ -140,39 +140,39 @@ discard block |
||
140 | 140 | $params = $this->extractRequestParams(); |
141 | 141 | $result = $this->getResult(); |
142 | 142 | |
143 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
144 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
143 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
144 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
145 | 145 | |
146 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
147 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
146 | + $this->checkPropertyIds($propertyIds, $result); |
|
147 | + $this->checkConstraintIds($constraintIds, $result); |
|
148 | 148 | |
149 | - $result->addValue( null, 'success', 1 ); |
|
149 | + $result->addValue(null, 'success', 1); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
153 | 153 | * @param array|null $propertyIdSerializations |
154 | 154 | * @return PropertyId[] |
155 | 155 | */ |
156 | - private function parsePropertyIds( $propertyIdSerializations ) { |
|
157 | - if ( $propertyIdSerializations === null ) { |
|
156 | + private function parsePropertyIds($propertyIdSerializations) { |
|
157 | + if ($propertyIdSerializations === null) { |
|
158 | 158 | return []; |
159 | - } elseif ( empty( $propertyIdSerializations ) ) { |
|
159 | + } elseif (empty($propertyIdSerializations)) { |
|
160 | 160 | $this->apiErrorReporter->dieError( |
161 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
161 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
162 | 162 | 'no-data' |
163 | 163 | ); |
164 | 164 | } |
165 | 165 | |
166 | 166 | return array_map( |
167 | - function ( $propertyIdSerialization ) { |
|
167 | + function($propertyIdSerialization) { |
|
168 | 168 | try { |
169 | - return new PropertyId( $propertyIdSerialization ); |
|
170 | - } catch ( InvalidArgumentException $e ) { |
|
169 | + return new PropertyId($propertyIdSerialization); |
|
170 | + } catch (InvalidArgumentException $e) { |
|
171 | 171 | $this->apiErrorReporter->dieError( |
172 | 172 | "Invalid id: $propertyIdSerialization", |
173 | 173 | 'invalid-property-id', |
174 | 174 | 0, // default argument |
175 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
175 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
176 | 176 | ); |
177 | 177 | } |
178 | 178 | }, |
@@ -184,35 +184,35 @@ discard block |
||
184 | 184 | * @param array|null $constraintIds |
185 | 185 | * @return string[] |
186 | 186 | */ |
187 | - private function parseConstraintIds( $constraintIds ) { |
|
188 | - if ( $constraintIds === null ) { |
|
187 | + private function parseConstraintIds($constraintIds) { |
|
188 | + if ($constraintIds === null) { |
|
189 | 189 | return []; |
190 | - } elseif ( empty( $constraintIds ) ) { |
|
190 | + } elseif (empty($constraintIds)) { |
|
191 | 191 | $this->apiErrorReporter->dieError( |
192 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
192 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
193 | 193 | 'no-data' |
194 | 194 | ); |
195 | 195 | } |
196 | 196 | |
197 | 197 | return array_map( |
198 | - function ( $constraintId ) { |
|
198 | + function($constraintId) { |
|
199 | 199 | try { |
200 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
201 | - if ( !$propertyId instanceof PropertyId ) { |
|
200 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
201 | + if (!$propertyId instanceof PropertyId) { |
|
202 | 202 | $this->apiErrorReporter->dieError( |
203 | 203 | "Invalid property ID: {$propertyId->getSerialization()}", |
204 | 204 | 'invalid-property-id', |
205 | 205 | 0, // default argument |
206 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
206 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
207 | 207 | ); |
208 | 208 | } |
209 | 209 | return $constraintId; |
210 | - } catch ( StatementGuidParsingException $e ) { |
|
210 | + } catch (StatementGuidParsingException $e) { |
|
211 | 211 | $this->apiErrorReporter->dieError( |
212 | 212 | "Invalid statement GUID: $constraintId", |
213 | 213 | 'invalid-guid', |
214 | 214 | 0, // default argument |
215 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
215 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
216 | 216 | ); |
217 | 217 | } |
218 | 218 | }, |
@@ -224,12 +224,12 @@ discard block |
||
224 | 224 | * @param PropertyId[] $propertyIds |
225 | 225 | * @param ApiResult $result |
226 | 226 | */ |
227 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ) { |
|
228 | - foreach ( $propertyIds as $propertyId ) { |
|
229 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
227 | + private function checkPropertyIds(array $propertyIds, ApiResult $result) { |
|
228 | + foreach ($propertyIds as $propertyId) { |
|
229 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
230 | 230 | $allConstraintExceptions = $this->delegatingConstraintChecker |
231 | - ->checkConstraintParametersOnPropertyId( $propertyId ); |
|
232 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
231 | + ->checkConstraintParametersOnPropertyId($propertyId); |
|
232 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
233 | 233 | $this->addConstraintParameterExceptionsToResult( |
234 | 234 | $constraintId, |
235 | 235 | $constraintParameterExceptions, |
@@ -243,15 +243,15 @@ discard block |
||
243 | 243 | * @param string[] $constraintIds |
244 | 244 | * @param ApiResult $result |
245 | 245 | */ |
246 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ) { |
|
247 | - foreach ( $constraintIds as $constraintId ) { |
|
248 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
246 | + private function checkConstraintIds(array $constraintIds, ApiResult $result) { |
|
247 | + foreach ($constraintIds as $constraintId) { |
|
248 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
249 | 249 | // already checked as part of checkPropertyIds() |
250 | 250 | continue; |
251 | 251 | } |
252 | 252 | $constraintParameterExceptions = $this->delegatingConstraintChecker |
253 | - ->checkConstraintParametersOnConstraintId( $constraintId ); |
|
254 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
253 | + ->checkConstraintParametersOnConstraintId($constraintId); |
|
254 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
@@ -259,18 +259,18 @@ discard block |
||
259 | 259 | * @param PropertyId $propertyId |
260 | 260 | * @return string[] |
261 | 261 | */ |
262 | - private function getResultPathForPropertyId( PropertyId $propertyId ) { |
|
263 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
262 | + private function getResultPathForPropertyId(PropertyId $propertyId) { |
|
263 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
267 | 267 | * @param string $constraintId |
268 | 268 | * @return string[] |
269 | 269 | */ |
270 | - private function getResultPathForConstraintId( $constraintId ) { |
|
271 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
270 | + private function getResultPathForConstraintId($constraintId) { |
|
271 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
272 | 272 | '@phan-var PropertyId $propertyId'; |
273 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
273 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | $constraintParameterExceptions, |
286 | 286 | ApiResult $result |
287 | 287 | ) { |
288 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
289 | - if ( $constraintParameterExceptions === null ) { |
|
288 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
289 | + if ($constraintParameterExceptions === null) { |
|
290 | 290 | $result->addValue( |
291 | 291 | $path, |
292 | 292 | self::KEY_STATUS, |
@@ -296,12 +296,12 @@ discard block |
||
296 | 296 | $result->addValue( |
297 | 297 | $path, |
298 | 298 | self::KEY_STATUS, |
299 | - empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
299 | + empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
300 | 300 | ); |
301 | 301 | $result->addValue( |
302 | 302 | $path, |
303 | 303 | self::KEY_PROBLEMS, |
304 | - array_map( [ $this, 'formatConstraintParameterException' ], $constraintParameterExceptions ) |
|
304 | + array_map([$this, 'formatConstraintParameterException'], $constraintParameterExceptions) |
|
305 | 305 | ); |
306 | 306 | } |
307 | 307 | } |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | * @param ConstraintParameterException $e |
313 | 313 | * @return string[] |
314 | 314 | */ |
315 | - private function formatConstraintParameterException( ConstraintParameterException $e ) { |
|
315 | + private function formatConstraintParameterException(ConstraintParameterException $e) { |
|
316 | 316 | return [ |
317 | 317 | self::KEY_MESSAGE_HTML => $this->violationMessageRenderer->render( |
318 | 318 | $e->getViolationMessage() |
@@ -345,8 +345,8 @@ discard block |
||
345 | 345 | return [ |
346 | 346 | 'action=wbcheckconstraintparameters&propertyid=P247' |
347 | 347 | => 'apihelp-wbcheckconstraintparameters-example-propertyid-1', |
348 | - 'action=wbcheckconstraintparameters&' . |
|
349 | - 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' . |
|
348 | + 'action=wbcheckconstraintparameters&'. |
|
349 | + 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'. |
|
350 | 350 | 'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f' |
351 | 351 | => 'apihelp-wbcheckconstraintparameters-example-constraintid-2', |
352 | 352 | ]; |
@@ -28,46 +28,46 @@ 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 ) { |
|
44 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
45 | - $propertySource = $sourceDefinitions->getSourceForEntityType( Property::ENTITY_TYPE ); |
|
43 | + ConstraintsServices::CONSTRAINT_STORE => function(MediaWikiServices $services) { |
|
44 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
45 | + $propertySource = $sourceDefinitions->getSourceForEntityType(Property::ENTITY_TYPE); |
|
46 | 46 | $dbName = $propertySource->getDatabaseName(); |
47 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
47 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
48 | 48 | |
49 | - if ( $propertySource->getSourceName() !== $localEntitySourceName ) { |
|
50 | - throw new \RuntimeException( 'Can\'t get a ConstraintStore for a non local entity source.' ); |
|
49 | + if ($propertySource->getSourceName() !== $localEntitySourceName) { |
|
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 ) { |
|
60 | - $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
61 | - $propertySource = $sourceDefinitions->getSourceForEntityType( Property::ENTITY_TYPE ); |
|
59 | + ConstraintsServices::CONSTRAINT_LOOKUP => function(MediaWikiServices $services) { |
|
60 | + $sourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
61 | + $propertySource = $sourceDefinitions->getSourceForEntityType(Property::ENTITY_TYPE); |
|
62 | 62 | $dbName = $propertySource->getDatabaseName(); |
63 | 63 | $rawLookup = new ConstraintRepositoryLookup( |
64 | - $services->getDBLoadBalancerFactory()->getMainLB( $dbName ), |
|
64 | + $services->getDBLoadBalancerFactory()->getMainLB($dbName), |
|
65 | 65 | $dbName |
66 | 66 | ); |
67 | - return new CachingConstraintLookup( $rawLookup ); |
|
67 | + return new CachingConstraintLookup($rawLookup); |
|
68 | 68 | }, |
69 | 69 | |
70 | - ConstraintsServices::CHECK_RESULT_SERIALIZER => function ( MediaWikiServices $services ) { |
|
70 | + ConstraintsServices::CHECK_RESULT_SERIALIZER => function(MediaWikiServices $services) { |
|
71 | 71 | return new CheckResultSerializer( |
72 | 72 | new ConstraintSerializer( |
73 | 73 | false // constraint parameters are not exposed |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | ); |
79 | 79 | }, |
80 | 80 | |
81 | - ConstraintsServices::CHECK_RESULT_DESERIALIZER => function ( MediaWikiServices $services ) { |
|
82 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
83 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
81 | + ConstraintsServices::CHECK_RESULT_DESERIALIZER => function(MediaWikiServices $services) { |
|
82 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
83 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
84 | 84 | |
85 | 85 | return new CheckResultDeserializer( |
86 | 86 | new ConstraintDeserializer(), |
@@ -93,13 +93,13 @@ discard block |
||
93 | 93 | ); |
94 | 94 | }, |
95 | 95 | |
96 | - ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => function ( MediaWikiServices $services ) { |
|
96 | + ConstraintsServices::VIOLATION_MESSAGE_SERIALIZER => function(MediaWikiServices $services) { |
|
97 | 97 | return new ViolationMessageSerializer(); |
98 | 98 | }, |
99 | 99 | |
100 | - ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => function ( MediaWikiServices $services ) { |
|
101 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
102 | - $dataValueFactory = WikibaseRepo::getDataValueFactory( $services ); |
|
100 | + ConstraintsServices::VIOLATION_MESSAGE_DESERIALIZER => function(MediaWikiServices $services) { |
|
101 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
102 | + $dataValueFactory = WikibaseRepo::getDataValueFactory($services); |
|
103 | 103 | |
104 | 104 | return new ViolationMessageDeserializer( |
105 | 105 | $entityIdParser, |
@@ -107,24 +107,24 @@ discard block |
||
107 | 107 | ); |
108 | 108 | }, |
109 | 109 | |
110 | - ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => function ( MediaWikiServices $services ) { |
|
110 | + ConstraintsServices::CONSTRAINT_PARAMETER_PARSER => function(MediaWikiServices $services) { |
|
111 | 111 | // TODO in the future, get DeserializerFactory from $services? |
112 | 112 | $repo = WikibaseRepo::getDefaultInstance(); |
113 | 113 | $deserializerFactory = $repo->getBaseDataModelDeserializerFactory(); |
114 | - $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions( $services ); |
|
114 | + $entitySourceDefinitions = WikibaseRepo::getEntitySourceDefinitions($services); |
|
115 | 115 | |
116 | 116 | return new ConstraintParameterParser( |
117 | 117 | $services->getMainConfig(), |
118 | 118 | $deserializerFactory, |
119 | - $entitySourceDefinitions->getSourceForEntityType( 'item' )->getConceptBaseUri() |
|
119 | + $entitySourceDefinitions->getSourceForEntityType('item')->getConceptBaseUri() |
|
120 | 120 | ); |
121 | 121 | }, |
122 | 122 | |
123 | - ConstraintsServices::CONNECTION_CHECKER_HELPER => function ( MediaWikiServices $services ) { |
|
123 | + ConstraintsServices::CONNECTION_CHECKER_HELPER => function(MediaWikiServices $services) { |
|
124 | 124 | return new ConnectionCheckerHelper(); |
125 | 125 | }, |
126 | 126 | |
127 | - ConstraintsServices::RANGE_CHECKER_HELPER => function ( MediaWikiServices $services ) { |
|
127 | + ConstraintsServices::RANGE_CHECKER_HELPER => function(MediaWikiServices $services) { |
|
128 | 128 | // TODO in the future, get UnitConverter from $services? |
129 | 129 | $repo = WikibaseRepo::getDefaultInstance(); |
130 | 130 | $unitConverter = $repo->getUnitConverter(); |
@@ -135,16 +135,16 @@ discard block |
||
135 | 135 | ); |
136 | 136 | }, |
137 | 137 | |
138 | - ConstraintsServices::SPARQL_HELPER => function ( MediaWikiServices $services ) { |
|
139 | - $endpoint = $services->getMainConfig()->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
140 | - if ( $endpoint === '' ) { |
|
138 | + ConstraintsServices::SPARQL_HELPER => function(MediaWikiServices $services) { |
|
139 | + $endpoint = $services->getMainConfig()->get('WBQualityConstraintsSparqlEndpoint'); |
|
140 | + if ($endpoint === '') { |
|
141 | 141 | return new DummySparqlHelper(); |
142 | 142 | } |
143 | 143 | |
144 | 144 | // TODO get PropertyDataTypeLookup from $services |
145 | 145 | $repo = WikibaseRepo::getDefaultInstance(); |
146 | - $rdfVocabulary = WikibaseRepo::getRdfVocabulary( $services ); |
|
147 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
146 | + $rdfVocabulary = WikibaseRepo::getRdfVocabulary($services); |
|
147 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
148 | 148 | $propertyDataTypeLookup = $repo->getPropertyDataTypeLookup(); |
149 | 149 | |
150 | 150 | return new SparqlHelper( |
@@ -153,122 +153,122 @@ discard block |
||
153 | 153 | $entityIdParser, |
154 | 154 | $propertyDataTypeLookup, |
155 | 155 | $services->getMainWANObjectCache(), |
156 | - ConstraintsServices::getViolationMessageSerializer( $services ), |
|
157 | - ConstraintsServices::getViolationMessageDeserializer( $services ), |
|
156 | + ConstraintsServices::getViolationMessageSerializer($services), |
|
157 | + ConstraintsServices::getViolationMessageDeserializer($services), |
|
158 | 158 | $services->getStatsdDataFactory(), |
159 | - ConstraintsServices::getExpiryLock( $services ), |
|
159 | + ConstraintsServices::getExpiryLock($services), |
|
160 | 160 | ConstraintsServices::getLoggingHelper(), |
161 | - wfWikiID() . ' WikibaseQualityConstraints ' . Http::userAgent(), |
|
161 | + wfWikiID().' WikibaseQualityConstraints '.Http::userAgent(), |
|
162 | 162 | $services->getHttpRequestFactory() |
163 | 163 | ); |
164 | 164 | }, |
165 | 165 | |
166 | - ConstraintsServices::TYPE_CHECKER_HELPER => function ( MediaWikiServices $services ) { |
|
166 | + ConstraintsServices::TYPE_CHECKER_HELPER => function(MediaWikiServices $services) { |
|
167 | 167 | return new TypeCheckerHelper( |
168 | - WikibaseServices::getEntityLookup( $services ), |
|
168 | + WikibaseServices::getEntityLookup($services), |
|
169 | 169 | $services->getMainConfig(), |
170 | - ConstraintsServices::getSparqlHelper( $services ), |
|
170 | + ConstraintsServices::getSparqlHelper($services), |
|
171 | 171 | $services->getStatsdDataFactory() |
172 | 172 | ); |
173 | 173 | }, |
174 | 174 | |
175 | - ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => function ( MediaWikiServices $services ) { |
|
176 | - $statementGuidParser = WikibaseRepo::getStatementGuidParser( $services ); |
|
175 | + ConstraintsServices::DELEGATING_CONSTRAINT_CHECKER => function(MediaWikiServices $services) { |
|
176 | + $statementGuidParser = WikibaseRepo::getStatementGuidParser($services); |
|
177 | 177 | |
178 | 178 | $config = $services->getMainConfig(); |
179 | 179 | $checkerMap = [ |
180 | - $config->get( 'WBQualityConstraintsConflictsWithConstraintId' ) |
|
181 | - => ConstraintCheckerServices::getConflictsWithChecker( $services ), |
|
182 | - $config->get( 'WBQualityConstraintsItemRequiresClaimConstraintId' ) |
|
183 | - => ConstraintCheckerServices::getItemChecker( $services ), |
|
184 | - $config->get( 'WBQualityConstraintsValueRequiresClaimConstraintId' ) |
|
185 | - => ConstraintCheckerServices::getTargetRequiredClaimChecker( $services ), |
|
186 | - $config->get( 'WBQualityConstraintsSymmetricConstraintId' ) |
|
187 | - => ConstraintCheckerServices::getSymmetricChecker( $services ), |
|
188 | - $config->get( 'WBQualityConstraintsInverseConstraintId' ) |
|
189 | - => ConstraintCheckerServices::getInverseChecker( $services ), |
|
190 | - $config->get( 'WBQualityConstraintsUsedAsQualifierConstraintId' ) |
|
191 | - => ConstraintCheckerServices::getQualifierChecker( $services ), |
|
192 | - $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ) |
|
193 | - => ConstraintCheckerServices::getQualifiersChecker( $services ), |
|
194 | - $config->get( 'WBQualityConstraintsMandatoryQualifierConstraintId' ) |
|
195 | - => ConstraintCheckerServices::getMandatoryQualifiersChecker( $services ), |
|
196 | - $config->get( 'WBQualityConstraintsRangeConstraintId' ) |
|
197 | - => ConstraintCheckerServices::getRangeChecker( $services ), |
|
198 | - $config->get( 'WBQualityConstraintsDifferenceWithinRangeConstraintId' ) |
|
199 | - => ConstraintCheckerServices::getDiffWithinRangeChecker( $services ), |
|
200 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ) |
|
201 | - => ConstraintCheckerServices::getTypeChecker( $services ), |
|
202 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ) |
|
203 | - => ConstraintCheckerServices::getValueTypeChecker( $services ), |
|
204 | - $config->get( 'WBQualityConstraintsSingleValueConstraintId' ) |
|
205 | - => ConstraintCheckerServices::getSingleValueChecker( $services ), |
|
206 | - $config->get( 'WBQualityConstraintsMultiValueConstraintId' ) |
|
207 | - => ConstraintCheckerServices::getMultiValueChecker( $services ), |
|
208 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ) |
|
209 | - => ConstraintCheckerServices::getUniqueValueChecker( $services ), |
|
210 | - $config->get( 'WBQualityConstraintsFormatConstraintId' ) |
|
211 | - => ConstraintCheckerServices::getFormatChecker( $services ), |
|
212 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ) |
|
213 | - => ConstraintCheckerServices::getCommonsLinkChecker( $services ), |
|
214 | - $config->get( 'WBQualityConstraintsOneOfConstraintId' ) |
|
215 | - => ConstraintCheckerServices::getOneOfChecker( $services ), |
|
216 | - $config->get( 'WBQualityConstraintsUsedForValuesOnlyConstraintId' ) |
|
217 | - => ConstraintCheckerServices::getValueOnlyChecker( $services ), |
|
218 | - $config->get( 'WBQualityConstraintsUsedAsReferenceConstraintId' ) |
|
219 | - => ConstraintCheckerServices::getReferenceChecker( $services ), |
|
220 | - $config->get( 'WBQualityConstraintsNoBoundsConstraintId' ) |
|
221 | - => ConstraintCheckerServices::getNoBoundsChecker( $services ), |
|
222 | - $config->get( 'WBQualityConstraintsAllowedUnitsConstraintId' ) |
|
223 | - => ConstraintCheckerServices::getAllowedUnitsChecker( $services ), |
|
224 | - $config->get( 'WBQualityConstraintsSingleBestValueConstraintId' ) |
|
225 | - => ConstraintCheckerServices::getSingleBestValueChecker( $services ), |
|
226 | - $config->get( 'WBQualityConstraintsAllowedEntityTypesConstraintId' ) |
|
227 | - => ConstraintCheckerServices::getEntityTypeChecker( $services ), |
|
228 | - $config->get( 'WBQualityConstraintsNoneOfConstraintId' ) |
|
229 | - => ConstraintCheckerServices::getNoneOfChecker( $services ), |
|
230 | - $config->get( 'WBQualityConstraintsIntegerConstraintId' ) |
|
231 | - => ConstraintCheckerServices::getIntegerChecker( $services ), |
|
232 | - $config->get( 'WBQualityConstraintsCitationNeededConstraintId' ) |
|
233 | - => ConstraintCheckerServices::getCitationNeededChecker( $services ), |
|
234 | - $config->get( 'WBQualityConstraintsPropertyScopeConstraintId' ) |
|
235 | - => ConstraintCheckerServices::getPropertyScopeChecker( $services ), |
|
236 | - $config->get( 'WBQualityConstraintsContemporaryConstraintId' ) |
|
237 | - => ConstraintCheckerServices::getContemporaryChecker( $services ), |
|
180 | + $config->get('WBQualityConstraintsConflictsWithConstraintId') |
|
181 | + => ConstraintCheckerServices::getConflictsWithChecker($services), |
|
182 | + $config->get('WBQualityConstraintsItemRequiresClaimConstraintId') |
|
183 | + => ConstraintCheckerServices::getItemChecker($services), |
|
184 | + $config->get('WBQualityConstraintsValueRequiresClaimConstraintId') |
|
185 | + => ConstraintCheckerServices::getTargetRequiredClaimChecker($services), |
|
186 | + $config->get('WBQualityConstraintsSymmetricConstraintId') |
|
187 | + => ConstraintCheckerServices::getSymmetricChecker($services), |
|
188 | + $config->get('WBQualityConstraintsInverseConstraintId') |
|
189 | + => ConstraintCheckerServices::getInverseChecker($services), |
|
190 | + $config->get('WBQualityConstraintsUsedAsQualifierConstraintId') |
|
191 | + => ConstraintCheckerServices::getQualifierChecker($services), |
|
192 | + $config->get('WBQualityConstraintsAllowedQualifiersConstraintId') |
|
193 | + => ConstraintCheckerServices::getQualifiersChecker($services), |
|
194 | + $config->get('WBQualityConstraintsMandatoryQualifierConstraintId') |
|
195 | + => ConstraintCheckerServices::getMandatoryQualifiersChecker($services), |
|
196 | + $config->get('WBQualityConstraintsRangeConstraintId') |
|
197 | + => ConstraintCheckerServices::getRangeChecker($services), |
|
198 | + $config->get('WBQualityConstraintsDifferenceWithinRangeConstraintId') |
|
199 | + => ConstraintCheckerServices::getDiffWithinRangeChecker($services), |
|
200 | + $config->get('WBQualityConstraintsTypeConstraintId') |
|
201 | + => ConstraintCheckerServices::getTypeChecker($services), |
|
202 | + $config->get('WBQualityConstraintsValueTypeConstraintId') |
|
203 | + => ConstraintCheckerServices::getValueTypeChecker($services), |
|
204 | + $config->get('WBQualityConstraintsSingleValueConstraintId') |
|
205 | + => ConstraintCheckerServices::getSingleValueChecker($services), |
|
206 | + $config->get('WBQualityConstraintsMultiValueConstraintId') |
|
207 | + => ConstraintCheckerServices::getMultiValueChecker($services), |
|
208 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId') |
|
209 | + => ConstraintCheckerServices::getUniqueValueChecker($services), |
|
210 | + $config->get('WBQualityConstraintsFormatConstraintId') |
|
211 | + => ConstraintCheckerServices::getFormatChecker($services), |
|
212 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId') |
|
213 | + => ConstraintCheckerServices::getCommonsLinkChecker($services), |
|
214 | + $config->get('WBQualityConstraintsOneOfConstraintId') |
|
215 | + => ConstraintCheckerServices::getOneOfChecker($services), |
|
216 | + $config->get('WBQualityConstraintsUsedForValuesOnlyConstraintId') |
|
217 | + => ConstraintCheckerServices::getValueOnlyChecker($services), |
|
218 | + $config->get('WBQualityConstraintsUsedAsReferenceConstraintId') |
|
219 | + => ConstraintCheckerServices::getReferenceChecker($services), |
|
220 | + $config->get('WBQualityConstraintsNoBoundsConstraintId') |
|
221 | + => ConstraintCheckerServices::getNoBoundsChecker($services), |
|
222 | + $config->get('WBQualityConstraintsAllowedUnitsConstraintId') |
|
223 | + => ConstraintCheckerServices::getAllowedUnitsChecker($services), |
|
224 | + $config->get('WBQualityConstraintsSingleBestValueConstraintId') |
|
225 | + => ConstraintCheckerServices::getSingleBestValueChecker($services), |
|
226 | + $config->get('WBQualityConstraintsAllowedEntityTypesConstraintId') |
|
227 | + => ConstraintCheckerServices::getEntityTypeChecker($services), |
|
228 | + $config->get('WBQualityConstraintsNoneOfConstraintId') |
|
229 | + => ConstraintCheckerServices::getNoneOfChecker($services), |
|
230 | + $config->get('WBQualityConstraintsIntegerConstraintId') |
|
231 | + => ConstraintCheckerServices::getIntegerChecker($services), |
|
232 | + $config->get('WBQualityConstraintsCitationNeededConstraintId') |
|
233 | + => ConstraintCheckerServices::getCitationNeededChecker($services), |
|
234 | + $config->get('WBQualityConstraintsPropertyScopeConstraintId') |
|
235 | + => ConstraintCheckerServices::getPropertyScopeChecker($services), |
|
236 | + $config->get('WBQualityConstraintsContemporaryConstraintId') |
|
237 | + => ConstraintCheckerServices::getContemporaryChecker($services), |
|
238 | 238 | ]; |
239 | 239 | |
240 | 240 | return new DelegatingConstraintChecker( |
241 | - WikibaseServices::getEntityLookup( $services ), |
|
241 | + WikibaseServices::getEntityLookup($services), |
|
242 | 242 | $checkerMap, |
243 | - ConstraintsServices::getConstraintLookup( $services ), |
|
244 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
243 | + ConstraintsServices::getConstraintLookup($services), |
|
244 | + ConstraintsServices::getConstraintParameterParser($services), |
|
245 | 245 | $statementGuidParser, |
246 | - ConstraintsServices::getLoggingHelper( $services ), |
|
247 | - $config->get( 'WBQualityConstraintsCheckQualifiers' ), |
|
248 | - $config->get( 'WBQualityConstraintsCheckReferences' ), |
|
249 | - $config->get( 'WBQualityConstraintsPropertiesWithViolatingQualifiers' ) |
|
246 | + ConstraintsServices::getLoggingHelper($services), |
|
247 | + $config->get('WBQualityConstraintsCheckQualifiers'), |
|
248 | + $config->get('WBQualityConstraintsCheckReferences'), |
|
249 | + $config->get('WBQualityConstraintsPropertiesWithViolatingQualifiers') |
|
250 | 250 | ); |
251 | 251 | }, |
252 | 252 | |
253 | - ConstraintsServices::RESULTS_SOURCE => function ( MediaWikiServices $services ) { |
|
253 | + ConstraintsServices::RESULTS_SOURCE => function(MediaWikiServices $services) { |
|
254 | 254 | $config = $services->getMainConfig(); |
255 | 255 | $resultsSource = new CheckingResultsSource( |
256 | - ConstraintsServices::getDelegatingConstraintChecker( $services ) |
|
256 | + ConstraintsServices::getDelegatingConstraintChecker($services) |
|
257 | 257 | ); |
258 | 258 | |
259 | 259 | $cacheCheckConstraintsResults = false; |
260 | 260 | |
261 | - if ( $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) ) { |
|
261 | + if ($config->get('WBQualityConstraintsCacheCheckConstraintsResults')) { |
|
262 | 262 | $cacheCheckConstraintsResults = true; |
263 | 263 | // check that we can use getLocalRepoWikiPageMetaDataAccessor() |
264 | 264 | // TODO we should always be able to cache constraint check results (T244726) |
265 | - $entitySources = WikibaseRepo::getEntitySourceDefinitions( $services )->getSources(); |
|
266 | - $localEntitySourceName = WikibaseRepo::getLocalEntitySource( $services )->getSourceName(); |
|
265 | + $entitySources = WikibaseRepo::getEntitySourceDefinitions($services)->getSources(); |
|
266 | + $localEntitySourceName = WikibaseRepo::getLocalEntitySource($services)->getSourceName(); |
|
267 | 267 | |
268 | - foreach ( $entitySources as $entitySource ) { |
|
269 | - if ( $entitySource->getSourceName() !== $localEntitySourceName ) { |
|
270 | - LoggerFactory::getInstance( 'WikibaseQualityConstraints' )->warning( |
|
271 | - 'Cannot cache constraint check results for non-local source: ' . |
|
268 | + foreach ($entitySources as $entitySource) { |
|
269 | + if ($entitySource->getSourceName() !== $localEntitySourceName) { |
|
270 | + LoggerFactory::getInstance('WikibaseQualityConstraints')->warning( |
|
271 | + 'Cannot cache constraint check results for non-local source: '. |
|
272 | 272 | $entitySource->getSourceName() |
273 | 273 | ); |
274 | 274 | $cacheCheckConstraintsResults = false; |
@@ -277,29 +277,29 @@ discard block |
||
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
280 | - if ( $cacheCheckConstraintsResults ) { |
|
280 | + if ($cacheCheckConstraintsResults) { |
|
281 | 281 | $possiblyStaleConstraintTypes = [ |
282 | - $config->get( 'WBQualityConstraintsCommonsLinkConstraintId' ), |
|
283 | - $config->get( 'WBQualityConstraintsTypeConstraintId' ), |
|
284 | - $config->get( 'WBQualityConstraintsValueTypeConstraintId' ), |
|
285 | - $config->get( 'WBQualityConstraintsDistinctValuesConstraintId' ), |
|
282 | + $config->get('WBQualityConstraintsCommonsLinkConstraintId'), |
|
283 | + $config->get('WBQualityConstraintsTypeConstraintId'), |
|
284 | + $config->get('WBQualityConstraintsValueTypeConstraintId'), |
|
285 | + $config->get('WBQualityConstraintsDistinctValuesConstraintId'), |
|
286 | 286 | ]; |
287 | 287 | // TODO in the future, get WikiPageEntityMetaDataAccessor from $services? |
288 | 288 | $repo = WikibaseRepo::getDefaultInstance(); |
289 | - $entityIdParser = WikibaseRepo::getEntityIdParser( $services ); |
|
289 | + $entityIdParser = WikibaseRepo::getEntityIdParser($services); |
|
290 | 290 | $wikiPageEntityMetaDataAccessor = $repo->getLocalRepoWikiPageMetaDataAccessor(); |
291 | 291 | |
292 | 292 | $resultsSource = new CachingResultsSource( |
293 | 293 | $resultsSource, |
294 | 294 | ResultsCache::getDefaultInstance(), |
295 | - ConstraintsServices::getCheckResultSerializer( $services ), |
|
296 | - ConstraintsServices::getCheckResultDeserializer( $services ), |
|
295 | + ConstraintsServices::getCheckResultSerializer($services), |
|
296 | + ConstraintsServices::getCheckResultDeserializer($services), |
|
297 | 297 | $wikiPageEntityMetaDataAccessor, |
298 | 298 | $entityIdParser, |
299 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsTTLSeconds' ), |
|
299 | + $config->get('WBQualityConstraintsCacheCheckConstraintsTTLSeconds'), |
|
300 | 300 | $possiblyStaleConstraintTypes, |
301 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds' ), |
|
302 | - ConstraintsServices::getLoggingHelper( $services ) |
|
301 | + $config->get('WBQualityConstraintsCacheCheckConstraintsMaximumRevisionIds'), |
|
302 | + ConstraintsServices::getLoggingHelper($services) |
|
303 | 303 | ); |
304 | 304 | } |
305 | 305 |
@@ -28,27 +28,27 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @param DatabaseUpdater $updater |
30 | 30 | */ |
31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
32 | - $dir = dirname( __DIR__ ) . '/sql/'; |
|
31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
32 | + $dir = dirname(__DIR__).'/sql/'; |
|
33 | 33 | |
34 | 34 | $updater->addExtensionTable( |
35 | 35 | 'wbqc_constraints', |
36 | - $dir . "/{$updater->getDB()->getType()}/tables-generated.sql" |
|
36 | + $dir."/{$updater->getDB()->getType()}/tables-generated.sql" |
|
37 | 37 | ); |
38 | 38 | $updater->addExtensionField( |
39 | 39 | 'wbqc_constraints', |
40 | 40 | 'constraint_id', |
41 | - $dir . '/patch-wbqc_constraints-constraint_id.sql' |
|
41 | + $dir.'/patch-wbqc_constraints-constraint_id.sql' |
|
42 | 42 | ); |
43 | 43 | $updater->addExtensionIndex( |
44 | 44 | 'wbqc_constraints', |
45 | 45 | 'wbqc_constraints_guid_uniq', |
46 | - $dir . '/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
46 | + $dir.'/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
47 | 47 | ); |
48 | 48 | } |
49 | 49 | |
50 | - public static function onWikibaseChange( Change $change ) { |
|
51 | - if ( !( $change instanceof EntityChange ) ) { |
|
50 | + public static function onWikibaseChange(Change $change) { |
|
51 | + if (!($change instanceof EntityChange)) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
@@ -57,48 +57,48 @@ discard block |
||
57 | 57 | |
58 | 58 | // If jobs are enabled and the results would be stored in some way run a job. |
59 | 59 | if ( |
60 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
61 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
60 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
61 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
62 | 62 | self::isSelectedForJobRunBasedOnPercentage() |
63 | 63 | ) { |
64 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
64 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
65 | 65 | JobQueueGroup::singleton()->lazyPush( |
66 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
66 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
67 | 67 | ); |
68 | 68 | } |
69 | 69 | |
70 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
71 | - self::isConstraintStatementsChange( $config, $change ) |
|
70 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
71 | + self::isConstraintStatementsChange($config, $change) |
|
72 | 72 | ) { |
73 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
73 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
74 | 74 | $metadata = $change->getMetadata(); |
75 | - if ( array_key_exists( 'rev_id', $metadata ) ) { |
|
75 | + if (array_key_exists('rev_id', $metadata)) { |
|
76 | 76 | $params['revisionId'] = $metadata['rev_id']; |
77 | 77 | } |
78 | 78 | JobQueueGroup::singleton()->push( |
79 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
79 | + new JobSpecification('constraintsTableUpdate', $params) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | 84 | private static function isSelectedForJobRunBasedOnPercentage() { |
85 | 85 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
86 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
86 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
87 | 87 | |
88 | - return mt_rand( 1, 100 ) <= $percentage; |
|
88 | + return mt_rand(1, 100) <= $percentage; |
|
89 | 89 | } |
90 | 90 | |
91 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
92 | - if ( !( $change instanceof EntityChange ) || |
|
91 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
92 | + if (!($change instanceof EntityChange) || |
|
93 | 93 | $change->getAction() !== EntityChange::UPDATE || |
94 | - !( $change->getEntityId() instanceof PropertyId ) |
|
94 | + !($change->getEntityId() instanceof PropertyId) |
|
95 | 95 | ) { |
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | |
99 | 99 | $info = $change->getInfo(); |
100 | 100 | |
101 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
101 | + if (!array_key_exists('compactDiff', $info)) { |
|
102 | 102 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
103 | 103 | // so we only know that the change *might* affect the constraint statements |
104 | 104 | return true; |
@@ -107,45 +107,45 @@ discard block |
||
107 | 107 | /** @var EntityDiffChangedAspects $aspects */ |
108 | 108 | $aspects = $info['compactDiff']; |
109 | 109 | |
110 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
111 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
110 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
111 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
112 | 112 | } |
113 | 113 | |
114 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
114 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
115 | 115 | $entityContentFactory = WikibaseRepo::getEntityContentFactory(); |
116 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
116 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
117 | 117 | $entityIdLookup = WikibaseRepo::getEntityIdLookup(); |
118 | - $entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
119 | - if ( $entityId !== null ) { |
|
118 | + $entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle()); |
|
119 | + if ($entityId !== null) { |
|
120 | 120 | $resultsCache = ResultsCache::getDefaultInstance(); |
121 | - $resultsCache->delete( $entityId ); |
|
121 | + $resultsCache->delete($entityId); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
126 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
127 | 127 | $repo = WikibaseRepo::getDefaultInstance(); |
128 | 128 | |
129 | 129 | $lookup = $repo->getEntityNamespaceLookup(); |
130 | 130 | $title = $out->getTitle(); |
131 | - if ( $title === null ) { |
|
131 | + if ($title === null) { |
|
132 | 132 | return; |
133 | 133 | } |
134 | 134 | |
135 | - if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) { |
|
135 | + if (!$lookup->isNamespaceWithEntities($title->getNamespace())) { |
|
136 | 136 | return; |
137 | 137 | } |
138 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
138 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
142 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
142 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
143 | 143 | |
144 | - if ( !$out->getUser()->isRegistered() ) { |
|
144 | + if (!$out->getUser()->isRegistered()) { |
|
145 | 145 | return; |
146 | 146 | } |
147 | 147 | |
148 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
148 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | } |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | |
87 | 87 | $language = $repo->getUserLanguage(); |
88 | 88 | $formatterOptions = new FormatterOptions(); |
89 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
90 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
89 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
90 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
91 | 91 | |
92 | 92 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
93 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $language ); |
|
93 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($language); |
|
94 | 94 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
95 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $language ); |
|
95 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($language); |
|
96 | 96 | |
97 | 97 | $checkResultsRenderer = new CheckResultsRenderer( |
98 | 98 | $entityTitleLookup, |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $name, |
111 | 111 | $entityIdParser, |
112 | 112 | $statementGuidValidator, |
113 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
113 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
114 | 114 | $resultsSource, |
115 | 115 | $checkResultsRenderer, |
116 | 116 | $dataFactory |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | CheckResultsRenderer $checkResultsRenderer, |
138 | 138 | IBufferingStatsdDataFactory $dataFactory |
139 | 139 | ) { |
140 | - parent::__construct( $main, $name ); |
|
140 | + parent::__construct($main, $name); |
|
141 | 141 | $this->entityIdParser = $entityIdParser; |
142 | 142 | $this->statementGuidValidator = $statementGuidValidator; |
143 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
144 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
143 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
144 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
145 | 145 | $this->resultsSource = $resultsSource; |
146 | 146 | $this->checkResultsRenderer = $checkResultsRenderer; |
147 | 147 | $this->dataFactory = $dataFactory; |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | |
158 | 158 | $params = $this->extractRequestParams(); |
159 | 159 | |
160 | - $this->validateParameters( $params ); |
|
161 | - $entityIds = $this->parseEntityIds( $params ); |
|
162 | - $claimIds = $this->parseClaimIds( $params ); |
|
160 | + $this->validateParameters($params); |
|
161 | + $entityIds = $this->parseEntityIds($params); |
|
162 | + $claimIds = $this->parseClaimIds($params); |
|
163 | 163 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
164 | 164 | $statuses = $params[self::PARAM_STATUS]; |
165 | 165 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | ) |
176 | 176 | )->getArray() |
177 | 177 | ); |
178 | - $this->resultBuilder->markSuccess( 1 ); |
|
178 | + $this->resultBuilder->markSuccess(1); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -183,24 +183,24 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return EntityId[] |
185 | 185 | */ |
186 | - private function parseEntityIds( array $params ) { |
|
186 | + private function parseEntityIds(array $params) { |
|
187 | 187 | $ids = $params[self::PARAM_ID]; |
188 | 188 | |
189 | - if ( $ids === null ) { |
|
189 | + if ($ids === null) { |
|
190 | 190 | return []; |
191 | - } elseif ( $ids === [] ) { |
|
191 | + } elseif ($ids === []) { |
|
192 | 192 | $this->errorReporter->dieError( |
193 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
193 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
194 | 194 | } |
195 | 195 | |
196 | - return array_map( function ( $id ) { |
|
196 | + return array_map(function($id) { |
|
197 | 197 | try { |
198 | - return $this->entityIdParser->parse( $id ); |
|
199 | - } catch ( EntityIdParsingException $e ) { |
|
198 | + return $this->entityIdParser->parse($id); |
|
199 | + } catch (EntityIdParsingException $e) { |
|
200 | 200 | $this->errorReporter->dieError( |
201 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
201 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
202 | 202 | } |
203 | - }, $ids ); |
|
203 | + }, $ids); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -208,35 +208,35 @@ discard block |
||
208 | 208 | * |
209 | 209 | * @return string[] |
210 | 210 | */ |
211 | - private function parseClaimIds( array $params ) { |
|
211 | + private function parseClaimIds(array $params) { |
|
212 | 212 | $ids = $params[self::PARAM_CLAIM_ID]; |
213 | 213 | |
214 | - if ( $ids === null ) { |
|
214 | + if ($ids === null) { |
|
215 | 215 | return []; |
216 | - } elseif ( $ids === [] ) { |
|
216 | + } elseif ($ids === []) { |
|
217 | 217 | $this->errorReporter->dieError( |
218 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
218 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
219 | 219 | } |
220 | 220 | |
221 | - foreach ( $ids as $id ) { |
|
222 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
221 | + foreach ($ids as $id) { |
|
222 | + if (!$this->statementGuidValidator->validate($id)) { |
|
223 | 223 | $this->errorReporter->dieError( |
224 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
224 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
228 | 228 | return $ids; |
229 | 229 | } |
230 | 230 | |
231 | - private function validateParameters( array $params ) { |
|
232 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
233 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
231 | + private function validateParameters(array $params) { |
|
232 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
233 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
234 | 234 | ) { |
235 | 235 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
236 | 236 | $this->errorReporter->dieError( |
237 | 237 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
238 | 238 | } |
239 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
239 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
240 | 240 | $paramId = self::PARAM_ID; |
241 | 241 | $paramClaimId = self::PARAM_CLAIM_ID; |
242 | 242 | $this->errorReporter->dieError( |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | ], |
278 | 278 | ApiBase::PARAM_ISMULTI => true, |
279 | 279 | ApiBase::PARAM_ALL => true, |
280 | - ApiBase::PARAM_DFLT => implode( '|', CachingResultsSource::CACHED_STATUSES ), |
|
280 | + ApiBase::PARAM_DFLT => implode('|', CachingResultsSource::CACHED_STATUSES), |
|
281 | 281 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
282 | 282 | ], |
283 | 283 | ]; |