@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | use Wikibase\Repo\WikibaseRepo; |
18 | 18 | |
19 | 19 | // @codeCoverageIgnoreStart |
20 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
21 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
20 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
21 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
22 | 22 | |
23 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
23 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
24 | 24 | // @codeCoverageIgnoreEnd |
25 | 25 | |
26 | 26 | /** |
@@ -59,20 +59,20 @@ discard block |
||
59 | 59 | parent::__construct(); |
60 | 60 | |
61 | 61 | $this->addDescription( |
62 | - 'Import entities needed for constraint checks ' . |
|
62 | + 'Import entities needed for constraint checks '. |
|
63 | 63 | 'from Wikidata into the local repository.' |
64 | 64 | ); |
65 | 65 | $this->addOption( |
66 | 66 | 'config-format', |
67 | - 'The format in which the resulting configuration will be omitted: ' . |
|
68 | - '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' . |
|
67 | + 'The format in which the resulting configuration will be omitted: '. |
|
68 | + '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '. |
|
69 | 69 | 'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.' |
70 | 70 | ); |
71 | 71 | $this->addOption( |
72 | 72 | 'dry-run', |
73 | 73 | 'Don’t actually import entities, just print which ones would be imported.' |
74 | 74 | ); |
75 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
75 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | */ |
81 | 81 | private function setupServices() { |
82 | 82 | $services = MediaWikiServices::getInstance(); |
83 | - $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer( $services ); |
|
84 | - $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer( $services ); |
|
85 | - $this->entityStore = WikibaseRepo::getEntityStore( $services ); |
|
83 | + $this->entitySerializer = WikibaseRepo::getAllTypesEntitySerializer($services); |
|
84 | + $this->entityDeserializer = WikibaseRepo::getInternalFormatEntityDeserializer($services); |
|
85 | + $this->entityStore = WikibaseRepo::getEntityStore($services); |
|
86 | 86 | $this->httpRequestFactory = $services->getHttpRequestFactory(); |
87 | - if ( !$this->getOption( 'dry-run', false ) ) { |
|
88 | - $this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' ); |
|
87 | + if (!$this->getOption('dry-run', false)) { |
|
88 | + $this->user = User::newSystemUser('WikibaseQualityConstraints importer'); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -94,21 +94,21 @@ discard block |
||
94 | 94 | |
95 | 95 | $configUpdates = []; |
96 | 96 | |
97 | - $extensionJsonFile = __DIR__ . '/../extension.json'; |
|
98 | - $extensionJsonText = file_get_contents( $extensionJsonFile ); |
|
99 | - $extensionJson = json_decode( $extensionJsonText, /* assoc = */ true ); |
|
97 | + $extensionJsonFile = __DIR__.'/../extension.json'; |
|
98 | + $extensionJsonText = file_get_contents($extensionJsonFile); |
|
99 | + $extensionJson = json_decode($extensionJsonText, /* assoc = */ true); |
|
100 | 100 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
101 | - $wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() ); |
|
101 | + $wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig()); |
|
102 | 102 | |
103 | - foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) { |
|
104 | - $localEntityId = $this->importEntityFromWikidata( $wikidataEntityId ); |
|
103 | + foreach ($wikidataEntityIds as $key => $wikidataEntityId) { |
|
104 | + $localEntityId = $this->importEntityFromWikidata($wikidataEntityId); |
|
105 | 105 | $configUpdates[$key] = [ |
106 | 106 | 'wikidata' => $wikidataEntityId, |
107 | 107 | 'local' => $localEntityId, |
108 | 108 | ]; |
109 | 109 | } |
110 | 110 | |
111 | - $this->outputConfigUpdates( $configUpdates ); |
|
111 | + $this->outputConfigUpdates($configUpdates); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -116,18 +116,18 @@ discard block |
||
116 | 116 | * @param Config $wikiConfig |
117 | 117 | * @return string[] |
118 | 118 | */ |
119 | - private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) { |
|
119 | + private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) { |
|
120 | 120 | $wikidataEntityIds = []; |
121 | 121 | |
122 | - foreach ( $extensionJsonConfig as $key => $value ) { |
|
123 | - if ( !preg_match( '/Id$/', $key ) ) { |
|
122 | + foreach ($extensionJsonConfig as $key => $value) { |
|
123 | + if (!preg_match('/Id$/', $key)) { |
|
124 | 124 | continue; |
125 | 125 | } |
126 | 126 | |
127 | 127 | $wikidataEntityId = $value['value']; |
128 | - $localEntityId = $wikiConfig->get( $key ); |
|
128 | + $localEntityId = $wikiConfig->get($key); |
|
129 | 129 | |
130 | - if ( $localEntityId === $wikidataEntityId ) { |
|
130 | + if ($localEntityId === $wikidataEntityId) { |
|
131 | 131 | $wikidataEntityIds[$key] = $wikidataEntityId; |
132 | 132 | } |
133 | 133 | } |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | * @param string $wikidataEntityId |
140 | 140 | * @return string local entity ID |
141 | 141 | */ |
142 | - private function importEntityFromWikidata( $wikidataEntityId ) { |
|
142 | + private function importEntityFromWikidata($wikidataEntityId) { |
|
143 | 143 | $wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json"; |
144 | - $wikidataEntitiesJson = $this->httpRequestFactory->get( $wikidataEntityUrl, [], __METHOD__ ); |
|
145 | - return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ); |
|
144 | + $wikidataEntitiesJson = $this->httpRequestFactory->get($wikidataEntityUrl, [], __METHOD__); |
|
145 | + return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -150,24 +150,24 @@ discard block |
||
150 | 150 | * @param string $wikidataEntitiesJson |
151 | 151 | * @return string local entity ID |
152 | 152 | */ |
153 | - private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) { |
|
153 | + private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) { |
|
154 | 154 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
155 | - $wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId]; |
|
156 | - $wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray ); |
|
155 | + $wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId]; |
|
156 | + $wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray); |
|
157 | 157 | |
158 | - $wikidataEntity->setId( null ); |
|
158 | + $wikidataEntity->setId(null); |
|
159 | 159 | |
160 | - if ( $wikidataEntity instanceof StatementListProvider ) { |
|
160 | + if ($wikidataEntity instanceof StatementListProvider) { |
|
161 | 161 | $wikidataEntity->getStatements()->clear(); |
162 | 162 | } |
163 | 163 | |
164 | - if ( $wikidataEntity instanceof Item ) { |
|
165 | - $wikidataEntity->setSiteLinkList( new SiteLinkList() ); |
|
164 | + if ($wikidataEntity instanceof Item) { |
|
165 | + $wikidataEntity->setSiteLinkList(new SiteLinkList()); |
|
166 | 166 | } |
167 | 167 | |
168 | - if ( $this->getOption( 'dry-run', false ) ) { |
|
169 | - $wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) ); |
|
170 | - $this->output( $wikidataEntityJson . "\n" ); |
|
168 | + if ($this->getOption('dry-run', false)) { |
|
169 | + $wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity)); |
|
170 | + $this->output($wikidataEntityJson."\n"); |
|
171 | 171 | return "-$wikidataEntityId"; |
172 | 172 | } |
173 | 173 | |
@@ -180,12 +180,12 @@ discard block |
||
180 | 180 | )->getEntity(); |
181 | 181 | |
182 | 182 | return $localEntity->getId()->getSerialization(); |
183 | - } catch ( StorageException $storageException ) { |
|
184 | - return $this->storageExceptionToEntityId( $storageException ); |
|
183 | + } catch (StorageException $storageException) { |
|
184 | + return $this->storageExceptionToEntityId($storageException); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | - private function storageExceptionToEntityId( StorageException $storageException ) { |
|
188 | + private function storageExceptionToEntityId(StorageException $storageException) { |
|
189 | 189 | $message = $storageException->getMessage(); |
190 | 190 | // example messages: |
191 | 191 | // * Item [[Item:Q475|Q475]] already has label "as references" |
@@ -195,25 +195,25 @@ discard block |
||
195 | 195 | // * Property [[Property:P694|P694]] already has label "instance of" |
196 | 196 | // associated with language code en. |
197 | 197 | $pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/'; |
198 | - if ( preg_match( $pattern, $message, $matches ) ) { |
|
198 | + if (preg_match($pattern, $message, $matches)) { |
|
199 | 199 | return $matches[1]; |
200 | 200 | } else { |
201 | 201 | throw $storageException; |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | - private function outputConfigUpdates( array $configUpdates ) { |
|
206 | - $configFormat = $this->getOption( 'config-format', 'globals' ); |
|
207 | - switch ( $configFormat ) { |
|
205 | + private function outputConfigUpdates(array $configUpdates) { |
|
206 | + $configFormat = $this->getOption('config-format', 'globals'); |
|
207 | + switch ($configFormat) { |
|
208 | 208 | case 'globals': |
209 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
209 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
210 | 210 | break; |
211 | 211 | case 'wgConf': |
212 | - $this->outputConfigUpdatesWgConf( $configUpdates ); |
|
212 | + $this->outputConfigUpdatesWgConf($configUpdates); |
|
213 | 213 | break; |
214 | 214 | default: |
215 | - $this->error( "Invalid config format \"$configFormat\", using \"globals\"" ); |
|
216 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
215 | + $this->error("Invalid config format \"$configFormat\", using \"globals\""); |
|
216 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
217 | 217 | break; |
218 | 218 | } |
219 | 219 | } |
@@ -221,22 +221,22 @@ discard block |
||
221 | 221 | /** |
222 | 222 | * @param array[] $configUpdates |
223 | 223 | */ |
224 | - private function outputConfigUpdatesGlobals( array $configUpdates ) { |
|
225 | - foreach ( $configUpdates as $key => $value ) { |
|
226 | - $localValueCode = var_export( $value['local'], true ); |
|
227 | - $this->output( "\$wg$key = $localValueCode;\n" ); |
|
224 | + private function outputConfigUpdatesGlobals(array $configUpdates) { |
|
225 | + foreach ($configUpdates as $key => $value) { |
|
226 | + $localValueCode = var_export($value['local'], true); |
|
227 | + $this->output("\$wg$key = $localValueCode;\n"); |
|
228 | 228 | } |
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
232 | 232 | * @param array[] $configUpdates |
233 | 233 | */ |
234 | - private function outputConfigUpdatesWgConf( array $configUpdates ) { |
|
235 | - foreach ( $configUpdates as $key => $value ) { |
|
236 | - $keyCode = var_export( "wg$key", true ); |
|
237 | - $wikidataValueCode = var_export( $value['wikidata'], true ); |
|
238 | - $localValueCode = var_export( $value['local'], true ); |
|
239 | - $wikiIdCode = var_export( wfWikiID(), true ); |
|
234 | + private function outputConfigUpdatesWgConf(array $configUpdates) { |
|
235 | + foreach ($configUpdates as $key => $value) { |
|
236 | + $keyCode = var_export("wg$key", true); |
|
237 | + $wikidataValueCode = var_export($value['wikidata'], true); |
|
238 | + $localValueCode = var_export($value['local'], true); |
|
239 | + $wikiIdCode = var_export(wfWikiID(), true); |
|
240 | 240 | $block = <<< EOF |
241 | 241 | $keyCode => [ |
242 | 242 | 'default' => $wikidataValueCode, |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | |
246 | 246 | |
247 | 247 | EOF; |
248 | - $this->output( $block ); |
|
248 | + $this->output($block); |
|
249 | 249 | } |
250 | 250 | } |
251 | 251 |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | |
86 | 86 | $language = WikibaseRepo::getUserLanguage(); |
87 | 87 | $formatterOptions = new FormatterOptions(); |
88 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
89 | - $valueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
88 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
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 | |
96 | 96 | $checkResultsRenderer = new CheckResultsRenderer( |
97 | 97 | $entityTitleLookup, |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $name, |
110 | 110 | $entityIdParser, |
111 | 111 | $statementGuidValidator, |
112 | - $repo->getApiHelperFactory( $main->getContext() ), |
|
112 | + $repo->getApiHelperFactory($main->getContext()), |
|
113 | 113 | $resultsSource, |
114 | 114 | $checkResultsRenderer, |
115 | 115 | $dataFactory |
@@ -136,11 +136,11 @@ discard block |
||
136 | 136 | CheckResultsRenderer $checkResultsRenderer, |
137 | 137 | IBufferingStatsdDataFactory $dataFactory |
138 | 138 | ) { |
139 | - parent::__construct( $main, $name ); |
|
139 | + parent::__construct($main, $name); |
|
140 | 140 | $this->entityIdParser = $entityIdParser; |
141 | 141 | $this->statementGuidValidator = $statementGuidValidator; |
142 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
143 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
142 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
143 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
144 | 144 | $this->resultsSource = $resultsSource; |
145 | 145 | $this->checkResultsRenderer = $checkResultsRenderer; |
146 | 146 | $this->dataFactory = $dataFactory; |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | |
157 | 157 | $params = $this->extractRequestParams(); |
158 | 158 | |
159 | - $this->validateParameters( $params ); |
|
160 | - $entityIds = $this->parseEntityIds( $params ); |
|
161 | - $claimIds = $this->parseClaimIds( $params ); |
|
159 | + $this->validateParameters($params); |
|
160 | + $entityIds = $this->parseEntityIds($params); |
|
161 | + $claimIds = $this->parseClaimIds($params); |
|
162 | 162 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
163 | 163 | $statuses = $params[self::PARAM_STATUS]; |
164 | 164 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | ) |
175 | 175 | )->getArray() |
176 | 176 | ); |
177 | - $this->resultBuilder->markSuccess( 1 ); |
|
177 | + $this->resultBuilder->markSuccess(1); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -182,24 +182,24 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return EntityId[] |
184 | 184 | */ |
185 | - private function parseEntityIds( array $params ) { |
|
185 | + private function parseEntityIds(array $params) { |
|
186 | 186 | $ids = $params[self::PARAM_ID]; |
187 | 187 | |
188 | - if ( $ids === null ) { |
|
188 | + if ($ids === null) { |
|
189 | 189 | return []; |
190 | - } elseif ( $ids === [] ) { |
|
190 | + } elseif ($ids === []) { |
|
191 | 191 | $this->errorReporter->dieError( |
192 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
192 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
193 | 193 | } |
194 | 194 | |
195 | - return array_map( function ( $id ) { |
|
195 | + return array_map(function($id) { |
|
196 | 196 | try { |
197 | - return $this->entityIdParser->parse( $id ); |
|
198 | - } catch ( EntityIdParsingException $e ) { |
|
197 | + return $this->entityIdParser->parse($id); |
|
198 | + } catch (EntityIdParsingException $e) { |
|
199 | 199 | $this->errorReporter->dieError( |
200 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
200 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
201 | 201 | } |
202 | - }, $ids ); |
|
202 | + }, $ids); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -207,35 +207,35 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @return string[] |
209 | 209 | */ |
210 | - private function parseClaimIds( array $params ) { |
|
210 | + private function parseClaimIds(array $params) { |
|
211 | 211 | $ids = $params[self::PARAM_CLAIM_ID]; |
212 | 212 | |
213 | - if ( $ids === null ) { |
|
213 | + if ($ids === null) { |
|
214 | 214 | return []; |
215 | - } elseif ( $ids === [] ) { |
|
215 | + } elseif ($ids === []) { |
|
216 | 216 | $this->errorReporter->dieError( |
217 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
217 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
218 | 218 | } |
219 | 219 | |
220 | - foreach ( $ids as $id ) { |
|
221 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
220 | + foreach ($ids as $id) { |
|
221 | + if (!$this->statementGuidValidator->validate($id)) { |
|
222 | 222 | $this->errorReporter->dieError( |
223 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
223 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
224 | 224 | } |
225 | 225 | } |
226 | 226 | |
227 | 227 | return $ids; |
228 | 228 | } |
229 | 229 | |
230 | - private function validateParameters( array $params ) { |
|
231 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
232 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
230 | + private function validateParameters(array $params) { |
|
231 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
232 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
233 | 233 | ) { |
234 | 234 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
235 | 235 | $this->errorReporter->dieError( |
236 | 236 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
237 | 237 | } |
238 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
238 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
239 | 239 | $paramId = self::PARAM_ID; |
240 | 240 | $paramClaimId = self::PARAM_CLAIM_ID; |
241 | 241 | $this->errorReporter->dieError( |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | ], |
277 | 277 | ApiBase::PARAM_ISMULTI => true, |
278 | 278 | ApiBase::PARAM_ALL => true, |
279 | - ApiBase::PARAM_DFLT => implode( '|', CachingResultsSource::CACHED_STATUSES ), |
|
279 | + ApiBase::PARAM_DFLT => implode('|', CachingResultsSource::CACHED_STATUSES), |
|
280 | 280 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
281 | 281 | ], |
282 | 282 | ]; |
@@ -77,16 +77,16 @@ discard block |
||
77 | 77 | DelegatingConstraintChecker $delegatingConstraintChecker |
78 | 78 | ): self { |
79 | 79 | $repo = WikibaseRepo::getDefaultInstance(); |
80 | - $helperFactory = $repo->getApiHelperFactory( $main->getContext() ); |
|
80 | + $helperFactory = $repo->getApiHelperFactory($main->getContext()); |
|
81 | 81 | $language = WikibaseRepo::getUserLanguage(); |
82 | 82 | |
83 | 83 | $entityIdHtmlLinkFormatterFactory = $repo->getEntityIdHtmlLinkFormatterFactory(); |
84 | 84 | $entityIdHtmlLinkFormatter = $entityIdHtmlLinkFormatterFactory |
85 | - ->getEntityIdFormatter( $language ); |
|
85 | + ->getEntityIdFormatter($language); |
|
86 | 86 | $formatterOptions = new FormatterOptions(); |
87 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
87 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
88 | 88 | $dataValueFormatter = $valueFormatterFactory |
89 | - ->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
89 | + ->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
90 | 90 | $violationMessageRenderer = new MultilingualTextViolationMessageRenderer( |
91 | 91 | $entityIdHtmlLinkFormatter, |
92 | 92 | $dataValueFormatter, |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | StatementGuidParser $statementGuidParser, |
123 | 123 | IBufferingStatsdDataFactory $dataFactory |
124 | 124 | ) { |
125 | - parent::__construct( $main, $name ); |
|
125 | + parent::__construct($main, $name); |
|
126 | 126 | |
127 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
127 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
128 | 128 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
129 | 129 | $this->violationMessageRenderer = $violationMessageRenderer; |
130 | 130 | $this->statementGuidParser = $statementGuidParser; |
@@ -139,39 +139,39 @@ discard block |
||
139 | 139 | $params = $this->extractRequestParams(); |
140 | 140 | $result = $this->getResult(); |
141 | 141 | |
142 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
143 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
142 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
143 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
144 | 144 | |
145 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
146 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
145 | + $this->checkPropertyIds($propertyIds, $result); |
|
146 | + $this->checkConstraintIds($constraintIds, $result); |
|
147 | 147 | |
148 | - $result->addValue( null, 'success', 1 ); |
|
148 | + $result->addValue(null, 'success', 1); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
152 | 152 | * @param array|null $propertyIdSerializations |
153 | 153 | * @return PropertyId[] |
154 | 154 | */ |
155 | - private function parsePropertyIds( $propertyIdSerializations ) { |
|
156 | - if ( $propertyIdSerializations === null ) { |
|
155 | + private function parsePropertyIds($propertyIdSerializations) { |
|
156 | + if ($propertyIdSerializations === null) { |
|
157 | 157 | return []; |
158 | - } elseif ( empty( $propertyIdSerializations ) ) { |
|
158 | + } elseif (empty($propertyIdSerializations)) { |
|
159 | 159 | $this->apiErrorReporter->dieError( |
160 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
160 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
161 | 161 | 'no-data' |
162 | 162 | ); |
163 | 163 | } |
164 | 164 | |
165 | 165 | return array_map( |
166 | - function ( $propertyIdSerialization ) { |
|
166 | + function($propertyIdSerialization) { |
|
167 | 167 | try { |
168 | - return new PropertyId( $propertyIdSerialization ); |
|
169 | - } catch ( InvalidArgumentException $e ) { |
|
168 | + return new PropertyId($propertyIdSerialization); |
|
169 | + } catch (InvalidArgumentException $e) { |
|
170 | 170 | $this->apiErrorReporter->dieError( |
171 | 171 | "Invalid id: $propertyIdSerialization", |
172 | 172 | 'invalid-property-id', |
173 | 173 | 0, // default argument |
174 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
174 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
175 | 175 | ); |
176 | 176 | } |
177 | 177 | }, |
@@ -183,35 +183,35 @@ discard block |
||
183 | 183 | * @param array|null $constraintIds |
184 | 184 | * @return string[] |
185 | 185 | */ |
186 | - private function parseConstraintIds( $constraintIds ) { |
|
187 | - if ( $constraintIds === null ) { |
|
186 | + private function parseConstraintIds($constraintIds) { |
|
187 | + if ($constraintIds === null) { |
|
188 | 188 | return []; |
189 | - } elseif ( empty( $constraintIds ) ) { |
|
189 | + } elseif (empty($constraintIds)) { |
|
190 | 190 | $this->apiErrorReporter->dieError( |
191 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
191 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
192 | 192 | 'no-data' |
193 | 193 | ); |
194 | 194 | } |
195 | 195 | |
196 | 196 | return array_map( |
197 | - function ( $constraintId ) { |
|
197 | + function($constraintId) { |
|
198 | 198 | try { |
199 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
200 | - if ( !$propertyId instanceof PropertyId ) { |
|
199 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
200 | + if (!$propertyId instanceof PropertyId) { |
|
201 | 201 | $this->apiErrorReporter->dieError( |
202 | 202 | "Invalid property ID: {$propertyId->getSerialization()}", |
203 | 203 | 'invalid-property-id', |
204 | 204 | 0, // default argument |
205 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
205 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
206 | 206 | ); |
207 | 207 | } |
208 | 208 | return $constraintId; |
209 | - } catch ( StatementGuidParsingException $e ) { |
|
209 | + } catch (StatementGuidParsingException $e) { |
|
210 | 210 | $this->apiErrorReporter->dieError( |
211 | 211 | "Invalid statement GUID: $constraintId", |
212 | 212 | 'invalid-guid', |
213 | 213 | 0, // default argument |
214 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
214 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
215 | 215 | ); |
216 | 216 | } |
217 | 217 | }, |
@@ -223,12 +223,12 @@ discard block |
||
223 | 223 | * @param PropertyId[] $propertyIds |
224 | 224 | * @param ApiResult $result |
225 | 225 | */ |
226 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ) { |
|
227 | - foreach ( $propertyIds as $propertyId ) { |
|
228 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
226 | + private function checkPropertyIds(array $propertyIds, ApiResult $result) { |
|
227 | + foreach ($propertyIds as $propertyId) { |
|
228 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
229 | 229 | $allConstraintExceptions = $this->delegatingConstraintChecker |
230 | - ->checkConstraintParametersOnPropertyId( $propertyId ); |
|
231 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
230 | + ->checkConstraintParametersOnPropertyId($propertyId); |
|
231 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
232 | 232 | $this->addConstraintParameterExceptionsToResult( |
233 | 233 | $constraintId, |
234 | 234 | $constraintParameterExceptions, |
@@ -242,15 +242,15 @@ discard block |
||
242 | 242 | * @param string[] $constraintIds |
243 | 243 | * @param ApiResult $result |
244 | 244 | */ |
245 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ) { |
|
246 | - foreach ( $constraintIds as $constraintId ) { |
|
247 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
245 | + private function checkConstraintIds(array $constraintIds, ApiResult $result) { |
|
246 | + foreach ($constraintIds as $constraintId) { |
|
247 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
248 | 248 | // already checked as part of checkPropertyIds() |
249 | 249 | continue; |
250 | 250 | } |
251 | 251 | $constraintParameterExceptions = $this->delegatingConstraintChecker |
252 | - ->checkConstraintParametersOnConstraintId( $constraintId ); |
|
253 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
252 | + ->checkConstraintParametersOnConstraintId($constraintId); |
|
253 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
254 | 254 | } |
255 | 255 | } |
256 | 256 | |
@@ -258,18 +258,18 @@ discard block |
||
258 | 258 | * @param PropertyId $propertyId |
259 | 259 | * @return string[] |
260 | 260 | */ |
261 | - private function getResultPathForPropertyId( PropertyId $propertyId ) { |
|
262 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
261 | + private function getResultPathForPropertyId(PropertyId $propertyId) { |
|
262 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
266 | 266 | * @param string $constraintId |
267 | 267 | * @return string[] |
268 | 268 | */ |
269 | - private function getResultPathForConstraintId( $constraintId ) { |
|
270 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
269 | + private function getResultPathForConstraintId($constraintId) { |
|
270 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
271 | 271 | '@phan-var PropertyId $propertyId'; |
272 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
272 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | $constraintParameterExceptions, |
285 | 285 | ApiResult $result |
286 | 286 | ) { |
287 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
288 | - if ( $constraintParameterExceptions === null ) { |
|
287 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
288 | + if ($constraintParameterExceptions === null) { |
|
289 | 289 | $result->addValue( |
290 | 290 | $path, |
291 | 291 | self::KEY_STATUS, |
@@ -295,12 +295,12 @@ discard block |
||
295 | 295 | $result->addValue( |
296 | 296 | $path, |
297 | 297 | self::KEY_STATUS, |
298 | - empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
298 | + empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
299 | 299 | ); |
300 | 300 | $result->addValue( |
301 | 301 | $path, |
302 | 302 | self::KEY_PROBLEMS, |
303 | - array_map( [ $this, 'formatConstraintParameterException' ], $constraintParameterExceptions ) |
|
303 | + array_map([$this, 'formatConstraintParameterException'], $constraintParameterExceptions) |
|
304 | 304 | ); |
305 | 305 | } |
306 | 306 | } |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | * @param ConstraintParameterException $e |
312 | 312 | * @return string[] |
313 | 313 | */ |
314 | - private function formatConstraintParameterException( ConstraintParameterException $e ) { |
|
314 | + private function formatConstraintParameterException(ConstraintParameterException $e) { |
|
315 | 315 | return [ |
316 | 316 | self::KEY_MESSAGE_HTML => $this->violationMessageRenderer->render( |
317 | 317 | $e->getViolationMessage() |
@@ -344,8 +344,8 @@ discard block |
||
344 | 344 | return [ |
345 | 345 | 'action=wbcheckconstraintparameters&propertyid=P247' |
346 | 346 | => 'apihelp-wbcheckconstraintparameters-example-propertyid-1', |
347 | - 'action=wbcheckconstraintparameters&' . |
|
348 | - 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' . |
|
347 | + 'action=wbcheckconstraintparameters&'. |
|
348 | + 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'. |
|
349 | 349 | 'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f' |
350 | 350 | => 'apihelp-wbcheckconstraintparameters-example-constraintid-2', |
351 | 351 | ]; |
@@ -8,20 +8,20 @@ |
||
8 | 8 | use Wikibase\Repo\WikibaseRepo; |
9 | 9 | |
10 | 10 | return [ |
11 | - WikibaseServices::ENTITY_LOOKUP => function ( MediaWikiServices $services ) { |
|
11 | + WikibaseServices::ENTITY_LOOKUP => function(MediaWikiServices $services) { |
|
12 | 12 | return new ExceptionIgnoringEntityLookup( |
13 | - WikibaseRepo::getEntityLookup( $services ) |
|
13 | + WikibaseRepo::getEntityLookup($services) |
|
14 | 14 | ); |
15 | 15 | }, |
16 | 16 | |
17 | - WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => function ( MediaWikiServices $services ) { |
|
17 | + WikibaseServices::ENTITY_LOOKUP_WITHOUT_CACHE => function(MediaWikiServices $services) { |
|
18 | 18 | return new ExceptionIgnoringEntityLookup( |
19 | - WikibaseRepo::getStore( $services ) |
|
20 | - ->getEntityLookup( Store::LOOKUP_CACHING_RETRIEVE_ONLY ) |
|
19 | + WikibaseRepo::getStore($services) |
|
20 | + ->getEntityLookup(Store::LOOKUP_CACHING_RETRIEVE_ONLY) |
|
21 | 21 | ); |
22 | 22 | }, |
23 | 23 | |
24 | - WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => function ( MediaWikiServices $services ) { |
|
24 | + WikibaseServices::PROPERTY_DATA_TYPE_LOOKUP => function(MediaWikiServices $services) { |
|
25 | 25 | return WikibaseRepo::getDefaultInstance()->getPropertyDataTypeLookup(); |
26 | 26 | }, |
27 | 27 | ]; |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | */ |
39 | 39 | private const BATCH_SIZE = 50; |
40 | 40 | |
41 | - public static function newFromGlobalState( Title $title, array $params ) { |
|
42 | - Assert::parameterType( 'string', $params['propertyId'], '$params["propertyId"]' ); |
|
41 | + public static function newFromGlobalState(Title $title, array $params) { |
|
42 | + Assert::parameterType('string', $params['propertyId'], '$params["propertyId"]'); |
|
43 | 43 | $services = MediaWikiServices::getInstance(); |
44 | 44 | $repo = WikibaseRepo::getDefaultInstance(); |
45 | 45 | return new UpdateConstraintsTableJob( |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | $services->getMainConfig(), |
51 | 51 | ConstraintsServices::getConstraintStore(), |
52 | 52 | $services->getDBLoadBalancerFactory(), |
53 | - WikibaseRepo::getStore()->getEntityRevisionLookup( Store::LOOKUP_CACHING_DISABLED ), |
|
54 | - WikibaseRepo::getBaseDataModelSerializerFactory( $services ) |
|
53 | + WikibaseRepo::getStore()->getEntityRevisionLookup(Store::LOOKUP_CACHING_DISABLED), |
|
54 | + WikibaseRepo::getBaseDataModelSerializerFactory($services) |
|
55 | 55 | ->newSnakSerializer() |
56 | 56 | ); |
57 | 57 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | EntityRevisionLookup $entityRevisionLookup, |
112 | 112 | Serializer $snakSerializer |
113 | 113 | ) { |
114 | - parent::__construct( 'constraintsTableUpdate', $title, $params ); |
|
114 | + parent::__construct('constraintsTableUpdate', $title, $params); |
|
115 | 115 | |
116 | 116 | $this->propertyId = $propertyId; |
117 | 117 | $this->revisionId = $revisionId; |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | $this->snakSerializer = $snakSerializer; |
123 | 123 | } |
124 | 124 | |
125 | - public function extractParametersFromQualifiers( SnakList $qualifiers ) { |
|
125 | + public function extractParametersFromQualifiers(SnakList $qualifiers) { |
|
126 | 126 | $parameters = []; |
127 | - foreach ( $qualifiers as $qualifier ) { |
|
127 | + foreach ($qualifiers as $qualifier) { |
|
128 | 128 | $qualifierId = $qualifier->getPropertyId()->getSerialization(); |
129 | - $paramSerialization = $this->snakSerializer->serialize( $qualifier ); |
|
129 | + $paramSerialization = $this->snakSerializer->serialize($qualifier); |
|
130 | 130 | $parameters[$qualifierId][] = $paramSerialization; |
131 | 131 | } |
132 | 132 | return $parameters; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | '@phan-var \Wikibase\DataModel\Entity\EntityIdValue $dataValue'; |
144 | 144 | $entityId = $dataValue->getEntityId(); |
145 | 145 | $constraintTypeQid = $entityId->getSerialization(); |
146 | - $parameters = $this->extractParametersFromQualifiers( $constraintStatement->getQualifiers() ); |
|
146 | + $parameters = $this->extractParametersFromQualifiers($constraintStatement->getQualifiers()); |
|
147 | 147 | return new Constraint( |
148 | 148 | $constraintId, |
149 | 149 | $propertyId, |
@@ -158,24 +158,24 @@ discard block |
||
158 | 158 | PropertyId $propertyConstraintPropertyId |
159 | 159 | ) { |
160 | 160 | $constraintsStatements = $property->getStatements() |
161 | - ->getByPropertyId( $propertyConstraintPropertyId ) |
|
162 | - ->getByRank( [ Statement::RANK_PREFERRED, Statement::RANK_NORMAL ] ); |
|
161 | + ->getByPropertyId($propertyConstraintPropertyId) |
|
162 | + ->getByRank([Statement::RANK_PREFERRED, Statement::RANK_NORMAL]); |
|
163 | 163 | $constraints = []; |
164 | - foreach ( $constraintsStatements->getIterator() as $constraintStatement ) { |
|
165 | - $constraints[] = $this->extractConstraintFromStatement( $property->getId(), $constraintStatement ); |
|
166 | - if ( count( $constraints ) >= self::BATCH_SIZE ) { |
|
167 | - $constraintStore->insertBatch( $constraints ); |
|
164 | + foreach ($constraintsStatements->getIterator() as $constraintStatement) { |
|
165 | + $constraints[] = $this->extractConstraintFromStatement($property->getId(), $constraintStatement); |
|
166 | + if (count($constraints) >= self::BATCH_SIZE) { |
|
167 | + $constraintStore->insertBatch($constraints); |
|
168 | 168 | // interrupt transaction and wait for replication |
169 | - $connection = $this->lbFactory->getMainLB()->getConnection( DB_MASTER ); |
|
170 | - $connection->endAtomic( __CLASS__ ); |
|
171 | - if ( !$connection->explicitTrxActive() ) { |
|
169 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_MASTER); |
|
170 | + $connection->endAtomic(__CLASS__); |
|
171 | + if (!$connection->explicitTrxActive()) { |
|
172 | 172 | $this->lbFactory->waitForReplication(); |
173 | 173 | } |
174 | - $connection->startAtomic( __CLASS__ ); |
|
174 | + $connection->startAtomic(__CLASS__); |
|
175 | 175 | $constraints = []; |
176 | 176 | } |
177 | 177 | } |
178 | - $constraintStore->insertBatch( $constraints ); |
|
178 | + $constraintStore->insertBatch($constraints); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -186,24 +186,24 @@ discard block |
||
186 | 186 | public function run() { |
187 | 187 | // TODO in the future: only touch constraints affected by the edit (requires T163465) |
188 | 188 | |
189 | - $propertyId = new PropertyId( $this->propertyId ); |
|
189 | + $propertyId = new PropertyId($this->propertyId); |
|
190 | 190 | $propertyRevision = $this->entityRevisionLookup->getEntityRevision( |
191 | 191 | $propertyId, |
192 | 192 | 0, // latest |
193 | 193 | LookupConstants::LATEST_FROM_REPLICA |
194 | 194 | ); |
195 | 195 | |
196 | - if ( $this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId ) { |
|
197 | - JobQueueGroup::singleton()->push( $this ); |
|
196 | + if ($this->revisionId !== null && $propertyRevision->getRevisionId() < $this->revisionId) { |
|
197 | + JobQueueGroup::singleton()->push($this); |
|
198 | 198 | return true; |
199 | 199 | } |
200 | 200 | |
201 | - $connection = $this->lbFactory->getMainLB()->getConnection( DB_MASTER ); |
|
201 | + $connection = $this->lbFactory->getMainLB()->getConnection(DB_MASTER); |
|
202 | 202 | // start transaction (if not started yet) – using __CLASS__, not __METHOD__, |
203 | 203 | // because importConstraintsForProperty() can interrupt the transaction |
204 | - $connection->startAtomic( __CLASS__ ); |
|
204 | + $connection->startAtomic(__CLASS__); |
|
205 | 205 | |
206 | - $this->constraintStore->deleteForProperty( $propertyId ); |
|
206 | + $this->constraintStore->deleteForProperty($propertyId); |
|
207 | 207 | |
208 | 208 | /** @var Property $property */ |
209 | 209 | $property = $propertyRevision->getEntity(); |
@@ -211,10 +211,10 @@ discard block |
||
211 | 211 | $this->importConstraintsForProperty( |
212 | 212 | $property, |
213 | 213 | $this->constraintStore, |
214 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ) |
|
214 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')) |
|
215 | 215 | ); |
216 | 216 | |
217 | - $connection->endAtomic( __CLASS__ ); |
|
217 | + $connection->endAtomic(__CLASS__); |
|
218 | 218 | |
219 | 219 | return true; |
220 | 220 | } |