@@ -28,27 +28,27 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @param DatabaseUpdater $updater |
30 | 30 | */ |
31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
32 | - $dir = dirname( __DIR__ ) . '/sql/'; |
|
31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
32 | + $dir = dirname(__DIR__).'/sql/'; |
|
33 | 33 | |
34 | 34 | $updater->addExtensionTable( |
35 | 35 | 'wbqc_constraints', |
36 | - $dir . "/{$updater->getDB()->getType()}/tables-generated.sql" |
|
36 | + $dir."/{$updater->getDB()->getType()}/tables-generated.sql" |
|
37 | 37 | ); |
38 | 38 | $updater->addExtensionField( |
39 | 39 | 'wbqc_constraints', |
40 | 40 | 'constraint_id', |
41 | - $dir . '/patch-wbqc_constraints-constraint_id.sql' |
|
41 | + $dir.'/patch-wbqc_constraints-constraint_id.sql' |
|
42 | 42 | ); |
43 | 43 | $updater->addExtensionIndex( |
44 | 44 | 'wbqc_constraints', |
45 | 45 | 'wbqc_constraints_guid_uniq', |
46 | - $dir . '/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
46 | + $dir.'/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
47 | 47 | ); |
48 | 48 | } |
49 | 49 | |
50 | - public static function onWikibaseChange( Change $change ) { |
|
51 | - if ( !( $change instanceof EntityChange ) ) { |
|
50 | + public static function onWikibaseChange(Change $change) { |
|
51 | + if (!($change instanceof EntityChange)) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
@@ -57,48 +57,48 @@ discard block |
||
57 | 57 | |
58 | 58 | // If jobs are enabled and the results would be stored in some way run a job. |
59 | 59 | if ( |
60 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
61 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
60 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
61 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
62 | 62 | self::isSelectedForJobRunBasedOnPercentage() |
63 | 63 | ) { |
64 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
64 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
65 | 65 | JobQueueGroup::singleton()->lazyPush( |
66 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
66 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
67 | 67 | ); |
68 | 68 | } |
69 | 69 | |
70 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
71 | - self::isConstraintStatementsChange( $config, $change ) |
|
70 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
71 | + self::isConstraintStatementsChange($config, $change) |
|
72 | 72 | ) { |
73 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
73 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
74 | 74 | $metadata = $change->getMetadata(); |
75 | - if ( array_key_exists( 'rev_id', $metadata ) ) { |
|
75 | + if (array_key_exists('rev_id', $metadata)) { |
|
76 | 76 | $params['revisionId'] = $metadata['rev_id']; |
77 | 77 | } |
78 | 78 | JobQueueGroup::singleton()->push( |
79 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
79 | + new JobSpecification('constraintsTableUpdate', $params) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | 84 | private static function isSelectedForJobRunBasedOnPercentage() { |
85 | 85 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
86 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
86 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
87 | 87 | |
88 | - return mt_rand( 1, 100 ) <= $percentage; |
|
88 | + return mt_rand(1, 100) <= $percentage; |
|
89 | 89 | } |
90 | 90 | |
91 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
92 | - if ( !( $change instanceof EntityChange ) || |
|
91 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
92 | + if (!($change instanceof EntityChange) || |
|
93 | 93 | $change->getAction() !== EntityChange::UPDATE || |
94 | - !( $change->getEntityId() instanceof PropertyId ) |
|
94 | + !($change->getEntityId() instanceof PropertyId) |
|
95 | 95 | ) { |
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | |
99 | 99 | $info = $change->getInfo(); |
100 | 100 | |
101 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
101 | + if (!array_key_exists('compactDiff', $info)) { |
|
102 | 102 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
103 | 103 | // so we only know that the change *might* affect the constraint statements |
104 | 104 | return true; |
@@ -107,43 +107,43 @@ discard block |
||
107 | 107 | /** @var EntityDiffChangedAspects $aspects */ |
108 | 108 | $aspects = $info['compactDiff']; |
109 | 109 | |
110 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
111 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
110 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
111 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
112 | 112 | } |
113 | 113 | |
114 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
114 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
115 | 115 | $entityContentFactory = WikibaseRepo::getEntityContentFactory(); |
116 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
116 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
117 | 117 | $entityIdLookup = WikibaseRepo::getEntityIdLookup(); |
118 | - $entityId = $entityIdLookup->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
119 | - if ( $entityId !== null ) { |
|
118 | + $entityId = $entityIdLookup->getEntityIdForTitle($wikiPage->getTitle()); |
|
119 | + if ($entityId !== null) { |
|
120 | 120 | $resultsCache = ResultsCache::getDefaultInstance(); |
121 | - $resultsCache->delete( $entityId ); |
|
121 | + $resultsCache->delete($entityId); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
126 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
127 | 127 | $lookup = WikibaseRepo::getEntityNamespaceLookup(); |
128 | 128 | $title = $out->getTitle(); |
129 | - if ( $title === null ) { |
|
129 | + if ($title === null) { |
|
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
133 | - if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) { |
|
133 | + if (!$lookup->isNamespaceWithEntities($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()->isRegistered() ) { |
|
142 | + if (!$out->getUser()->isRegistered()) { |
|
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 | } |
@@ -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 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\Api; |
6 | 6 | |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | $this->violationMessageRendererFactory = $violationMessageRendererFactory; |
34 | 34 | } |
35 | 35 | |
36 | - public function getCheckResultsRenderer( Language $language ): CheckResultsRenderer { |
|
36 | + public function getCheckResultsRenderer(Language $language): CheckResultsRenderer { |
|
37 | 37 | return new CheckResultsRenderer( |
38 | 38 | $this->entityTitleLookup, |
39 | 39 | $this->entityIdLabelFormatterFactory |
40 | - ->getEntityIdFormatter( $language ), |
|
40 | + ->getEntityIdFormatter($language), |
|
41 | 41 | $this->violationMessageRendererFactory |
42 | - ->getViolationMessageRenderer( $language ) |
|
42 | + ->getViolationMessageRenderer($language) |
|
43 | 43 | ); |
44 | 44 | } |
45 | 45 |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | StatementGuidParser $statementGuidParser, |
103 | 103 | IBufferingStatsdDataFactory $dataFactory |
104 | 104 | ) { |
105 | - parent::__construct( $main, $name ); |
|
105 | + parent::__construct($main, $name); |
|
106 | 106 | |
107 | - $this->apiErrorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
107 | + $this->apiErrorReporter = $apiHelperFactory->getErrorReporter($this); |
|
108 | 108 | $this->delegatingConstraintChecker = $delegatingConstraintChecker; |
109 | 109 | $this->violationMessageRendererFactory = $violationMessageRendererFactory; |
110 | 110 | $this->statementGuidParser = $statementGuidParser; |
@@ -119,39 +119,39 @@ discard block |
||
119 | 119 | $params = $this->extractRequestParams(); |
120 | 120 | $result = $this->getResult(); |
121 | 121 | |
122 | - $propertyIds = $this->parsePropertyIds( $params[self::PARAM_PROPERTY_ID] ); |
|
123 | - $constraintIds = $this->parseConstraintIds( $params[self::PARAM_CONSTRAINT_ID] ); |
|
122 | + $propertyIds = $this->parsePropertyIds($params[self::PARAM_PROPERTY_ID]); |
|
123 | + $constraintIds = $this->parseConstraintIds($params[self::PARAM_CONSTRAINT_ID]); |
|
124 | 124 | |
125 | - $this->checkPropertyIds( $propertyIds, $result ); |
|
126 | - $this->checkConstraintIds( $constraintIds, $result ); |
|
125 | + $this->checkPropertyIds($propertyIds, $result); |
|
126 | + $this->checkConstraintIds($constraintIds, $result); |
|
127 | 127 | |
128 | - $result->addValue( null, 'success', 1 ); |
|
128 | + $result->addValue(null, 'success', 1); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
132 | 132 | * @param array|null $propertyIdSerializations |
133 | 133 | * @return PropertyId[] |
134 | 134 | */ |
135 | - private function parsePropertyIds( $propertyIdSerializations ) { |
|
136 | - if ( $propertyIdSerializations === null ) { |
|
135 | + private function parsePropertyIds($propertyIdSerializations) { |
|
136 | + if ($propertyIdSerializations === null) { |
|
137 | 137 | return []; |
138 | - } elseif ( empty( $propertyIdSerializations ) ) { |
|
138 | + } elseif (empty($propertyIdSerializations)) { |
|
139 | 139 | $this->apiErrorReporter->dieError( |
140 | - 'If ' . self::PARAM_PROPERTY_ID . ' is specified, it must be nonempty.', |
|
140 | + 'If '.self::PARAM_PROPERTY_ID.' is specified, it must be nonempty.', |
|
141 | 141 | 'no-data' |
142 | 142 | ); |
143 | 143 | } |
144 | 144 | |
145 | 145 | return array_map( |
146 | - function ( $propertyIdSerialization ) { |
|
146 | + function($propertyIdSerialization) { |
|
147 | 147 | try { |
148 | - return new PropertyId( $propertyIdSerialization ); |
|
149 | - } catch ( InvalidArgumentException $e ) { |
|
148 | + return new PropertyId($propertyIdSerialization); |
|
149 | + } catch (InvalidArgumentException $e) { |
|
150 | 150 | $this->apiErrorReporter->dieError( |
151 | 151 | "Invalid id: $propertyIdSerialization", |
152 | 152 | 'invalid-property-id', |
153 | 153 | 0, // default argument |
154 | - [ self::PARAM_PROPERTY_ID => $propertyIdSerialization ] |
|
154 | + [self::PARAM_PROPERTY_ID => $propertyIdSerialization] |
|
155 | 155 | ); |
156 | 156 | } |
157 | 157 | }, |
@@ -163,35 +163,35 @@ discard block |
||
163 | 163 | * @param array|null $constraintIds |
164 | 164 | * @return string[] |
165 | 165 | */ |
166 | - private function parseConstraintIds( $constraintIds ) { |
|
167 | - if ( $constraintIds === null ) { |
|
166 | + private function parseConstraintIds($constraintIds) { |
|
167 | + if ($constraintIds === null) { |
|
168 | 168 | return []; |
169 | - } elseif ( empty( $constraintIds ) ) { |
|
169 | + } elseif (empty($constraintIds)) { |
|
170 | 170 | $this->apiErrorReporter->dieError( |
171 | - 'If ' . self::PARAM_CONSTRAINT_ID . ' is specified, it must be nonempty.', |
|
171 | + 'If '.self::PARAM_CONSTRAINT_ID.' is specified, it must be nonempty.', |
|
172 | 172 | 'no-data' |
173 | 173 | ); |
174 | 174 | } |
175 | 175 | |
176 | 176 | return array_map( |
177 | - function ( $constraintId ) { |
|
177 | + function($constraintId) { |
|
178 | 178 | try { |
179 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
180 | - if ( !$propertyId instanceof PropertyId ) { |
|
179 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
180 | + if (!$propertyId instanceof PropertyId) { |
|
181 | 181 | $this->apiErrorReporter->dieError( |
182 | 182 | "Invalid property ID: {$propertyId->getSerialization()}", |
183 | 183 | 'invalid-property-id', |
184 | 184 | 0, // default argument |
185 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
185 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
186 | 186 | ); |
187 | 187 | } |
188 | 188 | return $constraintId; |
189 | - } catch ( StatementGuidParsingException $e ) { |
|
189 | + } catch (StatementGuidParsingException $e) { |
|
190 | 190 | $this->apiErrorReporter->dieError( |
191 | 191 | "Invalid statement GUID: $constraintId", |
192 | 192 | 'invalid-guid', |
193 | 193 | 0, // default argument |
194 | - [ self::PARAM_CONSTRAINT_ID => $constraintId ] |
|
194 | + [self::PARAM_CONSTRAINT_ID => $constraintId] |
|
195 | 195 | ); |
196 | 196 | } |
197 | 197 | }, |
@@ -203,12 +203,12 @@ discard block |
||
203 | 203 | * @param PropertyId[] $propertyIds |
204 | 204 | * @param ApiResult $result |
205 | 205 | */ |
206 | - private function checkPropertyIds( array $propertyIds, ApiResult $result ) { |
|
207 | - foreach ( $propertyIds as $propertyId ) { |
|
208 | - $result->addArrayType( $this->getResultPathForPropertyId( $propertyId ), 'assoc' ); |
|
206 | + private function checkPropertyIds(array $propertyIds, ApiResult $result) { |
|
207 | + foreach ($propertyIds as $propertyId) { |
|
208 | + $result->addArrayType($this->getResultPathForPropertyId($propertyId), 'assoc'); |
|
209 | 209 | $allConstraintExceptions = $this->delegatingConstraintChecker |
210 | - ->checkConstraintParametersOnPropertyId( $propertyId ); |
|
211 | - foreach ( $allConstraintExceptions as $constraintId => $constraintParameterExceptions ) { |
|
210 | + ->checkConstraintParametersOnPropertyId($propertyId); |
|
211 | + foreach ($allConstraintExceptions as $constraintId => $constraintParameterExceptions) { |
|
212 | 212 | $this->addConstraintParameterExceptionsToResult( |
213 | 213 | $constraintId, |
214 | 214 | $constraintParameterExceptions, |
@@ -222,15 +222,15 @@ discard block |
||
222 | 222 | * @param string[] $constraintIds |
223 | 223 | * @param ApiResult $result |
224 | 224 | */ |
225 | - private function checkConstraintIds( array $constraintIds, ApiResult $result ) { |
|
226 | - foreach ( $constraintIds as $constraintId ) { |
|
227 | - if ( $result->getResultData( $this->getResultPathForConstraintId( $constraintId ) ) ) { |
|
225 | + private function checkConstraintIds(array $constraintIds, ApiResult $result) { |
|
226 | + foreach ($constraintIds as $constraintId) { |
|
227 | + if ($result->getResultData($this->getResultPathForConstraintId($constraintId))) { |
|
228 | 228 | // already checked as part of checkPropertyIds() |
229 | 229 | continue; |
230 | 230 | } |
231 | 231 | $constraintParameterExceptions = $this->delegatingConstraintChecker |
232 | - ->checkConstraintParametersOnConstraintId( $constraintId ); |
|
233 | - $this->addConstraintParameterExceptionsToResult( $constraintId, $constraintParameterExceptions, $result ); |
|
232 | + ->checkConstraintParametersOnConstraintId($constraintId); |
|
233 | + $this->addConstraintParameterExceptionsToResult($constraintId, $constraintParameterExceptions, $result); |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
@@ -238,18 +238,18 @@ discard block |
||
238 | 238 | * @param PropertyId $propertyId |
239 | 239 | * @return string[] |
240 | 240 | */ |
241 | - private function getResultPathForPropertyId( PropertyId $propertyId ) { |
|
242 | - return [ $this->getModuleName(), $propertyId->getSerialization() ]; |
|
241 | + private function getResultPathForPropertyId(PropertyId $propertyId) { |
|
242 | + return [$this->getModuleName(), $propertyId->getSerialization()]; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | 246 | * @param string $constraintId |
247 | 247 | * @return string[] |
248 | 248 | */ |
249 | - private function getResultPathForConstraintId( $constraintId ) { |
|
250 | - $propertyId = $this->statementGuidParser->parse( $constraintId )->getEntityId(); |
|
249 | + private function getResultPathForConstraintId($constraintId) { |
|
250 | + $propertyId = $this->statementGuidParser->parse($constraintId)->getEntityId(); |
|
251 | 251 | '@phan-var PropertyId $propertyId'; |
252 | - return array_merge( $this->getResultPathForPropertyId( $propertyId ), [ $constraintId ] ); |
|
252 | + return array_merge($this->getResultPathForPropertyId($propertyId), [$constraintId]); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | $constraintParameterExceptions, |
265 | 265 | ApiResult $result |
266 | 266 | ) { |
267 | - $path = $this->getResultPathForConstraintId( $constraintId ); |
|
268 | - if ( $constraintParameterExceptions === null ) { |
|
267 | + $path = $this->getResultPathForConstraintId($constraintId); |
|
268 | + if ($constraintParameterExceptions === null) { |
|
269 | 269 | $result->addValue( |
270 | 270 | $path, |
271 | 271 | self::KEY_STATUS, |
@@ -275,13 +275,13 @@ discard block |
||
275 | 275 | $result->addValue( |
276 | 276 | $path, |
277 | 277 | self::KEY_STATUS, |
278 | - empty( $constraintParameterExceptions ) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
278 | + empty($constraintParameterExceptions) ? self::STATUS_OKAY : self::STATUS_NOT_OKAY |
|
279 | 279 | ); |
280 | 280 | |
281 | 281 | $violationMessageRenderer = $this->violationMessageRendererFactory |
282 | - ->getViolationMessageRenderer( $this->getLanguage() ); |
|
282 | + ->getViolationMessageRenderer($this->getLanguage()); |
|
283 | 283 | $problems = []; |
284 | - foreach ( $constraintParameterExceptions as $constraintParameterException ) { |
|
284 | + foreach ($constraintParameterExceptions as $constraintParameterException) { |
|
285 | 285 | $problems[] = [ |
286 | 286 | self::KEY_MESSAGE_HTML => $violationMessageRenderer->render( |
287 | 287 | $constraintParameterException->getViolationMessage() ), |
@@ -320,8 +320,8 @@ discard block |
||
320 | 320 | return [ |
321 | 321 | 'action=wbcheckconstraintparameters&propertyid=P247' |
322 | 322 | => 'apihelp-wbcheckconstraintparameters-example-propertyid-1', |
323 | - 'action=wbcheckconstraintparameters&' . |
|
324 | - 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|' . |
|
323 | + 'action=wbcheckconstraintparameters&'. |
|
324 | + 'constraintid=P247$0fe1711e-4c0f-82ce-3af0-830b721d0fba|'. |
|
325 | 325 | 'P225$cdc71e4a-47a0-12c5-dfb3-3f6fc0b6613f' |
326 | 326 | => 'apihelp-wbcheckconstraintparameters-example-constraintid-2', |
327 | 327 | ]; |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | CheckResultsRendererFactory $checkResultsRendererFactory, |
117 | 117 | IBufferingStatsdDataFactory $dataFactory |
118 | 118 | ) { |
119 | - parent::__construct( $main, $name ); |
|
119 | + parent::__construct($main, $name); |
|
120 | 120 | $this->entityIdParser = $entityIdParser; |
121 | 121 | $this->statementGuidValidator = $statementGuidValidator; |
122 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
123 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
122 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
123 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
124 | 124 | $this->resultsSource = $resultsSource; |
125 | 125 | $this->checkResultsRendererFactory = $checkResultsRendererFactory; |
126 | 126 | $this->dataFactory = $dataFactory; |
@@ -136,14 +136,14 @@ discard block |
||
136 | 136 | |
137 | 137 | $params = $this->extractRequestParams(); |
138 | 138 | |
139 | - $this->validateParameters( $params ); |
|
140 | - $entityIds = $this->parseEntityIds( $params ); |
|
141 | - $claimIds = $this->parseClaimIds( $params ); |
|
139 | + $this->validateParameters($params); |
|
140 | + $entityIds = $this->parseEntityIds($params); |
|
141 | + $claimIds = $this->parseClaimIds($params); |
|
142 | 142 | $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; |
143 | 143 | $statuses = $params[self::PARAM_STATUS]; |
144 | 144 | |
145 | 145 | $checkResultsRenderer = $this->checkResultsRendererFactory |
146 | - ->getCheckResultsRenderer( $this->getLanguage() ); |
|
146 | + ->getCheckResultsRenderer($this->getLanguage()); |
|
147 | 147 | |
148 | 148 | $this->getResult()->addValue( |
149 | 149 | null, |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | ) |
158 | 158 | )->getArray() |
159 | 159 | ); |
160 | - $this->resultBuilder->markSuccess( 1 ); |
|
160 | + $this->resultBuilder->markSuccess(1); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -165,24 +165,24 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @return EntityId[] |
167 | 167 | */ |
168 | - private function parseEntityIds( array $params ) { |
|
168 | + private function parseEntityIds(array $params) { |
|
169 | 169 | $ids = $params[self::PARAM_ID]; |
170 | 170 | |
171 | - if ( $ids === null ) { |
|
171 | + if ($ids === null) { |
|
172 | 172 | return []; |
173 | - } elseif ( $ids === [] ) { |
|
173 | + } elseif ($ids === []) { |
|
174 | 174 | $this->errorReporter->dieError( |
175 | - 'If ' . self::PARAM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
175 | + 'If '.self::PARAM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
176 | 176 | } |
177 | 177 | |
178 | - return array_map( function ( $id ) { |
|
178 | + return array_map(function($id) { |
|
179 | 179 | try { |
180 | - return $this->entityIdParser->parse( $id ); |
|
181 | - } catch ( EntityIdParsingException $e ) { |
|
180 | + return $this->entityIdParser->parse($id); |
|
181 | + } catch (EntityIdParsingException $e) { |
|
182 | 182 | $this->errorReporter->dieError( |
183 | - "Invalid id: $id", 'invalid-entity-id', 0, [ self::PARAM_ID => $id ] ); |
|
183 | + "Invalid id: $id", 'invalid-entity-id', 0, [self::PARAM_ID => $id] ); |
|
184 | 184 | } |
185 | - }, $ids ); |
|
185 | + }, $ids); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -190,35 +190,35 @@ discard block |
||
190 | 190 | * |
191 | 191 | * @return string[] |
192 | 192 | */ |
193 | - private function parseClaimIds( array $params ) { |
|
193 | + private function parseClaimIds(array $params) { |
|
194 | 194 | $ids = $params[self::PARAM_CLAIM_ID]; |
195 | 195 | |
196 | - if ( $ids === null ) { |
|
196 | + if ($ids === null) { |
|
197 | 197 | return []; |
198 | - } elseif ( $ids === [] ) { |
|
198 | + } elseif ($ids === []) { |
|
199 | 199 | $this->errorReporter->dieError( |
200 | - 'If ' . self::PARAM_CLAIM_ID . ' is specified, it must be nonempty.', 'no-data' ); |
|
200 | + 'If '.self::PARAM_CLAIM_ID.' is specified, it must be nonempty.', 'no-data' ); |
|
201 | 201 | } |
202 | 202 | |
203 | - foreach ( $ids as $id ) { |
|
204 | - if ( !$this->statementGuidValidator->validate( $id ) ) { |
|
203 | + foreach ($ids as $id) { |
|
204 | + if (!$this->statementGuidValidator->validate($id)) { |
|
205 | 205 | $this->errorReporter->dieError( |
206 | - "Invalid claim id: $id", 'invalid-guid', 0, [ self::PARAM_CLAIM_ID => $id ] ); |
|
206 | + "Invalid claim id: $id", 'invalid-guid', 0, [self::PARAM_CLAIM_ID => $id] ); |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
210 | 210 | return $ids; |
211 | 211 | } |
212 | 212 | |
213 | - private function validateParameters( array $params ) { |
|
214 | - if ( $params[self::PARAM_CONSTRAINT_ID] !== null |
|
215 | - && empty( $params[self::PARAM_CONSTRAINT_ID] ) |
|
213 | + private function validateParameters(array $params) { |
|
214 | + if ($params[self::PARAM_CONSTRAINT_ID] !== null |
|
215 | + && empty($params[self::PARAM_CONSTRAINT_ID]) |
|
216 | 216 | ) { |
217 | 217 | $paramConstraintId = self::PARAM_CONSTRAINT_ID; |
218 | 218 | $this->errorReporter->dieError( |
219 | 219 | "If $paramConstraintId is specified, it must be nonempty.", 'no-data' ); |
220 | 220 | } |
221 | - if ( $params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null ) { |
|
221 | + if ($params[self::PARAM_ID] === null && $params[self::PARAM_CLAIM_ID] === null) { |
|
222 | 222 | $paramId = self::PARAM_ID; |
223 | 223 | $paramClaimId = self::PARAM_CLAIM_ID; |
224 | 224 | $this->errorReporter->dieError( |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | ], |
260 | 260 | ApiBase::PARAM_ISMULTI => true, |
261 | 261 | ApiBase::PARAM_ALL => true, |
262 | - ApiBase::PARAM_DFLT => implode( '|', CachingResultsSource::CACHED_STATUSES ), |
|
262 | + ApiBase::PARAM_DFLT => implode('|', CachingResultsSource::CACHED_STATUSES), |
|
263 | 263 | ApiBase::PARAM_HELP_MSG_PER_VALUE => [], |
264 | 264 | ], |
265 | 265 | ]; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -declare( strict_types = 1 ); |
|
3 | +declare(strict_types=1); |
|
4 | 4 | |
5 | 5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Message; |
6 | 6 | |
@@ -41,14 +41,14 @@ discard block |
||
41 | 41 | $this->valueFormatterFactory = $valueFormatterFactory; |
42 | 42 | } |
43 | 43 | |
44 | - public function getViolationMessageRenderer( Language $language ): ViolationMessageRenderer { |
|
44 | + public function getViolationMessageRenderer(Language $language): ViolationMessageRenderer { |
|
45 | 45 | $formatterOptions = new FormatterOptions(); |
46 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
46 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
47 | 47 | return new MultilingualTextViolationMessageRenderer( |
48 | 48 | $this->entityIdHtmlLinkFormatterFactory |
49 | - ->getEntityIdFormatter( $language ), |
|
49 | + ->getEntityIdFormatter($language), |
|
50 | 50 | $this->valueFormatterFactory |
51 | - ->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ), |
|
51 | + ->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions), |
|
52 | 52 | $this->messageLocalizer, |
53 | 53 | $this->config |
54 | 54 | ); |
@@ -11,10 +11,10 @@ discard block |
||
11 | 11 | use Wikimedia\Rdbms\ILBFactory; |
12 | 12 | |
13 | 13 | // @codeCoverageIgnoreStart |
14 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
15 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
14 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
15 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
16 | 16 | |
17 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
17 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
18 | 18 | // @codeCoverageIgnoreEnd |
19 | 19 | |
20 | 20 | /** |
@@ -46,57 +46,57 @@ discard block |
||
46 | 46 | |
47 | 47 | public function __construct() { |
48 | 48 | parent::__construct(); |
49 | - $this->newUpdateConstraintsTableJob = static function ( $propertyIdSerialization ) { |
|
49 | + $this->newUpdateConstraintsTableJob = static function($propertyIdSerialization) { |
|
50 | 50 | return UpdateConstraintsTableJob::newFromGlobalState( |
51 | 51 | Title::newMainPage(), |
52 | - [ 'propertyId' => $propertyIdSerialization ] |
|
52 | + ['propertyId' => $propertyIdSerialization] |
|
53 | 53 | ); |
54 | 54 | }; |
55 | 55 | |
56 | - $this->addDescription( 'Imports property constraints from statements on properties' ); |
|
57 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
58 | - $this->setBatchSize( 10 ); |
|
56 | + $this->addDescription('Imports property constraints from statements on properties'); |
|
57 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
58 | + $this->setBatchSize(10); |
|
59 | 59 | |
60 | 60 | // Wikibase classes are not yet loaded, so setup services in a callback run in execute |
61 | 61 | // that can be overridden in tests. |
62 | - $this->setupServices = function () { |
|
62 | + $this->setupServices = function() { |
|
63 | 63 | $services = MediaWikiServices::getInstance(); |
64 | - $this->propertyInfoLookup = WikibaseRepo::getStore( $services )->getPropertyInfoLookup(); |
|
64 | + $this->propertyInfoLookup = WikibaseRepo::getStore($services)->getPropertyInfoLookup(); |
|
65 | 65 | $this->lbFactory = $services->getDBLoadBalancerFactory(); |
66 | 66 | }; |
67 | 67 | } |
68 | 68 | |
69 | 69 | public function execute() { |
70 | - ( $this->setupServices )(); |
|
71 | - if ( !$this->getConfig()->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) ) { |
|
72 | - $this->error( 'Constraint statements are not enabled. Aborting.' ); |
|
70 | + ($this->setupServices)(); |
|
71 | + if (!$this->getConfig()->get('WBQualityConstraintsEnableConstraintsImportFromStatements')) { |
|
72 | + $this->error('Constraint statements are not enabled. Aborting.'); |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | 76 | $propertyInfos = $this->propertyInfoLookup->getAllPropertyInfo(); |
77 | - $propertyIds = array_keys( $propertyInfos ); |
|
77 | + $propertyIds = array_keys($propertyInfos); |
|
78 | 78 | |
79 | - foreach ( array_chunk( $propertyIds, $this->getBatchSize() ) as $propertyIdsChunk ) { |
|
80 | - foreach ( $propertyIdsChunk as $propertyIdSerialization ) { |
|
81 | - $this->output( sprintf( |
|
79 | + foreach (array_chunk($propertyIds, $this->getBatchSize()) as $propertyIdsChunk) { |
|
80 | + foreach ($propertyIdsChunk as $propertyIdSerialization) { |
|
81 | + $this->output(sprintf( |
|
82 | 82 | 'Importing constraint statements for % 6s... ', |
83 | 83 | $propertyIdSerialization ), |
84 | 84 | $propertyIdSerialization |
85 | 85 | ); |
86 | - $startTime = microtime( true ); |
|
87 | - $job = call_user_func( $this->newUpdateConstraintsTableJob, $propertyIdSerialization ); |
|
86 | + $startTime = microtime(true); |
|
87 | + $job = call_user_func($this->newUpdateConstraintsTableJob, $propertyIdSerialization); |
|
88 | 88 | $job->run(); |
89 | - $endTime = microtime( true ); |
|
90 | - $millis = ( $endTime - $startTime ) * 1000; |
|
91 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), $propertyIdSerialization ); |
|
89 | + $endTime = microtime(true); |
|
90 | + $millis = ($endTime - $startTime) * 1000; |
|
91 | + $this->output(sprintf('done in % 6.2f ms.', $millis), $propertyIdSerialization); |
|
92 | 92 | } |
93 | 93 | |
94 | - $this->output( 'Waiting for replication... ', 'waitForReplication' ); |
|
95 | - $startTime = microtime( true ); |
|
94 | + $this->output('Waiting for replication... ', 'waitForReplication'); |
|
95 | + $startTime = microtime(true); |
|
96 | 96 | $this->lbFactory->waitForReplication(); |
97 | - $endTime = microtime( true ); |
|
98 | - $millis = ( $endTime - $startTime ) * 1000; |
|
99 | - $this->output( sprintf( 'done in % 6.2f ms.', $millis ), 'waitForReplication' ); |
|
97 | + $endTime = microtime(true); |
|
98 | + $millis = ($endTime - $startTime) * 1000; |
|
99 | + $this->output(sprintf('done in % 6.2f ms.', $millis), 'waitForReplication'); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 |
@@ -142,14 +142,14 @@ discard block |
||
142 | 142 | ) { |
143 | 143 | $results = []; |
144 | 144 | $metadatas = []; |
145 | - if ( $this->canUseStoredResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
145 | + if ($this->canUseStoredResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
146 | 146 | $storedEntityIds = []; |
147 | - foreach ( $entityIds as $entityId ) { |
|
148 | - $storedResults = $this->getStoredResults( $entityId ); |
|
149 | - if ( $storedResults !== null ) { |
|
150 | - $this->loggingHelper->logCheckConstraintsCacheHit( $entityId ); |
|
151 | - foreach ( $storedResults->getArray() as $checkResult ) { |
|
152 | - if ( $this->statusSelected( $statuses, $checkResult ) ) { |
|
147 | + foreach ($entityIds as $entityId) { |
|
148 | + $storedResults = $this->getStoredResults($entityId); |
|
149 | + if ($storedResults !== null) { |
|
150 | + $this->loggingHelper->logCheckConstraintsCacheHit($entityId); |
|
151 | + foreach ($storedResults->getArray() as $checkResult) { |
|
152 | + if ($this->statusSelected($statuses, $checkResult)) { |
|
153 | 153 | $results[] = $checkResult; |
154 | 154 | } |
155 | 155 | } |
@@ -157,19 +157,19 @@ discard block |
||
157 | 157 | $storedEntityIds[] = $entityId; |
158 | 158 | } |
159 | 159 | } |
160 | - $entityIds = array_values( array_diff( $entityIds, $storedEntityIds ) ); |
|
160 | + $entityIds = array_values(array_diff($entityIds, $storedEntityIds)); |
|
161 | 161 | } |
162 | - if ( $entityIds !== [] || $claimIds !== [] ) { |
|
163 | - if ( $entityIds !== [] ) { |
|
164 | - $this->loggingHelper->logCheckConstraintsCacheMisses( $entityIds ); |
|
162 | + if ($entityIds !== [] || $claimIds !== []) { |
|
163 | + if ($entityIds !== []) { |
|
164 | + $this->loggingHelper->logCheckConstraintsCacheMisses($entityIds); |
|
165 | 165 | } |
166 | - $response = $this->getAndStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
167 | - $results = array_merge( $results, $response->getArray() ); |
|
166 | + $response = $this->getAndStoreResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
167 | + $results = array_merge($results, $response->getArray()); |
|
168 | 168 | $metadatas[] = $response->getMetadata(); |
169 | 169 | } |
170 | 170 | return new CachedCheckResults( |
171 | 171 | $results, |
172 | - Metadata::merge( $metadatas ) |
|
172 | + Metadata::merge($metadatas) |
|
173 | 173 | ); |
174 | 174 | } |
175 | 175 | |
@@ -192,13 +192,13 @@ discard block |
||
192 | 192 | ?array $constraintIds, |
193 | 193 | array $statuses |
194 | 194 | ) { |
195 | - if ( $claimIds !== [] ) { |
|
195 | + if ($claimIds !== []) { |
|
196 | 196 | return false; |
197 | 197 | } |
198 | - if ( $constraintIds !== null ) { |
|
198 | + if ($constraintIds !== null) { |
|
199 | 199 | return false; |
200 | 200 | } |
201 | - if ( array_diff( $statuses, self::CACHED_STATUSES ) !== [] ) { |
|
201 | + if (array_diff($statuses, self::CACHED_STATUSES) !== []) { |
|
202 | 202 | return false; |
203 | 203 | } |
204 | 204 | return true; |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | * @param CheckResult $result |
214 | 214 | * @return bool |
215 | 215 | */ |
216 | - private function statusSelected( array $statuses, CheckResult $result ) { |
|
217 | - return in_array( $result->getStatus(), $statuses, true ) || |
|
216 | + private function statusSelected(array $statuses, CheckResult $result) { |
|
217 | + return in_array($result->getStatus(), $statuses, true) || |
|
218 | 218 | $result instanceof NullResult; |
219 | 219 | } |
220 | 220 | |
@@ -231,11 +231,11 @@ discard block |
||
231 | 231 | ?array $constraintIds, |
232 | 232 | array $statuses |
233 | 233 | ) { |
234 | - $results = $this->resultsSource->getResults( $entityIds, $claimIds, $constraintIds, $statuses ); |
|
234 | + $results = $this->resultsSource->getResults($entityIds, $claimIds, $constraintIds, $statuses); |
|
235 | 235 | |
236 | - if ( $this->canStoreResults( $entityIds, $claimIds, $constraintIds, $statuses ) ) { |
|
237 | - foreach ( $entityIds as $entityId ) { |
|
238 | - $this->storeResults( $entityId, $results ); |
|
236 | + if ($this->canStoreResults($entityIds, $claimIds, $constraintIds, $statuses)) { |
|
237 | + foreach ($entityIds as $entityId) { |
|
238 | + $this->storeResults($entityId, $results); |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 | |
@@ -266,10 +266,10 @@ discard block |
||
266 | 266 | ?array $constraintIds, |
267 | 267 | array $statuses |
268 | 268 | ) { |
269 | - if ( $constraintIds !== null ) { |
|
269 | + if ($constraintIds !== null) { |
|
270 | 270 | return false; |
271 | 271 | } |
272 | - if ( array_diff( self::CACHED_STATUSES, $statuses ) !== [] ) { |
|
272 | + if (array_diff(self::CACHED_STATUSES, $statuses) !== []) { |
|
273 | 273 | return false; |
274 | 274 | } |
275 | 275 | return true; |
@@ -283,21 +283,21 @@ discard block |
||
283 | 283 | * May include check results for other entity IDs as well, |
284 | 284 | * or check results with statuses that we’re not interested in caching. |
285 | 285 | */ |
286 | - private function storeResults( EntityId $entityId, CachedCheckResults $results ) { |
|
286 | + private function storeResults(EntityId $entityId, CachedCheckResults $results) { |
|
287 | 287 | $latestRevisionIds = $this->getLatestRevisionIds( |
288 | 288 | $results->getMetadata()->getDependencyMetadata()->getEntityIds() |
289 | 289 | ); |
290 | - if ( $latestRevisionIds === null ) { |
|
290 | + if ($latestRevisionIds === null) { |
|
291 | 291 | return; |
292 | 292 | } |
293 | 293 | |
294 | 294 | $resultSerializations = []; |
295 | - foreach ( $results->getArray() as $checkResult ) { |
|
296 | - if ( $checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization() ) { |
|
295 | + foreach ($results->getArray() as $checkResult) { |
|
296 | + if ($checkResult->getContextCursor()->getEntityId() !== $entityId->getSerialization()) { |
|
297 | 297 | continue; |
298 | 298 | } |
299 | - if ( $this->statusSelected( self::CACHED_STATUSES, $checkResult ) ) { |
|
300 | - $resultSerializations[] = $this->checkResultSerializer->serialize( $checkResult ); |
|
299 | + if ($this->statusSelected(self::CACHED_STATUSES, $checkResult)) { |
|
300 | + $resultSerializations[] = $this->checkResultSerializer->serialize($checkResult); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
@@ -306,11 +306,11 @@ discard block |
||
306 | 306 | 'latestRevisionIds' => $latestRevisionIds, |
307 | 307 | ]; |
308 | 308 | $futureTime = $results->getMetadata()->getDependencyMetadata()->getFutureTime(); |
309 | - if ( $futureTime !== null ) { |
|
309 | + if ($futureTime !== null) { |
|
310 | 310 | $value['futureTime'] = $futureTime->getArrayValue(); |
311 | 311 | } |
312 | 312 | |
313 | - $this->cache->set( $entityId, $value, $this->ttlInSeconds ); |
|
313 | + $this->cache->set($entityId, $value, $this->ttlInSeconds); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
@@ -324,31 +324,30 @@ discard block |
||
324 | 324 | EntityId $entityId, |
325 | 325 | $forRevision = 0 |
326 | 326 | ) { |
327 | - $value = $this->cache->get( $entityId, $curTTL, [], $asOf ); |
|
328 | - $now = call_user_func( $this->microtime, true ); |
|
327 | + $value = $this->cache->get($entityId, $curTTL, [], $asOf); |
|
328 | + $now = call_user_func($this->microtime, true); |
|
329 | 329 | |
330 | - $dependencyMetadata = $this->checkDependencyMetadata( $value, |
|
331 | - [ $entityId->getSerialization() => $forRevision ] ); |
|
332 | - if ( $dependencyMetadata === null ) { |
|
330 | + $dependencyMetadata = $this->checkDependencyMetadata($value, |
|
331 | + [$entityId->getSerialization() => $forRevision]); |
|
332 | + if ($dependencyMetadata === null) { |
|
333 | 333 | return null; |
334 | 334 | } |
335 | 335 | |
336 | - $ageInSeconds = (int)ceil( $now - $asOf ); |
|
336 | + $ageInSeconds = (int) ceil($now - $asOf); |
|
337 | 337 | $cachingMetadata = $ageInSeconds > 0 ? |
338 | - CachingMetadata::ofMaximumAgeInSeconds( $ageInSeconds ) : |
|
339 | - CachingMetadata::fresh(); |
|
338 | + CachingMetadata::ofMaximumAgeInSeconds($ageInSeconds) : CachingMetadata::fresh(); |
|
340 | 339 | |
341 | 340 | $results = []; |
342 | - foreach ( $value['results'] as $resultSerialization ) { |
|
343 | - $results[] = $this->deserializeCheckResult( $resultSerialization, $cachingMetadata ); |
|
341 | + foreach ($value['results'] as $resultSerialization) { |
|
342 | + $results[] = $this->deserializeCheckResult($resultSerialization, $cachingMetadata); |
|
344 | 343 | } |
345 | 344 | |
346 | 345 | return new CachedCheckResults( |
347 | 346 | $results, |
348 | - Metadata::merge( [ |
|
349 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
350 | - Metadata::ofDependencyMetadata( $dependencyMetadata ), |
|
351 | - ] ) |
|
347 | + Metadata::merge([ |
|
348 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
349 | + Metadata::ofDependencyMetadata($dependencyMetadata), |
|
350 | + ]) |
|
352 | 351 | ); |
353 | 352 | } |
354 | 353 | |
@@ -364,43 +363,43 @@ discard block |
||
364 | 363 | * @return DependencyMetadata|null the dependency metadata, |
365 | 364 | * or null if $value should no longer be used |
366 | 365 | */ |
367 | - private function checkDependencyMetadata( $value, $paramRevs ) { |
|
368 | - if ( $value === false ) { |
|
366 | + private function checkDependencyMetadata($value, $paramRevs) { |
|
367 | + if ($value === false) { |
|
369 | 368 | return null; |
370 | 369 | } |
371 | 370 | |
372 | - if ( array_key_exists( 'futureTime', $value ) ) { |
|
373 | - $futureTime = TimeValue::newFromArray( $value['futureTime'] ); |
|
374 | - if ( !$this->timeValueComparer->isFutureTime( $futureTime ) ) { |
|
371 | + if (array_key_exists('futureTime', $value)) { |
|
372 | + $futureTime = TimeValue::newFromArray($value['futureTime']); |
|
373 | + if (!$this->timeValueComparer->isFutureTime($futureTime)) { |
|
375 | 374 | return null; |
376 | 375 | } |
377 | - $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime( $futureTime ); |
|
376 | + $futureTimeDependencyMetadata = DependencyMetadata::ofFutureTime($futureTime); |
|
378 | 377 | } else { |
379 | 378 | $futureTimeDependencyMetadata = DependencyMetadata::blank(); |
380 | 379 | } |
381 | 380 | |
382 | - foreach ( $paramRevs as $id => $revision ) { |
|
383 | - if ( $revision > 0 ) { |
|
384 | - $value['latestRevisionIds'][$id] = min( $revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX ); |
|
381 | + foreach ($paramRevs as $id => $revision) { |
|
382 | + if ($revision > 0) { |
|
383 | + $value['latestRevisionIds'][$id] = min($revision, $value['latestRevisionIds'][$id] ?? PHP_INT_MAX); |
|
385 | 384 | } |
386 | 385 | } |
387 | 386 | |
388 | 387 | $dependedEntityIds = array_map( |
389 | - [ $this->entityIdParser, "parse" ], |
|
390 | - array_keys( $value['latestRevisionIds'] ) |
|
388 | + [$this->entityIdParser, "parse"], |
|
389 | + array_keys($value['latestRevisionIds']) |
|
391 | 390 | ); |
392 | 391 | |
393 | - if ( $value['latestRevisionIds'] !== $this->getLatestRevisionIds( $dependedEntityIds ) ) { |
|
392 | + if ($value['latestRevisionIds'] !== $this->getLatestRevisionIds($dependedEntityIds)) { |
|
394 | 393 | return null; |
395 | 394 | } |
396 | 395 | |
397 | 396 | return array_reduce( |
398 | 397 | $dependedEntityIds, |
399 | - static function ( DependencyMetadata $metadata, EntityId $entityId ) { |
|
400 | - return DependencyMetadata::merge( [ |
|
398 | + static function(DependencyMetadata $metadata, EntityId $entityId) { |
|
399 | + return DependencyMetadata::merge([ |
|
401 | 400 | $metadata, |
402 | - DependencyMetadata::ofEntityId( $entityId ) |
|
403 | - ] ); |
|
401 | + DependencyMetadata::ofEntityId($entityId) |
|
402 | + ]); |
|
404 | 403 | }, |
405 | 404 | $futureTimeDependencyMetadata |
406 | 405 | ); |
@@ -420,13 +419,13 @@ discard block |
||
420 | 419 | array $resultSerialization, |
421 | 420 | CachingMetadata $cachingMetadata |
422 | 421 | ) { |
423 | - $result = $this->checkResultDeserializer->deserialize( $resultSerialization ); |
|
424 | - if ( $this->isPossiblyStaleResult( $result ) ) { |
|
422 | + $result = $this->checkResultDeserializer->deserialize($resultSerialization); |
|
423 | + if ($this->isPossiblyStaleResult($result)) { |
|
425 | 424 | $result->withMetadata( |
426 | - Metadata::merge( [ |
|
425 | + Metadata::merge([ |
|
427 | 426 | $result->getMetadata(), |
428 | - Metadata::ofCachingMetadata( $cachingMetadata ), |
|
429 | - ] ) |
|
427 | + Metadata::ofCachingMetadata($cachingMetadata), |
|
428 | + ]) |
|
430 | 429 | ); |
431 | 430 | } |
432 | 431 | return $result; |
@@ -436,8 +435,8 @@ discard block |
||
436 | 435 | * @param CheckResult $result |
437 | 436 | * @return bool |
438 | 437 | */ |
439 | - private function isPossiblyStaleResult( CheckResult $result ) { |
|
440 | - if ( $result instanceof NullResult ) { |
|
438 | + private function isPossiblyStaleResult(CheckResult $result) { |
|
439 | + if ($result instanceof NullResult) { |
|
441 | 440 | return false; |
442 | 441 | } |
443 | 442 | |
@@ -452,14 +451,14 @@ discard block |
||
452 | 451 | * @return int[]|null array from entity ID serializations to revision ID, |
453 | 452 | * or null to indicate that not all revision IDs could be loaded |
454 | 453 | */ |
455 | - private function getLatestRevisionIds( array $entityIds ) { |
|
456 | - if ( $entityIds === [] ) { |
|
454 | + private function getLatestRevisionIds(array $entityIds) { |
|
455 | + if ($entityIds === []) { |
|
457 | 456 | $this->loggingHelper->logEmptyDependencyMetadata(); |
458 | 457 | return []; |
459 | 458 | } |
460 | - if ( count( $entityIds ) > $this->maxRevisionIds ) { |
|
459 | + if (count($entityIds) > $this->maxRevisionIds) { |
|
461 | 460 | // one of those entities will probably be edited soon, so might as well skip caching |
462 | - $this->loggingHelper->logHugeDependencyMetadata( $entityIds, $this->maxRevisionIds ); |
|
461 | + $this->loggingHelper->logHugeDependencyMetadata($entityIds, $this->maxRevisionIds); |
|
463 | 462 | return null; |
464 | 463 | } |
465 | 464 | |
@@ -467,7 +466,7 @@ discard block |
||
467 | 466 | $entityIds, |
468 | 467 | LookupConstants::LATEST_FROM_REPLICA |
469 | 468 | ); |
470 | - if ( $this->hasFalseElements( $latestRevisionIds ) ) { |
|
469 | + if ($this->hasFalseElements($latestRevisionIds)) { |
|
471 | 470 | return null; |
472 | 471 | } |
473 | 472 | return $latestRevisionIds; |
@@ -477,8 +476,8 @@ discard block |
||
477 | 476 | * @param array $array |
478 | 477 | * @return bool |
479 | 478 | */ |
480 | - private function hasFalseElements( array $array ) { |
|
481 | - return in_array( false, $array, true ); |
|
479 | + private function hasFalseElements(array $array) { |
|
480 | + return in_array(false, $array, true); |
|
482 | 481 | } |
483 | 482 | |
484 | 483 | /** |
@@ -486,7 +485,7 @@ discard block |
||
486 | 485 | * |
487 | 486 | * @param callable $microtime |
488 | 487 | */ |
489 | - public function setMicrotimeFunction( callable $microtime ) { |
|
488 | + public function setMicrotimeFunction(callable $microtime) { |
|
490 | 489 | $this->microtime = $microtime; |
491 | 490 | } |
492 | 491 |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | Config $config, |
135 | 135 | IBufferingStatsdDataFactory $dataFactory |
136 | 136 | ) { |
137 | - parent::__construct( 'ConstraintReport' ); |
|
137 | + parent::__construct('ConstraintReport'); |
|
138 | 138 | |
139 | 139 | $this->entityLookup = $entityLookup; |
140 | 140 | $this->entityTitleLookup = $entityTitleLookup; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | $language = $this->getLanguage(); |
144 | 144 | |
145 | 145 | $formatterOptions = new FormatterOptions(); |
146 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $language->getCode() ); |
|
146 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $language->getCode()); |
|
147 | 147 | $this->dataValueFormatter = $valueFormatterFactory->getValueFormatter( |
148 | 148 | SnakFormatter::FORMAT_HTML, |
149 | 149 | $formatterOptions |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @return string |
204 | 204 | */ |
205 | 205 | public function getDescription() { |
206 | - return $this->msg( 'wbqc-constraintreport' )->escaped(); |
|
206 | + return $this->msg('wbqc-constraintreport')->escaped(); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -215,43 +215,43 @@ discard block |
||
215 | 215 | * @throws EntityIdParsingException |
216 | 216 | * @throws UnexpectedValueException |
217 | 217 | */ |
218 | - public function execute( $subPage ) { |
|
218 | + public function execute($subPage) { |
|
219 | 219 | $out = $this->getOutput(); |
220 | 220 | |
221 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
222 | - if ( $postRequest ) { |
|
223 | - $out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() ); |
|
221 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
222 | + if ($postRequest) { |
|
223 | + $out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL()); |
|
224 | 224 | return; |
225 | 225 | } |
226 | 226 | |
227 | 227 | $out->enableOOUI(); |
228 | - $out->addModules( $this->getModules() ); |
|
228 | + $out->addModules($this->getModules()); |
|
229 | 229 | |
230 | 230 | $this->setHeaders(); |
231 | 231 | |
232 | - $out->addHTML( $this->getExplanationText() ); |
|
232 | + $out->addHTML($this->getExplanationText()); |
|
233 | 233 | $this->buildEntityIdForm(); |
234 | 234 | |
235 | - if ( !$subPage ) { |
|
235 | + if (!$subPage) { |
|
236 | 236 | return; |
237 | 237 | } |
238 | 238 | |
239 | - if ( !is_string( $subPage ) ) { |
|
240 | - throw new InvalidArgumentException( '$subPage must be string.' ); |
|
239 | + if (!is_string($subPage)) { |
|
240 | + throw new InvalidArgumentException('$subPage must be string.'); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | try { |
244 | - $entityId = $this->entityIdParser->parse( $subPage ); |
|
245 | - } catch ( EntityIdParsingException $e ) { |
|
244 | + $entityId = $this->entityIdParser->parse($subPage); |
|
245 | + } catch (EntityIdParsingException $e) { |
|
246 | 246 | $out->addHTML( |
247 | - $this->buildNotice( 'wbqc-constraintreport-invalid-entity-id', true ) |
|
247 | + $this->buildNotice('wbqc-constraintreport-invalid-entity-id', true) |
|
248 | 248 | ); |
249 | 249 | return; |
250 | 250 | } |
251 | 251 | |
252 | - if ( !$this->entityLookup->hasEntity( $entityId ) ) { |
|
252 | + if (!$this->entityLookup->hasEntity($entityId)) { |
|
253 | 253 | $out->addHTML( |
254 | - $this->buildNotice( 'wbqc-constraintreport-not-existent-entity', true ) |
|
254 | + $this->buildNotice('wbqc-constraintreport-not-existent-entity', true) |
|
255 | 255 | ); |
256 | 256 | return; |
257 | 257 | } |
@@ -259,18 +259,18 @@ discard block |
||
259 | 259 | $this->dataFactory->increment( |
260 | 260 | 'wikibase.quality.constraints.specials.specialConstraintReport.executeCheck' |
261 | 261 | ); |
262 | - $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId( $entityId ); |
|
262 | + $results = $this->constraintChecker->checkAgainstConstraintsOnEntityId($entityId); |
|
263 | 263 | |
264 | - if ( $results !== [] ) { |
|
264 | + if ($results !== []) { |
|
265 | 265 | $out->addHTML( |
266 | - $this->buildResultHeader( $entityId ) |
|
267 | - . $this->buildSummary( $results ) |
|
268 | - . $this->buildResultTable( $entityId, $results ) |
|
266 | + $this->buildResultHeader($entityId) |
|
267 | + . $this->buildSummary($results) |
|
268 | + . $this->buildResultTable($entityId, $results) |
|
269 | 269 | ); |
270 | 270 | } else { |
271 | 271 | $out->addHTML( |
272 | - $this->buildResultHeader( $entityId ) |
|
273 | - . $this->buildNotice( 'wbqc-constraintreport-empty-result' ) |
|
272 | + $this->buildResultHeader($entityId) |
|
273 | + . $this->buildNotice('wbqc-constraintreport-empty-result') |
|
274 | 274 | ); |
275 | 275 | } |
276 | 276 | } |
@@ -286,15 +286,15 @@ discard block |
||
286 | 286 | 'name' => 'entityid', |
287 | 287 | 'label-message' => 'wbqc-constraintreport-form-entityid-label', |
288 | 288 | 'cssclass' => 'wbqc-constraintreport-form-entity-id', |
289 | - 'placeholder' => $this->msg( 'wbqc-constraintreport-form-entityid-placeholder' )->escaped() |
|
289 | + 'placeholder' => $this->msg('wbqc-constraintreport-form-entityid-placeholder')->escaped() |
|
290 | 290 | ] |
291 | 291 | ]; |
292 | - $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form' ); |
|
293 | - $htmlForm->setSubmitText( $this->msg( 'wbqc-constraintreport-form-submit-label' )->escaped() ); |
|
294 | - $htmlForm->setSubmitCallback( static function () { |
|
292 | + $htmlForm = HTMLForm::factory('ooui', $formDescriptor, $this->getContext(), 'wbqc-constraintreport-form'); |
|
293 | + $htmlForm->setSubmitText($this->msg('wbqc-constraintreport-form-submit-label')->escaped()); |
|
294 | + $htmlForm->setSubmitCallback(static function() { |
|
295 | 295 | return false; |
296 | 296 | } ); |
297 | - $htmlForm->setMethod( 'post' ); |
|
297 | + $htmlForm->setMethod('post'); |
|
298 | 298 | $htmlForm->show(); |
299 | 299 | } |
300 | 300 | |
@@ -308,16 +308,16 @@ discard block |
||
308 | 308 | * |
309 | 309 | * @return string HTML |
310 | 310 | */ |
311 | - private function buildNotice( $messageKey, $error = false ) { |
|
312 | - if ( !is_string( $messageKey ) ) { |
|
313 | - throw new InvalidArgumentException( '$message must be string.' ); |
|
311 | + private function buildNotice($messageKey, $error = false) { |
|
312 | + if (!is_string($messageKey)) { |
|
313 | + throw new InvalidArgumentException('$message must be string.'); |
|
314 | 314 | } |
315 | - if ( !is_bool( $error ) ) { |
|
316 | - throw new InvalidArgumentException( '$error must be bool.' ); |
|
315 | + if (!is_bool($error)) { |
|
316 | + throw new InvalidArgumentException('$error must be bool.'); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | $cssClasses = 'wbqc-constraintreport-notice'; |
320 | - if ( $error ) { |
|
320 | + if ($error) { |
|
321 | 321 | $cssClasses .= ' wbqc-constraintreport-notice-error'; |
322 | 322 | } |
323 | 323 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | [ |
327 | 327 | 'class' => $cssClasses |
328 | 328 | ], |
329 | - $this->msg( $messageKey )->escaped() |
|
329 | + $this->msg($messageKey)->escaped() |
|
330 | 330 | ); |
331 | 331 | } |
332 | 332 | |
@@ -336,16 +336,16 @@ discard block |
||
336 | 336 | private function getExplanationText() { |
337 | 337 | return Html::rawElement( |
338 | 338 | 'div', |
339 | - [ 'class' => 'wbqc-explanation' ], |
|
339 | + ['class' => 'wbqc-explanation'], |
|
340 | 340 | Html::rawElement( |
341 | 341 | 'p', |
342 | 342 | [], |
343 | - $this->msg( 'wbqc-constraintreport-explanation-part-one' )->escaped() |
|
343 | + $this->msg('wbqc-constraintreport-explanation-part-one')->escaped() |
|
344 | 344 | ) |
345 | 345 | . Html::rawElement( |
346 | 346 | 'p', |
347 | 347 | [], |
348 | - $this->msg( 'wbqc-constraintreport-explanation-part-two' )->escaped() |
|
348 | + $this->msg('wbqc-constraintreport-explanation-part-two')->escaped() |
|
349 | 349 | ) |
350 | 350 | ); |
351 | 351 | } |
@@ -357,72 +357,72 @@ discard block |
||
357 | 357 | * @return string HTML |
358 | 358 | * @suppress SecurityCheck-DoubleEscaped |
359 | 359 | */ |
360 | - private function buildResultTable( EntityId $entityId, array $results ) { |
|
360 | + private function buildResultTable(EntityId $entityId, array $results) { |
|
361 | 361 | // Set table headers |
362 | 362 | $table = new HtmlTableBuilder( |
363 | 363 | [ |
364 | 364 | new HtmlTableHeaderBuilder( |
365 | - $this->msg( 'wbqc-constraintreport-result-table-header-status' )->escaped(), |
|
365 | + $this->msg('wbqc-constraintreport-result-table-header-status')->escaped(), |
|
366 | 366 | true |
367 | 367 | ), |
368 | 368 | new HtmlTableHeaderBuilder( |
369 | - $this->msg( 'wbqc-constraintreport-result-table-header-property' )->escaped(), |
|
369 | + $this->msg('wbqc-constraintreport-result-table-header-property')->escaped(), |
|
370 | 370 | true |
371 | 371 | ), |
372 | 372 | new HtmlTableHeaderBuilder( |
373 | - $this->msg( 'wbqc-constraintreport-result-table-header-message' )->escaped(), |
|
373 | + $this->msg('wbqc-constraintreport-result-table-header-message')->escaped(), |
|
374 | 374 | true |
375 | 375 | ), |
376 | 376 | new HtmlTableHeaderBuilder( |
377 | - $this->msg( 'wbqc-constraintreport-result-table-header-constraint' )->escaped(), |
|
377 | + $this->msg('wbqc-constraintreport-result-table-header-constraint')->escaped(), |
|
378 | 378 | true |
379 | 379 | ) |
380 | 380 | ] |
381 | 381 | ); |
382 | 382 | |
383 | - foreach ( $results as $result ) { |
|
384 | - $table = $this->appendToResultTable( $table, $entityId, $result ); |
|
383 | + foreach ($results as $result) { |
|
384 | + $table = $this->appendToResultTable($table, $entityId, $result); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | return $table->toHtml(); |
388 | 388 | } |
389 | 389 | |
390 | - private function appendToResultTable( HtmlTableBuilder $table, EntityId $entityId, CheckResult $result ) { |
|
390 | + private function appendToResultTable(HtmlTableBuilder $table, EntityId $entityId, CheckResult $result) { |
|
391 | 391 | $message = $result->getMessage(); |
392 | - if ( $message === null ) { |
|
392 | + if ($message === null) { |
|
393 | 393 | // no row for this result |
394 | 394 | return $table; |
395 | 395 | } |
396 | 396 | |
397 | 397 | // Status column |
398 | - $statusColumn = $this->formatStatus( $result->getStatus() ); |
|
398 | + $statusColumn = $this->formatStatus($result->getStatus()); |
|
399 | 399 | |
400 | 400 | // Property column |
401 | - $propertyId = new PropertyId( $result->getContextCursor()->getSnakPropertyId() ); |
|
401 | + $propertyId = new PropertyId($result->getContextCursor()->getSnakPropertyId()); |
|
402 | 402 | $propertyColumn = $this->getClaimLink( |
403 | 403 | $entityId, |
404 | 404 | $propertyId, |
405 | - $this->entityIdLabelFormatter->formatEntityId( $propertyId ) |
|
405 | + $this->entityIdLabelFormatter->formatEntityId($propertyId) |
|
406 | 406 | ); |
407 | 407 | |
408 | 408 | // Message column |
409 | - $messageColumn = $this->violationMessageRenderer->render( $message ); |
|
409 | + $messageColumn = $this->violationMessageRenderer->render($message); |
|
410 | 410 | |
411 | 411 | // Constraint column |
412 | 412 | $constraintTypeItemId = $result->getConstraint()->getConstraintTypeItemId(); |
413 | 413 | try { |
414 | - $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $constraintTypeItemId ) ); |
|
415 | - } catch ( InvalidArgumentException $e ) { |
|
416 | - $constraintTypeLabel = htmlspecialchars( $constraintTypeItemId ); |
|
414 | + $constraintTypeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($constraintTypeItemId)); |
|
415 | + } catch (InvalidArgumentException $e) { |
|
416 | + $constraintTypeLabel = htmlspecialchars($constraintTypeItemId); |
|
417 | 417 | } |
418 | 418 | $constraintLink = $this->getClaimLink( |
419 | 419 | $propertyId, |
420 | - new PropertyId( $this->config->get( 'WBQualityConstraintsPropertyConstraintId' ) ), |
|
420 | + new PropertyId($this->config->get('WBQualityConstraintsPropertyConstraintId')), |
|
421 | 421 | $constraintTypeLabel |
422 | 422 | ); |
423 | 423 | $constraintColumn = $this->buildExpandableElement( |
424 | 424 | $constraintLink, |
425 | - $this->constraintParameterRenderer->formatParameters( $result->getParameters() ), |
|
425 | + $this->constraintParameterRenderer->formatParameters($result->getParameters()), |
|
426 | 426 | '[...]' |
427 | 427 | ); |
428 | 428 | |
@@ -462,15 +462,15 @@ discard block |
||
462 | 462 | * |
463 | 463 | * @return string HTML |
464 | 464 | */ |
465 | - protected function buildResultHeader( EntityId $entityId ) { |
|
466 | - $entityLink = sprintf( '%s (%s)', |
|
467 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
468 | - htmlspecialchars( $entityId->getSerialization() ) ); |
|
465 | + protected function buildResultHeader(EntityId $entityId) { |
|
466 | + $entityLink = sprintf('%s (%s)', |
|
467 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
468 | + htmlspecialchars($entityId->getSerialization())); |
|
469 | 469 | |
470 | 470 | return Html::rawElement( |
471 | 471 | 'h3', |
472 | 472 | [], |
473 | - sprintf( '%s %s', $this->msg( 'wbqc-constraintreport-result-headline' )->escaped(), $entityLink ) |
|
473 | + sprintf('%s %s', $this->msg('wbqc-constraintreport-result-headline')->escaped(), $entityLink) |
|
474 | 474 | ); |
475 | 475 | } |
476 | 476 | |
@@ -481,24 +481,24 @@ discard block |
||
481 | 481 | * |
482 | 482 | * @return string HTML |
483 | 483 | */ |
484 | - protected function buildSummary( array $results ) { |
|
484 | + protected function buildSummary(array $results) { |
|
485 | 485 | $statuses = []; |
486 | - foreach ( $results as $result ) { |
|
487 | - $status = strtolower( $result->getStatus() ); |
|
488 | - $statuses[$status] = isset( $statuses[$status] ) ? $statuses[$status] + 1 : 1; |
|
486 | + foreach ($results as $result) { |
|
487 | + $status = strtolower($result->getStatus()); |
|
488 | + $statuses[$status] = isset($statuses[$status]) ? $statuses[$status] + 1 : 1; |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | $statusElements = []; |
492 | - foreach ( $statuses as $status => $count ) { |
|
493 | - if ( $count > 0 ) { |
|
492 | + foreach ($statuses as $status => $count) { |
|
493 | + if ($count > 0) { |
|
494 | 494 | $statusElements[] = |
495 | - $this->formatStatus( $status ) |
|
495 | + $this->formatStatus($status) |
|
496 | 496 | . ': ' |
497 | 497 | . $count; |
498 | 498 | } |
499 | 499 | } |
500 | 500 | |
501 | - return Html::rawElement( 'p', [], implode( ', ', $statusElements ) ); |
|
501 | + return Html::rawElement('p', [], implode(', ', $statusElements)); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | /** |
@@ -513,15 +513,15 @@ discard block |
||
513 | 513 | * |
514 | 514 | * @return string HTML |
515 | 515 | */ |
516 | - protected function buildExpandableElement( $content, $expandableContent, $indicator ) { |
|
517 | - if ( !is_string( $content ) ) { |
|
518 | - throw new InvalidArgumentException( '$content has to be string.' ); |
|
516 | + protected function buildExpandableElement($content, $expandableContent, $indicator) { |
|
517 | + if (!is_string($content)) { |
|
518 | + throw new InvalidArgumentException('$content has to be string.'); |
|
519 | 519 | } |
520 | - if ( $expandableContent && ( !is_string( $expandableContent ) ) ) { |
|
521 | - throw new InvalidArgumentException( '$tooltipContent, if provided, has to be string.' ); |
|
520 | + if ($expandableContent && (!is_string($expandableContent))) { |
|
521 | + throw new InvalidArgumentException('$tooltipContent, if provided, has to be string.'); |
|
522 | 522 | } |
523 | 523 | |
524 | - if ( empty( $expandableContent ) ) { |
|
524 | + if (empty($expandableContent)) { |
|
525 | 525 | return $content; |
526 | 526 | } |
527 | 527 | |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | $expandableContent |
542 | 542 | ); |
543 | 543 | |
544 | - return sprintf( '%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent ); |
|
544 | + return sprintf('%s %s %s', $content, $tooltipIndicator, $wrappedExpandableContent); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -553,8 +553,8 @@ discard block |
||
553 | 553 | * |
554 | 554 | * @return string HTML |
555 | 555 | */ |
556 | - private function formatStatus( $status ) { |
|
557 | - $messageName = "wbqc-constraintreport-status-" . strtolower( $status ); |
|
556 | + private function formatStatus($status) { |
|
557 | + $messageName = "wbqc-constraintreport-status-".strtolower($status); |
|
558 | 558 | $statusIcons = [ |
559 | 559 | CheckResult::STATUS_SUGGESTION => [ |
560 | 560 | 'icon' => 'suggestion-constraint-violation', |
@@ -571,25 +571,25 @@ discard block |
||
571 | 571 | ], |
572 | 572 | ]; |
573 | 573 | |
574 | - if ( array_key_exists( $status, $statusIcons ) ) { |
|
575 | - $iconWidget = new IconWidget( $statusIcons[$status] ); |
|
576 | - $iconHtml = $iconWidget->toString() . ' '; |
|
574 | + if (array_key_exists($status, $statusIcons)) { |
|
575 | + $iconWidget = new IconWidget($statusIcons[$status]); |
|
576 | + $iconHtml = $iconWidget->toString().' '; |
|
577 | 577 | } else { |
578 | 578 | $iconHtml = ''; |
579 | 579 | } |
580 | 580 | |
581 | - $labelWidget = new LabelWidget( [ |
|
582 | - 'label' => $this->msg( $messageName )->text(), |
|
583 | - ] ); |
|
581 | + $labelWidget = new LabelWidget([ |
|
582 | + 'label' => $this->msg($messageName)->text(), |
|
583 | + ]); |
|
584 | 584 | $labelHtml = $labelWidget->toString(); |
585 | 585 | |
586 | 586 | $formattedStatus = |
587 | 587 | Html::rawElement( |
588 | 588 | 'span', |
589 | 589 | [ |
590 | - 'class' => 'wbqc-status wbqc-status-' . $status |
|
590 | + 'class' => 'wbqc-status wbqc-status-'.$status |
|
591 | 591 | ], |
592 | - $iconHtml . $labelHtml |
|
592 | + $iconHtml.$labelHtml |
|
593 | 593 | ); |
594 | 594 | |
595 | 595 | return $formattedStatus; |
@@ -605,26 +605,26 @@ discard block |
||
605 | 605 | * |
606 | 606 | * @return string HTML |
607 | 607 | */ |
608 | - protected function formatDataValues( $dataValues, $separator = ', ' ) { |
|
609 | - if ( $dataValues instanceof DataValue ) { |
|
610 | - $dataValues = [ $dataValues ]; |
|
611 | - } elseif ( !is_array( $dataValues ) ) { |
|
612 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
608 | + protected function formatDataValues($dataValues, $separator = ', ') { |
|
609 | + if ($dataValues instanceof DataValue) { |
|
610 | + $dataValues = [$dataValues]; |
|
611 | + } elseif (!is_array($dataValues)) { |
|
612 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
613 | 613 | } |
614 | 614 | |
615 | 615 | $formattedDataValues = []; |
616 | - foreach ( $dataValues as $dataValue ) { |
|
617 | - if ( !( $dataValue instanceof DataValue ) ) { |
|
618 | - throw new InvalidArgumentException( '$dataValues has to be instance of DataValue or an array of DataValues.' ); |
|
616 | + foreach ($dataValues as $dataValue) { |
|
617 | + if (!($dataValue instanceof DataValue)) { |
|
618 | + throw new InvalidArgumentException('$dataValues has to be instance of DataValue or an array of DataValues.'); |
|
619 | 619 | } |
620 | - if ( $dataValue instanceof EntityIdValue ) { |
|
621 | - $formattedDataValues[ ] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() ); |
|
620 | + if ($dataValue instanceof EntityIdValue) { |
|
621 | + $formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId()); |
|
622 | 622 | } else { |
623 | - $formattedDataValues[ ] = $this->dataValueFormatter->format( $dataValue ); |
|
623 | + $formattedDataValues[] = $this->dataValueFormatter->format($dataValue); |
|
624 | 624 | } |
625 | 625 | } |
626 | 626 | |
627 | - return implode( $separator, $formattedDataValues ); |
|
627 | + return implode($separator, $formattedDataValues); |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
@@ -636,11 +636,11 @@ discard block |
||
636 | 636 | * |
637 | 637 | * @return string HTML |
638 | 638 | */ |
639 | - private function getClaimLink( EntityId $entityId, PropertyId $propertyId, $text ) { |
|
639 | + private function getClaimLink(EntityId $entityId, PropertyId $propertyId, $text) { |
|
640 | 640 | return Html::rawElement( |
641 | 641 | 'a', |
642 | 642 | [ |
643 | - 'href' => $this->getClaimUrl( $entityId, $propertyId ), |
|
643 | + 'href' => $this->getClaimUrl($entityId, $propertyId), |
|
644 | 644 | 'target' => '_blank' |
645 | 645 | ], |
646 | 646 | $text |
@@ -655,9 +655,9 @@ discard block |
||
655 | 655 | * |
656 | 656 | * @return string |
657 | 657 | */ |
658 | - private function getClaimUrl( EntityId $entityId, PropertyId $propertyId ) { |
|
659 | - $title = $this->entityTitleLookup->getTitleForId( $entityId ); |
|
660 | - $entityUrl = sprintf( '%s#%s', $title->getLocalURL(), $propertyId->getSerialization() ); |
|
658 | + private function getClaimUrl(EntityId $entityId, PropertyId $propertyId) { |
|
659 | + $title = $this->entityTitleLookup->getTitleForId($entityId); |
|
660 | + $entityUrl = sprintf('%s#%s', $title->getLocalURL(), $propertyId->getSerialization()); |
|
661 | 661 | |
662 | 662 | return $entityUrl; |
663 | 663 | } |