Dan-nl has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/134073

Change subject: Max title length
......................................................................

Max title length

* adjusted i18n messages
* adjusted the Config:$title_max_length to 240
* changed the title logic: no longer truncate the title; issue an exception
  when the title is too long
* changed the key gwtoolset-title-identifier to gwtoolset-title for
  clarity within the metadata mapping form and in the code

Bug: 65323
Change-Id: I92dfe622e40bf9873e0b0c615a0d0ad8a9daf3e0
---
M i18n/en.json
M i18n/qqq.json
M includes/Config.php
M includes/Handlers/Forms/MetadataMappingHandler.php
M includes/Handlers/UploadHandler.php
M includes/Handlers/Xml/XmlDetectHandler.php
M includes/Handlers/Xml/XmlMappingHandler.php
M includes/Models/MediawikiTemplate.php
8 files changed, 62 insertions(+), 72 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GWToolset 
refs/changes/73/134073/1

diff --git a/i18n/en.json b/i18n/en.json
index 3a6258b..9491bdc 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -147,8 +147,7 @@
        "gwtoolset-maps-to": "Maps to",
        "gwtoolset-mapping-media-file-url-extension-bad": "The file extension 
could not be determined from the file URL: $1.",
        "gwtoolset-mapping-media-file-url-bad": "The media file URL could not 
be evaluated. The URL delivers the content in a way that is not yet handled by 
this extension or there was an HTTP request issue. URL given was \"$1\". HTTP 
request error \"$2\".",
-       "gwtoolset-mapping-no-title": "The metadata mapping contains no title, 
which is needed in order to create the page.",
-       "gwtoolset-mapping-no-title-identifier": "The metadata mapping contains 
no title identifier, which is used to create a unique page title. Make sure you 
map a metadata field to the MediaWiki template parameter title identifier.",
+       "gwtoolset-mapping-no-gwtoolset-title": "The metadata mapping contains 
no gwtoolset title, which is needed in order to create the page.",
        "gwtoolset-metadata-field": "Metadata field",
        "gwtoolset-metadata-file": "Metadata file",
        "gwtoolset-metadata-mapping-legend": "Map your metadata",
@@ -201,5 +200,8 @@
        "gwtoolset-verify-php-version": "The $1 extension requires PHP >= 
5.3.3.",
        "gwtoolset-verify-uploads-enabled": "The $1 extension requires that 
file uploads are enabled.\n\nPlease make sure that 
<code>$wgEnableUploads</code> is set to <code>true</code> in 
<code>LocalSettings.php</code>.",
        "gwtoolset-verify-xmlreader": "The $1 extension requires that PHP 
[http://www.php.net/manual/en/xmlreader.setup.php XMLReader] be installed.",
-       "gwtoolset-wiki-checks-not-passed": "Wiki checks did not pass"
+       "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 
{{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"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 0794712..acce229 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -198,5 +198,8 @@
        "gwtoolset-verify-php-version": "Message that appears when the PHP 
version is less than version 5.3.3. Parameters:\n* $1 - \"GWToolset\" 
(untranslatable)",
        "gwtoolset-verify-uploads-enabled": "Message that appears when the wiki 
does not allow file uploads. Parameters:\n* $1 - \"GWToolset\" 
(untranslatable)",
        "gwtoolset-verify-xmlreader": "Message that appears when PHP XMLReader 
is not available. Parameters:\n* $1 - \"GWToolset\" (untranslatable)",
-       "gwtoolset-wiki-checks-not-passed": "Heading used when a wiki 
requirement is not met."
+       "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."
 }
diff --git a/includes/Config.php b/includes/Config.php
index a354690..57d175d 100644
--- a/includes/Config.php
+++ b/includes/Config.php
@@ -218,7 +218,7 @@
         * title maximum length in bytes
         * @see https://commons.wikimedia.org/wiki/Commons:File_naming
         */
-       public static $title_max_length = 207;
+       public static $title_max_length = 240;
 
        /**
         * @var {string}
diff --git a/includes/Handlers/Forms/MetadataMappingHandler.php 
b/includes/Handlers/Forms/MetadataMappingHandler.php
index a9dbe98..9c8840c 100644
--- a/includes/Handlers/Forms/MetadataMappingHandler.php
+++ b/includes/Handlers/Forms/MetadataMappingHandler.php
@@ -252,9 +252,9 @@
                                ? 
(bool)$this->_whitelisted_post['save-as-batch-job']
                                : false,
 
-                       'gwtoolset-title-identifier' =>
-                               !empty( 
$this->_whitelisted_post['gwtoolset-title-identifier'] )
-                               ? 
$this->_whitelisted_post['gwtoolset-title-identifier']
+                       'gwtoolset-title' =>
+                               !empty( 
$this->_whitelisted_post['gwtoolset-title'] )
+                               ? $this->_whitelisted_post['gwtoolset-title']
                                : null,
 
                        'gwtoolset-reupload-media' =>
@@ -504,7 +504,7 @@
                                'gwtoolset-mediawiki-template-name',
                                'gwtoolset-record-count',
                                'gwtoolset-record-element-name',
-                               'gwtoolset-title-identifier',
+                               'gwtoolset-title',
                                'gwtoolset-url-to-the-media-file',
                                'gwtoolset-metadata-file-relative-path'
                        )
diff --git a/includes/Handlers/UploadHandler.php 
b/includes/Handlers/UploadHandler.php
index 6025d8b..62a95d5 100644
--- a/includes/Handlers/UploadHandler.php
+++ b/includes/Handlers/UploadHandler.php
@@ -911,7 +911,9 @@
                                        ->params( wfMessage( 
'gwtoolset-no-text' )->escaped() )
                                        ->parse()
                        );
-               }if ( empty( $options['title'] ) ) {
+               }
+
+               if ( empty( $options['title'] ) ) {
                        throw new MWException(
                                wfMessage( 'gwtoolset-developer-issue' )
                                        ->params( wfMessage( 
'gwtoolset-no-title' )->escaped() )
diff --git a/includes/Handlers/Xml/XmlDetectHandler.php 
b/includes/Handlers/Xml/XmlDetectHandler.php
index e8bbf9b..360aa44 100644
--- a/includes/Handlers/Xml/XmlDetectHandler.php
+++ b/includes/Handlers/Xml/XmlDetectHandler.php
@@ -280,11 +280,18 @@
         */
        protected function getFormLabel( $parameter ) {
                $result = Utils::sanitizeString( $parameter );
-               $result = str_replace(
-                       array( '_', '-', 'gwtoolset' ),
-                       array( ' ', ' ', '' ),
-                       $result
-               );
+
+               if ( $parameter === 'gwtoolset-title' ) {
+                       $result = wfMessage( 'gwtoolset-title-label' 
)->escaped();
+               } else if ( $parameter === 'gwtoolset-url-to-the-media-file' ) {
+                       $result = wfMessage( 
'gwtoolset-url-to-the-media-file-label' )->escaped();
+               } else {
+                       $result = str_replace(
+                               array( '_', '-' ),
+                               array( ' ', ' ' ),
+                               $result
+                       );
+               }
 
                return $result;
        }
@@ -375,7 +382,7 @@
                $parameter_as_id = Utils::normalizeSpace( $parameter );
                $first_row_placed = false;
                $required = null;
-               $required_fields = array( 'gwtoolset-title-identifier', 
'gwtoolset-url-to-the-media-file' );
+               $required_fields = array( 'gwtoolset-title', 
'gwtoolset-url-to-the-media-file' );
 
                if ( isset( $Mapping->mapping_array[$parameter] ) ) {
                        $selected_options = $Mapping->mapping_array[$parameter];
diff --git a/includes/Handlers/Xml/XmlMappingHandler.php 
b/includes/Handlers/Xml/XmlMappingHandler.php
index 890c0e0..94a480a 100644
--- a/includes/Handlers/Xml/XmlMappingHandler.php
+++ b/includes/Handlers/Xml/XmlMappingHandler.php
@@ -204,7 +204,7 @@
                                        }
                                } else {
                                        if ( !isset( 
$elements_mapped[$template_parameter] ) ) {
-                                               if ( $template_parameter === 
'gwtoolset-title-identifier'
+                                               if ( $template_parameter === 
'gwtoolset-title'
                                                        || $template_parameter 
=== 'title'
                                                ) {
                                                        
$elements_mapped[$template_parameter] =
@@ -218,7 +218,7 @@
                                                                
$this->getFilteredNodeValue( $DOMNodeElement, $is_url );
                                                }
                                        } else {
-                                               if ( $template_parameter === 
'gwtoolset-title-identifier'
+                                               if ( $template_parameter === 
'gwtoolset-title'
                                                        || $template_parameter 
=== 'title'
                                                ) {
                                                        
$elements_mapped[$template_parameter] .=
diff --git a/includes/Models/MediawikiTemplate.php 
b/includes/Models/MediawikiTemplate.php
index f6d783d..8f0961d 100644
--- a/includes/Models/MediawikiTemplate.php
+++ b/includes/Models/MediawikiTemplate.php
@@ -151,9 +151,9 @@
        public function getGWToolsetTemplateAsWikiText() {
                return
                        '{{Uploaded with GWToolset' . PHP_EOL .
-                       ' | gwtoolset-title-identifier = ' .
+                       ' | gwtoolset-title = ' .
                                        Utils::sanitizeString(
-                                               
$this->mediawiki_template_array['gwtoolset-title-identifier']
+                                               
$this->mediawiki_template_array['gwtoolset-title']
                                        ) . PHP_EOL .
                        ' | gwtoolset-url-to-the-media-file = ' .
                                        Utils::sanitizeString(
@@ -169,7 +169,7 @@
         * this does not include categories, raw metadata, or raw
         * mapping information, which are added via other methods.
         *
-        * @todo move the $parameter['gwtoolset-title-identifier']
+        * @todo move the $parameter['gwtoolset-title']
         * and $parameter['gwtoolset-url-to-the-media-file'] out of the
         * $this->mediawiki_template_array and into their own
         * gwtoolset_template_array
@@ -186,7 +186,7 @@
                $template = '{{' . $this->mediawiki_template_name . PHP_EOL . 
'%s}}';
 
                foreach ( $this->mediawiki_template_array as $parameter => 
$content ) {
-                       if ( $parameter === 'gwtoolset-title-identifier'
+                       if ( $parameter === 'gwtoolset-title'
                                || $parameter === 
'gwtoolset-url-to-the-media-file'
                        ) {
                                continue;
@@ -371,11 +371,12 @@
        }
 
        /**
-        * creates a title string that will be used to create a wiki title for 
a media file.
-        * the title string is based on :
+        * creates a title string that will be used to create a wiki title
+        * for a media file. the title string is evaluated using PHP’s strlen()
+        * function, which evaluates the number of bytes in a string. the
+        * title string is based on :
         *
-        *   - title
-        *   - title identifier
+        *   - gwtoolset title
         *   - url to the media file’s extension
         *
         * the title length is limited to Config::$title_max_length
@@ -383,57 +384,32 @@
         *
         * @param {array} $options
         * @throws {GWTException}
-        * @return {string} the string is not filtered.
+        *
+        * @return {string}
+        * the string is not sanitized
         */
-       public function getTitle( array &$options ) {
-               $result = null;
-               $file_extension_length = 0;
-
-               if ( empty( 
$this->mediawiki_template_array['gwtoolset-title-identifier'] ) ) {
-                       throw new GWTException( 
'gwtoolset-mapping-no-title-identifier' );
+       public function getTitle( array $options ) {
+               if (
+                       empty( 
$this->mediawiki_template_array['gwtoolset-title'] )
+               ) {
+                       throw new GWTException( 
'gwtoolset-mapping-no-gwtoolset-title' );
                }
 
                if ( empty( $options['evaluated-media-file-extension'] ) ) {
+                       throw new GWTException( 'gwtoolset-no-extension' );
+               }
+
+               $result =
+                       $this->mediawiki_template_array['gwtoolset-title'] .
+                       '.' .
+                       $options['evaluated-media-file-extension'];
+
+               $result_length = strlen( $result );
+
+               if ( $result_length > Config::$title_max_length ) {
                        throw new GWTException(
-                               array(
-                                       
'gwtoolset-mapping-media-file-url-extension-bad' =>
-                                       array( 
$options['gwtoolset-url-to-the-media-file'] )
-                               )
+                               array( 'gwtoolset-title-too-long' => array( 
$result_length, $result ) )
                        );
-               }
-
-               if ( !empty( $this->mediawiki_template_array['title'] ) ) {
-                       $title_length = strlen( 
$this->mediawiki_template_array['title'] );
-                       $title_identifier_length =
-                               strlen( 
$this->mediawiki_template_array['gwtoolset-title-identifier'] );
-                       $file_extension_length = strlen( 
$options['evaluated-media-file-extension'] ) + 1;
-
-                       if ( ( $title_length + $title_identifier_length + 
$file_extension_length + 1 )
-                               > Config::$title_max_length
-                       ) {
-                               $result = substr(
-                                       
$this->mediawiki_template_array['title'],
-                                       0,
-                                       ( Config::$title_max_length - 
$title_identifier_length - $file_extension_length - 1 )
-                               );
-                       } else {
-                               $result = 
$this->mediawiki_template_array['title'];
-                       }
-
-                       $result .= Config::$title_separator;
-               }
-
-               $result .= 
$this->mediawiki_template_array['gwtoolset-title-identifier'];
-               $result .= '.' . $options['evaluated-media-file-extension'];
-
-               if ( strlen( $result ) > Config::$title_max_length ) {
-                       $result = substr(
-                               
$this->mediawiki_template_array['gwtoolset-title-identifier'],
-                               0,
-                               ( Config::$title_max_length - 
$file_extension_length - 1 )
-                       );
-
-                       $result .= '.' . 
$options['evaluated-media-file-extension'];
                }
 
                return $result;
@@ -506,7 +482,7 @@
                $this->mediawiki_template_array = json_decode( 
$this->mediawiki_template_json, true );
 
                // add aditional mediawiki template fields that the extension 
needs
-               $this->mediawiki_template_array['gwtoolset-title-identifier'] = 
null;
+               $this->mediawiki_template_array['gwtoolset-title'] = null;
                
$this->mediawiki_template_array['gwtoolset-url-to-the-media-file'] = null;
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/134073
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I92dfe622e40bf9873e0b0c615a0d0ad8a9daf3e0
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

Reply via email to