jenkins-bot has submitted this change and it was merged. Change subject: Make template wrapping optional ......................................................................
Make template wrapping optional adjusted the template wrapping so that: * wrapping a creator parameter in a creator template is optional. * reversing last name, first name of the creator value is optional. * wrapping the institution value in an institution template is optional. * wrapping of elements using lang= in a language template is optional. * detecting and creating a permission template is optional. * a global permission can be used instead of a metadata value. * added new i18n messages * added new form fields * adjusted logic accordingly Bug: 64060 Bug: 65248 Change-Id: Ia5f7f54f17c19f7373cc264eee5329565d585f54 --- M i18n/en.json M i18n/qqq.json M includes/Forms/MetadataMappingForm.php M includes/Handlers/Forms/MetadataMappingHandler.php M includes/Handlers/Xml/XmlMappingHandler.php M includes/Models/MediawikiTemplate.php 6 files changed, 459 insertions(+), 127 deletions(-) Approvals: Gilles: Looks good to me, approved jenkins-bot: Verified diff --git a/i18n/en.json b/i18n/en.json index 6041f8e..c6caca9 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -203,5 +203,21 @@ "gwtoolset-wiki-checks-not-passed": "Wiki checks did not pass", "gwtoolset-title-too-long": "The evaluated title is too long; a title can be up to a maximum of 240 bytes in length. This title evaluates to $1 {{PLURAL:$1|byte|bytes}} in length.\n\n$2.", "gwtoolset-title-label": "GWToolset title", - "gwtoolset-url-to-the-media-file-label": "URL to the media file" + "gwtoolset-url-to-the-media-file-label": "URL to the media file", + "gwtoolset-reverse-creator": "Reverse last name, first name", + "gwtoolset-reverse-creator-explanation": "Sometimes the creator value is listed as last name, first name in the metadata; checking this checkbox will reverse that order and remove the comma; e.g., da Vinci, Leonardo would become Leonardo da Vinci. Note, this relies on a single comma in the value; if there is no comma in the value, no change will be made. If there is more than one comma, the change will only be made using the first comma.", + "gwtoolset-wrap-creator": "Wrap creator in the creator template", + "gwtoolset-wrap-creator-explanation": "The MediaWiki template may have an <code>author</code>, <code>artist</code>, <code>publisher</code> or similar parameter; when it does, the metadata value mapped to it can automatically be wrapped in <code>{{Creator:<value>}}</code>.", + "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 <code>{{Institution:<value>}}</code>.", + "gwtoolset-wrap-institution-heading": "Institution template", + "gwtoolset-wrap-language": "Wrap metadata in a language template", + "gwtoolset-wrap-language-explanation": "Sometimes a metadata element may contain a <code>lang</code> attribute; when it does, the value can be wrapped in a language template; e.g., <code><dc:description lang=\"en\">A sentence written in English.</dc:description></code> would become {{en|A sentence written in English.}}", + "gwtoolset-wrap-language-heading": "Language template", + "gwtoolset-detect-license": "Attempt to detect the license", + "gwtoolset-detect-license-explanation": "The MediaWiki template may have a <code>permission</code> 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., https://creativecommons.org/licenses/by-sa/3.0/ matches the MediaWiki license template <code>{{tl|Template:Cc-by-sa-3.0}}</code>. 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 7c611d1..33a1699 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -199,5 +199,21 @@ "gwtoolset-wiki-checks-not-passed": "Heading used when a wiki requirement is not met.", "gwtoolset-title-too-long": "Message that appears when an evaluated title for an item is greater than 240 bytes. Parameters:\n* $1 is the length in bytes for this item's title.\n* $2 is the evaluated title.", "gwtoolset-title-label": "Label used in the metadata mapping section of Step 2: Metadata mapping.", - "gwtoolset-url-to-the-media-file-label": "Label used in the metadata mapping section of Step 2: Metadata mapping. The translation should not be longer than 21 characters; if it is, please leave it in English." + "gwtoolset-url-to-the-media-file-label": "Label used in the metadata mapping section of Step 2: Metadata mapping. The translation should not be longer than 21 characters; if it is, please leave it in English.", + "gwtoolset-reverse-creator": "Label used for the corresponding checkbox in the Step 2: Metadata mapping form.", + "gwtoolset-reverse-creator-explanation": "Explanation of the corresponding checkbox in the Step 2: Metadata mapping form.", + "gwtoolset-wrap-creator": "Label used for the corresponding checkbox in the Step 2: Metadata mapping form.", + "gwtoolset-wrap-creator-explanation": "Explanation of the corresponding checkbox in the Step 2: Metadata mapping form.", + "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-language": "Label used for the corresponding checkbox in the Step 2: Metadata mapping form.", + "gwtoolset-wrap-language-explanation": "Explanation of the corresponding checkbox in the Step 2: Metadata mapping form.", + "gwtoolset-wrap-language-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 d98888f..dca19b4 100644 --- a/includes/Forms/MetadataMappingForm.php +++ b/includes/Forms/MetadataMappingForm.php @@ -342,6 +342,157 @@ wfMessage( 'copyrightwarning2' )->parseAsBlock() . + // creator template + Html::rawElement( + 'h3', + array( 'style' => 'margin-top:1em;'), + wfMessage( 'gwtoolset-wrap-creator-heading' )->escaped() + ) . + + Html::rawElement( + 'p', + array(), + Html::rawElement( + 'label', + array(), + Html::rawElement( + 'input', + array( + 'type' => 'checkbox', + 'name' => 'gwtoolset-wrap-creator', + 'value' => 'true' + ) + ) . + ' ' . wfMessage( 'gwtoolset-wrap-creator' )->escaped() . + Html::rawElement( 'br' ) . + wfMessage( 'gwtoolset-wrap-creator-explanation' )->parse() + ) + ) . + + Html::rawElement( + 'p', + array(), + Html::rawElement( + 'label', + array(), + Html::rawElement( + 'input', + array( + 'type' => 'checkbox', + 'name' => 'gwtoolset-reverse-creator', + 'value' => 'true' + ) + ) . + ' ' . wfMessage( 'gwtoolset-reverse-creator' )->escaped() . + Html::rawElement( 'br' ) . + wfMessage( 'gwtoolset-reverse-creator-explanation' )->escaped() + ) + ) . + + // institution template + Html::rawElement( + 'h3', + array( 'style' => 'margin-top:1em;'), + wfMessage( 'gwtoolset-wrap-institution-heading' )->escaped() + ) . + + Html::rawElement( + 'p', + array(), + Html::rawElement( + 'label', + array(), + Html::rawElement( + 'input', + array( + 'type' => 'checkbox', + 'name' => 'gwtoolset-wrap-institution', + 'value' => 'true' + ) + ) . + ' ' . wfMessage( 'gwtoolset-wrap-institution' )->escaped() . + Html::rawElement( 'br' ) . + wfMessage( 'gwtoolset-wrap-institution-explanation' )->parse() + ) + ) . + + // language template + Html::rawElement( + 'h3', + array( 'style' => 'margin-top:1em;'), + wfMessage( 'gwtoolset-wrap-language-heading' )->escaped() + ) . + + Html::rawElement( + 'p', + array(), + Html::rawElement( + 'label', + array(), + Html::rawElement( + 'input', + array( + 'type' => 'checkbox', + 'name' => 'gwtoolset-wrap-language', + 'value' => 'true' + ) + ) . + ' ' . wfMessage( 'gwtoolset-wrap-language' )->escaped() . + Html::rawElement( 'br' ) . + wfMessage( 'gwtoolset-wrap-language-explanation' )->parse() + ) + ) . + + // 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' )->parse() + ) + ) . + + 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', array( 'style' => 'margin-top:1em;'), diff --git a/includes/Handlers/Forms/MetadataMappingHandler.php b/includes/Handlers/Forms/MetadataMappingHandler.php index 9c8840c..3d1b844 100644 --- a/includes/Handlers/Forms/MetadataMappingHandler.php +++ b/includes/Handlers/Forms/MetadataMappingHandler.php @@ -55,7 +55,13 @@ 'gwtoolset-record-begin' => array( 'size' => 255 ), 'gwtoolset-record-count' => array( 'size' => 255 ), 'gwtoolset-record-element-name' => array( 'size' => 255 ), - 'gwtoolset-reupload-media' => array( 'size' => 255 ), + 'gwtoolset-reupload-media' => array( 'size' => 4 ), + 'gwtoolset-reverse-creator' => array( 'size' => 4 ), + 'gwtoolset-wrap-creator' => array( 'size' => 4 ), + 'gwtoolset-wrap-institution' => array( 'size' => 4 ), + 'gwtoolset-wrap-language' => array( 'size' => 4 ), + 'gwtoolset-detect-license' => array( 'size' => 4 ), + 'gwtoolset-global-license' => array( 'size' => 255 ), 'wpEditToken' => array( 'size' => 255 ), 'wpSummary' => array( 'size' => 255 ) ); @@ -184,10 +190,20 @@ ? $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'] ) @@ -262,6 +278,26 @@ ? (bool)$this->_whitelisted_post['gwtoolset-reupload-media'] : false, + 'gwtoolset-reverse-creator' => + !empty( $this->_whitelisted_post['gwtoolset-reverse-creator'] ) + ? (bool)$this->_whitelisted_post['gwtoolset-reverse-creator'] + : false, + + 'gwtoolset-wrap-creator' => + !empty( $this->_whitelisted_post['gwtoolset-wrap-creator'] ) + ? (bool)$this->_whitelisted_post['gwtoolset-wrap-creator'] + : false, + + 'gwtoolset-wrap-institution' => + !empty( $this->_whitelisted_post['gwtoolset-wrap-institution'] ) + ? (bool)$this->_whitelisted_post['gwtoolset-wrap-institution'] + : false, + + 'gwtoolset-wrap-language' => + !empty( $this->_whitelisted_post['gwtoolset-wrap-language'] ) + ? (bool)$this->_whitelisted_post['gwtoolset-wrap-language'] + : false, + 'gwtoolset-url-to-the-media-file' => !empty( $this->_whitelisted_post['gwtoolset-url-to-the-media-file'] ) ? $this->_whitelisted_post['gwtoolset-url-to-the-media-file'] diff --git a/includes/Handlers/Xml/XmlMappingHandler.php b/includes/Handlers/Xml/XmlMappingHandler.php index 94a480a..e5d9871 100644 --- a/includes/Handlers/Xml/XmlMappingHandler.php +++ b/includes/Handlers/Xml/XmlMappingHandler.php @@ -135,13 +135,14 @@ * @todo possibly refactor so that it works with getDOMElementAsArray * * @param {DOMELement} $DOMElement + * @param {array} $user_options * * @return {array} * the keys and values in the array have not been filtered * an array that maps mediawiki template parameters to the metadata record * values provided by the DOMElement */ - protected function getDOMElementMapped( DOMElement $DOMElement ) { + protected function getDOMElementMapped( DOMElement $DOMElement, array $user_options ) { $elements_mapped = array(); $DOMNodeList = $DOMElement->getElementsByTagName( '*' ); @@ -173,7 +174,7 @@ foreach ( $template_parameters as $template_parameter ) { $is_url = strpos( $template_parameter, 'url' ) !== false; - if ( !empty( $lang ) ) { + if ( !empty( $lang ) && $user_options['gwtoolset-wrap-language'] ) { // within a record, multimple elements with the same element name, e.g., description // can exist. some may have a lang attribute and some may not. if the first element // found does not have a lang attribute it is stored as a value in @@ -377,7 +378,8 @@ $user_options, array( 'metadata-as-array' => $this->getDOMElementAsArray( $record ), - 'metadata-mapped-to-mediawiki-template' => $this->getDOMElementMapped( $record ), + 'metadata-mapped-to-mediawiki-template' => + $this->getDOMElementMapped( $record, $user_options ), 'metadata-raw' => $outer_xml ) ); diff --git a/includes/Models/MediawikiTemplate.php b/includes/Models/MediawikiTemplate.php index 8f0961d..c1c8974 100644 --- a/includes/Models/MediawikiTemplate.php +++ b/includes/Models/MediawikiTemplate.php @@ -51,7 +51,6 @@ */ protected $_sub_templates = array( 'language' => '{{%s|%s}}', - 'institution' => '{{Institution:%s}}', 'creator' => array( 'template' => '{{Creator:%s}}', 'parameters' => array( @@ -79,6 +78,104 @@ } public function delete( array &$options = array() ) { + } + + /** + * determines the MediaWiki template creator parameter + * evaluates whether or not the user has chosen to: + * + * - use the metadata value mapped to the institution parameter as is + * - or wrap the metadata value in an institution template + * + * @param {string} $content + * @param {array} $user_options + * @return {string} + */ + protected function getCreator( $content, array $user_options ) { + $result = ''; + + // assumes that there could be more than one creator in the string + // and uses the configured metadata separator for evaluation + $creators = explode( Config::$metadata_separator, $content ); + + foreach ( $creators as $creator ) { + // assumes that a creator entry could be last name, first + if ( $user_options['gwtoolset-reverse-creator'] ) { + $creator = explode( ',', $creator, 2 ); + } else { + $creator = array( $creator ); + } + + // handle empty string + if ( count( $creator ) === 1 && trim( $creator[0] ) === '' ) { + return $result; + } else { + // only consider the first 2 pieces of a reversed name + // e.g. Motzart, Wolfgang Amadeus = Wolfgang Amadeus Motzart + // e.g. Motzart, Wolfgang, Amadeus = Wolfgang Motzart + if ( count( $creator ) === 2 ) { + $creator = trim( $creator[1] ) . ' ' . trim( $creator[0] ); + } else { + $creator = $creator[0]; + } + + if ( $user_options['gwtoolset-wrap-creator'] ) { + $result .= sprintf( + $this->_sub_templates['creator']['template'], + $creator + ) . PHP_EOL; + } else { + $result .= $creator . PHP_EOL; + } + } + } + + return $result; + } + + /** + * creates wiki text for the GWToolset parameters + * + * @todo move this into a GWToolsetTemplate model + * + * @return {string} + * the result is sanitized + */ + public function getGWToolsetTemplateAsWikiText() { + return + '{{Uploaded with GWToolset' . PHP_EOL . + ' | gwtoolset-title = ' . + Utils::sanitizeString( + $this->mediawiki_template_array['gwtoolset-title'] + ) . PHP_EOL . + ' | gwtoolset-url-to-the-media-file = ' . + Utils::sanitizeString( + $this->mediawiki_template_array['gwtoolset-url-to-the-media-file'] + ) . PHP_EOL . + '}}' . + PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL; + } + + /** + * determines the MediaWiki template institution parameter + * evaluates whether or not the user has chosen to: + * + * - use the metadata value mapped to the institution parameter as is + * - or wrap the metadata value in an institution template + * + * @param {string} $content + * @param {array} $user_options + * @return {string} + */ + protected function getInstitution( $content, array $user_options ) { + if ( + trim( $content ) === '' + || !$user_options['gwtoolset-wrap-institution'] + ) { + return $content; + } + + return sprintf( '{{Institution:%s}}', $content ); } /** @@ -141,26 +238,105 @@ } /** - * creates wiki text for the GWToolset parameters + * determines the MediaWiki template permission parameter + * evaluates whether or not the user has chosen to: * - * @todo move this into a GWToolsetTemplate model + * - use a free text global license + * - detect and create a license template based on a cc license URL + * - use the metadata value mapped to the permission parameter * + * e.g. https://creativecommons.org/licenses/by-sa/3.0/ corresponds with + * the MediaWiki license template {{Template:Cc-by-sa-3.0}} + * + * @see http://commons.wikimedia.org/wiki/Category:Creative_Commons_licenses + * + * @param {string} $content + * @param {array} $user_options * @return {string} - * the result is sanitized */ - public function getGWToolsetTemplateAsWikiText() { - return - '{{Uploaded with GWToolset' . PHP_EOL . - ' | gwtoolset-title = ' . - Utils::sanitizeString( - $this->mediawiki_template_array['gwtoolset-title'] - ) . PHP_EOL . - ' | gwtoolset-url-to-the-media-file = ' . - Utils::sanitizeString( - $this->mediawiki_template_array['gwtoolset-url-to-the-media-file'] - ) . PHP_EOL . - '}}' . - PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL; + protected function getPermission( $content, array $user_options ) { + if ( !empty( $user_options['gwtoolset-global-license'] ) ) { + return $user_options['gwtoolset-global-license']; + } else if ( $user_options['gwtoolset-detect-license'] ) { + $permission = strtolower( $content ); + } else { + return $content; + } + + if ( !strstr( $permission, 'creativecommons.org/' ) ) { + return $content; + } + + $licenses = array( + '/(http|https):\/\/(www\.|)creativecommons.org\/publicdomain\/mark\/1.0\//' => + '{{PD-US}}{{PD-old}}', // Public Domain Mark 1.0 + '/(http|https):\/\/(www\.|)creativecommons.org\/publicdomain\/zero\/1.0\//' => + '{{Cc-zero}}', // CC0 1.0 Universal (CC0 1.0) Public Domain Dedication + '/(http|https):\/\/(www\.|)creativecommons.org\/licenses\//' => + '', + '/deed\.*/' => + '' + ); + + $permission = preg_replace( + array_keys( $licenses ), + array_values( $licenses ), + $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; + } + + /** + * determines the MediaWiki template source parameter + * evaluates whether or not the user has chosen to: + * + * - use a free text source template + * adds the metadata value mapped to the source parameter + * and adds the free text value + * assumes that the free text value must be wrapped in {{}} + * - use the metadata value mapped to the source parameter + * + * @param {string} $content + * @param {array} $user_options + * @return {string} + */ + protected function getSource( $content, array $user_options ) { + if ( !empty( $user_options['partner-template-name'] ) ) { + return + $content . + '{{' . + Utils::sanitizeString( $user_options['partner-template-name'] ) . + '}}'; + } else { + return $content; + } } /** @@ -180,7 +356,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}}'; @@ -194,16 +370,19 @@ $sections .= ' | ' . Utils::sanitizeString( $parameter ) . ' = '; - /** - * sometimes the metadata element has several "shared" metadata - * elements with the same element name. at the moment the - * application will add elements that use lang= attribute to an - * associative array element 'language' indicating that the mediawiki - * template should use the language subtemplate - */ + // sometimes a metadata element has an XML attribute that the tools + // looks for in order to possibly place the metadata into a + // sub-template, e.g., <dc:description lang="en"> + // + // currently the application only looks for XML elements with the + // attribute lang; those elements are placed into an associative array + // 'language' and are processed here. no other array grouping is + // currently created. + // + // this section is meant to handle this current scenario and any future + // scenarios of this type. if ( is_array( $content ) ) { foreach ( $content as $sub_template_name => $sub_template_content ) { - // currently only language is handled as a sub-template if ( $sub_template_name === 'language' ) { foreach ( $sub_template_content as $language => $language_content ) { $sections .= sprintf( @@ -212,112 +391,44 @@ Utils::sanitizeString( $language_content ) ) . PHP_EOL; } - /** - * sometimes the "shared" metadata element will indicate lang, - * sometimes not this section handles those "shared" metadata - * elements that do not specify a lang attribute - */ + + // sometimes there is more than one metadata element with the same + // element name that falls into this sub-templating scenario; one + // has an XML attribute the tool looks for, and another does not. + // when one of those "shared" elements does not have the XML + // attribute the tool is looking for, it falls into this section and + // is not wrapped in a sub-template. } else { $sections .= Utils::sanitizeString( $sub_template_content ) . PHP_EOL; } } } else { - $content = trim( $content ); - + // institution parameter if ( $parameter === 'institution' ) { - if ( trim( $content ) === '' ) { - $sections .= PHP_EOL; - } else { - $sections .= sprintf( - $this->_sub_templates['institution'], - Utils::sanitizeString( $content ) - ) . PHP_EOL; - } - } elseif ( in_array( $parameter, $this->_sub_templates['creator']['parameters'] ) ) { - // assumes that there could be more than one creator and uses the - // configured metadata separator to determine that - $creators = explode( Config::$metadata_separator, $content ); + $institution = $this->getInstitution( $content, $user_options ); + $sections .= Utils::sanitizeString( $institution ) . PHP_EOL; - foreach ( $creators as $creator ) { - // assumes that a creator entry could be last name, first - // no other assumptions are made other than this one - $creator = explode( ',', $creator, 2 ); + // creator parameter + } elseif ( + in_array( + $parameter, + $this->_sub_templates['creator']['parameters'] + ) + ) { + $creator = $this->getCreator( $content, $user_options ); + $sections .= Utils::sanitizeString( $creator ); - if ( count( $creator ) <= 1 && trim( $creator[0] ) === '' ) { - $sections .= PHP_EOL; - } else { - if ( count( $creator ) === 2 ) { - $creator = trim( $creator[1] ) . ' ' . trim( $creator[0] ); - } else { - $creator = trim( $creator[0] ); - } - - $sections .= sprintf( - $this->_sub_templates['creator']['template'], - Utils::sanitizeString( $creator ) - ) . PHP_EOL; - } - } + // permission parameter } 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]; - } - } else { - $permission = $content; - } - + $permission = $this->getPermission( $content, $user_options ); $sections .= Utils::sanitizeString( $permission ) . PHP_EOL; + + // source parameter } elseif ( $parameter === 'source' ) { - if ( !empty( $user_options['partner-template-name'] ) ) { - $sections .= Utils::sanitizeString( $content ) . - '{{' . - Utils::sanitizeString( $user_options['partner-template-name'] ) . - '}}' . - PHP_EOL; - } else { - $sections .= Utils::sanitizeString( $content ) . PHP_EOL; - } + $source = $this->getSource( $content, $user_options ); + $sections .= Utils::sanitizeString( $source ) . PHP_EOL; + + // all other parameters } else { $sections .= Utils::sanitizeString( $content ) . PHP_EOL; } -- To view, visit https://gerrit.wikimedia.org/r/133476 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ia5f7f54f17c19f7373cc264eee5329565d585f54 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/GWToolset Gerrit-Branch: master Gerrit-Owner: Dan-nl <d_ent...@yahoo.com> Gerrit-Reviewer: Dan-nl <d_ent...@yahoo.com> Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org> Gerrit-Reviewer: Gilles <gdu...@wikimedia.org> Gerrit-Reviewer: MarkTraceur <mtrac...@member.fsf.org> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: Steinsplitter <steinsplit...@wikipedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits