Hoo man has uploaded a new change for review.

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

Change subject: Extract subdomain when pasting full URL into siteselector
......................................................................

Extract subdomain when pasting full URL into siteselector

(Alternative to I62578bdfac821ec1030dde4bfca4fbf25c488da8, see below)

This is a trivial first step towards the idea to allow pasting full
Wikipedia URLs into the sitelinks editor. This patch does have a
single effect: Before, nothing was found when a user tried to paste a
URL. Now, it finds the site (but not the page).

This has been adopted from I62578bdfac821ec1030dde4bfca4fbf25c488da8
by Marius Hoch, so that it matches the pasted URL with the site URL,
instead of trying to match the pasted URL with the site id.

Bug: T144310
Change-Id: Ifb5b3b2f2cbef186f7349c5c65964ee430fe626d
---
M .jscsrc
M .jshintrc
M lib/resources/jquery.wikibase/jquery.wikibase.siteselector.js
M lib/tests/qunit/jquery.wikibase/jquery.wikibase.siteselector.tests.js
4 files changed, 29 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/24/311324/1

diff --git a/.jscsrc b/.jscsrc
index 179fec4..4a6edcf 100644
--- a/.jscsrc
+++ b/.jscsrc
@@ -1,5 +1,5 @@
 {
-       // 
https://github.com/jscs-dev/node-jscs/blob/master/presets/wikimedia.json
+       // 
https://github.com/wikimedia/jscs-preset-wikimedia/blob/master/presets/wikimedia.json
        "preset": "wikimedia",
 
        // ----
@@ -10,6 +10,7 @@
        "disallowDanglingUnderscores": null,
        "requireSpacesInsideBrackets": null,
        "requireVarDeclFirst": null,
+       "requireCamelCaseOrUpperCaseIdentifiers": { "allExcept": [ "zh_min_nan" 
] },
        "jsDoc": {
                // what we don't yet follow is commented out
                "checkAnnotations": {
diff --git a/.jshintrc b/.jshintrc
index 720300f..055265d 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -1,5 +1,5 @@
 {
-       "camelcase": true,
+       "camelcase": false, // conflicts with JSCS' disallowQuotedKeysInObjects
        "curly": true,
        "eqeqeq": true,
        "immed": true,
diff --git a/lib/resources/jquery.wikibase/jquery.wikibase.siteselector.js 
b/lib/resources/jquery.wikibase/jquery.wikibase.siteselector.js
index 6325663..55ee20a 100644
--- a/lib/resources/jquery.wikibase/jquery.wikibase.siteselector.js
+++ b/lib/resources/jquery.wikibase/jquery.wikibase.siteselector.js
@@ -215,6 +215,14 @@
                                return self._considerSuggestion( site );
                        } );
 
+                       if ( suggestedSites.length === 0 ) {
+                               var removePrefix = /^(\w*:)?(\/\/)?/;
+                               var siteId = this._term.replace( removePrefix, 
'' ).replace( /\..*/, '' );
+                               suggestedSites = $.grep( source, function( site 
) {
+                                       return site.getApi().replace( 
removePrefix, '' ).indexOf( siteId ) === 0;
+                               } );
+                       }
+
                        return deferred.resolve( suggestedSites, term 
).promise();
                },
 
diff --git 
a/lib/tests/qunit/jquery.wikibase/jquery.wikibase.siteselector.tests.js 
b/lib/tests/qunit/jquery.wikibase/jquery.wikibase.siteselector.tests.js
index 32248fa..c688127 100644
--- a/lib/tests/qunit/jquery.wikibase/jquery.wikibase.siteselector.tests.js
+++ b/lib/tests/qunit/jquery.wikibase/jquery.wikibase.siteselector.tests.js
@@ -45,6 +45,15 @@
                        languageCode: 'frr',
                        id: 'frrwiki',
                        group: 'foo'
+               },
+               {
+                       apiUrl: 'http://zh-min-nan.wikipedia.org/w/api.php',
+                       name: 'Chinese',
+                       pageUrl: 'http://zh-min-nan.wikipedia.org/wiki/$1',
+                       shortName: 'Chinese',
+                       languageCode: 'zh-min-nan',
+                       id: 'zh_min_nan',
+                       group: 'dummy'
                }
        ];
 
@@ -96,13 +105,13 @@
                }
        } ) );
 
-       QUnit.test( 'getSelectedSite()', 23, function( assert ) {
+       QUnit.test( 'getSelectedSite()', 36, function( assert ) {
                var $siteSelector = newTestSiteSelector(),
                        siteSelector = $siteSelector.data( 'siteselector' );
 
                /**
                 * Key: Expected site id / Value: Input string.
-                * @type {Object}
+                * @type {Object[]}
                 */
                var testStrings = [
                        { enwiki: 'en' },
@@ -111,7 +120,13 @@
                        { dewiki: 'deutsch' },
                        { nowiki: 'no' }, // Prefer language code.
                        { enwiki: 'enwiki' },
-                       { frrwiki: 'nord' }
+                       { frrwiki: 'nord' },
+                       { zh_min_nan: 
'https://zh-min-nan.wikipedia.org/wiki/Dummy' },
+                       { zh_min_nan: 
'https://zh-min-nan.wikipedia.org/wiki/Dummy' },
+                       { zh_min_nan: 'https://zh-min-nan.wikipedia.org/wiki/' 
},
+                       { zh_min_nan: 'https://zh-min-nan.wikipedia.org' },
+                       { zh_min_nan: '//zh-min-nan.wikipedia.org' },
+                       { zh_min_nan: 'zh-min-nan.wikipedia.org/foo/bar' }
                ];
 
                /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb5b3b2f2cbef186f7349c5c65964ee430fe626d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <h...@online.de>
Gerrit-Reviewer: Thiemo M├Ąttig (WMDE) <thiemo.maet...@wikimedia.de>

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

Reply via email to