Dan-nl has uploaded a new change for review. https://gerrit.wikimedia.org/r/133293
Change subject: Global permission, license, copyright tag ...................................................................... Global permission, license, copyright tag * added new i18n messages * added new form fields * adjusted logic accordingly Bug: 65248 Change-Id: I3cf59fb5f67702177e4acbe0e916885084230104 --- M i18n/en.json M i18n/qqq.json M includes/Forms/MetadataMappingForm.php M includes/Handlers/Forms/MetadataMappingHandler.php M includes/Models/MediawikiTemplate.php 5 files changed, 138 insertions(+), 47 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GWToolset refs/changes/93/133293/1 diff --git a/i18n/en.json b/i18n/en.json index a14a703..32ef580 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -205,5 +205,10 @@ "gwtoolset-wrap-creator-heading": "Creator template", "gwtoolset-wrap-institution": "Wrap institution in the institution template", "gwtoolset-wrap-institution-explanation": "The MediaWiki template may have an institution parameter; when it does, the metadata value mapped to it can automatically be wrapped in {{Institution:<value>}}.", - "gwtoolset-wrap-institution-heading": "Institution template" + "gwtoolset-wrap-institution-heading": "Institution template", + "gwtoolset-detect-license": "Attempt to detect the license", + "gwtoolset-detect-license-explanation": "The MediaWiki template may have a permission parameter; when it does, an attempt to detect the copyright license based on the metadata value can be made. GWToolset looks for creative commons urls that match possible copyright licenses; e.g., http://creativecommons.org/licenses/by-sa/3.0/ matches the MediaWiki license template {{Template:Cc-by-sa-3.0}}. If this checkbox is left unchecked, the raw metadata value for each item in the batch upload will be placed in the permission parameter.", + "gwtoolset-detect-license-heading": "License template", + "gwtoolset-global-license": "Global license", + "gwtoolset-global-license-explanation": "Or you can specific a global license below that will be applied to all items in the batch upload. This value can be a free text value or a MediaWiki template. If this field has a value in it then any metadata value mapped to the permission parameter will be ignored." } diff --git a/i18n/qqq.json b/i18n/qqq.json index d53aa32..ffd828b 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -206,5 +206,10 @@ "gwtoolset-wrap-creator-heading": "Heading for the corresponding section in the Step 2: Metadata mapping form.", "gwtoolset-wrap-institution": "Label used for the corresponding checkbox in the Step 2: Metadata mapping form.", "gwtoolset-wrap-institution-explanation": "Explanation of the corresponding checkbox in the Step 2: Metadata mapping form.", - "gwtoolset-wrap-institution-heading": "Heading for the corresponding section in the Step 2: Metadata mapping form." + "gwtoolset-wrap-institution-heading": "Heading for the corresponding section in the Step 2: Metadata mapping form.", + "gwtoolset-detect-license": "Label used for the corresponding checkbox in the Step 2: Metadata mapping form.", + "gwtoolset-detect-license-explanation": "Explanation of the corresponding checkbox in the Step 2: Metadata mapping form.", + "gwtoolset-detect-license-heading": "Heading for the corresponding section in the Step 2: Metadata mapping form.", + "gwtoolset-global-license": "Label used for the corresponding input field in the Step 2: Metadata mapping form.", + "gwtoolset-global-license-explanation": "Explanation of the corresponding input field in the Step 2: Metadata mapping form." } diff --git a/includes/Forms/MetadataMappingForm.php b/includes/Forms/MetadataMappingForm.php index 8fa50ee..f8f1803 100644 --- a/includes/Forms/MetadataMappingForm.php +++ b/includes/Forms/MetadataMappingForm.php @@ -416,6 +416,55 @@ ) ) . + // permission/license template + Html::rawElement( + 'h3', + array( 'style' => 'margin-top:1em;'), + wfMessage( 'gwtoolset-detect-license-heading' )->escaped() + ) . + + Html::rawElement( + 'p', + array(), + Html::rawElement( + 'label', + array(), + Html::rawElement( + 'input', + array( + 'type' => 'checkbox', + 'name' => 'gwtoolset-detect-license', + 'value' => 'true' + ) + ) . + ' ' . wfMessage( 'gwtoolset-detect-license' )->escaped() . + Html::rawElement( 'br' ) . + wfMessage( 'gwtoolset-detect-license-explanation' )->plain() + ) + ) . + + Html::rawElement( + 'p', + array(), + Html::rawElement( + 'span', + array( 'style' => 'font-style:italic;text-decoration:underline;' ), + wfMessage( 'gwtoolset-global-license' )->escaped() + ) . + Html::rawElement( 'br' ) . + wfMessage( 'gwtoolset-global-license-explanation' )->escaped() + ) . + + Html::rawElement( + 'input', + array( + 'type' => 'text', + 'name' => 'gwtoolset-global-license', + 'placeholder' => wfMessage( 'gwtoolset-global-license' ), + 'class' => 'gwtoolset-url-input' + ) + ) . + // global categories Html::rawElement( 'h3', diff --git a/includes/Handlers/Forms/MetadataMappingHandler.php b/includes/Handlers/Forms/MetadataMappingHandler.php index eb4e3fb..219875a 100644 --- a/includes/Handlers/Forms/MetadataMappingHandler.php +++ b/includes/Handlers/Forms/MetadataMappingHandler.php @@ -59,6 +59,8 @@ 'gwtoolset-reverse-creator' => array( 'size' => 4 ), 'gwtoolset-wrap-creator' => array( 'size' => 4 ), 'gwtoolset-wrap-institution' => array( 'size' => 4 ), + 'gwtoolset-detect-license' => array( 'size' => 4 ), + 'gwtoolset-global-license' => array( 'size' => 255 ), 'wpEditToken' => array( 'size' => 255 ), 'wpSummary' => array( 'size' => 255 ) ); @@ -187,11 +189,21 @@ ? $this->_whitelisted_post['gwtoolset-category-metadata'] : array(), + 'gwtoolset-detect-license' => + !empty( $this->_whitelisted_post['gwtoolset-detect-license'] ) + ? (bool)$this->_whitelisted_post['gwtoolset-detect-license'] + : false, + 'comment' => !empty( $this->_whitelisted_post['wpSummary'] ) ? $this->_whitelisted_post['wpSummary'] : '', + 'gwtoolset-global-license' => + !empty( $this->_whitelisted_post['gwtoolset-global-license'] ) + ? $this->_whitelisted_post['gwtoolset-global-license'] + : null, + 'gwtoolset-mediafile-throttle' => !empty( $this->_whitelisted_post['gwtoolset-mediafile-throttle'] ) ? Utils::sanitizeNumericRange( diff --git a/includes/Models/MediawikiTemplate.php b/includes/Models/MediawikiTemplate.php index 16c6114..f3dd93f 100644 --- a/includes/Models/MediawikiTemplate.php +++ b/includes/Models/MediawikiTemplate.php @@ -164,6 +164,66 @@ } /** + * attempts to detect a valid cc license in the string given and if found, + * places the license within a wikitext template + * + * @see http://commons.wikimedia.org/wiki/Category:Creative_Commons_licenses + * + * @param {string} $content + * @return {string} + */ + protected function getPermissionTemplate( $content ) { + $permission = strtolower( $content ); + + if ( !strstr( $permission, 'creativecommons.org/' ) ) { + return $content; + } + + $patterns = array( + '/(http|https):\/\/(www\.|)creativecommons.org\/publicdomain\/mark\/1.0\//', + '/(http|https):\/\/(www\.|)creativecommons.org\/publicdomain\/zero\/1.0\//', + '/(http|https):\/\/(www\.|)creativecommons.org\/licenses\//', + '/deed\.*/' + ); + + $replacements = array( + '{{PD-US}}{{PD-old}}', // Public Domain Mark 1.0 + '{{Cc-zero}}', // CC0 1.0 Universal (CC0 1.0) Public Domain Dedication + '', + '' + ); + + $permission = preg_replace( $patterns, $replacements, $permission ); + $permission = explode( '/', $permission ); + + if ( count( $permission ) > 1 ) { + $i = 0; + $string = '{{Cc-'; + + foreach ( $permission as $piece ) { + if ( !empty( $piece ) ) { + $string .= $piece . '-'; + } + + $i++; + + // limit licenses path depth to 3 + if ( $i == 3 ) { + break; + } + } + + $string = substr( $string, 0, strlen( $string ) - 1 ); + $string .= '}}'; + $permission = $string; + } else { + $permission = $permission[0]; + } + + return $permission; + } + + /** * creates wiki text for a given mediawiki template. * creates the mediawiki template section of the template. * this does not include categories, raw metadata, or raw @@ -180,7 +240,7 @@ * @return {string} * the resulting wiki text is filtered */ - public function getTemplateAsWikiText( array &$user_options ) { + public function getTemplateAsWikiText( array $user_options ) { $result = ''; $sections = null; $template = '{{' . $this->mediawiki_template_name . PHP_EOL . '%s}}'; @@ -271,50 +331,10 @@ } } } elseif ( $parameter === 'permission' ) { - // http://commons.wikimedia.org/wiki/Category:Creative_Commons_licenses - $permission = strtolower( $content ); - - if ( strstr( $permission, 'creativecommons.org/' ) ) { - $patterns = array( - '/(http|https):\/\/(www\.|)creativecommons.org\/publicdomain\/mark\/1.0\//', - '/(http|https):\/\/(www\.|)creativecommons.org\/publicdomain\/zero\/1.0\//', - '/(http|https):\/\/(www\.|)creativecommons.org\/licenses\//', - '/deed\.*/' - ); - - $replacements = array( - '{{PD-US}}{{PD-old}}', // Public Domain Mark 1.0 - '{{Cc-zero}}', // CC0 1.0 Universal (CC0 1.0) Public Domain Dedication - '', - '' - ); - - $permission = preg_replace( $patterns, $replacements, $permission ); - $permission = explode( '/', $permission ); - - if ( count( $permission ) > 1 ) { - $i = 0; - $string = '{{Cc-'; - - foreach ( $permission as $piece ) { - if ( !empty( $piece ) ) { - $string .= $piece . '-'; - } - - $i++; - - // limit licenses path depth to 3 - if ( $i == 3 ) { - break; - } - } - - $string = substr( $string, 0, strlen( $string ) - 1 ); - $string .= '}}'; - $permission = $string; - } else { - $permission = $permission[0]; - } + if ( !empty( $user_options['gwtoolset-global-license'] ) ) { + $permission = $user_options['gwtoolset-global-license']; + } else if ( $user_options['gwtoolset-detect-license'] ) { + $permission = $this->getPermissionTemplate( $content ); } else { $permission = $content; } -- To view, visit https://gerrit.wikimedia.org/r/133293 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3cf59fb5f67702177e4acbe0e916885084230104 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/GWToolset Gerrit-Branch: master Gerrit-Owner: Dan-nl <d_ent...@yahoo.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits