@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | private $crossCheckResultSerializer; |
20 | 20 | |
21 | - public function __construct( Serializer $crossCheckResultSerializer ) { |
|
21 | + public function __construct(Serializer $crossCheckResultSerializer) { |
|
22 | 22 | $this->crossCheckResultSerializer = $crossCheckResultSerializer; |
23 | 23 | } |
24 | 24 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return bool |
31 | 31 | */ |
32 | - public function isSerializerFor( $object ) { |
|
32 | + public function isSerializerFor($object) { |
|
33 | 33 | return $object instanceof CrossCheckResultList; |
34 | 34 | } |
35 | 35 | |
@@ -41,29 +41,29 @@ discard block |
||
41 | 41 | * @return array |
42 | 42 | * @throws UnsupportedObjectException |
43 | 43 | */ |
44 | - public function serialize( $object ) { |
|
45 | - if ( !$this->isSerializerFor( $object ) ) { |
|
44 | + public function serialize($object) { |
|
45 | + if (!$this->isSerializerFor($object)) { |
|
46 | 46 | throw new UnsupportedObjectException( |
47 | 47 | $object, |
48 | 48 | 'CrossCheckResultListSerializer can only serialize CrossCheckResultList objects.' |
49 | 49 | ); |
50 | 50 | } |
51 | 51 | |
52 | - return $this->getSerialized( $object ); |
|
52 | + return $this->getSerialized($object); |
|
53 | 53 | } |
54 | 54 | |
55 | - private function getSerialized( CrossCheckResultList $resultList ) { |
|
55 | + private function getSerialized(CrossCheckResultList $resultList) { |
|
56 | 56 | $serialization = []; |
57 | - $this->setKeyAttributeName( $serialization, 'property', 'id' ); |
|
57 | + $this->setKeyAttributeName($serialization, 'property', 'id'); |
|
58 | 58 | |
59 | - foreach ( $resultList->getPropertyIds() as $propertyId ) { |
|
59 | + foreach ($resultList->getPropertyIds() as $propertyId) { |
|
60 | 60 | $id = $propertyId->getSerialization(); |
61 | 61 | $resultSerialization = []; |
62 | 62 | |
63 | - $this->setIndexedTagName( $resultSerialization, 'result' ); |
|
63 | + $this->setIndexedTagName($resultSerialization, 'result'); |
|
64 | 64 | |
65 | - foreach ( $resultList->getByPropertyId( $propertyId ) as $result ) { |
|
66 | - $resultSerialization[] = $this->crossCheckResultSerializer->serialize( $result ); |
|
65 | + foreach ($resultList->getByPropertyId($propertyId) as $result) { |
|
66 | + $resultSerialization[] = $this->crossCheckResultSerializer->serialize($result); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | $serialization[$id] = $resultSerialization; |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | private $referenceSerializer; |
20 | 20 | |
21 | - public function __construct( Serializer $referenceSerializer ) { |
|
21 | + public function __construct(Serializer $referenceSerializer) { |
|
22 | 22 | $this->referenceSerializer = $referenceSerializer; |
23 | 23 | } |
24 | 24 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return bool |
31 | 31 | */ |
32 | - public function isSerializerFor( $object ) { |
|
32 | + public function isSerializerFor($object) { |
|
33 | 33 | return $object instanceof ReferenceResult; |
34 | 34 | } |
35 | 35 | |
@@ -41,20 +41,20 @@ discard block |
||
41 | 41 | * @return array |
42 | 42 | * @throws UnsupportedObjectException |
43 | 43 | */ |
44 | - public function serialize( $object ) { |
|
45 | - if ( !$this->isSerializerFor( $object ) ) { |
|
44 | + public function serialize($object) { |
|
45 | + if (!$this->isSerializerFor($object)) { |
|
46 | 46 | throw new UnsupportedObjectException( |
47 | 47 | $object, |
48 | 48 | 'ReferenceResultSerializer can only serialize ReferenceResult objects.' |
49 | 49 | ); |
50 | 50 | } |
51 | 51 | |
52 | - return $this->getSerialized( $object ); |
|
52 | + return $this->getSerialized($object); |
|
53 | 53 | } |
54 | 54 | |
55 | - private function getSerialized( ReferenceResult $referenceResult ) { |
|
55 | + private function getSerialized(ReferenceResult $referenceResult) { |
|
56 | 56 | return [ |
57 | - 'reference' => $this->referenceSerializer->serialize( $referenceResult->getReference() ), |
|
57 | + 'reference' => $this->referenceSerializer->serialize($referenceResult->getReference()), |
|
58 | 58 | 'status' => $referenceResult->getStatus() |
59 | 59 | ]; |
60 | 60 | } |
@@ -15,10 +15,10 @@ |
||
15 | 15 | * |
16 | 16 | * @return bool |
17 | 17 | */ |
18 | - public static function onCreateSchema( DatabaseUpdater $updater ) { |
|
19 | - $updater->addExtensionTable( 'wbqev_dump_information', __DIR__ . '/sql/create_wbqev_dump_information.sql' ); |
|
20 | - $updater->addExtensionTable( 'wbqev_external_data', __DIR__ . '/sql/create_wbqev_external_data.sql' ); |
|
21 | - $updater->addExtensionTable( 'wbqev_identifier_properties', __DIR__ . '/sql/create_wbqev_identifier_properties.sql' ); |
|
18 | + public static function onCreateSchema(DatabaseUpdater $updater) { |
|
19 | + $updater->addExtensionTable('wbqev_dump_information', __DIR__.'/sql/create_wbqev_dump_information.sql'); |
|
20 | + $updater->addExtensionTable('wbqev_external_data', __DIR__.'/sql/create_wbqev_external_data.sql'); |
|
21 | + $updater->addExtensionTable('wbqev_identifier_properties', __DIR__.'/sql/create_wbqev_identifier_properties.sql'); |
|
22 | 22 | |
23 | 23 | return true; |
24 | 24 | } |
@@ -28,18 +28,18 @@ discard block |
||
28 | 28 | * @return DumpMetaInformation[] |
29 | 29 | * @throws InvalidArgumentException |
30 | 30 | */ |
31 | - public function getWithIds( array $dumpIds ) { |
|
32 | - if ( $dumpIds === [] ) { |
|
31 | + public function getWithIds(array $dumpIds) { |
|
32 | + if ($dumpIds === []) { |
|
33 | 33 | return []; |
34 | 34 | } |
35 | 35 | |
36 | - foreach ( $dumpIds as $dumpId ) { |
|
37 | - if ( !is_string( $dumpId ) ) { |
|
38 | - throw new InvalidArgumentException( '$dumpIds must contain only strings.' ); |
|
36 | + foreach ($dumpIds as $dumpId) { |
|
37 | + if (!is_string($dumpId)) { |
|
38 | + throw new InvalidArgumentException('$dumpIds must contain only strings.'); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
42 | - $db = wfGetDB( DB_REPLICA ); |
|
42 | + $db = wfGetDB(DB_REPLICA); |
|
43 | 43 | $result = $db->select( |
44 | 44 | [ |
45 | 45 | self::META_TABLE_NAME, |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | ] |
60 | 60 | ); |
61 | 61 | |
62 | - return $this->buildDumpMetaInformationFromResult( $result ); |
|
62 | + return $this->buildDumpMetaInformationFromResult($result); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -71,20 +71,20 @@ discard block |
||
71 | 71 | * @throws InvalidArgumentException |
72 | 72 | * @return DumpMetaInformation[] |
73 | 73 | */ |
74 | - public function getWithIdentifierProperties( array $identifierPropertyIds ) { |
|
75 | - if ( $identifierPropertyIds === [] ) { |
|
74 | + public function getWithIdentifierProperties(array $identifierPropertyIds) { |
|
75 | + if ($identifierPropertyIds === []) { |
|
76 | 76 | return []; |
77 | 77 | } |
78 | 78 | |
79 | - foreach ( $identifierPropertyIds as $propertyId ) { |
|
80 | - if ( !( $propertyId instanceof PropertyId ) ) { |
|
81 | - throw new InvalidArgumentException( '$identifierProperties must contain only PropertyIds.' ); |
|
79 | + foreach ($identifierPropertyIds as $propertyId) { |
|
80 | + if (!($propertyId instanceof PropertyId)) { |
|
81 | + throw new InvalidArgumentException('$identifierProperties must contain only PropertyIds.'); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | - $db = wfGetDB( DB_REPLICA ); |
|
85 | + $db = wfGetDB(DB_REPLICA); |
|
86 | 86 | $identifierPropertyIds = array_map( |
87 | - function( PropertyId $id ) { |
|
87 | + function(PropertyId $id) { |
|
88 | 88 | return $id->getSerialization(); |
89 | 89 | }, |
90 | 90 | $identifierPropertyIds |
@@ -97,13 +97,13 @@ discard block |
||
97 | 97 | ] |
98 | 98 | ); |
99 | 99 | $dumpIds = []; |
100 | - foreach ( $result as $row ) { |
|
101 | - if ( !in_array( $row->dump_id, $dumpIds ) ) { |
|
100 | + foreach ($result as $row) { |
|
101 | + if (!in_array($row->dump_id, $dumpIds)) { |
|
102 | 102 | $dumpIds[] = $row->dump_id; |
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | - return $this->getWithIds( $dumpIds ); |
|
106 | + return $this->getWithIds($dumpIds); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @return DumpMetaInformation[] |
114 | 114 | */ |
115 | 115 | public function getAll() { |
116 | - $db = wfGetDB( DB_REPLICA ); |
|
116 | + $db = wfGetDB(DB_REPLICA); |
|
117 | 117 | $result = $db->select( |
118 | 118 | [ |
119 | 119 | self::META_TABLE_NAME, |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | ] |
132 | 132 | ); |
133 | 133 | |
134 | - return $this->buildDumpMetaInformationFromResult( $result ); |
|
134 | + return $this->buildDumpMetaInformationFromResult($result); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,34 +139,34 @@ discard block |
||
139 | 139 | * @return null|array |
140 | 140 | * @throws UnexpectedValueException |
141 | 141 | */ |
142 | - private function buildDumpMetaInformationFromResult( IResultWrapper $result ) { |
|
142 | + private function buildDumpMetaInformationFromResult(IResultWrapper $result) { |
|
143 | 143 | $aggregatedRows = []; |
144 | - foreach ( $result as $row ) { |
|
145 | - if ( array_key_exists( $row->id, $aggregatedRows ) ) { |
|
146 | - $propertyId = new PropertyId( $row->identifier_pid ); |
|
144 | + foreach ($result as $row) { |
|
145 | + if (array_key_exists($row->id, $aggregatedRows)) { |
|
146 | + $propertyId = new PropertyId($row->identifier_pid); |
|
147 | 147 | $aggregatedRows[$row->id]->identifier_pid[] = $propertyId; |
148 | 148 | } else { |
149 | - if ( $row->identifier_pid !== null ) { |
|
150 | - $propertyId = new PropertyId( $row->identifier_pid ); |
|
151 | - $row->identifier_pid = [ $propertyId ]; |
|
149 | + if ($row->identifier_pid !== null) { |
|
150 | + $propertyId = new PropertyId($row->identifier_pid); |
|
151 | + $row->identifier_pid = [$propertyId]; |
|
152 | 152 | } |
153 | 153 | $aggregatedRows[$row->id] = $row; |
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | 157 | $dumpMetaInformation = []; |
158 | - foreach ( $aggregatedRows as $row ) { |
|
158 | + foreach ($aggregatedRows as $row) { |
|
159 | 159 | $dumpId = $row->id; |
160 | - $sourceItemId = new ItemId( $row->source_qid ); |
|
161 | - $importDate = wfTimestamp( TS_MW, $row->import_date ); |
|
160 | + $sourceItemId = new ItemId($row->source_qid); |
|
161 | + $importDate = wfTimestamp(TS_MW, $row->import_date); |
|
162 | 162 | $language = $row->language; |
163 | 163 | $sourceUrl = $row->source_url; |
164 | 164 | $size = (int)$row->size; |
165 | - $licenseItemId = new ItemId( $row->license_qid ); |
|
165 | + $licenseItemId = new ItemId($row->license_qid); |
|
166 | 166 | $identifierPropertyIds = $row->identifier_pid; |
167 | 167 | |
168 | 168 | $dumpMetaInformation[$row->dump_id] = |
169 | - new DumpMetaInformation( $dumpId, |
|
169 | + new DumpMetaInformation($dumpId, |
|
170 | 170 | $sourceItemId, |
171 | 171 | $identifierPropertyIds, |
172 | 172 | $importDate, |
@@ -185,22 +185,22 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @param DumpMetaInformation $dumpMetaInformation |
187 | 187 | */ |
188 | - public function save( DumpMetaInformation $dumpMetaInformation ) { |
|
189 | - $db = wfGetDB( DB_REPLICA ); |
|
188 | + public function save(DumpMetaInformation $dumpMetaInformation) { |
|
189 | + $db = wfGetDB(DB_REPLICA); |
|
190 | 190 | $dumpId = $dumpMetaInformation->getDumpId(); |
191 | - $accumulator = $this->getDumpInformationFields( $db, $dumpMetaInformation ); |
|
191 | + $accumulator = $this->getDumpInformationFields($db, $dumpMetaInformation); |
|
192 | 192 | |
193 | 193 | $existing = $db->selectRow( |
194 | 194 | self::META_TABLE_NAME, |
195 | - [ 'id' ], |
|
196 | - [ 'id' => $dumpId ] |
|
195 | + ['id'], |
|
196 | + ['id' => $dumpId] |
|
197 | 197 | ); |
198 | 198 | |
199 | - if ( $existing ) { |
|
199 | + if ($existing) { |
|
200 | 200 | $db->update( |
201 | 201 | self::META_TABLE_NAME, |
202 | 202 | $accumulator, |
203 | - [ 'id' => $dumpId ] |
|
203 | + ['id' => $dumpId] |
|
204 | 204 | ); |
205 | 205 | } else { |
206 | 206 | $db->insert( |
@@ -211,12 +211,12 @@ discard block |
||
211 | 211 | |
212 | 212 | $db->delete( |
213 | 213 | self::IDENTIFIER_PROPERTIES_TABLE_NAME, |
214 | - [ 'dump_id' => $dumpId ] |
|
214 | + ['dump_id' => $dumpId] |
|
215 | 215 | ); |
216 | 216 | $db->insert( |
217 | 217 | self::IDENTIFIER_PROPERTIES_TABLE_NAME, |
218 | 218 | array_map( |
219 | - function ( PropertyId $identifierPropertyId ) use ( $dumpId ) { |
|
219 | + function(PropertyId $identifierPropertyId) use ($dumpId) { |
|
220 | 220 | return [ |
221 | 221 | 'dump_id' => $dumpId, |
222 | 222 | 'identifier_pid' => $identifierPropertyId->getSerialization() |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | * @param DumpMetaInformation $dumpMetaInformation |
233 | 233 | * @return array |
234 | 234 | */ |
235 | - private function getDumpInformationFields( IDatabase $db, DumpMetaInformation $dumpMetaInformation ) { |
|
235 | + private function getDumpInformationFields(IDatabase $db, DumpMetaInformation $dumpMetaInformation) { |
|
236 | 236 | return [ |
237 | 237 | 'id' => $dumpMetaInformation->getDumpId(), |
238 | 238 | 'source_qid' => $dumpMetaInformation->getSourceItemId()->getSerialization(), |
239 | - 'import_date' => $db->timestamp( $dumpMetaInformation->getImportDate() ), |
|
239 | + 'import_date' => $db->timestamp($dumpMetaInformation->getImportDate()), |
|
240 | 240 | 'language' => $dumpMetaInformation->getLanguageCode(), |
241 | 241 | 'source_url' => $dumpMetaInformation->getSourceUrl(), |
242 | 242 | 'size' => $dumpMetaInformation->getSize(), |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | public function import() { |
48 | 48 | $dumpIds = $this->insertMetaInformation(); |
49 | 49 | |
50 | - $this->log( "\nDelete old database entries...\n" ); |
|
50 | + $this->log("\nDelete old database entries...\n"); |
|
51 | 51 | |
52 | - foreach ( $dumpIds as $dumpId ) { |
|
53 | - $this->externalDataRepo->deleteOfDump( $dumpId, $this->importSettings->getBatchSize() ); |
|
52 | + foreach ($dumpIds as $dumpId) { |
|
53 | + $this->externalDataRepo->deleteOfDump($dumpId, $this->importSettings->getBatchSize()); |
|
54 | 54 | } |
55 | 55 | |
56 | - $this->log( "\n" ); |
|
56 | + $this->log("\n"); |
|
57 | 57 | |
58 | 58 | $this->insertExternalValues(); |
59 | 59 | } |
@@ -64,52 +64,52 @@ discard block |
||
64 | 64 | * @return array |
65 | 65 | */ |
66 | 66 | protected function insertMetaInformation() { |
67 | - $this->log( "Insert new dump meta information\n" ); |
|
67 | + $this->log("Insert new dump meta information\n"); |
|
68 | 68 | |
69 | - $csvFile = fopen( $this->importSettings->getDumpInformationFilePath(), 'rb' ); |
|
70 | - if ( !$csvFile ) { |
|
71 | - exit( 'Error while reading CSV file.' ); |
|
69 | + $csvFile = fopen($this->importSettings->getDumpInformationFilePath(), 'rb'); |
|
70 | + if (!$csvFile) { |
|
71 | + exit('Error while reading CSV file.'); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | $i = 0; |
75 | 75 | $dumpIds = []; |
76 | - while ( $data = fgetcsv( $csvFile ) ) { |
|
76 | + while ($data = fgetcsv($csvFile)) { |
|
77 | 77 | $identifierPropertyIds = array_map( |
78 | - function ( $propertyId ) { |
|
79 | - return new PropertyId( $propertyId ); |
|
78 | + function($propertyId) { |
|
79 | + return new PropertyId($propertyId); |
|
80 | 80 | }, |
81 | - json_decode( $data[2] ) |
|
81 | + json_decode($data[2]) |
|
82 | 82 | ); |
83 | 83 | try { |
84 | 84 | $dumpMetaInformation = new DumpMetaInformation( |
85 | 85 | $data[0], |
86 | - new ItemId( $data[1] ), |
|
86 | + new ItemId($data[1]), |
|
87 | 87 | $identifierPropertyIds, |
88 | 88 | $data[3], |
89 | 89 | $data[4], |
90 | 90 | $data[5], |
91 | - intval( $data[6] ), |
|
92 | - new ItemId( $data[7] ) |
|
91 | + intval($data[6]), |
|
92 | + new ItemId($data[7]) |
|
93 | 93 | ); |
94 | - } catch ( \InvalidArgumentException $e ) { |
|
95 | - exit( 'Input file has bad formatted values.' ); |
|
94 | + } catch (\InvalidArgumentException $e) { |
|
95 | + exit('Input file has bad formatted values.'); |
|
96 | 96 | } |
97 | 97 | $dumpIds[] = $dumpMetaInformation->getDumpId(); |
98 | 98 | |
99 | 99 | try { |
100 | - $this->dumpMetaInformationStore->save( $dumpMetaInformation ); |
|
101 | - } catch ( DBError $e ) { |
|
102 | - exit( 'Unknown database error occurred.' ); |
|
100 | + $this->dumpMetaInformationStore->save($dumpMetaInformation); |
|
101 | + } catch (DBError $e) { |
|
102 | + exit('Unknown database error occurred.'); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | $i++; |
106 | - $this->log( "\r\033[K" ); |
|
107 | - $this->log( "$i rows inserted or updated" ); |
|
106 | + $this->log("\r\033[K"); |
|
107 | + $this->log("$i rows inserted or updated"); |
|
108 | 108 | } |
109 | 109 | |
110 | - fclose( $csvFile ); |
|
110 | + fclose($csvFile); |
|
111 | 111 | |
112 | - $this->log( "\n" ); |
|
112 | + $this->log("\n"); |
|
113 | 113 | |
114 | 114 | return $dumpIds; |
115 | 115 | } |
@@ -118,32 +118,32 @@ discard block |
||
118 | 118 | * Inserts external values stored in csv file into database |
119 | 119 | */ |
120 | 120 | private function insertExternalValues() { |
121 | - $this->log( "Insert new data values\n" ); |
|
121 | + $this->log("Insert new data values\n"); |
|
122 | 122 | |
123 | - $csvFile = fopen( $this->importSettings->getExternalValuesFilePath(), 'rb' ); |
|
124 | - if ( !$csvFile ) { |
|
125 | - exit( 'Error while reading CSV file.' ); |
|
123 | + $csvFile = fopen($this->importSettings->getExternalValuesFilePath(), 'rb'); |
|
124 | + if (!$csvFile) { |
|
125 | + exit('Error while reading CSV file.'); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | $i = 0; |
129 | 129 | $accumulator = []; |
130 | 130 | $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); |
131 | - while ( true ) { |
|
132 | - $data = fgetcsv( $csvFile ); |
|
133 | - if ( $data === false || ++$i % $this->importSettings->getBatchSize() === 0 ) { |
|
131 | + while (true) { |
|
132 | + $data = fgetcsv($csvFile); |
|
133 | + if ($data === false || ++$i % $this->importSettings->getBatchSize() === 0) { |
|
134 | 134 | try { |
135 | - $this->externalDataRepo->insertBatch( $accumulator ); |
|
136 | - } catch ( DBError $e ) { |
|
137 | - exit( 'Unknown database error occurred.' ); |
|
135 | + $this->externalDataRepo->insertBatch($accumulator); |
|
136 | + } catch (DBError $e) { |
|
137 | + exit('Unknown database error occurred.'); |
|
138 | 138 | } |
139 | 139 | $lbFactory->waitForReplication(); |
140 | 140 | |
141 | - $this->log( "\r\033[K" ); |
|
142 | - $this->log( "$i rows inserted" ); |
|
141 | + $this->log("\r\033[K"); |
|
142 | + $this->log("$i rows inserted"); |
|
143 | 143 | |
144 | 144 | $accumulator = []; |
145 | 145 | |
146 | - if ( $data === false ) { |
|
146 | + if ($data === false) { |
|
147 | 147 | break; |
148 | 148 | } |
149 | 149 | } |
@@ -151,16 +151,16 @@ discard block |
||
151 | 151 | $accumulator[] = $data; |
152 | 152 | } |
153 | 153 | |
154 | - fclose( $csvFile ); |
|
154 | + fclose($csvFile); |
|
155 | 155 | |
156 | - $this->log( "\n" ); |
|
156 | + $this->log("\n"); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | 160 | * @param string $text |
161 | 161 | */ |
162 | - private function log( $text ) { |
|
163 | - if ( !$this->importSettings->isQuiet() ) { |
|
162 | + private function log($text) { |
|
163 | + if (!$this->importSettings->isQuiet()) { |
|
164 | 164 | print $text; |
165 | 165 | } |
166 | 166 | } |
@@ -98,18 +98,18 @@ discard block |
||
98 | 98 | OutputFormatValueFormatterFactory $valueFormatterFactory, |
99 | 99 | CrossCheckInteractor $crossCheckInteractor |
100 | 100 | ) { |
101 | - parent::__construct( 'CrossCheck' ); |
|
101 | + parent::__construct('CrossCheck'); |
|
102 | 102 | |
103 | 103 | $this->entityLookup = $entityLookup; |
104 | 104 | $this->entityIdParser = $entityIdParser; |
105 | 105 | |
106 | 106 | $formatterOptions = new FormatterOptions(); |
107 | - $formatterOptions->setOption( SnakFormatter::OPT_LANG, $this->getLanguage()->getCode() ); |
|
108 | - $this->dataValueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
|
107 | + $formatterOptions->setOption(SnakFormatter::OPT_LANG, $this->getLanguage()->getCode()); |
|
108 | + $this->dataValueFormatter = $valueFormatterFactory->getValueFormatter(SnakFormatter::FORMAT_HTML, $formatterOptions); |
|
109 | 109 | |
110 | - $labelLookup = new LanguageLabelDescriptionLookup( $termLookup, $this->getLanguage()->getCode() ); |
|
111 | - $this->entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelLookup ); |
|
112 | - $this->entityIdLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelLookup ); |
|
110 | + $labelLookup = new LanguageLabelDescriptionLookup($termLookup, $this->getLanguage()->getCode()); |
|
111 | + $this->entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter($labelLookup); |
|
112 | + $this->entityIdLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter($labelLookup); |
|
113 | 113 | |
114 | 114 | $this->crossCheckInteractor = $crossCheckInteractor; |
115 | 115 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @return string (plain text) |
130 | 130 | */ |
131 | 131 | public function getDescription() { |
132 | - return $this->msg( 'wbqev-crosscheck' )->text(); |
|
132 | + return $this->msg('wbqev-crosscheck')->text(); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -141,55 +141,55 @@ discard block |
||
141 | 141 | * @throws EntityIdParsingException |
142 | 142 | * @throws UnexpectedValueException |
143 | 143 | */ |
144 | - public function execute( $subPage ) { |
|
144 | + public function execute($subPage) { |
|
145 | 145 | $out = $this->getOutput(); |
146 | - $postRequest = $this->getContext()->getRequest()->getVal( 'entityid' ); |
|
147 | - if ( $postRequest ) { |
|
148 | - $out->redirect( $this->getPageTitle( strtoupper( $postRequest ) )->getLocalURL() ); |
|
146 | + $postRequest = $this->getContext()->getRequest()->getVal('entityid'); |
|
147 | + if ($postRequest) { |
|
148 | + $out->redirect($this->getPageTitle(strtoupper($postRequest))->getLocalURL()); |
|
149 | 149 | return; |
150 | 150 | } |
151 | 151 | |
152 | - $out->addModules( 'SpecialCrossCheckPage' ); |
|
152 | + $out->addModules('SpecialCrossCheckPage'); |
|
153 | 153 | |
154 | 154 | $this->setHeaders(); |
155 | 155 | |
156 | - $out->addHTML( $this->buildInfoBox() ); |
|
156 | + $out->addHTML($this->buildInfoBox()); |
|
157 | 157 | $this->buildEntityIdForm(); |
158 | 158 | |
159 | - if ( $subPage ) { |
|
160 | - $this->buildResult( $subPage ); |
|
159 | + if ($subPage) { |
|
160 | + $this->buildResult($subPage); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
165 | 165 | * @param string $idSerialization |
166 | 166 | */ |
167 | - private function buildResult( $idSerialization ) { |
|
167 | + private function buildResult($idSerialization) { |
|
168 | 168 | $out = $this->getOutput(); |
169 | 169 | |
170 | 170 | try { |
171 | - $entityId = $this->entityIdParser->parse( $idSerialization ); |
|
172 | - } catch ( EntityIdParsingException $ex ) { |
|
173 | - $out->addHTML( $this->buildNotice( 'wbqev-crosscheck-invalid-entity-id', true ) ); |
|
171 | + $entityId = $this->entityIdParser->parse($idSerialization); |
|
172 | + } catch (EntityIdParsingException $ex) { |
|
173 | + $out->addHTML($this->buildNotice('wbqev-crosscheck-invalid-entity-id', true)); |
|
174 | 174 | return; |
175 | 175 | } |
176 | 176 | |
177 | - $out->addHTML( $this->buildResultHeader( $entityId ) ); |
|
177 | + $out->addHTML($this->buildResultHeader($entityId)); |
|
178 | 178 | |
179 | - $entity = $this->entityLookup->getEntity( $entityId ); |
|
180 | - if ( $entity === null ) { |
|
181 | - $out->addHTML( $this->buildNotice( 'wbqev-crosscheck-not-existent-entity', true ) ); |
|
179 | + $entity = $this->entityLookup->getEntity($entityId); |
|
180 | + if ($entity === null) { |
|
181 | + $out->addHTML($this->buildNotice('wbqev-crosscheck-not-existent-entity', true)); |
|
182 | 182 | return; |
183 | 183 | } |
184 | 184 | |
185 | - $results = $this->getCrossCheckResultsFromEntity( $entity ); |
|
185 | + $results = $this->getCrossCheckResultsFromEntity($entity); |
|
186 | 186 | |
187 | - if ( $results === null || $results->toArray() === [] ) { |
|
188 | - $out->addHTML( $this->buildNotice( 'wbqev-crosscheck-empty-result' ) ); |
|
187 | + if ($results === null || $results->toArray() === []) { |
|
188 | + $out->addHTML($this->buildNotice('wbqev-crosscheck-empty-result')); |
|
189 | 189 | } else { |
190 | 190 | $out->addHTML( |
191 | - $this->buildSummary( $results ) |
|
192 | - . $this->buildResultTable( $results ) |
|
191 | + $this->buildSummary($results) |
|
192 | + . $this->buildResultTable($results) |
|
193 | 193 | ); |
194 | 194 | } |
195 | 195 | } |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @return CrossCheckResultList|null |
201 | 201 | */ |
202 | - private function getCrossCheckResultsFromEntity( EntityDocument $entity ) { |
|
203 | - if ( $entity instanceof StatementListProvider ) { |
|
204 | - return $this->crossCheckInteractor->crossCheckStatements( $entity->getStatements() ); |
|
202 | + private function getCrossCheckResultsFromEntity(EntityDocument $entity) { |
|
203 | + if ($entity instanceof StatementListProvider) { |
|
204 | + return $this->crossCheckInteractor->crossCheckStatements($entity->getStatements()); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | return null; |
@@ -218,15 +218,15 @@ discard block |
||
218 | 218 | 'name' => 'entityid', |
219 | 219 | 'label-message' => 'wbqev-crosscheck-form-entityid-label', |
220 | 220 | 'cssclass' => 'wbqev-crosscheck-form-entity-id', |
221 | - 'placeholder' => $this->msg( 'wbqev-crosscheck-form-entityid-placeholder' )->escaped() |
|
221 | + 'placeholder' => $this->msg('wbqev-crosscheck-form-entityid-placeholder')->escaped() |
|
222 | 222 | ] |
223 | 223 | ]; |
224 | - $htmlForm = new HTMLForm( $formDescriptor, $this->getContext(), 'wbqev-crosscheck-form' ); |
|
225 | - $htmlForm->setSubmitText( $this->msg( 'wbqev-crosscheck-form-submit-label' )->escaped() ); |
|
226 | - $htmlForm->setSubmitCallback( function() { |
|
224 | + $htmlForm = new HTMLForm($formDescriptor, $this->getContext(), 'wbqev-crosscheck-form'); |
|
225 | + $htmlForm->setSubmitText($this->msg('wbqev-crosscheck-form-submit-label')->escaped()); |
|
226 | + $htmlForm->setSubmitCallback(function() { |
|
227 | 227 | return false; |
228 | 228 | } ); |
229 | - $htmlForm->setMethod( 'post' ); |
|
229 | + $htmlForm->setMethod('post'); |
|
230 | 230 | $htmlForm->show(); |
231 | 231 | } |
232 | 232 | |
@@ -236,18 +236,18 @@ discard block |
||
236 | 236 | * @return string HTML |
237 | 237 | */ |
238 | 238 | private function buildInfoBox() { |
239 | - $externalDbLink = Linker::specialLink( 'ExternalDatabases', 'wbqev-externaldbs' ); |
|
239 | + $externalDbLink = Linker::specialLink('ExternalDatabases', 'wbqev-externaldbs'); |
|
240 | 240 | $infoBox = |
241 | 241 | Html::openElement( |
242 | 242 | 'div', |
243 | - [ 'class' => 'wbqev-infobox' ] |
|
243 | + ['class' => 'wbqev-infobox'] |
|
244 | 244 | ) |
245 | - . $this->msg( 'wbqev-crosscheck-explanation-general' )->parse() |
|
246 | - . sprintf( ' %s.', $externalDbLink ) |
|
247 | - . Html::element( 'br' ) |
|
248 | - . Html::element( 'br' ) |
|
249 | - . $this->msg( 'wbqev-crosscheck-explanation-detail' )->parse() |
|
250 | - . Html::closeElement( 'div' ); |
|
245 | + . $this->msg('wbqev-crosscheck-explanation-general')->parse() |
|
246 | + . sprintf(' %s.', $externalDbLink) |
|
247 | + . Html::element('br') |
|
248 | + . Html::element('br') |
|
249 | + . $this->msg('wbqev-crosscheck-explanation-detail')->parse() |
|
250 | + . Html::closeElement('div'); |
|
251 | 251 | |
252 | 252 | return $infoBox; |
253 | 253 | } |
@@ -262,16 +262,16 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @return string HTML |
264 | 264 | */ |
265 | - private function buildNotice( $messageKey, $error = false ) { |
|
265 | + private function buildNotice($messageKey, $error = false) { |
|
266 | 266 | $cssClasses = 'wbqev-crosscheck-notice'; |
267 | - if ( $error ) { |
|
267 | + if ($error) { |
|
268 | 268 | $cssClasses .= ' wbqev-crosscheck-notice-error'; |
269 | 269 | } |
270 | 270 | |
271 | 271 | return Html::element( |
272 | 272 | 'p', |
273 | - [ 'class' => $cssClasses ], |
|
274 | - $this->msg( $messageKey )->text() |
|
273 | + ['class' => $cssClasses], |
|
274 | + $this->msg($messageKey)->text() |
|
275 | 275 | ); |
276 | 276 | } |
277 | 277 | |
@@ -282,17 +282,17 @@ discard block |
||
282 | 282 | * |
283 | 283 | * @return string HTML |
284 | 284 | */ |
285 | - private function buildResultHeader( EntityId $entityId ) { |
|
285 | + private function buildResultHeader(EntityId $entityId) { |
|
286 | 286 | $entityLink = sprintf( |
287 | 287 | '%s (%s)', |
288 | - $this->entityIdLinkFormatter->formatEntityId( $entityId ), |
|
289 | - htmlspecialchars( $entityId->getSerialization() ) |
|
288 | + $this->entityIdLinkFormatter->formatEntityId($entityId), |
|
289 | + htmlspecialchars($entityId->getSerialization()) |
|
290 | 290 | ); |
291 | 291 | |
292 | 292 | return Html::rawElement( |
293 | 293 | 'h3', |
294 | 294 | [], |
295 | - sprintf( '%s %s', $this->msg( 'wbqev-crosscheck-result-headline' )->escaped(), $entityLink ) |
|
295 | + sprintf('%s %s', $this->msg('wbqev-crosscheck-result-headline')->escaped(), $entityLink) |
|
296 | 296 | ); |
297 | 297 | } |
298 | 298 | |
@@ -303,11 +303,11 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @return string HTML |
305 | 305 | */ |
306 | - private function buildSummary( $results ) { |
|
306 | + private function buildSummary($results) { |
|
307 | 307 | $statuses = []; |
308 | - foreach ( $results as $result ) { |
|
309 | - $status = strtolower( $result->getComparisonResult()->getStatus() ); |
|
310 | - if ( array_key_exists( $status, $statuses ) ) { |
|
308 | + foreach ($results as $result) { |
|
309 | + $status = strtolower($result->getComparisonResult()->getStatus()); |
|
310 | + if (array_key_exists($status, $statuses)) { |
|
311 | 311 | $statuses[$status]++; |
312 | 312 | } else { |
313 | 313 | $statuses[$status] = 1; |
@@ -315,15 +315,15 @@ discard block |
||
315 | 315 | } |
316 | 316 | |
317 | 317 | $statusElements = []; |
318 | - foreach ( $statuses as $status => $count ) { |
|
319 | - if ( $count > 0 ) { |
|
320 | - $statusElements[] = $this->formatStatus( $status ) . ': ' . $count; |
|
318 | + foreach ($statuses as $status => $count) { |
|
319 | + if ($count > 0) { |
|
320 | + $statusElements[] = $this->formatStatus($status).': '.$count; |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | $summary = |
324 | - Html::openElement( 'p' ) |
|
325 | - . implode( ', ', $statusElements ) |
|
326 | - . Html::closeElement( 'p' ); |
|
324 | + Html::openElement('p') |
|
325 | + . implode(', ', $statusElements) |
|
326 | + . Html::closeElement('p'); |
|
327 | 327 | |
328 | 328 | return $summary; |
329 | 329 | } |
@@ -337,16 +337,16 @@ discard block |
||
337 | 337 | * |
338 | 338 | * @return string HTML |
339 | 339 | */ |
340 | - private function formatStatus( $status ) { |
|
341 | - $messageKey = 'wbqev-crosscheck-status-' . strtolower( $status ); |
|
340 | + private function formatStatus($status) { |
|
341 | + $messageKey = 'wbqev-crosscheck-status-'.strtolower($status); |
|
342 | 342 | |
343 | 343 | $formattedStatus = |
344 | 344 | Html::element( |
345 | 345 | 'span', |
346 | 346 | [ |
347 | - 'class' => 'wbqev-status wbqev-status-' . htmlspecialchars( $status ) |
|
347 | + 'class' => 'wbqev-status wbqev-status-'.htmlspecialchars($status) |
|
348 | 348 | ], |
349 | - $this->msg( $messageKey )->text() |
|
349 | + $this->msg($messageKey)->text() |
|
350 | 350 | ); |
351 | 351 | |
352 | 352 | return $formattedStatus; |
@@ -363,29 +363,29 @@ discard block |
||
363 | 363 | * |
364 | 364 | * @return string HTML |
365 | 365 | */ |
366 | - private function formatDataValues( $dataValues, $linking = true, $separator = null ) { |
|
367 | - if ( $dataValues instanceof DataValue ) { |
|
368 | - $dataValues = [ $dataValues ]; |
|
366 | + private function formatDataValues($dataValues, $linking = true, $separator = null) { |
|
367 | + if ($dataValues instanceof DataValue) { |
|
368 | + $dataValues = [$dataValues]; |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | $formattedDataValues = []; |
372 | - foreach ( $dataValues as $dataValue ) { |
|
373 | - if ( $dataValue instanceof EntityIdValue ) { |
|
374 | - if ( $linking ) { |
|
375 | - $formattedDataValues[] = $this->entityIdLinkFormatter->formatEntityId( $dataValue->getEntityId() ); |
|
372 | + foreach ($dataValues as $dataValue) { |
|
373 | + if ($dataValue instanceof EntityIdValue) { |
|
374 | + if ($linking) { |
|
375 | + $formattedDataValues[] = $this->entityIdLinkFormatter->formatEntityId($dataValue->getEntityId()); |
|
376 | 376 | } else { |
377 | - $formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId( $dataValue->getEntityId() ); |
|
377 | + $formattedDataValues[] = $this->entityIdLabelFormatter->formatEntityId($dataValue->getEntityId()); |
|
378 | 378 | } |
379 | 379 | } else { |
380 | - $formattedDataValues[] = $this->dataValueFormatter->format( $dataValue ); |
|
380 | + $formattedDataValues[] = $this->dataValueFormatter->format($dataValue); |
|
381 | 381 | } |
382 | 382 | } |
383 | 383 | |
384 | - if ( $separator ) { |
|
385 | - return implode( $separator, $formattedDataValues ); |
|
384 | + if ($separator) { |
|
385 | + return implode($separator, $formattedDataValues); |
|
386 | 386 | } |
387 | 387 | |
388 | - return $this->getLanguage()->commaList( $formattedDataValues ); |
|
388 | + return $this->getLanguage()->commaList($formattedDataValues); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | /** |
@@ -393,31 +393,31 @@ discard block |
||
393 | 393 | * |
394 | 394 | * @return string HTML |
395 | 395 | */ |
396 | - private function buildResultTable( $results ) { |
|
396 | + private function buildResultTable($results) { |
|
397 | 397 | $table = new HtmlTableBuilder( |
398 | 398 | [ |
399 | 399 | new HtmlTableHeaderBuilder( |
400 | - $this->msg( 'wbqev-crosscheck-result-table-header-status' )->escaped(), |
|
400 | + $this->msg('wbqev-crosscheck-result-table-header-status')->escaped(), |
|
401 | 401 | true |
402 | 402 | ), |
403 | 403 | new HtmlTableHeaderBuilder( |
404 | - $this->msg( 'datatypes-type-wikibase-property' )->escaped(), |
|
404 | + $this->msg('datatypes-type-wikibase-property')->escaped(), |
|
405 | 405 | true |
406 | 406 | ), |
407 | 407 | new HtmlTableHeaderBuilder( |
408 | - $this->msg( 'wbqev-crosscheck-result-table-header-local-value' )->escaped() |
|
408 | + $this->msg('wbqev-crosscheck-result-table-header-local-value')->escaped() |
|
409 | 409 | ), |
410 | 410 | new HtmlTableHeaderBuilder( |
411 | - $this->msg( 'wbqev-crosscheck-result-table-header-external-value' )->escaped() |
|
411 | + $this->msg('wbqev-crosscheck-result-table-header-external-value')->escaped() |
|
412 | 412 | ), |
413 | 413 | new HtmlTableHeaderBuilder( |
414 | - $this->msg( 'wbqev-crosscheck-result-table-header-references' )->escaped(), |
|
414 | + $this->msg('wbqev-crosscheck-result-table-header-references')->escaped(), |
|
415 | 415 | true |
416 | 416 | ), |
417 | 417 | new HtmlTableHeaderBuilder( |
418 | 418 | Linker::linkKnown( |
419 | - self::getTitleFor( 'ExternalDatabases' ), |
|
420 | - $this->msg( 'wbqev-crosscheck-result-table-header-external-source' )->escaped() |
|
419 | + self::getTitleFor('ExternalDatabases'), |
|
420 | + $this->msg('wbqev-crosscheck-result-table-header-external-source')->escaped() |
|
421 | 421 | ), |
422 | 422 | true, |
423 | 423 | true |
@@ -426,28 +426,28 @@ discard block |
||
426 | 426 | true |
427 | 427 | ); |
428 | 428 | |
429 | - foreach ( $results as $result ) { |
|
430 | - $status = $this->formatStatus( $result->getComparisonResult()->getStatus() ); |
|
431 | - $propertyId = $this->entityIdLinkFormatter->formatEntityId( $result->getPropertyId() ); |
|
432 | - $localValue = $this->formatDataValues( $result->getComparisonResult()->getLocalValue() ); |
|
429 | + foreach ($results as $result) { |
|
430 | + $status = $this->formatStatus($result->getComparisonResult()->getStatus()); |
|
431 | + $propertyId = $this->entityIdLinkFormatter->formatEntityId($result->getPropertyId()); |
|
432 | + $localValue = $this->formatDataValues($result->getComparisonResult()->getLocalValue()); |
|
433 | 433 | $externalValue = $this->formatDataValues( |
434 | 434 | $result->getComparisonResult()->getExternalValues(), |
435 | 435 | true, |
436 | - Html::element( 'br' ) |
|
436 | + Html::element('br') |
|
437 | 437 | ); |
438 | 438 | $referenceStatus = $this->msg( |
439 | - 'wbqev-crosscheck-status-' . $result->getReferenceResult()->getStatus() |
|
439 | + 'wbqev-crosscheck-status-'.$result->getReferenceResult()->getStatus() |
|
440 | 440 | )->text(); |
441 | - $dataSource = $this->entityIdLinkFormatter->formatEntityId( $result->getDumpMetaInformation()->getSourceItemId() ); |
|
441 | + $dataSource = $this->entityIdLinkFormatter->formatEntityId($result->getDumpMetaInformation()->getSourceItemId()); |
|
442 | 442 | |
443 | 443 | $table->appendRow( |
444 | 444 | [ |
445 | - new HtmlTableCellBuilder( $status, [], true ), |
|
446 | - new HtmlTableCellBuilder( $propertyId, [], true ), |
|
447 | - new HtmlTableCellBuilder( $localValue, [], true ), |
|
448 | - new HtmlTableCellBuilder( $externalValue, [], true ), |
|
449 | - new HtmlTableCellBuilder( $referenceStatus, [] ), |
|
450 | - new HtmlTableCellBuilder( $dataSource, [], true ) |
|
445 | + new HtmlTableCellBuilder($status, [], true), |
|
446 | + new HtmlTableCellBuilder($propertyId, [], true), |
|
447 | + new HtmlTableCellBuilder($localValue, [], true), |
|
448 | + new HtmlTableCellBuilder($externalValue, [], true), |
|
449 | + new HtmlTableCellBuilder($referenceStatus, []), |
|
450 | + new HtmlTableCellBuilder($dataSource, [], true) |
|
451 | 451 | ] |
452 | 452 | ); |
453 | 453 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | private $stringNormalizer; |
24 | 24 | |
25 | - public function __construct( StringNormalizer $stringNormalizer ) { |
|
25 | + public function __construct(StringNormalizer $stringNormalizer) { |
|
26 | 26 | $this->stringNormalizer = $stringNormalizer; |
27 | 27 | } |
28 | 28 | |
@@ -33,16 +33,16 @@ discard block |
||
33 | 33 | * @param string $comparativeValue |
34 | 34 | * @return string |
35 | 35 | */ |
36 | - public function compare( $value, $comparativeValue ) { |
|
37 | - Assert::parameterType( 'string', $value, '$value' ); |
|
38 | - Assert::parameterType( 'string', $comparativeValue, '$comparativeValue' ); |
|
36 | + public function compare($value, $comparativeValue) { |
|
37 | + Assert::parameterType('string', $value, '$value'); |
|
38 | + Assert::parameterType('string', $comparativeValue, '$comparativeValue'); |
|
39 | 39 | |
40 | - $value = $this->cleanDataString( $value ); |
|
41 | - $comparativeValue = $this->cleanDataString( $comparativeValue ); |
|
40 | + $value = $this->cleanDataString($value); |
|
41 | + $comparativeValue = $this->cleanDataString($comparativeValue); |
|
42 | 42 | |
43 | - if ( $value === $comparativeValue ) { |
|
43 | + if ($value === $comparativeValue) { |
|
44 | 44 | return ComparisonResult::STATUS_MATCH; |
45 | - } elseif ( $this->checkSimilarity( $value, $comparativeValue ) ) { |
|
45 | + } elseif ($this->checkSimilarity($value, $comparativeValue)) { |
|
46 | 46 | return ComparisonResult::STATUS_PARTIAL_MATCH; |
47 | 47 | } else { |
48 | 48 | return ComparisonResult::STATUS_MISMATCH; |
@@ -56,19 +56,19 @@ discard block |
||
56 | 56 | * @param array $comparativeValues |
57 | 57 | * @return string |
58 | 58 | */ |
59 | - public function compareWithArray( $value, array $comparativeValues ) { |
|
60 | - Assert::parameterType( 'string', $value, '$value' ); |
|
61 | - Assert::parameterElementType( 'string', $comparativeValues, '$comparativeValues' ); |
|
59 | + public function compareWithArray($value, array $comparativeValues) { |
|
60 | + Assert::parameterType('string', $value, '$value'); |
|
61 | + Assert::parameterElementType('string', $comparativeValues, '$comparativeValues'); |
|
62 | 62 | |
63 | - $value = $this->cleanDataString( $value ); |
|
64 | - $comparativeValues = $this->cleanDataArray( $comparativeValues ); |
|
63 | + $value = $this->cleanDataString($value); |
|
64 | + $comparativeValues = $this->cleanDataArray($comparativeValues); |
|
65 | 65 | |
66 | - if ( in_array( $value, $comparativeValues ) ) { |
|
66 | + if (in_array($value, $comparativeValues)) { |
|
67 | 67 | return ComparisonResult::STATUS_MATCH; |
68 | 68 | } |
69 | 69 | |
70 | - foreach ( $comparativeValues as $comparativeValue ) { |
|
71 | - if ( $this->checkSimilarity( $comparativeValue, $value ) ) { |
|
70 | + foreach ($comparativeValues as $comparativeValue) { |
|
71 | + if ($this->checkSimilarity($comparativeValue, $value)) { |
|
72 | 72 | return ComparisonResult::STATUS_PARTIAL_MATCH; |
73 | 73 | } |
74 | 74 | } |
@@ -83,10 +83,10 @@ discard block |
||
83 | 83 | * @param string $comparativeValue |
84 | 84 | * @return bool |
85 | 85 | */ |
86 | - private function checkSimilarity( $value, $comparativeValue ) { |
|
87 | - return $this->percentagePrefixSimilarity( $value, $comparativeValue ) > self::SIMILARITY_THRESHOLD |
|
88 | - || $this->percentageSuffixSimilarity( $value, $comparativeValue ) > self::SIMILARITY_THRESHOLD |
|
89 | - || $this->percentageLevenshteinDistance( $value, $comparativeValue ) > self::SIMILARITY_THRESHOLD; |
|
86 | + private function checkSimilarity($value, $comparativeValue) { |
|
87 | + return $this->percentagePrefixSimilarity($value, $comparativeValue) > self::SIMILARITY_THRESHOLD |
|
88 | + || $this->percentageSuffixSimilarity($value, $comparativeValue) > self::SIMILARITY_THRESHOLD |
|
89 | + || $this->percentageLevenshteinDistance($value, $comparativeValue) > self::SIMILARITY_THRESHOLD; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @return string |
98 | 98 | */ |
99 | - private function cleanDataString( $value ) { |
|
100 | - $value = $this->stringNormalizer->trimToNFC( $value ); |
|
99 | + private function cleanDataString($value) { |
|
100 | + $value = $this->stringNormalizer->trimToNFC($value); |
|
101 | 101 | |
102 | - return mb_strtolower( $value ); |
|
102 | + return mb_strtolower($value); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -109,10 +109,10 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @return array |
111 | 111 | */ |
112 | - private function cleanDataArray( array $array ) { |
|
112 | + private function cleanDataArray(array $array) { |
|
113 | 113 | |
114 | 114 | return array_map( |
115 | - [ $this, 'cleanDataString' ], |
|
115 | + [$this, 'cleanDataString'], |
|
116 | 116 | $array ); |
117 | 117 | } |
118 | 118 | |
@@ -124,19 +124,19 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @return float |
126 | 126 | */ |
127 | - private function percentagePrefixSimilarity( $value, $comparativeValue ) { |
|
127 | + private function percentagePrefixSimilarity($value, $comparativeValue) { |
|
128 | 128 | $prefixLength = 0; // common prefix length |
129 | - $localLength = strlen( $value ); |
|
130 | - $externalLength = strlen( $comparativeValue ); |
|
131 | - while ( $prefixLength < min( $localLength, $externalLength ) ) { |
|
129 | + $localLength = strlen($value); |
|
130 | + $externalLength = strlen($comparativeValue); |
|
131 | + while ($prefixLength < min($localLength, $externalLength)) { |
|
132 | 132 | $c = $value[$prefixLength]; |
133 | - if ( $externalLength > $prefixLength && $comparativeValue[$prefixLength] !== $c ) { |
|
133 | + if ($externalLength > $prefixLength && $comparativeValue[$prefixLength] !== $c) { |
|
134 | 134 | break; |
135 | 135 | } |
136 | 136 | $prefixLength++; |
137 | 137 | } |
138 | 138 | |
139 | - return $prefixLength / max( $localLength, $externalLength ); |
|
139 | + return $prefixLength / max($localLength, $externalLength); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -147,19 +147,19 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @return float |
149 | 149 | */ |
150 | - private function percentageSuffixSimilarity( $value, $comparativeValue ) { |
|
150 | + private function percentageSuffixSimilarity($value, $comparativeValue) { |
|
151 | 151 | $suffixLength = 0; // common suffix length |
152 | - $localLength = strlen( $value ); |
|
153 | - $externalLength = strlen( $comparativeValue ); |
|
154 | - while ( $suffixLength < min( $localLength, $externalLength ) ) { |
|
152 | + $localLength = strlen($value); |
|
153 | + $externalLength = strlen($comparativeValue); |
|
154 | + while ($suffixLength < min($localLength, $externalLength)) { |
|
155 | 155 | $c = $value[$localLength - 1 - $suffixLength]; |
156 | - if ( $externalLength > $suffixLength && $comparativeValue[$externalLength - 1 - $suffixLength] !== $c ) { |
|
156 | + if ($externalLength > $suffixLength && $comparativeValue[$externalLength - 1 - $suffixLength] !== $c) { |
|
157 | 157 | break; |
158 | 158 | } |
159 | 159 | $suffixLength++; |
160 | 160 | } |
161 | 161 | |
162 | - return $suffixLength / max( $localLength, $externalLength ); |
|
162 | + return $suffixLength / max($localLength, $externalLength); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @return float |
172 | 172 | */ |
173 | - private function percentageLevenshteinDistance( $value, $comparativeValue ) { |
|
174 | - $distance = levenshtein( $value, $comparativeValue ); |
|
175 | - $percentage = 1.0 - $distance / max( strlen( $value ), strlen( $comparativeValue ) ); |
|
173 | + private function percentageLevenshteinDistance($value, $comparativeValue) { |
|
174 | + $distance = levenshtein($value, $comparativeValue); |
|
175 | + $percentage = 1.0 - $distance / max(strlen($value), strlen($comparativeValue)); |
|
176 | 176 | |
177 | 177 | return $percentage; |
178 | 178 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return self |
66 | 66 | */ |
67 | - public static function newFromGlobalState( ApiMain $main, $name, $prefix = '' ) { |
|
67 | + public static function newFromGlobalState(ApiMain $main, $name, $prefix = '') { |
|
68 | 68 | $repo = WikibaseRepo::getDefaultInstance(); |
69 | 69 | $externalValidationServices = ExternalValidationServices::getDefaultInstance(); |
70 | 70 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $repo->getStatementGuidValidator(), |
77 | 77 | $externalValidationServices->getCrossCheckInteractor(), |
78 | 78 | $externalValidationServices->getSerializerFactory(), |
79 | - $repo->getApiHelperFactory( RequestContext::getMain() ) |
|
79 | + $repo->getApiHelperFactory(RequestContext::getMain()) |
|
80 | 80 | ); |
81 | 81 | } |
82 | 82 | |
@@ -100,14 +100,14 @@ discard block |
||
100 | 100 | SerializerFactory $serializerFactory, |
101 | 101 | ApiHelperFactory $apiHelperFactory |
102 | 102 | ) { |
103 | - parent::__construct( $main, $name, $prefix ); |
|
103 | + parent::__construct($main, $name, $prefix); |
|
104 | 104 | |
105 | 105 | $this->entityIdParser = $entityIdParser; |
106 | 106 | $this->statementGuidValidator = $statementGuidValidator; |
107 | 107 | $this->crossCheckInteractor = $crossCheckInteractor; |
108 | 108 | $this->serializerFactory = $serializerFactory; |
109 | - $this->resultBuilder = $apiHelperFactory->getResultBuilder( $this ); |
|
110 | - $this->errorReporter = $apiHelperFactory->getErrorReporter( $this ); |
|
109 | + $this->resultBuilder = $apiHelperFactory->getResultBuilder($this); |
|
110 | + $this->errorReporter = $apiHelperFactory->getErrorReporter($this); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -116,34 +116,34 @@ discard block |
||
116 | 116 | public function execute() { |
117 | 117 | $params = $this->extractRequestParams(); |
118 | 118 | |
119 | - if ( $params['entities'] && $params['claims'] ) { |
|
119 | + if ($params['entities'] && $params['claims']) { |
|
120 | 120 | $this->errorReporter->dieError( |
121 | 121 | 'Either provide the ids of entities or ids of claims, that should be cross-checked.', |
122 | 122 | 'param-invalid' |
123 | 123 | ); |
124 | 124 | throw new LogicException(); |
125 | - } elseif ( $params['entities'] ) { |
|
126 | - $entityIds = $this->parseEntityIds( $params['entities'] ); |
|
127 | - if ( $params['properties'] ) { |
|
128 | - $propertyIds = $this->parseEntityIds( $params['properties'] ); |
|
129 | - $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIdWithProperties( $entityIds, $propertyIds ); |
|
125 | + } elseif ($params['entities']) { |
|
126 | + $entityIds = $this->parseEntityIds($params['entities']); |
|
127 | + if ($params['properties']) { |
|
128 | + $propertyIds = $this->parseEntityIds($params['properties']); |
|
129 | + $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIdWithProperties($entityIds, $propertyIds); |
|
130 | 130 | } else { |
131 | - $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIds( $entityIds ); |
|
131 | + $resultLists = $this->crossCheckInteractor->crossCheckEntitiesByIds($entityIds); |
|
132 | 132 | } |
133 | - } elseif ( $params['claims'] ) { |
|
133 | + } elseif ($params['claims']) { |
|
134 | 134 | $guids = $params['claims']; |
135 | - $this->assertAreValidClaimGuids( $guids ); |
|
136 | - $resultLists = $this->crossCheckInteractor->crossCheckStatementsByGuids( $guids ); |
|
135 | + $this->assertAreValidClaimGuids($guids); |
|
136 | + $resultLists = $this->crossCheckInteractor->crossCheckStatementsByGuids($guids); |
|
137 | 137 | } else { |
138 | 138 | $this->errorReporter->dieWithError( |
139 | - [ 'wikibase-api-param-missing', 'entities|claims' ], |
|
139 | + ['wikibase-api-param-missing', 'entities|claims'], |
|
140 | 140 | 'param-missing' |
141 | 141 | ); |
142 | 142 | throw new LogicException(); |
143 | 143 | } |
144 | 144 | |
145 | 145 | // Print result lists |
146 | - $this->writeResultOutput( $resultLists ); |
|
146 | + $this->writeResultOutput($resultLists); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,9 +151,9 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @return EntityId[] |
153 | 153 | */ |
154 | - private function parseEntityIds( array $entityIds ) { |
|
154 | + private function parseEntityIds(array $entityIds) { |
|
155 | 155 | return array_map( |
156 | - [ $this->entityIdParser, 'parse' ], |
|
156 | + [$this->entityIdParser, 'parse'], |
|
157 | 157 | $entityIds |
158 | 158 | ); |
159 | 159 | } |
@@ -161,10 +161,10 @@ discard block |
||
161 | 161 | /** |
162 | 162 | * @param string[] $guids |
163 | 163 | */ |
164 | - private function assertAreValidClaimGuids( array $guids ) { |
|
165 | - foreach ( $guids as $guid ) { |
|
166 | - if ( $this->statementGuidValidator->validateFormat( $guid ) === false ) { |
|
167 | - $this->errorReporter->dieError( 'Invalid claim guid.', 'invalid-guid' ); |
|
164 | + private function assertAreValidClaimGuids(array $guids) { |
|
165 | + foreach ($guids as $guid) { |
|
166 | + if ($this->statementGuidValidator->validateFormat($guid) === false) { |
|
167 | + $this->errorReporter->dieError('Invalid claim guid.', 'invalid-guid'); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | } |
@@ -174,13 +174,13 @@ discard block |
||
174 | 174 | * |
175 | 175 | * @param array $resultLists |
176 | 176 | */ |
177 | - private function writeResultOutput( array $resultLists ) { |
|
177 | + private function writeResultOutput(array $resultLists) { |
|
178 | 178 | $serializer = $this->serializerFactory->newCrossCheckResultListSerializer(); |
179 | 179 | |
180 | 180 | $output = []; |
181 | - foreach ( $resultLists as $entityId => $resultList ) { |
|
182 | - if ( $resultList ) { |
|
183 | - $serializedResultList = $serializer->serialize( $resultList ); |
|
181 | + foreach ($resultLists as $entityId => $resultList) { |
|
182 | + if ($resultList) { |
|
183 | + $serializedResultList = $serializer->serialize($resultList); |
|
184 | 184 | |
185 | 185 | $output[$entityId] = $serializedResultList; |
186 | 186 | } else { |
@@ -190,10 +190,10 @@ discard block |
||
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
193 | - $this->getResult()->setIndexedTagName( $output, 'entity' ); |
|
194 | - $this->getResult()->setArrayType( $output, 'kvp', 'id' ); |
|
195 | - $this->getResult()->addValue( null, 'results', $output ); |
|
196 | - $this->resultBuilder->markSuccess( 1 ); |
|
193 | + $this->getResult()->setIndexedTagName($output, 'entity'); |
|
194 | + $this->getResult()->setArrayType($output, 'kvp', 'id'); |
|
195 | + $this->getResult()->addValue(null, 'results', $output); |
|
196 | + $this->resultBuilder->markSuccess(1); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -1,11 +1,11 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( function_exists( 'wfLoadExtension' ) ) { |
|
4 | - wfLoadExtension( 'WikibaseQualityExternalValidation', __DIR__ . '/extension.json' ); |
|
3 | +if (function_exists('wfLoadExtension')) { |
|
4 | + wfLoadExtension('WikibaseQualityExternalValidation', __DIR__.'/extension.json'); |
|
5 | 5 | // Keep i18n globals so mergeMessageFileList.php doesn't break |
6 | - $GLOBALS['wgMessagesDirs']['WikibaseQualityExternalValidation'] = __DIR__ . '/i18n'; |
|
6 | + $GLOBALS['wgMessagesDirs']['WikibaseQualityExternalValidation'] = __DIR__.'/i18n'; |
|
7 | 7 | $GLOBALS['wgExtensionMessagesFiles']['WikibaseQualityExternalValidationAlias'] = |
8 | - __DIR__ . '/WikibaseQualityExternalValidation.alias.php'; |
|
8 | + __DIR__.'/WikibaseQualityExternalValidation.alias.php'; |
|
9 | 9 | /* wfWarn( |
10 | 10 | 'Deprecated PHP entry point used for WikibaseQualityConstraints extension. ' . |
11 | 11 | 'Please use wfLoadExtension instead, ' . |
@@ -13,5 +13,5 @@ discard block |
||
13 | 13 | ); */ |
14 | 14 | return; |
15 | 15 | } else { |
16 | - die( 'This version of the WikibaseQualityExternalValidation extension requires MediaWiki 1.25+' ); |
|
16 | + die('This version of the WikibaseQualityExternalValidation extension requires MediaWiki 1.25+'); |
|
17 | 17 | } |