@@ -28,25 +28,25 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @param DatabaseUpdater $updater |
30 | 30 | */ |
31 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
31 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
32 | 32 | $updater->addExtensionTable( |
33 | 33 | 'wbqc_constraints', |
34 | - __DIR__ . '/../sql/create_wbqc_constraints.sql' |
|
34 | + __DIR__.'/../sql/create_wbqc_constraints.sql' |
|
35 | 35 | ); |
36 | 36 | $updater->addExtensionField( |
37 | 37 | 'wbqc_constraints', |
38 | 38 | 'constraint_id', |
39 | - __DIR__ . '/../sql/patch-wbqc_constraints-constraint_id.sql' |
|
39 | + __DIR__.'/../sql/patch-wbqc_constraints-constraint_id.sql' |
|
40 | 40 | ); |
41 | 41 | $updater->addExtensionIndex( |
42 | 42 | 'wbqc_constraints', |
43 | 43 | 'wbqc_constraints_guid_uniq', |
44 | - __DIR__ . '/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
44 | + __DIR__.'/../sql/patch-wbqc_constraints-wbqc_constraints_guid_uniq.sql' |
|
45 | 45 | ); |
46 | 46 | } |
47 | 47 | |
48 | - public static function onWikibaseChange( Change $change ) { |
|
49 | - if ( !( $change instanceof EntityChange ) ) { |
|
48 | + public static function onWikibaseChange(Change $change) { |
|
49 | + if (!($change instanceof EntityChange)) { |
|
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
@@ -55,48 +55,48 @@ discard block |
||
55 | 55 | |
56 | 56 | // If jobs are enabled and the results would be stored in some way run a job. |
57 | 57 | if ( |
58 | - $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobs' ) && |
|
59 | - $config->get( 'WBQualityConstraintsCacheCheckConstraintsResults' ) && |
|
58 | + $config->get('WBQualityConstraintsEnableConstraintsCheckJobs') && |
|
59 | + $config->get('WBQualityConstraintsCacheCheckConstraintsResults') && |
|
60 | 60 | self::isSelectedForJobRunBasedOnPercentage() |
61 | 61 | ) { |
62 | - $params = [ 'entityId' => $change->getEntityId()->getSerialization() ]; |
|
62 | + $params = ['entityId' => $change->getEntityId()->getSerialization()]; |
|
63 | 63 | JobQueueGroup::singleton()->push( |
64 | - new JobSpecification( CheckConstraintsJob::COMMAND, $params ) |
|
64 | + new JobSpecification(CheckConstraintsJob::COMMAND, $params) |
|
65 | 65 | ); |
66 | 66 | } |
67 | 67 | |
68 | - if ( $config->get( 'WBQualityConstraintsEnableConstraintsImportFromStatements' ) && |
|
69 | - self::isConstraintStatementsChange( $config, $change ) |
|
68 | + if ($config->get('WBQualityConstraintsEnableConstraintsImportFromStatements') && |
|
69 | + self::isConstraintStatementsChange($config, $change) |
|
70 | 70 | ) { |
71 | - $params = [ 'propertyId' => $change->getEntityId()->getSerialization() ]; |
|
71 | + $params = ['propertyId' => $change->getEntityId()->getSerialization()]; |
|
72 | 72 | $metadata = $change->getMetadata(); |
73 | - if ( array_key_exists( 'rev_id', $metadata ) ) { |
|
73 | + if (array_key_exists('rev_id', $metadata)) { |
|
74 | 74 | $params['revisionId'] = $metadata['rev_id']; |
75 | 75 | } |
76 | 76 | JobQueueGroup::singleton()->push( |
77 | - new JobSpecification( 'constraintsTableUpdate', $params ) |
|
77 | + new JobSpecification('constraintsTableUpdate', $params) |
|
78 | 78 | ); |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | 82 | private static function isSelectedForJobRunBasedOnPercentage() { |
83 | 83 | $config = MediaWikiServices::getInstance()->getMainConfig(); |
84 | - $percentage = $config->get( 'WBQualityConstraintsEnableConstraintsCheckJobsRatio' ); |
|
84 | + $percentage = $config->get('WBQualityConstraintsEnableConstraintsCheckJobsRatio'); |
|
85 | 85 | |
86 | - return mt_rand( 1, 100 ) <= $percentage; |
|
86 | + return mt_rand(1, 100) <= $percentage; |
|
87 | 87 | } |
88 | 88 | |
89 | - public static function isConstraintStatementsChange( Config $config, Change $change ) { |
|
90 | - if ( !( $change instanceof EntityChange ) || |
|
89 | + public static function isConstraintStatementsChange(Config $config, Change $change) { |
|
90 | + if (!($change instanceof EntityChange) || |
|
91 | 91 | $change->getAction() !== EntityChange::UPDATE || |
92 | - !( $change->getEntityId() instanceof PropertyId ) |
|
92 | + !($change->getEntityId() instanceof PropertyId) |
|
93 | 93 | ) { |
94 | 94 | return false; |
95 | 95 | } |
96 | 96 | |
97 | 97 | $info = $change->getInfo(); |
98 | 98 | |
99 | - if ( !array_key_exists( 'compactDiff', $info ) ) { |
|
99 | + if (!array_key_exists('compactDiff', $info)) { |
|
100 | 100 | // the non-compact diff ($info['diff']) does not contain statement diffs (T110996), |
101 | 101 | // so we only know that the change *might* affect the constraint statements |
102 | 102 | return true; |
@@ -105,46 +105,46 @@ discard block |
||
105 | 105 | /** @var EntityDiffChangedAspects $aspects */ |
106 | 106 | $aspects = $info['compactDiff']; |
107 | 107 | |
108 | - $propertyConstraintId = $config->get( 'WBQualityConstraintsPropertyConstraintId' ); |
|
109 | - return in_array( $propertyConstraintId, $aspects->getStatementChanges() ); |
|
108 | + $propertyConstraintId = $config->get('WBQualityConstraintsPropertyConstraintId'); |
|
109 | + return in_array($propertyConstraintId, $aspects->getStatementChanges()); |
|
110 | 110 | } |
111 | 111 | |
112 | - public static function onArticlePurge( WikiPage $wikiPage ) { |
|
112 | + public static function onArticlePurge(WikiPage $wikiPage) { |
|
113 | 113 | $repo = WikibaseRepo::getDefaultInstance(); |
114 | 114 | |
115 | 115 | $entityContentFactory = $repo->getEntityContentFactory(); |
116 | - if ( $entityContentFactory->isEntityContentModel( $wikiPage->getContentModel() ) ) { |
|
117 | - $entityId = $entityContentFactory->getEntityIdForTitle( $wikiPage->getTitle() ); |
|
118 | - if ( $entityId !== null ) { |
|
116 | + if ($entityContentFactory->isEntityContentModel($wikiPage->getContentModel())) { |
|
117 | + $entityId = $entityContentFactory->getEntityIdForTitle($wikiPage->getTitle()); |
|
118 | + if ($entityId !== null) { |
|
119 | 119 | $resultsCache = ResultsCache::getDefaultInstance(); |
120 | - $resultsCache->delete( $entityId ); |
|
120 | + $resultsCache->delete($entityId); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | - public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { |
|
125 | + public static function onBeforePageDisplay(OutputPage $out, Skin $skin) { |
|
126 | 126 | $repo = WikibaseRepo::getDefaultInstance(); |
127 | 127 | |
128 | 128 | $lookup = $repo->getEntityNamespaceLookup(); |
129 | 129 | $title = $out->getTitle(); |
130 | - if ( $title === null ) { |
|
130 | + if ($title === null) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | - if ( !$lookup->isNamespaceWithEntities( $title->getNamespace() ) ) { |
|
134 | + if (!$lookup->isNamespaceWithEntities($title->getNamespace())) { |
|
135 | 135 | return; |
136 | 136 | } |
137 | - if ( empty( $out->getJsConfigVars()['wbIsEditView'] ) ) { |
|
137 | + if (empty($out->getJsConfigVars()['wbIsEditView'])) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | 140 | |
141 | - $out->addModules( 'wikibase.quality.constraints.suggestions' ); |
|
141 | + $out->addModules('wikibase.quality.constraints.suggestions'); |
|
142 | 142 | |
143 | - if ( !$out->getUser()->isLoggedIn() ) { |
|
143 | + if (!$out->getUser()->isLoggedIn()) { |
|
144 | 144 | return; |
145 | 145 | } |
146 | 146 | |
147 | - $out->addModules( 'wikibase.quality.constraints.gadget' ); |
|
147 | + $out->addModules('wikibase.quality.constraints.gadget'); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | EntityIdLookup $entityIdLookup, |
48 | 48 | RdfVocabulary $rdfVocabulary |
49 | 49 | ) { |
50 | - parent::__construct( $page, $context ); |
|
50 | + parent::__construct($page, $context); |
|
51 | 51 | $this->resultsSource = $resultsSource; |
52 | 52 | $this->entityIdLookup = $entityIdLookup; |
53 | 53 | $this->rdfVocabulary = $rdfVocabulary; |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * @param string $guid |
109 | 109 | * @return string |
110 | 110 | */ |
111 | - private function cleanupGuid( $guid ) { |
|
112 | - return preg_replace( '/[^\w-]/', '-', $guid ); |
|
111 | + private function cleanupGuid($guid) { |
|
112 | + return preg_replace('/[^\w-]/', '-', $guid); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -121,60 +121,60 @@ discard block |
||
121 | 121 | $response = $this->getRequest()->response(); |
122 | 122 | $this->getOutput()->disable(); |
123 | 123 | |
124 | - if ( !$this->resultsSource instanceof CachingResultsSource ) { |
|
124 | + if (!$this->resultsSource instanceof CachingResultsSource) { |
|
125 | 125 | // TODO: make configurable whether only cached results are returned |
126 | - $response->statusHeader( 501 ); // Not Implemented |
|
126 | + $response->statusHeader(501); // Not Implemented |
|
127 | 127 | return null; |
128 | 128 | } |
129 | 129 | |
130 | - $entityId = $this->entityIdLookup->getEntityIdForTitle( $this->getTitle() ); |
|
131 | - if ( $entityId === null ) { |
|
132 | - $response->statusHeader( 404 ); // Not Found |
|
130 | + $entityId = $this->entityIdLookup->getEntityIdForTitle($this->getTitle()); |
|
131 | + if ($entityId === null) { |
|
132 | + $response->statusHeader(404); // Not Found |
|
133 | 133 | return null; |
134 | 134 | } |
135 | - $revId = $this->getRequest()->getInt( 'revision' ); |
|
135 | + $revId = $this->getRequest()->getInt('revision'); |
|
136 | 136 | |
137 | - $results = $this->resultsSource->getStoredResults( $entityId, $revId ); |
|
138 | - if ( $results === null ) { |
|
139 | - $response->statusHeader( 204 ); // No Content |
|
137 | + $results = $this->resultsSource->getStoredResults($entityId, $revId); |
|
138 | + if ($results === null) { |
|
139 | + $response->statusHeader(204); // No Content |
|
140 | 140 | return null; |
141 | 141 | } |
142 | 142 | |
143 | 143 | $format = 'ttl'; // TODO: make format an option |
144 | 144 | |
145 | 145 | $writerFactory = new RdfWriterFactory(); |
146 | - $formatName = $writerFactory->getFormatName( $format ); |
|
147 | - $contentType = $writerFactory->getMimeTypes( $formatName )[0]; |
|
146 | + $formatName = $writerFactory->getFormatName($format); |
|
147 | + $contentType = $writerFactory->getMimeTypes($formatName)[0]; |
|
148 | 148 | |
149 | - $writer = $writerFactory->getWriter( $formatName ); |
|
150 | - foreach ( [ RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY ] as $ns ) { |
|
151 | - $writer->prefix( $ns, $this->rdfVocabulary->getNamespaceURI( $ns ) ); |
|
149 | + $writer = $writerFactory->getWriter($formatName); |
|
150 | + foreach ([RdfVocabulary::NS_STATEMENT, RdfVocabulary::NS_ONTOLOGY] as $ns) { |
|
151 | + $writer->prefix($ns, $this->rdfVocabulary->getNamespaceURI($ns)); |
|
152 | 152 | } |
153 | 153 | $writer->start(); |
154 | 154 | $writtenAny = false; |
155 | 155 | |
156 | - foreach ( $results->getArray() as $checkResult ) { |
|
157 | - if ( $checkResult instanceof NullResult ) { |
|
156 | + foreach ($results->getArray() as $checkResult) { |
|
157 | + if ($checkResult instanceof NullResult) { |
|
158 | 158 | continue; |
159 | 159 | } |
160 | - if ( $checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS ) { |
|
160 | + if ($checkResult->getStatus() === CheckResult::STATUS_BAD_PARAMETERS) { |
|
161 | 161 | continue; |
162 | 162 | } |
163 | 163 | $writtenAny = true; |
164 | - $writer->about( RdfVocabulary::NS_STATEMENT, |
|
165 | - $this->cleanupGuid( $checkResult->getContextCursor()->getStatementGuid() ) ) |
|
166 | - ->say( RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint' ) |
|
167 | - ->is( RdfVocabulary::NS_STATEMENT, |
|
168 | - $this->cleanupGuid( $checkResult->getConstraint()->getConstraintId() ) ); |
|
164 | + $writer->about(RdfVocabulary::NS_STATEMENT, |
|
165 | + $this->cleanupGuid($checkResult->getContextCursor()->getStatementGuid())) |
|
166 | + ->say(RdfVocabulary::NS_ONTOLOGY, 'hasViolationForConstraint') |
|
167 | + ->is(RdfVocabulary::NS_STATEMENT, |
|
168 | + $this->cleanupGuid($checkResult->getConstraint()->getConstraintId())); |
|
169 | 169 | } |
170 | 170 | $writer->finish(); |
171 | - if ( $writtenAny ) { |
|
172 | - $response->header( "Content-Type: $contentType; charset=UTF-8" ); |
|
171 | + if ($writtenAny) { |
|
172 | + $response->header("Content-Type: $contentType; charset=UTF-8"); |
|
173 | 173 | echo $writer->drain(); |
174 | 174 | } else { |
175 | 175 | // Do not output RDF if we haven't written any actual statements. Output 204 instead |
176 | 176 | $writer->drain(); |
177 | - $response->statusHeader( 204 ); // No Content |
|
177 | + $response->statusHeader(204); // No Content |
|
178 | 178 | } |
179 | 179 | return null; |
180 | 180 | } |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | use Wikibase\Repo\WikibaseRepo; |
17 | 17 | |
18 | 18 | // @codeCoverageIgnoreStart |
19 | -$basePath = getenv( "MW_INSTALL_PATH" ) !== false |
|
20 | - ? getenv( "MW_INSTALL_PATH" ) : __DIR__ . "/../../.."; |
|
19 | +$basePath = getenv("MW_INSTALL_PATH") !== false |
|
20 | + ? getenv("MW_INSTALL_PATH") : __DIR__."/../../.."; |
|
21 | 21 | |
22 | -require_once $basePath . "/maintenance/Maintenance.php"; |
|
22 | +require_once $basePath."/maintenance/Maintenance.php"; |
|
23 | 23 | // @codeCoverageIgnoreEnd |
24 | 24 | |
25 | 25 | /** |
@@ -53,20 +53,20 @@ discard block |
||
53 | 53 | parent::__construct(); |
54 | 54 | |
55 | 55 | $this->addDescription( |
56 | - 'Import entities needed for constraint checks ' . |
|
56 | + 'Import entities needed for constraint checks '. |
|
57 | 57 | 'from Wikidata into the local repository.' |
58 | 58 | ); |
59 | 59 | $this->addOption( |
60 | 60 | 'config-format', |
61 | - 'The format in which the resulting configuration will be omitted: ' . |
|
62 | - '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), ' . |
|
61 | + 'The format in which the resulting configuration will be omitted: '. |
|
62 | + '"globals" for directly settings global variables, suitable for inclusion in LocalSettings.php (default), '. |
|
63 | 63 | 'or "wgConf" for printing parts of arrays suitable for inclusion in $wgConf->settings.' |
64 | 64 | ); |
65 | 65 | $this->addOption( |
66 | 66 | 'dry-run', |
67 | 67 | 'Don’t actually import entities, just print which ones would be imported.' |
68 | 68 | ); |
69 | - $this->requireExtension( 'WikibaseQualityConstraints' ); |
|
69 | + $this->requireExtension('WikibaseQualityConstraints'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -77,8 +77,8 @@ discard block |
||
77 | 77 | $this->entitySerializer = $repo->getAllTypesEntitySerializer(); |
78 | 78 | $this->entityDeserializer = $repo->getInternalFormatEntityDeserializer(); |
79 | 79 | $this->entityStore = $repo->getEntityStore(); |
80 | - if ( !$this->getOption( 'dry-run', false ) ) { |
|
81 | - $this->user = User::newSystemUser( 'WikibaseQualityConstraints importer' ); |
|
80 | + if (!$this->getOption('dry-run', false)) { |
|
81 | + $this->user = User::newSystemUser('WikibaseQualityConstraints importer'); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
@@ -87,21 +87,21 @@ discard block |
||
87 | 87 | |
88 | 88 | $configUpdates = []; |
89 | 89 | |
90 | - $extensionJsonFile = __DIR__ . '/../extension.json'; |
|
91 | - $extensionJsonText = file_get_contents( $extensionJsonFile ); |
|
92 | - $extensionJson = json_decode( $extensionJsonText, /* assoc = */ true ); |
|
90 | + $extensionJsonFile = __DIR__.'/../extension.json'; |
|
91 | + $extensionJsonText = file_get_contents($extensionJsonFile); |
|
92 | + $extensionJson = json_decode($extensionJsonText, /* assoc = */ true); |
|
93 | 93 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
94 | - $wikidataEntityIds = $this->getEntitiesToImport( $extensionJson['config'], $this->getConfig() ); |
|
94 | + $wikidataEntityIds = $this->getEntitiesToImport($extensionJson['config'], $this->getConfig()); |
|
95 | 95 | |
96 | - foreach ( $wikidataEntityIds as $key => $wikidataEntityId ) { |
|
97 | - $localEntityId = $this->importEntityFromWikidata( $wikidataEntityId ); |
|
96 | + foreach ($wikidataEntityIds as $key => $wikidataEntityId) { |
|
97 | + $localEntityId = $this->importEntityFromWikidata($wikidataEntityId); |
|
98 | 98 | $configUpdates[$key] = [ |
99 | 99 | 'wikidata' => $wikidataEntityId, |
100 | 100 | 'local' => $localEntityId, |
101 | 101 | ]; |
102 | 102 | } |
103 | 103 | |
104 | - $this->outputConfigUpdates( $configUpdates ); |
|
104 | + $this->outputConfigUpdates($configUpdates); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
@@ -109,18 +109,18 @@ discard block |
||
109 | 109 | * @param Config $wikiConfig |
110 | 110 | * @return string[] |
111 | 111 | */ |
112 | - private function getEntitiesToImport( array $extensionJsonConfig, Config $wikiConfig ) { |
|
112 | + private function getEntitiesToImport(array $extensionJsonConfig, Config $wikiConfig) { |
|
113 | 113 | $wikidataEntityIds = []; |
114 | 114 | |
115 | - foreach ( $extensionJsonConfig as $key => $value ) { |
|
116 | - if ( !preg_match( '/Id$/', $key ) ) { |
|
115 | + foreach ($extensionJsonConfig as $key => $value) { |
|
116 | + if (!preg_match('/Id$/', $key)) { |
|
117 | 117 | continue; |
118 | 118 | } |
119 | 119 | |
120 | 120 | $wikidataEntityId = $value['value']; |
121 | - $localEntityId = $wikiConfig->get( $key ); |
|
121 | + $localEntityId = $wikiConfig->get($key); |
|
122 | 122 | |
123 | - if ( $localEntityId === $wikidataEntityId ) { |
|
123 | + if ($localEntityId === $wikidataEntityId) { |
|
124 | 124 | $wikidataEntityIds[$key] = $wikidataEntityId; |
125 | 125 | } |
126 | 126 | } |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | * @param string $wikidataEntityId |
133 | 133 | * @return string local entity ID |
134 | 134 | */ |
135 | - private function importEntityFromWikidata( $wikidataEntityId ) { |
|
135 | + private function importEntityFromWikidata($wikidataEntityId) { |
|
136 | 136 | $wikidataEntityUrl = "https://www.wikidata.org/wiki/Special:EntityData/$wikidataEntityId.json"; |
137 | - $wikidataEntitiesJson = MediaWikiServices::getInstance()->getHttpRequestFactory()->get( $wikidataEntityUrl ); |
|
138 | - return $this->importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ); |
|
137 | + $wikidataEntitiesJson = MediaWikiServices::getInstance()->getHttpRequestFactory()->get($wikidataEntityUrl); |
|
138 | + return $this->importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -143,24 +143,24 @@ discard block |
||
143 | 143 | * @param string $wikidataEntitiesJson |
144 | 144 | * @return string local entity ID |
145 | 145 | */ |
146 | - private function importEntityFromJson( $wikidataEntityId, $wikidataEntitiesJson ) { |
|
146 | + private function importEntityFromJson($wikidataEntityId, $wikidataEntitiesJson) { |
|
147 | 147 | // @phan-suppress-next-line PhanTypeArraySuspiciousNullable |
148 | - $wikidataEntityArray = json_decode( $wikidataEntitiesJson, true )['entities'][$wikidataEntityId]; |
|
149 | - $wikidataEntity = $this->entityDeserializer->deserialize( $wikidataEntityArray ); |
|
148 | + $wikidataEntityArray = json_decode($wikidataEntitiesJson, true)['entities'][$wikidataEntityId]; |
|
149 | + $wikidataEntity = $this->entityDeserializer->deserialize($wikidataEntityArray); |
|
150 | 150 | |
151 | - $wikidataEntity->setId( null ); |
|
151 | + $wikidataEntity->setId(null); |
|
152 | 152 | |
153 | - if ( $wikidataEntity instanceof StatementListProvider ) { |
|
153 | + if ($wikidataEntity instanceof StatementListProvider) { |
|
154 | 154 | $wikidataEntity->getStatements()->clear(); |
155 | 155 | } |
156 | 156 | |
157 | - if ( $wikidataEntity instanceof Item ) { |
|
158 | - $wikidataEntity->setSiteLinkList( new SiteLinkList() ); |
|
157 | + if ($wikidataEntity instanceof Item) { |
|
158 | + $wikidataEntity->setSiteLinkList(new SiteLinkList()); |
|
159 | 159 | } |
160 | 160 | |
161 | - if ( $this->getOption( 'dry-run', false ) ) { |
|
162 | - $wikidataEntityJson = json_encode( $this->entitySerializer->serialize( $wikidataEntity ) ); |
|
163 | - $this->output( $wikidataEntityJson . "\n" ); |
|
161 | + if ($this->getOption('dry-run', false)) { |
|
162 | + $wikidataEntityJson = json_encode($this->entitySerializer->serialize($wikidataEntity)); |
|
163 | + $this->output($wikidataEntityJson."\n"); |
|
164 | 164 | return "-$wikidataEntityId"; |
165 | 165 | } |
166 | 166 | |
@@ -173,12 +173,12 @@ discard block |
||
173 | 173 | )->getEntity(); |
174 | 174 | |
175 | 175 | return $localEntity->getId()->getSerialization(); |
176 | - } catch ( StorageException $storageException ) { |
|
177 | - return $this->storageExceptionToEntityId( $storageException ); |
|
176 | + } catch (StorageException $storageException) { |
|
177 | + return $this->storageExceptionToEntityId($storageException); |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | - private function storageExceptionToEntityId( StorageException $storageException ) { |
|
181 | + private function storageExceptionToEntityId(StorageException $storageException) { |
|
182 | 182 | $message = $storageException->getMessage(); |
183 | 183 | // example messages: |
184 | 184 | // * Item [[Item:Q475|Q475]] already has label "as references" |
@@ -188,25 +188,25 @@ discard block |
||
188 | 188 | // * Property [[Property:P694|P694]] already has label "instance of" |
189 | 189 | // associated with language code en. |
190 | 190 | $pattern = '/[[|]([^][|]*)]] already has label .* associated with language code/'; |
191 | - if ( preg_match( $pattern, $message, $matches ) ) { |
|
191 | + if (preg_match($pattern, $message, $matches)) { |
|
192 | 192 | return $matches[1]; |
193 | 193 | } else { |
194 | 194 | throw $storageException; |
195 | 195 | } |
196 | 196 | } |
197 | 197 | |
198 | - private function outputConfigUpdates( array $configUpdates ) { |
|
199 | - $configFormat = $this->getOption( 'config-format', 'globals' ); |
|
200 | - switch ( $configFormat ) { |
|
198 | + private function outputConfigUpdates(array $configUpdates) { |
|
199 | + $configFormat = $this->getOption('config-format', 'globals'); |
|
200 | + switch ($configFormat) { |
|
201 | 201 | case 'globals': |
202 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
202 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
203 | 203 | break; |
204 | 204 | case 'wgConf': |
205 | - $this->outputConfigUpdatesWgConf( $configUpdates ); |
|
205 | + $this->outputConfigUpdatesWgConf($configUpdates); |
|
206 | 206 | break; |
207 | 207 | default: |
208 | - $this->error( "Invalid config format \"$configFormat\", using \"globals\"" ); |
|
209 | - $this->outputConfigUpdatesGlobals( $configUpdates ); |
|
208 | + $this->error("Invalid config format \"$configFormat\", using \"globals\""); |
|
209 | + $this->outputConfigUpdatesGlobals($configUpdates); |
|
210 | 210 | break; |
211 | 211 | } |
212 | 212 | } |
@@ -214,22 +214,22 @@ discard block |
||
214 | 214 | /** |
215 | 215 | * @param array[] $configUpdates |
216 | 216 | */ |
217 | - private function outputConfigUpdatesGlobals( array $configUpdates ) { |
|
218 | - foreach ( $configUpdates as $key => $value ) { |
|
219 | - $localValueCode = var_export( $value['local'], true ); |
|
220 | - $this->output( "\$wg$key = $localValueCode;\n" ); |
|
217 | + private function outputConfigUpdatesGlobals(array $configUpdates) { |
|
218 | + foreach ($configUpdates as $key => $value) { |
|
219 | + $localValueCode = var_export($value['local'], true); |
|
220 | + $this->output("\$wg$key = $localValueCode;\n"); |
|
221 | 221 | } |
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
225 | 225 | * @param array[] $configUpdates |
226 | 226 | */ |
227 | - private function outputConfigUpdatesWgConf( array $configUpdates ) { |
|
228 | - foreach ( $configUpdates as $key => $value ) { |
|
229 | - $keyCode = var_export( "wg$key", true ); |
|
230 | - $wikidataValueCode = var_export( $value['wikidata'], true ); |
|
231 | - $localValueCode = var_export( $value['local'], true ); |
|
232 | - $wikiIdCode = var_export( wfWikiID(), true ); |
|
227 | + private function outputConfigUpdatesWgConf(array $configUpdates) { |
|
228 | + foreach ($configUpdates as $key => $value) { |
|
229 | + $keyCode = var_export("wg$key", true); |
|
230 | + $wikidataValueCode = var_export($value['wikidata'], true); |
|
231 | + $localValueCode = var_export($value['local'], true); |
|
232 | + $wikiIdCode = var_export(wfWikiID(), true); |
|
233 | 233 | $block = <<< EOF |
234 | 234 | $keyCode => [ |
235 | 235 | 'default' => $wikidataValueCode, |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | |
239 | 239 | |
240 | 240 | EOF; |
241 | - $this->output( $block ); |
|
241 | + $this->output($block); |
|
242 | 242 | } |
243 | 243 | } |
244 | 244 |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | * @param CachedCheckResults $checkResults |
52 | 52 | * @return CachedCheckConstraintsResponse |
53 | 53 | */ |
54 | - public function render( CachedCheckResults $checkResults ) { |
|
54 | + public function render(CachedCheckResults $checkResults) { |
|
55 | 55 | $response = []; |
56 | - foreach ( $checkResults->getArray() as $checkResult ) { |
|
57 | - $resultArray = $this->checkResultToArray( $checkResult ); |
|
58 | - $checkResult->getContextCursor()->storeCheckResultInArray( $resultArray, $response ); |
|
56 | + foreach ($checkResults->getArray() as $checkResult) { |
|
57 | + $resultArray = $this->checkResultToArray($checkResult); |
|
58 | + $checkResult->getContextCursor()->storeCheckResultInArray($resultArray, $response); |
|
59 | 59 | } |
60 | 60 | return new CachedCheckConstraintsResponse( |
61 | 61 | $response, |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | ); |
64 | 64 | } |
65 | 65 | |
66 | - public function checkResultToArray( CheckResult $checkResult ) { |
|
67 | - if ( $checkResult instanceof NullResult ) { |
|
66 | + public function checkResultToArray(CheckResult $checkResult) { |
|
67 | + if ($checkResult instanceof NullResult) { |
|
68 | 68 | return null; |
69 | 69 | } |
70 | 70 | |
71 | 71 | $constraintId = $checkResult->getConstraint()->getConstraintId(); |
72 | 72 | $typeItemId = $checkResult->getConstraint()->getConstraintTypeItemId(); |
73 | - $constraintPropertyId = new PropertyId( $checkResult->getContextCursor()->getSnakPropertyId() ); |
|
73 | + $constraintPropertyId = new PropertyId($checkResult->getContextCursor()->getSnakPropertyId()); |
|
74 | 74 | |
75 | - $title = $this->entityTitleLookup->getTitleForId( $constraintPropertyId ); |
|
75 | + $title = $this->entityTitleLookup->getTitleForId($constraintPropertyId); |
|
76 | 76 | $talkTitle = $title->getTalkPageIfDefined(); |
77 | - $typeLabel = $this->entityIdLabelFormatter->formatEntityId( new ItemId( $typeItemId ) ); |
|
78 | - $link = $title->getFullURL() . '#' . $constraintId; |
|
77 | + $typeLabel = $this->entityIdLabelFormatter->formatEntityId(new ItemId($typeItemId)); |
|
78 | + $link = $title->getFullURL().'#'.$constraintId; |
|
79 | 79 | |
80 | 80 | $constraint = [ |
81 | 81 | 'id' => $constraintId, |
@@ -91,14 +91,14 @@ discard block |
||
91 | 91 | 'constraint' => $constraint |
92 | 92 | ]; |
93 | 93 | $message = $checkResult->getMessage(); |
94 | - if ( $message ) { |
|
95 | - $result['message-html'] = $this->violationMessageRenderer->render( $message ); |
|
94 | + if ($message) { |
|
95 | + $result['message-html'] = $this->violationMessageRenderer->render($message); |
|
96 | 96 | } |
97 | - if ( $checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT ) { |
|
97 | + if ($checkResult->getContextCursor()->getType() === Context::TYPE_STATEMENT) { |
|
98 | 98 | $result['claim'] = $checkResult->getContextCursor()->getStatementGuid(); |
99 | 99 | } |
100 | 100 | $cachingMetadataArray = $checkResult->getMetadata()->getCachingMetadata()->toArray(); |
101 | - if ( $cachingMetadataArray !== null ) { |
|
101 | + if ($cachingMetadataArray !== null) { |
|
102 | 102 | $result['cached'] = $cachingMetadataArray; |
103 | 103 | } |
104 | 104 |