@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | EntityIdLookup $entityIdLookup, |
40 | 40 | RdfVocabulary $rdfVocabulary |
41 | 41 | ) { |
42 | - parent::__construct( $page, $context ); |
|
42 | + parent::__construct($page, $context); |
|
43 | 43 | $this->resultsSource = $resultsSource; |
44 | 44 | $this->entityIdLookup = $entityIdLookup; |
45 | 45 | $this->rdfVocabulary = $rdfVocabulary; |
46 | 46 | } |
47 | 47 | |
48 | - public static function newFromGlobalState( Page $page, IContextSource $context = null ) { |
|
48 | + public static function newFromGlobalState(Page $page, IContextSource $context = null) { |
|
49 | 49 | $repo = WikibaseRepo::getDefaultInstance(); |
50 | 50 | |
51 | 51 | return new static( |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | * @param string $guid |
93 | 93 | * @return string |
94 | 94 | */ |
95 | - private function cleanupGuid( $guid ) { |
|
96 | - return preg_replace( '/[^\w-]/', '-', $guid ); |
|
95 | + private function cleanupGuid($guid) { |
|
96 | + return preg_replace('/[^\w-]/', '-', $guid); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -105,51 +105,51 @@ discard block |
||
105 | 105 | $response = $this->getRequest()->response(); |
106 | 106 | $this->getOutput()->disable(); |
107 | 107 | |
108 | - if ( !$this->resultsSource instanceof CachingResultsSource ) { |
|
108 | + if (!$this->resultsSource instanceof CachingResultsSource) { |
|
109 | 109 | // TODO: make configurable whether only cached results are returned |
110 | - $response->statusHeader( 501 ); // Not Implemented |
|
110 | + $response->statusHeader(501); // Not Implemented |
|
111 | 111 | return null; |
112 | 112 | } |
113 | 113 | |
114 | - $entityId = $this->entityIdLookup->getEntityIdForTitle( $this->getTitle() ); |
|
115 | - if ( $entityId === null ) { |
|
116 | - $response->statusHeader( 404 ); // Not Found |
|
114 | + $entityId = $this->entityIdLookup->getEntityIdForTitle($this->getTitle()); |
|
115 | + if ($entityId === null) { |
|
116 | + $response->statusHeader(404); // Not Found |
|
117 | 117 | return null; |
118 | 118 | } |
119 | 119 | |
120 | - $results = $this->resultsSource->getStoredResults( $entityId ); |
|
121 | - if ( $results === null ) { |
|
122 | - $response->statusHeader( 204 ); // No Content |
|
120 | + $results = $this->resultsSource->getStoredResults($entityId); |
|
121 | + if ($results === null) { |
|
122 | + $response->statusHeader(204); // No Content |
|
123 | 123 | return null; |
124 | 124 | } |
125 | 125 | |
126 | 126 | $format = 'ttl'; // TODO: make format an option |
127 | 127 | |
128 | 128 | $writerFactory = new RdfWriterFactory(); |
129 | - $formatName = $writerFactory->getFormatName( $format ); |
|
130 | - $contentType = $writerFactory->getMimeTypes( $formatName )[0]; |
|
129 | + $formatName = $writerFactory->getFormatName($format); |
|
130 | + $contentType = $writerFactory->getMimeTypes($formatName)[0]; |
|
131 | 131 | |
132 | - $response->header( "Content-Type: $contentType; charset=UTF-8" ); |
|
132 | + $response->header("Content-Type: $contentType; charset=UTF-8"); |
|
133 | 133 | |
134 | - $writer = $writerFactory->getWriter( $formatName ); |
|
135 | - foreach ( [ RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY ] as $ns ) { |
|
136 | - $writer->prefix( $ns, $this->rdfVocabulary->getNamespaceURI( $ns ) ); |
|
134 | + $writer = $writerFactory->getWriter($formatName); |
|
135 | + foreach ([RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY] as $ns) { |
|
136 | + $writer->prefix($ns, $this->rdfVocabulary->getNamespaceURI($ns)); |
|
137 | 137 | } |
138 | 138 | $writer->start(); |
139 | 139 | |
140 | - foreach ( $results->getArray() as $checkResult ) { |
|
141 | - if ( $checkResult instanceof NullResult ) { |
|
140 | + foreach ($results->getArray() as $checkResult) { |
|
141 | + if ($checkResult instanceof NullResult) { |
|
142 | 142 | continue; |
143 | 143 | } |
144 | - if ( $checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS ) { |
|
144 | + if ($checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS) { |
|
145 | 145 | continue; |
146 | 146 | } |
147 | 147 | |
148 | - $writer->about( RdfVocabulary::NS_STATEMENT, |
|
149 | - $this->cleanupGuid( $checkResult->getContextCursor()->getStatementGuid() ) ) |
|
150 | - ->say( RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint' ) |
|
151 | - ->is( RdfVocabulary::NS_STATEMENT, |
|
152 | - $this->cleanupGuid( $checkResult->getConstraint()->getConstraintId() ) ); |
|
148 | + $writer->about(RdfVocabulary::NS_STATEMENT, |
|
149 | + $this->cleanupGuid($checkResult->getContextCursor()->getStatementGuid())) |
|
150 | + ->say(RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint') |
|
151 | + ->is(RdfVocabulary::NS_STATEMENT, |
|
152 | + $this->cleanupGuid($checkResult->getConstraint()->getConstraintId())); |
|
153 | 153 | } |
154 | 154 | $writer->finish(); |
155 | 155 | echo $writer->drain(); |
@@ -79,19 +79,19 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @return self |
81 | 81 | */ |
82 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
82 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
83 | 83 | $repo = WikibaseRepo::getDefaultInstance(); |
84 | 84 | |
85 | 85 | $language = $repo->getUserLanguage(); |
86 | 86 | $formatterOptions = new FormatterOptions(); |
87 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
87 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
88 | 88 | $valueFormatterFactory = $repo->getValueFormatterFactory(); |
89 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
89 | + $valueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
90 | 90 | |
91 | 91 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
92 | - $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $language ); |
|
92 | + $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($language); |
|
93 | 93 | $entityIdLabelFormatterFactory = new EntityIdLabelFormatterFactory(); |
94 | - $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $language ); |
|
94 | + $entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($language); |
|
95 | 95 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
96 | 96 | $dataFactory = MediaWikiServices::getInstance()->getStatsdDataFactory(); |
97 | 97 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $prefix, |
114 | 114 | $repo->getEntityIdParser(), |
115 | 115 | $repo->getStatementGuidValidator(), |
116 | - $repo->getApiHelperFactory( RequestContext::getMain() ), |
|
116 | + $repo->getApiHelperFactory(RequestContext::getMain()), |
|
117 | 117 | $resultsSource, |
118 | 118 | $checkResultsRenderer, |
119 | 119 | $dataFactory |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | CheckResultsRenderer $checkResultsRenderer, |
143 | 143 | IBufferingStatsdDataFactory $dataFactory |
144 | 144 | ) { |
145 | - parent::__construct( $main, $name, $prefix ); |
|
145 | + parent::__construct($main, $name, $prefix); |
|
146 | 146 | $this->entityIdParser = $entityIdParser; |
147 | 147 | $this->statementGuidValidator = $statementGuidValidator; |
148 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
149 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
148 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
149 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
150 | 150 | $this->resultsSource = $resultsSource; |
151 | 151 | $this->checkResultsRenderer = $checkResultsRenderer; |
152 | 152 | $this->dataFactory = $dataFactory; |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | |
163 | 163 | $params = $this->extractRequestParams(); |
164 | 164 | |
165 | - $this->validateParameters( $params ); |
|
166 | - $entityIds = $this->parseEntityIds( $params ); |
|
167 | - $claimIds = $this->parseClaimIds( $params ); |
|
165 | + $this->validateParameters($params); |
|
166 | + $entityIds = $this->parseEntityIds($params); |
|
167 | + $claimIds = $this->parseClaimIds($params); |
|
168 | 168 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
169 | 169 | $statuses = $params[self::PARAM_STATUS]; |
170 | 170 | |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | ) |
181 | 181 | )->getArray() |
182 | 182 | ); |
183 | - $this->resultBuilder->markSuccess( 1 ); |
|
183 | + $this->resultBuilder->markSuccess(1); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -188,24 +188,24 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @return EntityId[] |
190 | 190 | */ |
191 | - private function parseEntityIds( array $params ) { |
|
191 | + private function parseEntityIds(array $params) { |
|
192 | 192 | $ids = $params[self::PARAM_ID]; |
193 | 193 | |
194 | - if ( $ids === null ) { |
|
194 | + if ($ids === null) { |
|
195 | 195 | return []; |
196 | - } elseif ( $ids === [] ) { |
|
196 | + } elseif ($ids === []) { |
|
197 | 197 | $this->errorReporter->dieError( |
198 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
198 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
199 | 199 | } |
200 | 200 | |
201 | - return array_map( function ( $id ) { |
|
201 | + return array_map(function($id) { |
|
202 | 202 | try { |
203 | - return $this->entityIdParser->parse( $id ); |
|
204 | - } catch ( EntityIdParsingException $e ) { |
|
203 | + return $this->entityIdParser->parse($id); |
|
204 | + } catch (EntityIdParsingException $e) { |
|
205 | 205 | $this->errorReporter->dieError( |
206 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
206 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
207 | 207 | } |
208 | - }, $ids ); |
|
208 | + }, $ids); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -213,35 +213,35 @@ discard block |
||
213 | 213 | * |
214 | 214 | * @return string[] |
215 | 215 | */ |
216 | - private function parseClaimIds( array $params ) { |
|
216 | + private function parseClaimIds(array $params) { |
|
217 | 217 | $ids = $params[self::PARAM_CLAIM_ID]; |
218 | 218 | |
219 | - if ( $ids === null ) { |
|
219 | + if ($ids === null) { |
|
220 | 220 | return []; |
221 | - } elseif ( $ids === [] ) { |
|
221 | + } elseif ($ids === []) { |
|
222 | 222 | $this->errorReporter->dieError( |
223 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
223 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
224 | 224 | } |
225 | 225 | |
226 | - foreach ( $ids as $id ) { |
|
227 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
226 | + foreach ($ids as $id) { |
|
227 | + if (!$this->statementGuidValidator->validate($id)) { |
|
228 | 228 | $this->errorReporter->dieError( |
229 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
229 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
230 | 230 | } |
231 | 231 | } |
232 | 232 | |
233 | 233 | return $ids; |
234 | 234 | } |
235 | 235 | |
236 | - private function validateParameters( array $params ) { |
|
237 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
238 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
236 | + private function validateParameters(array $params) { |
|
237 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
238 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
239 | 239 | ) { |
240 | 240 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
241 | 241 | $this->errorReporter->dieError( |
242 | 242 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
243 | 243 | } |
244 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
244 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
245 | 245 | $paramId = self::PARAM_ID; |
246 | 246 | $paramClaimId = self::PARAM_CLAIM_ID; |
247 | 247 | $this->errorReporter->dieError( |
@@ -281,11 +281,11 @@ discard block |
||
281 | 281 | ], |
282 | 282 | ApiBase::PARAM_ISMULTI => true, |
283 | 283 | ApiBase::PARAM_ALL => true, |
284 | - ApiBase::PARAM_DFLT => implode( '|', [ |
|
284 | + ApiBase::PARAM_DFLT => implode('|', [ |
|
285 | 285 | CheckResult::STATUS_VIOLATION, |
286 | 286 | CheckResult::STATUS_WARNING, |
287 | 287 | CheckResult::STATUS_BAD_PARAMETERS, |
288 | - ] ), |
|
288 | + ]), |
|
289 | 289 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
290 | 290 | ], |
291 | 291 | ]; |
@@ -35,124 +35,124 @@ discard block |
||
35 | 35 | use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker; |
36 | 36 | |
37 | 37 | return [ |
38 | - ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => function( MediaWikiServices $services ) { |
|
38 | + ConstraintCheckerServices::CONFLICTS_WITH_CHECKER => function(MediaWikiServices $services) { |
|
39 | 39 | return new ConflictsWithChecker( |
40 | - WikibaseServices::getEntityLookup( $services ), |
|
41 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
42 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
40 | + WikibaseServices::getEntityLookup($services), |
|
41 | + ConstraintsServices::getConstraintParameterParser($services), |
|
42 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
43 | 43 | ); |
44 | 44 | }, |
45 | 45 | |
46 | - ConstraintCheckerServices::ITEM_CHECKER => function( MediaWikiServices $services ) { |
|
46 | + ConstraintCheckerServices::ITEM_CHECKER => function(MediaWikiServices $services) { |
|
47 | 47 | return new ItemChecker( |
48 | - WikibaseServices::getEntityLookup( $services ), |
|
49 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
50 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
48 | + WikibaseServices::getEntityLookup($services), |
|
49 | + ConstraintsServices::getConstraintParameterParser($services), |
|
50 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
51 | 51 | ); |
52 | 52 | }, |
53 | 53 | |
54 | - ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => function( MediaWikiServices $services ) { |
|
54 | + ConstraintCheckerServices::TARGET_REQUIRED_CLAIM_CHECKER => function(MediaWikiServices $services) { |
|
55 | 55 | return new TargetRequiredClaimChecker( |
56 | - WikibaseServices::getEntityLookup( $services ), |
|
57 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
58 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
56 | + WikibaseServices::getEntityLookup($services), |
|
57 | + ConstraintsServices::getConstraintParameterParser($services), |
|
58 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
59 | 59 | ); |
60 | 60 | }, |
61 | 61 | |
62 | - ConstraintCheckerServices::SYMMETRIC_CHECKER => function( MediaWikiServices $services ) { |
|
62 | + ConstraintCheckerServices::SYMMETRIC_CHECKER => function(MediaWikiServices $services) { |
|
63 | 63 | return new SymmetricChecker( |
64 | - WikibaseServices::getEntityLookup( $services ), |
|
65 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
64 | + WikibaseServices::getEntityLookup($services), |
|
65 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
66 | 66 | ); |
67 | 67 | }, |
68 | 68 | |
69 | - ConstraintCheckerServices::INVERSE_CHECKER => function( MediaWikiServices $services ) { |
|
69 | + ConstraintCheckerServices::INVERSE_CHECKER => function(MediaWikiServices $services) { |
|
70 | 70 | return new InverseChecker( |
71 | - WikibaseServices::getEntityLookup( $services ), |
|
72 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
73 | - ConstraintsServices::getConnectionCheckerHelper( $services ) |
|
71 | + WikibaseServices::getEntityLookup($services), |
|
72 | + ConstraintsServices::getConstraintParameterParser($services), |
|
73 | + ConstraintsServices::getConnectionCheckerHelper($services) |
|
74 | 74 | ); |
75 | 75 | }, |
76 | 76 | |
77 | - ConstraintCheckerServices::QUALIFIER_CHECKER => function( MediaWikiServices $services ) { |
|
77 | + ConstraintCheckerServices::QUALIFIER_CHECKER => function(MediaWikiServices $services) { |
|
78 | 78 | return new QualifierChecker(); |
79 | 79 | }, |
80 | 80 | |
81 | - ConstraintCheckerServices::QUALIFIERS_CHECKER => function( MediaWikiServices $services ) { |
|
81 | + ConstraintCheckerServices::QUALIFIERS_CHECKER => function(MediaWikiServices $services) { |
|
82 | 82 | return new QualifiersChecker( |
83 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
83 | + ConstraintsServices::getConstraintParameterParser($services) |
|
84 | 84 | ); |
85 | 85 | }, |
86 | 86 | |
87 | - ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => function( MediaWikiServices $services ) { |
|
87 | + ConstraintCheckerServices::MANDATORY_QUALIFIERS_CHECKER => function(MediaWikiServices $services) { |
|
88 | 88 | return new MandatoryQualifiersChecker( |
89 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
89 | + ConstraintsServices::getConstraintParameterParser($services) |
|
90 | 90 | ); |
91 | 91 | }, |
92 | 92 | |
93 | - ConstraintCheckerServices::RANGE_CHECKER => function( MediaWikiServices $services ) { |
|
93 | + ConstraintCheckerServices::RANGE_CHECKER => function(MediaWikiServices $services) { |
|
94 | 94 | return new RangeChecker( |
95 | - WikibaseServices::getPropertyDataTypeLookup( $services ), |
|
96 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
97 | - ConstraintsServices::getRangeCheckerHelper( $services ) |
|
95 | + WikibaseServices::getPropertyDataTypeLookup($services), |
|
96 | + ConstraintsServices::getConstraintParameterParser($services), |
|
97 | + ConstraintsServices::getRangeCheckerHelper($services) |
|
98 | 98 | ); |
99 | 99 | }, |
100 | 100 | |
101 | - ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => function( MediaWikiServices $services ) { |
|
101 | + ConstraintCheckerServices::DIFF_WITHIN_RANGE_CHECKER => function(MediaWikiServices $services) { |
|
102 | 102 | return new DiffWithinRangeChecker( |
103 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
104 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
103 | + ConstraintsServices::getConstraintParameterParser($services), |
|
104 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
105 | 105 | $services->getMainConfig() |
106 | 106 | ); |
107 | 107 | }, |
108 | 108 | |
109 | - ConstraintCheckerServices::TYPE_CHECKER => function( MediaWikiServices $services ) { |
|
109 | + ConstraintCheckerServices::TYPE_CHECKER => function(MediaWikiServices $services) { |
|
110 | 110 | return new TypeChecker( |
111 | - WikibaseServices::getEntityLookup( $services ), |
|
112 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
113 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
111 | + WikibaseServices::getEntityLookup($services), |
|
112 | + ConstraintsServices::getConstraintParameterParser($services), |
|
113 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
114 | 114 | $services->getMainConfig() |
115 | 115 | ); |
116 | 116 | }, |
117 | 117 | |
118 | - ConstraintCheckerServices::VALUE_TYPE_CHECKER => function( MediaWikiServices $services ) { |
|
118 | + ConstraintCheckerServices::VALUE_TYPE_CHECKER => function(MediaWikiServices $services) { |
|
119 | 119 | return new ValueTypeChecker( |
120 | - WikibaseServices::getEntityLookup( $services ), |
|
121 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
122 | - ConstraintsServices::getTypeCheckerHelper( $services ), |
|
120 | + WikibaseServices::getEntityLookup($services), |
|
121 | + ConstraintsServices::getConstraintParameterParser($services), |
|
122 | + ConstraintsServices::getTypeCheckerHelper($services), |
|
123 | 123 | $services->getMainConfig() |
124 | 124 | ); |
125 | 125 | }, |
126 | 126 | |
127 | - ConstraintCheckerServices::SINGLE_VALUE_CHECKER => function( MediaWikiServices $services ) { |
|
127 | + ConstraintCheckerServices::SINGLE_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
128 | 128 | return new SingleValueChecker( |
129 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
129 | + ConstraintsServices::getConstraintParameterParser($services) |
|
130 | 130 | ); |
131 | 131 | }, |
132 | 132 | |
133 | - ConstraintCheckerServices::MULTI_VALUE_CHECKER => function( MediaWikiServices $services ) { |
|
133 | + ConstraintCheckerServices::MULTI_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
134 | 134 | return new MultiValueChecker( |
135 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
135 | + ConstraintsServices::getConstraintParameterParser($services) |
|
136 | 136 | ); |
137 | 137 | }, |
138 | 138 | |
139 | - ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => function( MediaWikiServices $services ) { |
|
139 | + ConstraintCheckerServices::UNIQUE_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
140 | 140 | // TODO return a different, dummy implementation if SPARQL is not available |
141 | 141 | return new UniqueValueChecker( |
142 | - ConstraintsServices::getSparqlHelper( $services ) |
|
142 | + ConstraintsServices::getSparqlHelper($services) |
|
143 | 143 | ); |
144 | 144 | }, |
145 | 145 | |
146 | - ConstraintCheckerServices::FORMAT_CHECKER => function( MediaWikiServices $services ) { |
|
146 | + ConstraintCheckerServices::FORMAT_CHECKER => function(MediaWikiServices $services) { |
|
147 | 147 | // TODO return a different, dummy implementation if SPARQL is not available |
148 | 148 | return new FormatChecker( |
149 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
149 | + ConstraintsServices::getConstraintParameterParser($services), |
|
150 | 150 | $services->getMainConfig(), |
151 | - ConstraintsServices::getSparqlHelper( $services ) |
|
151 | + ConstraintsServices::getSparqlHelper($services) |
|
152 | 152 | ); |
153 | 153 | }, |
154 | 154 | |
155 | - ConstraintCheckerServices::COMMONS_LINK_CHECKER => function( MediaWikiServices $services ) { |
|
155 | + ConstraintCheckerServices::COMMONS_LINK_CHECKER => function(MediaWikiServices $services) { |
|
156 | 156 | // TODO return different implementations for: |
157 | 157 | // - Wikimedia production ('commonswiki' database available) |
158 | 158 | // - InstantCommons wikis |
@@ -160,76 +160,76 @@ discard block |
||
160 | 160 | // - … |
161 | 161 | // ? (see also T169538) |
162 | 162 | return new CommonsLinkChecker( |
163 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
163 | + ConstraintsServices::getConstraintParameterParser($services), |
|
164 | 164 | $services->getTitleParser() |
165 | 165 | ); |
166 | 166 | }, |
167 | 167 | |
168 | - ConstraintCheckerServices::ONE_OF_CHECKER => function( MediaWikiServices $services ) { |
|
168 | + ConstraintCheckerServices::ONE_OF_CHECKER => function(MediaWikiServices $services) { |
|
169 | 169 | return new OneOfChecker( |
170 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
170 | + ConstraintsServices::getConstraintParameterParser($services) |
|
171 | 171 | ); |
172 | 172 | }, |
173 | 173 | |
174 | - ConstraintCheckerServices::VALUE_ONLY_CHECKER => function( MediaWikiServices $services ) { |
|
174 | + ConstraintCheckerServices::VALUE_ONLY_CHECKER => function(MediaWikiServices $services) { |
|
175 | 175 | return new ValueOnlyChecker(); |
176 | 176 | }, |
177 | 177 | |
178 | - ConstraintCheckerServices::REFERENCE_CHECKER => function( MediaWikiServices $services ) { |
|
178 | + ConstraintCheckerServices::REFERENCE_CHECKER => function(MediaWikiServices $services) { |
|
179 | 179 | return new ReferenceChecker(); |
180 | 180 | }, |
181 | 181 | |
182 | - ConstraintCheckerServices::NO_BOUNDS_CHECKER => function( MediaWikiServices $services ) { |
|
182 | + ConstraintCheckerServices::NO_BOUNDS_CHECKER => function(MediaWikiServices $services) { |
|
183 | 183 | return new NoBoundsChecker(); |
184 | 184 | }, |
185 | 185 | |
186 | - ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => function( MediaWikiServices $services ) { |
|
186 | + ConstraintCheckerServices::ALLOWED_UNITS_CHECKER => function(MediaWikiServices $services) { |
|
187 | 187 | // TODO in the future, get UnitConverter from $services? |
188 | 188 | $repo = WikibaseRepo::getDefaultInstance(); |
189 | 189 | $unitConverter = $repo->getUnitConverter(); |
190 | 190 | |
191 | 191 | return new AllowedUnitsChecker( |
192 | - ConstraintsServices::getConstraintParameterParser( $services ), |
|
192 | + ConstraintsServices::getConstraintParameterParser($services), |
|
193 | 193 | $unitConverter |
194 | 194 | ); |
195 | 195 | }, |
196 | 196 | |
197 | - ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => function( MediaWikiServices $services ) { |
|
197 | + ConstraintCheckerServices::SINGLE_BEST_VALUE_CHECKER => function(MediaWikiServices $services) { |
|
198 | 198 | return new SingleBestValueChecker( |
199 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
199 | + ConstraintsServices::getConstraintParameterParser($services) |
|
200 | 200 | ); |
201 | 201 | }, |
202 | 202 | |
203 | - ConstraintCheckerServices::ENTITY_TYPE_CHECKER => function( MediaWikiServices $services ) { |
|
203 | + ConstraintCheckerServices::ENTITY_TYPE_CHECKER => function(MediaWikiServices $services) { |
|
204 | 204 | return new EntityTypeChecker( |
205 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
205 | + ConstraintsServices::getConstraintParameterParser($services) |
|
206 | 206 | ); |
207 | 207 | }, |
208 | 208 | |
209 | - ConstraintCheckerServices::NONE_OF_CHECKER => function( MediaWikiServices $services ) { |
|
209 | + ConstraintCheckerServices::NONE_OF_CHECKER => function(MediaWikiServices $services) { |
|
210 | 210 | return new NoneOfChecker( |
211 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
211 | + ConstraintsServices::getConstraintParameterParser($services) |
|
212 | 212 | ); |
213 | 213 | }, |
214 | 214 | |
215 | - ConstraintCheckerServices::INTEGER_CHECKER => function( MediaWikiServices $services ) { |
|
215 | + ConstraintCheckerServices::INTEGER_CHECKER => function(MediaWikiServices $services) { |
|
216 | 216 | return new IntegerChecker(); |
217 | 217 | }, |
218 | 218 | |
219 | - ConstraintCheckerServices::CITATION_NEEDED_CHECKER => function( MediaWikiServices $services ) { |
|
219 | + ConstraintCheckerServices::CITATION_NEEDED_CHECKER => function(MediaWikiServices $services) { |
|
220 | 220 | return new CitationNeededChecker(); |
221 | 221 | }, |
222 | 222 | |
223 | - ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => function( MediaWikiServices $services ) { |
|
223 | + ConstraintCheckerServices::PROPERTY_SCOPE_CHECKER => function(MediaWikiServices $services) { |
|
224 | 224 | return new PropertyScopeChecker( |
225 | - ConstraintsServices::getConstraintParameterParser( $services ) |
|
225 | + ConstraintsServices::getConstraintParameterParser($services) |
|
226 | 226 | ); |
227 | 227 | }, |
228 | 228 | |
229 | - ConstraintCheckerServices::CONTEMPORARY_CHECKER => function( MediaWikiServices $services ) { |
|
229 | + ConstraintCheckerServices::CONTEMPORARY_CHECKER => function(MediaWikiServices $services) { |
|
230 | 230 | return new ContemporaryChecker( |
231 | - WikibaseServices::getEntityLookup( $services ), |
|
232 | - ConstraintsServices::getRangeCheckerHelper( $services ), |
|
231 | + WikibaseServices::getEntityLookup($services), |
|
232 | + ConstraintsServices::getRangeCheckerHelper($services), |
|
233 | 233 | $services->getMainConfig() |
234 | 234 | ); |
235 | 235 | }, |
@@ -40,10 +40,10 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @throws InvalidArgumentException |
42 | 42 | */ |
43 | - public function __construct( $content, $isSortable = false, $isRawContent = false ) { |
|
44 | - Assert::parameterType( 'string', $content, '$content' ); |
|
45 | - Assert::parameterType( 'boolean', $isSortable, '$isSortable' ); |
|
46 | - Assert::parameterType( 'boolean', $isRawContent, '$isRawContent' ); |
|
43 | + public function __construct($content, $isSortable = false, $isRawContent = false) { |
|
44 | + Assert::parameterType('string', $content, '$content'); |
|
45 | + Assert::parameterType('boolean', $isSortable, '$isSortable'); |
|
46 | + Assert::parameterType('boolean', $isRawContent, '$isRawContent'); |
|
47 | 47 | |
48 | 48 | $this->content = $content; |
49 | 49 | $this->isSortable = $isSortable; |
@@ -70,18 +70,18 @@ discard block |
||
70 | 70 | * @return string HTML |
71 | 71 | */ |
72 | 72 | public function toHtml() { |
73 | - $attributes = [ 'role' => 'columnheader button' ]; |
|
73 | + $attributes = ['role' => 'columnheader button']; |
|
74 | 74 | |
75 | - if ( !$this->isSortable ) { |
|
75 | + if (!$this->isSortable) { |
|
76 | 76 | $attributes['class'] = 'unsortable'; |
77 | 77 | } |
78 | 78 | |
79 | 79 | $content = $this->content; |
80 | - if ( !$this->isRawContent ) { |
|
81 | - $content = htmlspecialchars( $this->content ); |
|
80 | + if (!$this->isRawContent) { |
|
81 | + $content = htmlspecialchars($this->content); |
|
82 | 82 | } |
83 | 83 | |
84 | - return Html::rawElement( 'th', $attributes, $content ); |
|
84 | + return Html::rawElement('th', $attributes, $content); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | } |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @throws InvalidArgumentException |
40 | 40 | */ |
41 | - public function __construct( $content, array $attributes = [], $isRawContent = false ) { |
|
42 | - Assert::parameterType( 'string', $content, '$content' ); |
|
43 | - Assert::parameterType( 'boolean', $isRawContent, '$isRawContent' ); |
|
41 | + public function __construct($content, array $attributes = [], $isRawContent = false) { |
|
42 | + Assert::parameterType('string', $content, '$content'); |
|
43 | + Assert::parameterType('boolean', $isRawContent, '$isRawContent'); |
|
44 | 44 | |
45 | 45 | $this->content = $content; |
46 | 46 | $this->attributes = $attributes; |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | * @return string HTML |
66 | 66 | */ |
67 | 67 | public function toHtml() { |
68 | - if ( $this->isRawContent ) { |
|
69 | - return Html::rawElement( 'td', $this->getAttributes(), $this->content ); |
|
68 | + if ($this->isRawContent) { |
|
69 | + return Html::rawElement('td', $this->getAttributes(), $this->content); |
|
70 | 70 | } else { |
71 | - return Html::element( 'td', $this->getAttributes(), $this->content ); |
|
71 | + return Html::element('td', $this->getAttributes(), $this->content); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * @param array $headers |
34 | 34 | */ |
35 | - public function __construct( array $headers ) { |
|
36 | - foreach ( $headers as $header ) { |
|
37 | - $this->addHeader( $header ); |
|
35 | + public function __construct(array $headers) { |
|
36 | + foreach ($headers as $header) { |
|
37 | + $this->addHeader($header); |
|
38 | 38 | } |
39 | 39 | } |
40 | 40 | |
@@ -43,16 +43,16 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @throws InvalidArgumentException |
45 | 45 | */ |
46 | - private function addHeader( $header ) { |
|
47 | - Assert::parameterType( 'string|' . HtmlTableHeaderBuilder::class, $header, '$header' ); |
|
46 | + private function addHeader($header) { |
|
47 | + Assert::parameterType('string|'.HtmlTableHeaderBuilder::class, $header, '$header'); |
|
48 | 48 | |
49 | - if ( is_string( $header ) ) { |
|
50 | - $header = new HtmlTableHeaderBuilder( $header ); |
|
49 | + if (is_string($header)) { |
|
50 | + $header = new HtmlTableHeaderBuilder($header); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | $this->headers[] = $header; |
54 | 54 | |
55 | - if ( $header->getIsSortable() ) { |
|
55 | + if ($header->getIsSortable()) { |
|
56 | 56 | $this->isSortable = true; |
57 | 57 | } |
58 | 58 | } |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @throws InvalidArgumentException |
87 | 87 | */ |
88 | - public function appendRow( array $cells ) { |
|
89 | - foreach ( $cells as $key => $cell ) { |
|
90 | - if ( is_string( $cell ) ) { |
|
91 | - $cells[$key] = new HtmlTableCellBuilder( $cell ); |
|
92 | - } elseif ( !( $cell instanceof HtmlTableCellBuilder ) ) { |
|
93 | - throw new InvalidArgumentException( '$cells must be array of HtmlTableCell objects.' ); |
|
88 | + public function appendRow(array $cells) { |
|
89 | + foreach ($cells as $key => $cell) { |
|
90 | + if (is_string($cell)) { |
|
91 | + $cells[$key] = new HtmlTableCellBuilder($cell); |
|
92 | + } elseif (!($cell instanceof HtmlTableCellBuilder)) { |
|
93 | + throw new InvalidArgumentException('$cells must be array of HtmlTableCell objects.'); |
|
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @throws InvalidArgumentException |
106 | 106 | */ |
107 | - public function appendRows( array $rows ) { |
|
108 | - foreach ( $rows as $cells ) { |
|
109 | - if ( !is_array( $cells ) ) { |
|
110 | - throw new InvalidArgumentException( '$rows must be array of arrays of HtmlTableCell objects.' ); |
|
107 | + public function appendRows(array $rows) { |
|
108 | + foreach ($rows as $cells) { |
|
109 | + if (!is_array($cells)) { |
|
110 | + throw new InvalidArgumentException('$rows must be array of arrays of HtmlTableCell objects.'); |
|
111 | 111 | } |
112 | 112 | |
113 | - $this->appendRow( $cells ); |
|
113 | + $this->appendRow($cells); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
@@ -122,34 +122,34 @@ discard block |
||
122 | 122 | public function toHtml() { |
123 | 123 | // Open table |
124 | 124 | $tableClasses = 'wikitable'; |
125 | - if ( $this->isSortable ) { |
|
125 | + if ($this->isSortable) { |
|
126 | 126 | $tableClasses .= ' sortable jquery-tablesort'; |
127 | 127 | } |
128 | - $html = Html::openElement( 'table', [ 'class' => $tableClasses ] ); |
|
128 | + $html = Html::openElement('table', ['class' => $tableClasses]); |
|
129 | 129 | |
130 | 130 | // Write headers |
131 | - $html .= Html::openElement( 'tr' ); |
|
132 | - foreach ( $this->headers as $header ) { |
|
131 | + $html .= Html::openElement('tr'); |
|
132 | + foreach ($this->headers as $header) { |
|
133 | 133 | $html .= $header->toHtml(); |
134 | 134 | } |
135 | - $html .= Html::closeElement( 'tr' ); |
|
135 | + $html .= Html::closeElement('tr'); |
|
136 | 136 | |
137 | 137 | // Write rows |
138 | - foreach ( $this->rows as $row ) { |
|
139 | - $html .= Html::openElement( 'tr' ); |
|
138 | + foreach ($this->rows as $row) { |
|
139 | + $html .= Html::openElement('tr'); |
|
140 | 140 | |
141 | 141 | /** |
142 | 142 | * @var HtmlTableCellBuilder $cell |
143 | 143 | */ |
144 | - foreach ( $row as $cell ) { |
|
144 | + foreach ($row as $cell) { |
|
145 | 145 | $html .= $cell->toHtml(); |
146 | 146 | } |
147 | 147 | |
148 | - $html .= Html::closeElement( 'tr' ); |
|
148 | + $html .= Html::closeElement('tr'); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | // Close table |
152 | - $html .= Html::closeElement( 'table' ); |
|
152 | + $html .= Html::closeElement('table'); |
|
153 | 153 | |
154 | 154 | return $html; |
155 | 155 | } |
@@ -120,18 +120,18 @@ discard block |
||
120 | 120 | $this->dataFactory = $dataFactory; |
121 | 121 | $this->defaultUserAgent = $defaultUserAgent; |
122 | 122 | $this->requestFactory = $requestFactory; |
123 | - $this->entityPrefix = $rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY ); |
|
123 | + $this->entityPrefix = $rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY); |
|
124 | 124 | $this->prefixes = <<<EOT |
125 | -PREFIX wd: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_ENTITY )}> |
|
126 | -PREFIX wds: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_STATEMENT )}> |
|
127 | -PREFIX wdt: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_DIRECT_CLAIM )}> |
|
128 | -PREFIX wdv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NS_VALUE )}> |
|
129 | -PREFIX p: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM )}> |
|
130 | -PREFIX ps: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_CLAIM_STATEMENT )}> |
|
131 | -PREFIX pq: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER )}> |
|
132 | -PREFIX pqv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_QUALIFIER_VALUE )}> |
|
133 | -PREFIX pr: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE )}> |
|
134 | -PREFIX prv: <{$rdfVocabulary->getNamespaceURI( RdfVocabulary::NSP_REFERENCE_VALUE )}> |
|
125 | +PREFIX wd: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_ENTITY)}> |
|
126 | +PREFIX wds: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_STATEMENT)}> |
|
127 | +PREFIX wdt: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_DIRECT_CLAIM)}> |
|
128 | +PREFIX wdv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NS_VALUE)}> |
|
129 | +PREFIX p: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM)}> |
|
130 | +PREFIX ps: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_CLAIM_STATEMENT)}> |
|
131 | +PREFIX pq: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER)}> |
|
132 | +PREFIX pqv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_QUALIFIER_VALUE)}> |
|
133 | +PREFIX pr: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE)}> |
|
134 | +PREFIX prv: <{$rdfVocabulary->getNamespaceURI(RdfVocabulary::NSP_REFERENCE_VALUE)}> |
|
135 | 135 | PREFIX wikibase: <http://wikiba.se/ontology#> |
136 | 136 | PREFIX wikibase-beta: <http://wikiba.se/ontology-beta#> |
137 | 137 | EOT; |
@@ -146,21 +146,21 @@ discard block |
||
146 | 146 | * @return CachedBool |
147 | 147 | * @throws SparqlHelperException if the query times out or some other error occurs |
148 | 148 | */ |
149 | - public function hasType( $id, array $classes, $withInstance ) { |
|
150 | - $instanceOfId = $this->config->get( 'WBQualityConstraintsInstanceOfId' ); |
|
151 | - $subclassOfId = $this->config->get( 'WBQualityConstraintsSubclassOfId' ); |
|
149 | + public function hasType($id, array $classes, $withInstance) { |
|
150 | + $instanceOfId = $this->config->get('WBQualityConstraintsInstanceOfId'); |
|
151 | + $subclassOfId = $this->config->get('WBQualityConstraintsSubclassOfId'); |
|
152 | 152 | |
153 | - $path = ( $withInstance ? "wdt:$instanceOfId/" : "" ) . "wdt:$subclassOfId*"; |
|
153 | + $path = ($withInstance ? "wdt:$instanceOfId/" : "")."wdt:$subclassOfId*"; |
|
154 | 154 | |
155 | 155 | $metadatas = []; |
156 | 156 | |
157 | - foreach ( array_chunk( $classes, 20 ) as $classesChunk ) { |
|
158 | - $classesValues = implode( ' ', array_map( |
|
159 | - function( $class ) { |
|
160 | - return 'wd:' . $class; |
|
157 | + foreach (array_chunk($classes, 20) as $classesChunk) { |
|
158 | + $classesValues = implode(' ', array_map( |
|
159 | + function($class) { |
|
160 | + return 'wd:'.$class; |
|
161 | 161 | }, |
162 | 162 | $classesChunk |
163 | - ) ); |
|
163 | + )); |
|
164 | 164 | |
165 | 165 | $query = <<<EOF |
166 | 166 | ASK { |
@@ -171,19 +171,19 @@ discard block |
||
171 | 171 | EOF; |
172 | 172 | // TODO hint:gearing is a workaround for T168973 and can hopefully be removed eventually |
173 | 173 | |
174 | - $result = $this->runQuery( $query ); |
|
174 | + $result = $this->runQuery($query); |
|
175 | 175 | $metadatas[] = $result->getMetadata(); |
176 | - if ( $result->getArray()['boolean'] ) { |
|
176 | + if ($result->getArray()['boolean']) { |
|
177 | 177 | return new CachedBool( |
178 | 178 | true, |
179 | - Metadata::merge( $metadatas ) |
|
179 | + Metadata::merge($metadatas) |
|
180 | 180 | ); |
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | 184 | return new CachedBool( |
185 | 185 | false, |
186 | - Metadata::merge( $metadatas ) |
|
186 | + Metadata::merge($metadatas) |
|
187 | 187 | ); |
188 | 188 | } |
189 | 189 | |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | $ignoreDeprecatedStatements |
200 | 200 | ) { |
201 | 201 | $pid = $statement->getPropertyId()->serialize(); |
202 | - $guid = str_replace( '$', '-', $statement->getGuid() ); |
|
202 | + $guid = str_replace('$', '-', $statement->getGuid()); |
|
203 | 203 | |
204 | 204 | $deprecatedFilter = ''; |
205 | - if ( $ignoreDeprecatedStatements ) { |
|
205 | + if ($ignoreDeprecatedStatements) { |
|
206 | 206 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. }'; |
207 | 207 | $deprecatedFilter .= 'MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. }'; |
208 | 208 | } |
@@ -222,9 +222,9 @@ discard block |
||
222 | 222 | LIMIT 10 |
223 | 223 | EOF; |
224 | 224 | |
225 | - $result = $this->runQuery( $query ); |
|
225 | + $result = $this->runQuery($query); |
|
226 | 226 | |
227 | - return $this->getOtherEntities( $result ); |
|
227 | + return $this->getOtherEntities($result); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -249,16 +249,15 @@ discard block |
||
249 | 249 | $dataType = $this->propertyDataTypeLookup->getDataTypeIdForProperty( |
250 | 250 | $snak->getPropertyId() |
251 | 251 | ); |
252 | - list( $value, $isFullValue ) = $this->getRdfLiteral( $dataType, $dataValue ); |
|
253 | - if ( $isFullValue ) { |
|
252 | + list($value, $isFullValue) = $this->getRdfLiteral($dataType, $dataValue); |
|
253 | + if ($isFullValue) { |
|
254 | 254 | $prefix .= 'v'; |
255 | 255 | } |
256 | 256 | $path = $type === Context::TYPE_QUALIFIER ? |
257 | - "$prefix:$pid" : |
|
258 | - "prov:wasDerivedFrom/$prefix:$pid"; |
|
257 | + "$prefix:$pid" : "prov:wasDerivedFrom/$prefix:$pid"; |
|
259 | 258 | |
260 | 259 | $deprecatedFilter = ''; |
261 | - if ( $ignoreDeprecatedStatements ) { |
|
260 | + if ($ignoreDeprecatedStatements) { |
|
262 | 261 | $deprecatedFilter = <<< EOF |
263 | 262 | MINUS { ?otherStatement wikibase:rank wikibase:DeprecatedRank. } |
264 | 263 | MINUS { ?otherStatement wikibase-beta:rank wikibase-beta:DeprecatedRank. } |
@@ -279,9 +278,9 @@ discard block |
||
279 | 278 | LIMIT 10 |
280 | 279 | EOF; |
281 | 280 | |
282 | - $result = $this->runQuery( $query ); |
|
281 | + $result = $this->runQuery($query); |
|
283 | 282 | |
284 | - return $this->getOtherEntities( $result ); |
|
283 | + return $this->getOtherEntities($result); |
|
285 | 284 | } |
286 | 285 | |
287 | 286 | /** |
@@ -291,8 +290,8 @@ discard block |
||
291 | 290 | * |
292 | 291 | * @return string |
293 | 292 | */ |
294 | - private function stringLiteral( $text ) { |
|
295 | - return '"' . strtr( $text, [ '"' => '\\"', '\\' => '\\\\' ] ) . '"'; |
|
293 | + private function stringLiteral($text) { |
|
294 | + return '"'.strtr($text, ['"' => '\\"', '\\' => '\\\\']).'"'; |
|
296 | 295 | } |
297 | 296 | |
298 | 297 | /** |
@@ -302,17 +301,17 @@ discard block |
||
302 | 301 | * |
303 | 302 | * @return CachedEntityIds |
304 | 303 | */ |
305 | - private function getOtherEntities( CachedQueryResults $results ) { |
|
306 | - return new CachedEntityIds( array_map( |
|
307 | - function ( $resultBindings ) { |
|
304 | + private function getOtherEntities(CachedQueryResults $results) { |
|
305 | + return new CachedEntityIds(array_map( |
|
306 | + function($resultBindings) { |
|
308 | 307 | $entityIRI = $resultBindings['otherEntity']['value']; |
309 | - $entityPrefixLength = strlen( $this->entityPrefix ); |
|
310 | - if ( substr( $entityIRI, 0, $entityPrefixLength ) === $this->entityPrefix ) { |
|
308 | + $entityPrefixLength = strlen($this->entityPrefix); |
|
309 | + if (substr($entityIRI, 0, $entityPrefixLength) === $this->entityPrefix) { |
|
311 | 310 | try { |
312 | 311 | return $this->entityIdParser->parse( |
313 | - substr( $entityIRI, $entityPrefixLength ) |
|
312 | + substr($entityIRI, $entityPrefixLength) |
|
314 | 313 | ); |
315 | - } catch ( EntityIdParsingException $e ) { |
|
314 | + } catch (EntityIdParsingException $e) { |
|
316 | 315 | // fall through |
317 | 316 | } |
318 | 317 | } |
@@ -320,7 +319,7 @@ discard block |
||
320 | 319 | return null; |
321 | 320 | }, |
322 | 321 | $results->getArray()['results']['bindings'] |
323 | - ), $results->getMetadata() ); |
|
322 | + ), $results->getMetadata()); |
|
324 | 323 | } |
325 | 324 | |
326 | 325 | // @codingStandardsIgnoreStart cyclomatic complexity of this function is too high |
@@ -333,47 +332,47 @@ discard block |
||
333 | 332 | * @return array the literal or IRI as a string in SPARQL syntax, |
334 | 333 | * and a boolean indicating whether it refers to a full value node or not |
335 | 334 | */ |
336 | - private function getRdfLiteral( $dataType, DataValue $dataValue ) { |
|
337 | - switch ( $dataType ) { |
|
335 | + private function getRdfLiteral($dataType, DataValue $dataValue) { |
|
336 | + switch ($dataType) { |
|
338 | 337 | case 'string': |
339 | 338 | case 'external-id': |
340 | - return [ $this->stringLiteral( $dataValue->getValue() ), false ]; |
|
339 | + return [$this->stringLiteral($dataValue->getValue()), false]; |
|
341 | 340 | case 'commonsMedia': |
342 | - $url = $this->rdfVocabulary->getMediaFileURI( $dataValue->getValue() ); |
|
343 | - return [ '<' . $url . '>', false ]; |
|
341 | + $url = $this->rdfVocabulary->getMediaFileURI($dataValue->getValue()); |
|
342 | + return ['<'.$url.'>', false]; |
|
344 | 343 | case 'geo-shape': |
345 | - $url = $this->rdfVocabulary->getGeoShapeURI( $dataValue->getValue() ); |
|
346 | - return [ '<' . $url . '>', false ]; |
|
344 | + $url = $this->rdfVocabulary->getGeoShapeURI($dataValue->getValue()); |
|
345 | + return ['<'.$url.'>', false]; |
|
347 | 346 | case 'tabular-data': |
348 | - $url = $this->rdfVocabulary->getTabularDataURI( $dataValue->getValue() ); |
|
349 | - return [ '<' . $url . '>', false ]; |
|
347 | + $url = $this->rdfVocabulary->getTabularDataURI($dataValue->getValue()); |
|
348 | + return ['<'.$url.'>', false]; |
|
350 | 349 | case 'url': |
351 | 350 | $url = $dataValue->getValue(); |
352 | - if ( !preg_match( '/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url ) ) { |
|
351 | + if (!preg_match('/^[^<>"{}\\\\|^`\\x00-\\x20]*$/D', $url)) { |
|
353 | 352 | // not a valid URL for SPARQL (see SPARQL spec, production 139 IRIREF) |
354 | 353 | // such an URL should never reach us, so just throw |
355 | - throw new InvalidArgumentException( 'invalid URL: ' . $url ); |
|
354 | + throw new InvalidArgumentException('invalid URL: '.$url); |
|
356 | 355 | } |
357 | - return [ '<' . $url . '>', false ]; |
|
356 | + return ['<'.$url.'>', false]; |
|
358 | 357 | case 'wikibase-item': |
359 | 358 | case 'wikibase-property': |
360 | 359 | /** @var EntityIdValue $dataValue */ |
361 | - return [ 'wd:' . $dataValue->getEntityId()->getSerialization(), false ]; |
|
360 | + return ['wd:'.$dataValue->getEntityId()->getSerialization(), false]; |
|
362 | 361 | case 'monolingualtext': |
363 | 362 | /** @var MonolingualTextValue $dataValue */ |
364 | 363 | $lang = $dataValue->getLanguageCode(); |
365 | - if ( !preg_match( '/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang ) ) { |
|
364 | + if (!preg_match('/^[a-zA-Z]+(-[a-zA-Z0-9]+)*$/D', $lang)) { |
|
366 | 365 | // not a valid language tag for SPARQL (see SPARQL spec, production 145 LANGTAG) |
367 | 366 | // such a language tag should never reach us, so just throw |
368 | - throw new InvalidArgumentException( 'invalid language tag: ' . $lang ); |
|
367 | + throw new InvalidArgumentException('invalid language tag: '.$lang); |
|
369 | 368 | } |
370 | - return [ $this->stringLiteral( $dataValue->getText() ) . '@' . $lang, false ]; |
|
369 | + return [$this->stringLiteral($dataValue->getText()).'@'.$lang, false]; |
|
371 | 370 | case 'globe-coordinate': |
372 | 371 | case 'quantity': |
373 | 372 | case 'time': |
374 | - return [ 'wdv:' . $dataValue->getHash(), true ]; |
|
373 | + return ['wdv:'.$dataValue->getHash(), true]; |
|
375 | 374 | default: |
376 | - throw new InvalidArgumentException( 'unknown data type: ' . $dataType ); |
|
375 | + throw new InvalidArgumentException('unknown data type: '.$dataType); |
|
377 | 376 | } |
378 | 377 | } |
379 | 378 | // @codingStandardsIgnoreEnd |
@@ -386,44 +385,44 @@ discard block |
||
386 | 385 | * @throws SparqlHelperException if the query times out or some other error occurs |
387 | 386 | * @throws ConstraintParameterException if the $regex is invalid |
388 | 387 | */ |
389 | - public function matchesRegularExpression( $text, $regex ) { |
|
388 | + public function matchesRegularExpression($text, $regex) { |
|
390 | 389 | // caching wrapper around matchesRegularExpressionWithSparql |
391 | 390 | |
392 | - $textHash = hash( 'sha256', $text ); |
|
391 | + $textHash = hash('sha256', $text); |
|
393 | 392 | $cacheKey = $this->cache->makeKey( |
394 | 393 | 'WikibaseQualityConstraints', // extension |
395 | 394 | 'regex', // action |
396 | 395 | 'WDQS-Java', // regex flavor |
397 | - hash( 'sha256', $regex ) |
|
396 | + hash('sha256', $regex) |
|
398 | 397 | ); |
399 | - $cacheMapSize = $this->config->get( 'WBQualityConstraintsFormatCacheMapSize' ); |
|
398 | + $cacheMapSize = $this->config->get('WBQualityConstraintsFormatCacheMapSize'); |
|
400 | 399 | |
401 | 400 | $cacheMapArray = $this->cache->getWithSetCallback( |
402 | 401 | $cacheKey, |
403 | 402 | WANObjectCache::TTL_DAY, |
404 | - function( $cacheMapArray ) use ( $text, $regex, $textHash, $cacheMapSize ) { |
|
403 | + function($cacheMapArray) use ($text, $regex, $textHash, $cacheMapSize) { |
|
405 | 404 | // Initialize the cache map if not set |
406 | - if ( $cacheMapArray === false ) { |
|
405 | + if ($cacheMapArray === false) { |
|
407 | 406 | $key = 'wikibase.quality.constraints.regex.cache.refresh.init'; |
408 | - $this->dataFactory->increment( $key ); |
|
407 | + $this->dataFactory->increment($key); |
|
409 | 408 | return []; |
410 | 409 | } |
411 | 410 | |
412 | 411 | $key = 'wikibase.quality.constraints.regex.cache.refresh'; |
413 | - $this->dataFactory->increment( $key ); |
|
414 | - $cacheMap = MapCacheLRU::newFromArray( $cacheMapArray, $cacheMapSize ); |
|
415 | - if ( $cacheMap->has( $textHash ) ) { |
|
412 | + $this->dataFactory->increment($key); |
|
413 | + $cacheMap = MapCacheLRU::newFromArray($cacheMapArray, $cacheMapSize); |
|
414 | + if ($cacheMap->has($textHash)) { |
|
416 | 415 | $key = 'wikibase.quality.constraints.regex.cache.refresh.hit'; |
417 | - $this->dataFactory->increment( $key ); |
|
418 | - $cacheMap->get( $textHash ); // ping cache |
|
416 | + $this->dataFactory->increment($key); |
|
417 | + $cacheMap->get($textHash); // ping cache |
|
419 | 418 | } else { |
420 | 419 | $key = 'wikibase.quality.constraints.regex.cache.refresh.miss'; |
421 | - $this->dataFactory->increment( $key ); |
|
420 | + $this->dataFactory->increment($key); |
|
422 | 421 | try { |
423 | - $matches = $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
424 | - } catch ( ConstraintParameterException $e ) { |
|
425 | - $matches = $this->serializeConstraintParameterException( $e ); |
|
426 | - } catch ( SparqlHelperException $e ) { |
|
422 | + $matches = $this->matchesRegularExpressionWithSparql($text, $regex); |
|
423 | + } catch (ConstraintParameterException $e) { |
|
424 | + $matches = $this->serializeConstraintParameterException($e); |
|
425 | + } catch (SparqlHelperException $e) { |
|
427 | 426 | // don’t cache this |
428 | 427 | return $cacheMap->toArray(); |
429 | 428 | } |
@@ -447,42 +446,42 @@ discard block |
||
447 | 446 | ] |
448 | 447 | ); |
449 | 448 | |
450 | - if ( isset( $cacheMapArray[$textHash] ) ) { |
|
449 | + if (isset($cacheMapArray[$textHash])) { |
|
451 | 450 | $key = 'wikibase.quality.constraints.regex.cache.hit'; |
452 | - $this->dataFactory->increment( $key ); |
|
451 | + $this->dataFactory->increment($key); |
|
453 | 452 | $matches = $cacheMapArray[$textHash]; |
454 | - if ( is_bool( $matches ) ) { |
|
453 | + if (is_bool($matches)) { |
|
455 | 454 | return $matches; |
456 | - } elseif ( is_array( $matches ) && |
|
457 | - $matches['type'] == ConstraintParameterException::class ) { |
|
458 | - throw $this->deserializeConstraintParameterException( $matches ); |
|
455 | + } elseif (is_array($matches) && |
|
456 | + $matches['type'] == ConstraintParameterException::class) { |
|
457 | + throw $this->deserializeConstraintParameterException($matches); |
|
459 | 458 | } else { |
460 | 459 | throw new MWException( |
461 | - 'Value of unknown type in object cache (' . |
|
462 | - 'cache key: ' . $cacheKey . ', ' . |
|
463 | - 'cache map key: ' . $textHash . ', ' . |
|
464 | - 'value type: ' . gettype( $matches ) . ')' |
|
460 | + 'Value of unknown type in object cache ('. |
|
461 | + 'cache key: '.$cacheKey.', '. |
|
462 | + 'cache map key: '.$textHash.', '. |
|
463 | + 'value type: '.gettype($matches).')' |
|
465 | 464 | ); |
466 | 465 | } |
467 | 466 | } else { |
468 | 467 | $key = 'wikibase.quality.constraints.regex.cache.miss'; |
469 | - $this->dataFactory->increment( $key ); |
|
470 | - return $this->matchesRegularExpressionWithSparql( $text, $regex ); |
|
468 | + $this->dataFactory->increment($key); |
|
469 | + return $this->matchesRegularExpressionWithSparql($text, $regex); |
|
471 | 470 | } |
472 | 471 | } |
473 | 472 | |
474 | - private function serializeConstraintParameterException( ConstraintParameterException $cpe ) { |
|
473 | + private function serializeConstraintParameterException(ConstraintParameterException $cpe) { |
|
475 | 474 | return [ |
476 | 475 | 'type' => ConstraintParameterException::class, |
477 | - 'violationMessage' => $this->violationMessageSerializer->serialize( $cpe->getViolationMessage() ), |
|
476 | + 'violationMessage' => $this->violationMessageSerializer->serialize($cpe->getViolationMessage()), |
|
478 | 477 | ]; |
479 | 478 | } |
480 | 479 | |
481 | - private function deserializeConstraintParameterException( array $serialization ) { |
|
480 | + private function deserializeConstraintParameterException(array $serialization) { |
|
482 | 481 | $message = $this->violationMessageDeserializer->deserialize( |
483 | 482 | $serialization['violationMessage'] |
484 | 483 | ); |
485 | - return new ConstraintParameterException( $message ); |
|
484 | + return new ConstraintParameterException($message); |
|
486 | 485 | } |
487 | 486 | |
488 | 487 | /** |
@@ -496,25 +495,25 @@ discard block |
||
496 | 495 | * @throws SparqlHelperException if the query times out or some other error occurs |
497 | 496 | * @throws ConstraintParameterException if the $regex is invalid |
498 | 497 | */ |
499 | - public function matchesRegularExpressionWithSparql( $text, $regex ) { |
|
500 | - $textStringLiteral = $this->stringLiteral( $text ); |
|
501 | - $regexStringLiteral = $this->stringLiteral( '^(?:' . $regex . ')$' ); |
|
498 | + public function matchesRegularExpressionWithSparql($text, $regex) { |
|
499 | + $textStringLiteral = $this->stringLiteral($text); |
|
500 | + $regexStringLiteral = $this->stringLiteral('^(?:'.$regex.')$'); |
|
502 | 501 | |
503 | 502 | $query = <<<EOF |
504 | 503 | SELECT (REGEX($textStringLiteral, $regexStringLiteral) AS ?matches) {} |
505 | 504 | EOF; |
506 | 505 | |
507 | - $result = $this->runQuery( $query ); |
|
506 | + $result = $this->runQuery($query); |
|
508 | 507 | |
509 | 508 | $vars = $result->getArray()['results']['bindings'][0]; |
510 | - if ( array_key_exists( 'matches', $vars ) ) { |
|
509 | + if (array_key_exists('matches', $vars)) { |
|
511 | 510 | // true or false ⇒ regex okay, text matches or not |
512 | 511 | return $vars['matches']['value'] === 'true'; |
513 | 512 | } else { |
514 | 513 | // empty result: regex broken |
515 | 514 | throw new ConstraintParameterException( |
516 | - ( new ViolationMessage( 'wbqc-violation-message-parameter-regex' ) ) |
|
517 | - ->withInlineCode( $regex, Role::CONSTRAINT_PARAMETER_VALUE ) |
|
515 | + (new ViolationMessage('wbqc-violation-message-parameter-regex')) |
|
516 | + ->withInlineCode($regex, Role::CONSTRAINT_PARAMETER_VALUE) |
|
518 | 517 | ); |
519 | 518 | } |
520 | 519 | } |
@@ -526,14 +525,14 @@ discard block |
||
526 | 525 | * |
527 | 526 | * @return boolean |
528 | 527 | */ |
529 | - public function isTimeout( $responseContent ) { |
|
530 | - $timeoutRegex = implode( '|', array_map( |
|
531 | - function ( $fqn ) { |
|
532 | - return preg_quote( $fqn, '/' ); |
|
528 | + public function isTimeout($responseContent) { |
|
529 | + $timeoutRegex = implode('|', array_map( |
|
530 | + function($fqn) { |
|
531 | + return preg_quote($fqn, '/'); |
|
533 | 532 | }, |
534 | - $this->config->get( 'WBQualityConstraintsSparqlTimeoutExceptionClasses' ) |
|
535 | - ) ); |
|
536 | - return (bool)preg_match( '/' . $timeoutRegex . '/', $responseContent ); |
|
533 | + $this->config->get('WBQualityConstraintsSparqlTimeoutExceptionClasses') |
|
534 | + )); |
|
535 | + return (bool) preg_match('/'.$timeoutRegex.'/', $responseContent); |
|
537 | 536 | } |
538 | 537 | |
539 | 538 | /** |
@@ -545,17 +544,17 @@ discard block |
||
545 | 544 | * @return integer|boolean the max-age (in seconds) |
546 | 545 | * or a plain boolean if no max-age can be determined |
547 | 546 | */ |
548 | - public function getCacheMaxAge( $responseHeaders ) { |
|
547 | + public function getCacheMaxAge($responseHeaders) { |
|
549 | 548 | if ( |
550 | - array_key_exists( 'x-cache-status', $responseHeaders ) && |
|
551 | - preg_match( '/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0] ) |
|
549 | + array_key_exists('x-cache-status', $responseHeaders) && |
|
550 | + preg_match('/^hit(?:-.*)?$/', $responseHeaders['x-cache-status'][0]) |
|
552 | 551 | ) { |
553 | 552 | $maxage = []; |
554 | 553 | if ( |
555 | - array_key_exists( 'cache-control', $responseHeaders ) && |
|
556 | - preg_match( '/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage ) |
|
554 | + array_key_exists('cache-control', $responseHeaders) && |
|
555 | + preg_match('/\bmax-age=(\d+)\b/', $responseHeaders['cache-control'][0], $maxage) |
|
557 | 556 | ) { |
558 | - return intval( $maxage[1] ); |
|
557 | + return intval($maxage[1]); |
|
559 | 558 | } else { |
560 | 559 | return true; |
561 | 560 | } |
@@ -573,59 +572,58 @@ discard block |
||
573 | 572 | * |
574 | 573 | * @throws SparqlHelperException if the query times out or some other error occurs |
575 | 574 | */ |
576 | - public function runQuery( $query ) { |
|
577 | - $endpoint = $this->config->get( 'WBQualityConstraintsSparqlEndpoint' ); |
|
578 | - $maxQueryTimeMillis = $this->config->get( 'WBQualityConstraintsSparqlMaxMillis' ); |
|
579 | - $url = $endpoint . '?' . http_build_query( |
|
575 | + public function runQuery($query) { |
|
576 | + $endpoint = $this->config->get('WBQualityConstraintsSparqlEndpoint'); |
|
577 | + $maxQueryTimeMillis = $this->config->get('WBQualityConstraintsSparqlMaxMillis'); |
|
578 | + $url = $endpoint.'?'.http_build_query( |
|
580 | 579 | [ |
581 | - 'query' => "#wbqc\n" . $this->prefixes . $query, |
|
580 | + 'query' => "#wbqc\n".$this->prefixes.$query, |
|
582 | 581 | 'format' => 'json', |
583 | 582 | 'maxQueryTimeMillis' => $maxQueryTimeMillis, |
584 | 583 | ], |
585 | - null, ini_get( 'arg_separator.output' ), |
|
584 | + null, ini_get('arg_separator.output'), |
|
586 | 585 | // encode spaces with %20, not + |
587 | 586 | PHP_QUERY_RFC3986 |
588 | 587 | ); |
589 | 588 | |
590 | 589 | $options = [ |
591 | 590 | 'method' => 'GET', |
592 | - 'timeout' => (int)round( ( $maxQueryTimeMillis + 1000 ) / 1000 ), |
|
591 | + 'timeout' => (int) round(($maxQueryTimeMillis + 1000) / 1000), |
|
593 | 592 | 'connectTimeout' => 'default', |
594 | 593 | 'userAgent' => $this->defaultUserAgent, |
595 | 594 | ]; |
596 | - $request = $this->requestFactory->create( $url, $options ); |
|
597 | - $startTime = microtime( true ); |
|
595 | + $request = $this->requestFactory->create($url, $options); |
|
596 | + $startTime = microtime(true); |
|
598 | 597 | $status = $request->execute(); |
599 | - $endTime = microtime( true ); |
|
598 | + $endTime = microtime(true); |
|
600 | 599 | $this->dataFactory->timing( |
601 | 600 | 'wikibase.quality.constraints.sparql.timing', |
602 | - ( $endTime - $startTime ) * 1000 |
|
601 | + ($endTime - $startTime) * 1000 |
|
603 | 602 | ); |
604 | 603 | |
605 | - $maxAge = $this->getCacheMaxAge( $request->getResponseHeaders() ); |
|
606 | - if ( $maxAge ) { |
|
607 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.cached' ); |
|
604 | + $maxAge = $this->getCacheMaxAge($request->getResponseHeaders()); |
|
605 | + if ($maxAge) { |
|
606 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.cached'); |
|
608 | 607 | } |
609 | 608 | |
610 | - if ( $status->isOK() ) { |
|
609 | + if ($status->isOK()) { |
|
611 | 610 | $json = $request->getContent(); |
612 | - $arr = json_decode( $json, true ); |
|
611 | + $arr = json_decode($json, true); |
|
613 | 612 | return new CachedQueryResults( |
614 | 613 | $arr, |
615 | 614 | Metadata::ofCachingMetadata( |
616 | 615 | $maxAge ? |
617 | - CachingMetadata::ofMaximumAgeInSeconds( $maxAge ) : |
|
618 | - CachingMetadata::fresh() |
|
616 | + CachingMetadata::ofMaximumAgeInSeconds($maxAge) : CachingMetadata::fresh() |
|
619 | 617 | ) |
620 | 618 | ); |
621 | 619 | } else { |
622 | - $this->dataFactory->increment( 'wikibase.quality.constraints.sparql.error' ); |
|
620 | + $this->dataFactory->increment('wikibase.quality.constraints.sparql.error'); |
|
623 | 621 | |
624 | 622 | $this->dataFactory->increment( |
625 | 623 | "wikibase.quality.constraints.sparql.error.http.{$request->getStatus()}" |
626 | 624 | ); |
627 | 625 | |
628 | - if ( $this->isTimeout( $request->getContent() ) ) { |
|
626 | + if ($this->isTimeout($request->getContent())) { |
|
629 | 627 | $this->dataFactory->increment( |
630 | 628 | 'wikibase.quality.constraints.sparql.error.timeout' |
631 | 629 | ); |
@@ -31,25 +31,25 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * @param DatabaseUpdater $updater |
33 | 33 | */ |
34 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
34 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
35 | 35 | $updater->addExtensionTable( |
36 | 36 | 'wbqc_constraints', |
37 | - __DIR__ . '/../sql/create_wbqc_constraints.sql' |
|
37 | + __DIR__.'/../sql/create_wbqc_constraints.sql' |
|
38 | 38 | ); |
39 | 39 | $updater->addExtensionField( |
40 | 40 | 'wbqc_constraints', |
41 | 41 | 'constraint_id', |
42 | - __DIR__ . '/../sql/patch-wbqc_constraints-constraint_id.sql' |
|
42 | + __DIR__.'/../sql/patch-wbqc_constraints-constraint_id.sql' |
|
43 | 43 | ); |
44 | 44 | $updater->addExtensionIndex( |
45 | 45 | 'wbqc_constraints', |
46 | 46 | 'wbqc_constraints_guid_uniq', |
47 | - __DIR__ . '/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
47 | + __DIR__.'/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
48 | 48 | ); |
49 | 49 | } |
50 | 50 | |
51 | - public static function onWikibaseChange( Change $change ) { |
|
52 | - if ( !( $change instanceof EntityChange ) ) { |
|
51 | + public static function onWikibaseChange(Change $change) { |
|
52 | + if (!($change instanceof EntityChange)) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
@@ -58,44 +58,44 @@ discard block |
||
58 | 58 | |
59 | 59 | // If jobs are enabled and the results would be stored in some way run a job. |
60 | 60 | if ( |
61 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
62 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
61 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
62 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
63 | 63 | self::isSelectedForJobRunBasedOnPercentage() |
64 | 64 | ) { |
65 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
65 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
66 | 66 | JobQueueGroup::singleton()->push( |
67 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
67 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
68 | 68 | ); |
69 | 69 | } |
70 | 70 | |
71 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
72 | - self::isConstraintStatementsChange( $config, $change ) |
|
71 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
72 | + self::isConstraintStatementsChange($config, $change) |
|
73 | 73 | ) { |
74 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
74 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
75 | 75 | JobQueueGroup::singleton()->push( |
76 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
76 | + new JobSpecification('constraintsTableUpdate', $params) |
|
77 | 77 | ); |
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | 81 | private static function isSelectedForJobRunBasedOnPercentage() { |
82 | 82 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
83 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
83 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
84 | 84 | |
85 | - return mt_rand( 1, 100 ) <= $percentage; |
|
85 | + return mt_rand(1, 100) <= $percentage; |
|
86 | 86 | } |
87 | 87 | |
88 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
89 | - if ( !( $change instanceof EntityChange ) || |
|
88 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
89 | + if (!($change instanceof EntityChange) || |
|
90 | 90 | $change->getAction() !== EntityChange::UPDATE || |
91 | - !( $change->getEntityId() instanceof PropertyId ) |
|
91 | + !($change->getEntityId() instanceof PropertyId) |
|
92 | 92 | ) { |
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | |
96 | 96 | $info = $change->getInfo(); |
97 | 97 | |
98 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
98 | + if (!array_key_exists('compactDiff', $info)) { |
|
99 | 99 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
100 | 100 | // so we only know that the change *might* affect the constraint statements |
101 | 101 | return true; |
@@ -104,46 +104,46 @@ discard block |
||
104 | 104 | /** @var EntityDiffChangedAspects $aspects */ |
105 | 105 | $aspects = $info['compactDiff']; |
106 | 106 | |
107 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
108 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
107 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
108 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
109 | 109 | } |
110 | 110 | |
111 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
111 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
112 | 112 | $repo = WikibaseRepo::getDefaultInstance(); |
113 | 113 | |
114 | 114 | $entityContentFactory = $repo->getEntityContentFactory(); |
115 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
116 | - $entityId = $entityContentFactory->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
117 | - if ( $entityId !== null ) { |
|
115 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
116 | + $entityId = $entityContentFactory->getEntityIdForTitle($wikiPage->getTitle()); |
|
117 | + if ($entityId !== null) { |
|
118 | 118 | $resultsCache = ResultsCache::getDefaultInstance(); |
119 | - $resultsCache->delete( $entityId ); |
|
119 | + $resultsCache->delete($entityId); |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
124 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
125 | 125 | $repo = WikibaseRepo::getDefaultInstance(); |
126 | 126 | |
127 | 127 | $lookup = $repo->getEntityNamespaceLookup(); |
128 | 128 | $title = $out->getTitle(); |
129 | - if ( $title === null ) { |
|
129 | + if ($title === null) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
133 | - if ( !$lookup->isEntityNamespace( $title->getNamespace() ) ) { |
|
133 | + if (!$lookup->isEntityNamespace($title->getNamespace())) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
136 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
137 | 137 | return; |
138 | 138 | } |
139 | 139 | |
140 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
140 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
141 | 141 | |
142 | - if ( !$out->getUser()->isLoggedIn() ) { |
|
142 | + if (!$out->getUser()->isLoggedIn()) { |
|
143 | 143 | return; |
144 | 144 | } |
145 | 145 | |
146 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
146 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | * @param User $user |
153 | 153 | * @param array[] &$prefs |
154 | 154 | */ |
155 | - public static function onGetBetaFeaturePreferences( User $user, array &$prefs ) { |
|
155 | + public static function onGetBetaFeaturePreferences(User $user, array &$prefs) { |
|
156 | 156 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
157 | - $extensionAssetsPath = $config->get( 'ExtensionAssetsPath' ); |
|
158 | - if ( $config->get( 'WBQualityConstraintsSuggestionsBetaFeature' ) ) { |
|
157 | + $extensionAssetsPath = $config->get('ExtensionAssetsPath'); |
|
158 | + if ($config->get('WBQualityConstraintsSuggestionsBetaFeature')) { |
|
159 | 159 | $prefs['constraint-suggestions'] = [ |
160 | 160 | 'label-message' => 'wbqc-beta-feature-label-message', |
161 | 161 | 'desc-message' => 'wbqc-beta-feature-description-message', |
@@ -179,20 +179,20 @@ discard block |
||
179 | 179 | * @param array &$vars |
180 | 180 | * @param OutputPage $out |
181 | 181 | */ |
182 | - public static function addVariables( &$vars, OutputPage $out ) { |
|
182 | + public static function addVariables(&$vars, OutputPage $out) { |
|
183 | 183 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
184 | 184 | |
185 | - $vars['wbQualityConstraintsPropertyConstraintId'] = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
186 | - $vars['wbQualityConstraintsOneOfConstraintId'] = $config->get( 'WBQualityConstraintsOneOfConstraintId' ); |
|
187 | - $vars['wbQualityConstraintsAllowedQualifierConstraintId'] = $config->get( 'WBQualityConstraintsAllowedQualifiersConstraintId' ); |
|
188 | - $vars['wbQualityConstraintsPropertyId'] = $config->get( 'WBQualityConstraintsPropertyId' ); |
|
189 | - $vars['wbQualityConstraintsQualifierOfPropertyConstraintId'] = $config->get( 'WBQualityConstraintsQualifierOfPropertyConstraintId' ); |
|
185 | + $vars['wbQualityConstraintsPropertyConstraintId'] = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
186 | + $vars['wbQualityConstraintsOneOfConstraintId'] = $config->get('WBQualityConstraintsOneOfConstraintId'); |
|
187 | + $vars['wbQualityConstraintsAllowedQualifierConstraintId'] = $config->get('WBQualityConstraintsAllowedQualifiersConstraintId'); |
|
188 | + $vars['wbQualityConstraintsPropertyId'] = $config->get('WBQualityConstraintsPropertyId'); |
|
189 | + $vars['wbQualityConstraintsQualifierOfPropertyConstraintId'] = $config->get('WBQualityConstraintsQualifierOfPropertyConstraintId'); |
|
190 | 190 | |
191 | 191 | $vars['wbQualityConstraintsSuggestionsGloballyEnabled'] = false; |
192 | 192 | |
193 | - if ( $config->get( 'WBQualityConstraintsSuggestionsBetaFeature' ) && |
|
194 | - ExtensionRegistry::getInstance()->isLoaded( 'BetaFeatures' ) && |
|
195 | - BetaFeatures::isFeatureEnabled( $out->getUser(), 'constraint-suggestions' ) |
|
193 | + if ($config->get('WBQualityConstraintsSuggestionsBetaFeature') && |
|
194 | + ExtensionRegistry::getInstance()->isLoaded('BetaFeatures') && |
|
195 | + BetaFeatures::isFeatureEnabled($out->getUser(), 'constraint-suggestions') |
|
196 | 196 | ) { |
197 | 197 | $vars['wbQualityConstraintsSuggestionsGloballyEnabled'] = true; |
198 | 198 | } |
@@ -42,25 +42,25 @@ discard block |
||
42 | 42 | * @param Title $title |
43 | 43 | * @param string[] $params should contain 'entityId' => 'Q1234' |
44 | 44 | */ |
45 | - public function __construct( Title $title, array $params ) { |
|
46 | - parent::__construct( self::COMMAND, $title, $params ); |
|
45 | + public function __construct(Title $title, array $params) { |
|
46 | + parent::__construct(self::COMMAND, $title, $params); |
|
47 | 47 | $this->removeDuplicates = true; |
48 | 48 | |
49 | - Assert::parameterType( 'string', $params['entityId'], '$params[\'entityId\']' ); |
|
49 | + Assert::parameterType('string', $params['entityId'], '$params[\'entityId\']'); |
|
50 | 50 | $this->entityId = $params['entityId']; |
51 | 51 | |
52 | - $resultSource = ConstraintsServices::getResultsSource( MediaWikiServices::getInstance() ); |
|
52 | + $resultSource = ConstraintsServices::getResultsSource(MediaWikiServices::getInstance()); |
|
53 | 53 | // This job should only ever be used when caching result sources are used. |
54 | - $this->setResultsSource( $resultSource ); |
|
54 | + $this->setResultsSource($resultSource); |
|
55 | 55 | |
56 | - $this->setEntityIdParser( WikibaseRepo::getDefaultInstance()->getEntityIdParser() ); |
|
56 | + $this->setEntityIdParser(WikibaseRepo::getDefaultInstance()->getEntityIdParser()); |
|
57 | 57 | } |
58 | 58 | |
59 | - public function setResultsSource( CachingResultsSource $resultsSource ) { |
|
59 | + public function setResultsSource(CachingResultsSource $resultsSource) { |
|
60 | 60 | $this->resultsSource = $resultsSource; |
61 | 61 | } |
62 | 62 | |
63 | - public function setEntityIdParser( EntityIdParser $parser ) { |
|
63 | + public function setEntityIdParser(EntityIdParser $parser) { |
|
64 | 64 | $this->entityIdParser = $parser; |
65 | 65 | } |
66 | 66 | |
@@ -71,19 +71,19 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function run() { |
73 | 73 | try { |
74 | - $entityId = $this->entityIdParser->parse( $this->entityId ); |
|
75 | - } catch ( EntityIdParsingException $e ) { |
|
74 | + $entityId = $this->entityIdParser->parse($this->entityId); |
|
75 | + } catch (EntityIdParsingException $e) { |
|
76 | 76 | return false; |
77 | 77 | } |
78 | 78 | |
79 | - $this->checkConstraints( $entityId ); |
|
79 | + $this->checkConstraints($entityId); |
|
80 | 80 | |
81 | 81 | return true; |
82 | 82 | } |
83 | 83 | |
84 | - private function checkConstraints( EntityId $entityId ) { |
|
84 | + private function checkConstraints(EntityId $entityId) { |
|
85 | 85 | $this->resultsSource->getResults( |
86 | - [ $entityId ], |
|
86 | + [$entityId], |
|
87 | 87 | [], |
88 | 88 | null, |
89 | 89 | [] |