Tonina Zhelyazkova has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/405290 )

Change subject: Change the behavior of search term fields.
......................................................................

Change the behavior of search term fields.

Bug: T181296
Change-Id: I935fcdd537f02526bb09176c21bcf321376cb771
---
M i18n/en.json
M i18n/qqq.json
M modules/ext.advancedSearch.AdvancedOptionsBuilder.js
M modules/ui/ext.advancedSearch.ArbitraryWordInput.js
M tests/qunit/ui/ArbitraryWordInput.test.js
5 files changed, 47 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AdvancedSearch 
refs/changes/90/405290/1

diff --git a/i18n/en.json b/i18n/en.json
index dc5463a..1d2cfb8 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -33,7 +33,7 @@
        "advancedsearch-help-filew": ";Description\n:These fields allow you to 
specify the width of the file.\n;Be aware of the following\n:* This is only 
applicable to file types that have width and height, like videos and 
images.\n;Help 
page\n:[https://www.mediawiki.org/wiki/Help:CirrusSearch#File_measures 
Filemeasures]\n;Syntax-equivalent in the normal search\n:Numbers with 
<code>filew</code> before them like <code>filew:>800</code>.",
        "advancedsearch-help-fileh": ";Description\n:These fields allow you to 
specify the height of the file.\n;Be aware of the following\n:* This is only 
applicable to file types that have width and height, like videos and 
images.\n;Help 
page\n:[https://www.mediawiki.org/wiki/Help:CirrusSearch#File_measures 
Filemeasures]\n;Syntax-equivalent in the normal search\n:Numbers with 
<code>fileh</code> before them like <code>fileh:>600</code>.",
 
-       "advancedSearch-placeholder-commas": "Type words separated by comma 
e.g. cats, goats, ...",
+       "advancedSearch-placeholder-exact-text": "Put exact words in quotes: 
\"cat loves goat\"",
 
        "advancedsearch-filetype-section-types": "General file types",
        "advancedsearch-filetype-section-image": "Image formats",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index bfd63fb..dab425a 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -33,7 +33,7 @@
        "advancedsearch-help-filetype": "Help text shown in a dialog for the 
field for file type",
        "advancedsearch-help-filew": "Help text shown in a dialog for the field 
for file width in pixels",
        "advancedsearch-help-fileh": "Help text shown in a dialog for the field 
for file height in pixels",
-       "advancedSearch-placeholder-commas": "Placeholder text shown in fields 
that accept multiple values separated by commas",
+       "advancedSearch-placeholder-exact-text": "Placeholder that is shown for 
the field exact words",
        "advancedsearch-filetype-section-types": "Label for the file type 
section",
        "advancedsearch-filetype-section-image": "Label for the image format 
section",
        "advancedsearch-filetype-section-video": "Label for the video format 
section",
diff --git a/modules/ext.advancedSearch.AdvancedOptionsBuilder.js 
b/modules/ext.advancedSearch.AdvancedOptionsBuilder.js
index b12c630..d50e1c3 100644
--- a/modules/ext.advancedSearch.AdvancedOptionsBuilder.js
+++ b/modules/ext.advancedSearch.AdvancedOptionsBuilder.js
@@ -188,33 +188,56 @@
                                        group: 'text',
                                        id: 'plain',
                                        formatter: function ( val ) {
-                                               return val;
-                                       }
-                               },
-                               {
-                                       group: 'text',
-                                       id: 'phrase',
-                                       formatter: function ( val ) {
                                                if ( Array.isArray( val ) ) {
-                                                       return $.map( val, 
enforceQuotes ).join( ' ' );
+                                                       return val.join( ' ' );
                                                }
-                                               return enforceQuotes( val );
+                                               return val;
                                        },
                                        init: function () {
                                                return new 
mw.libs.advancedSearch.ui.ArbitraryWordInput(
                                                        self.state,
                                                        {
-                                                               optionId: 
'phrase',
-                                                               placeholder: 
mw.msg( 'advancedSearch-placeholder-commas' )
+                                                               optionId: 
'plain'
                                                        }
                                                );
                                        }
                                },
                                {
                                        group: 'text',
+                                       id: 'phrase',
+                                       formatter: function ( val ) {
+                                               return val;
+                                       },
+                                       init: function () {
+                                               return new 
mw.libs.advancedSearch.ui.TextInput(
+                                                       self.state,
+                                                       {
+                                                               id: 
'advancedSearchOption-phrase',
+                                                               optionId: 
'phrase',
+                                                               placeholder: 
mw.msg( 'advancedSearch-placeholder-exact-text' )
+                                                       }
+                                               );
+                                       }
+
+                               },
+                               {
+                                       group: 'text',
                                        id: 'not',
                                        formatter: function ( val ) {
-                                               return '-' + optionalQuotes( 
val );
+                                               if ( Array.isArray( val ) ) {
+                                                       return val.map( 
function ( el ) {
+                                                               return '-' + el;
+                                                       } ).join( ' ' );
+                                               }
+                                               return '-' + val;
+                                       },
+                                       init: function () {
+                                               return new 
mw.libs.advancedSearch.ui.ArbitraryWordInput(
+                                                       self.state,
+                                                       {
+                                                               optionId: 'not'
+                                                       }
+                                               );
                                        }
                                },
                                {
@@ -230,8 +253,7 @@
                                                return new 
mw.libs.advancedSearch.ui.ArbitraryWordInput(
                                                        self.state,
                                                        {
-                                                               optionId: 'or',
-                                                               placeholder: 
mw.msg( 'advancedSearch-placeholder-commas' )
+                                                               optionId: 'or'
                                                        }
                                                );
                                        }
diff --git a/modules/ui/ext.advancedSearch.ArbitraryWordInput.js 
b/modules/ui/ext.advancedSearch.ArbitraryWordInput.js
index 30e2813..01f60e6 100644
--- a/modules/ui/ext.advancedSearch.ArbitraryWordInput.js
+++ b/modules/ui/ext.advancedSearch.ArbitraryWordInput.js
@@ -53,7 +53,7 @@
        };
 
        
mw.libs.advancedSearch.ui.ArbitraryWordInput.prototype.buildTagsFromInput = 
function () {
-               var segments = this.input.getValue().split( ',' );
+               var segments = this.input.getValue().split( /[, ]/ );
 
                if ( segments.length > 1 ) {
                        var self = this;
diff --git a/tests/qunit/ui/ArbitraryWordInput.test.js 
b/tests/qunit/ui/ArbitraryWordInput.test.js
index c1f1573..aa55ffa 100644
--- a/tests/qunit/ui/ArbitraryWordInput.test.js
+++ b/tests/qunit/ui/ArbitraryWordInput.test.js
@@ -79,31 +79,33 @@
                assert.equal( input.getTextForPlaceholder(), '' );
        } );
 
-       QUnit.test( 'Text with commas gets turned into tags', function ( assert 
) {
+       QUnit.test( 'Text with commas and spaces gets turned into tags', 
function ( assert ) {
                var input = new ArbitraryWordInput( new Model(), {} );
-               input.input.setValue( 'initial, comma separated, values' );
+               input.input.setValue( 'initial,comma,separated values' );
                input.buildTagsFromInput();
 
                assert.deepEqual(
                        input.getValue(),
                        [
                                'initial',
-                               'comma separated',
+                               'comma',
+                               'separated',
                                'values'
                        ]
                );
        } );
 
-       QUnit.test( 'Extra commas do not cause empty tag creation', function ( 
assert ) {
+       QUnit.test( 'Extra commas and spaces do not cause empty tag creation', 
function ( assert ) {
                var input = new ArbitraryWordInput( new Model(), {} );
-               input.input.setValue( ',initial,, comma separated, values,,' );
+               input.input.setValue( ',initial,, comma   separated, values,,' 
);
                input.buildTagsFromInput();
 
                assert.deepEqual(
                        input.getValue(),
                        [
                                'initial',
-                               'comma separated',
+                               'comma',
+                               'separated',
                                'values'
                        ]
                );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I935fcdd537f02526bb09176c21bcf321376cb771
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AdvancedSearch
Gerrit-Branch: master
Gerrit-Owner: Tonina Zhelyazkova <tonina.zhelyazk...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to