Gergő Tisza has uploaded a new change for review.
https://gerrit.wikimedia.org/r/282142
Change subject: Check all license metadata blocks for nonfree flag
......................................................................
Check all license metadata blocks for nonfree flag
Bug: T131896
Change-Id: I65ab0ff56bf64bb519dd8e53d54ede520e120ffa
---
M DataCollector.php
M tests/phpunit/DataCollectorTest.php
2 files changed, 38 insertions(+), 2 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CommonsMetadata
refs/changes/42/282142/1
diff --git a/DataCollector.php b/DataCollector.php
index 12cc375..f423901 100644
--- a/DataCollector.php
+++ b/DataCollector.php
@@ -387,10 +387,22 @@
}
return $license['LicenseShortName'];
} );
-
// sortDataByLicensePriority puts things in right order but
also rearranges the keys - we don't want that
$sortedLicenses = array_values( $sortedLicenses );
- return $sortedLicenses ? $sortedLicenses[0] : array();
+
+ if ( !$sortedLicenses ) {
+ return array();
+ }
+
+ // T131896 - if any license template is marked nonfree, the
image is probably nonfree
+ foreach ( $sortedLicenses as $license ) {
+ if ( !empty( $license['NonFree'] ) ) {
+ $sortedLicenses[0]['NonFree'] =
$license['NonFree'];
+ break;
+ }
+ }
+
+ return $sortedLicenses[0];
}
/**
diff --git a/tests/phpunit/DataCollectorTest.php
b/tests/phpunit/DataCollectorTest.php
index d4c625d..5868c2a 100644
--- a/tests/phpunit/DataCollectorTest.php
+++ b/tests/phpunit/DataCollectorTest.php
@@ -195,6 +195,30 @@
$this->assertMetadataValue( 'AuthorCount', 2, $templateData );
}
+ public function testNonfreeFlag() {
+ // T131896 - NonFree flag cannot be overwritten
+ $getTemplateMetadataMethod = new \ReflectionMethod(
$this->dataCollector, 'getTemplateMetadata' );
+ $getTemplateMetadataMethod->setAccessible( true );
+
+ $template1 = array( 'LicenseShortName' => 'Fair Use' );
+ $template2 = array( 'LicenseShortName' => 'Fair Use', 'NonFree'
=> '1' );
+
+ $templateData = $getTemplateMetadataMethod->invokeArgs(
$this->dataCollector, array( array(
+ TemplateParser::LICENSES_KEY => array( $template1 ),
+ ) ) );
+ $this->assertArrayNotHasKey( 'NonFree', $templateData );
+
+ $templateData = $getTemplateMetadataMethod->invokeArgs(
$this->dataCollector, array( array(
+ TemplateParser::LICENSES_KEY => array( $template1,
$template2 ),
+ ) ) );
+ $this->assertMetadataValue( 'NonFree', '1', $templateData );
+
+ $templateData = $getTemplateMetadataMethod->invokeArgs(
$this->dataCollector, array( array(
+ TemplateParser::LICENSES_KEY => array( $template2,
$template1 ),
+ ) ) );
+ $this->assertMetadataValue( 'NonFree', '1', $templateData );
+ }
+
/*-------------------- verifyAttributionMetadata tests -------------*/
public function testVerifyAttributionMetadata() {
--
To view, visit https://gerrit.wikimedia.org/r/282142
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I65ab0ff56bf64bb519dd8e53d54ede520e120ffa
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CommonsMetadata
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits