[MediaWiki-commits] [Gerrit] data-values/value-view[master]: Allow pasting full Wikimedia Commons URLs
jenkins-bot has submitted this change and it was merged. Change subject: Allow pasting full Wikimedia Commons URLs .. Allow pasting full Wikimedia Commons URLs Slashes are never allowed in file names. This reduces full URLs to the pure file name, when at least two characters are left. Bug: T147917 Change-Id: Id8c6907f3a1b4301bdbf5f76240c0b8bfc75c8ee --- M lib/jquery.ui/jquery.ui.commonssuggester.js A tests/lib/jquery.ui/jquery.ui.commonssuggester.tests.js M tests/lib/resources.php 3 files changed, 120 insertions(+), 2 deletions(-) Approvals: Hoo man: Looks good to me, approved jenkins-bot: Verified diff --git a/lib/jquery.ui/jquery.ui.commonssuggester.js b/lib/jquery.ui/jquery.ui.commonssuggester.js index 89819a9..6979cf5 100644 --- a/lib/jquery.ui/jquery.ui.commonssuggester.js +++ b/lib/jquery.ui/jquery.ui.commonssuggester.js @@ -32,6 +32,8 @@ * @return {Function} */ _initDefaultSource: function() { + var self = this; + return function( term ) { var deferred = $.Deferred(); @@ -39,14 +41,14 @@ url: 'https://commons.wikimedia.org/w/api.php', dataType: 'jsonp', data: { - search: term, + search: self._grepFileTitleFromTerm( term ), action: 'opensearch', namespace: 6 }, timeout: 8000 } ) .done( function( response ) { - deferred.resolve( response[1], response[0] ); + deferred.resolve( response[1], term ); } ) .fail( function( jqXHR, textStatus ) { // Since this is a JSONP request, this will always fail with a timeout... @@ -58,6 +60,25 @@ }, /** +* @private +* +* @param {string} term +* @return {string} +*/ + _grepFileTitleFromTerm: function( term ) { + try { + // Make sure there are always at least 2 characters left + return decodeURIComponent( term + .replace( /^[^#]*\btitle=([^
[MediaWiki-commits] [Gerrit] data-values/value-view[master]: Allow pasting full Wikimedia Commons URLs
Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/308548 Change subject: Allow pasting full Wikimedia Commons URLs .. Allow pasting full Wikimedia Commons URLs Slashes are never allowed in file names. This reduces full URLs to the pure file name, when at least two characters are left. Change-Id: Id8c6907f3a1b4301bdbf5f76240c0b8bfc75c8ee --- M lib/jquery.ui/jquery.ui.commonssuggester.js 1 file changed, 10 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/data-values/value-view refs/changes/48/308548/1 diff --git a/lib/jquery.ui/jquery.ui.commonssuggester.js b/lib/jquery.ui/jquery.ui.commonssuggester.js index 89819a9..8ed68ec 100644 --- a/lib/jquery.ui/jquery.ui.commonssuggester.js +++ b/lib/jquery.ui/jquery.ui.commonssuggester.js @@ -33,20 +33,27 @@ */ _initDefaultSource: function() { return function( term ) { - var deferred = $.Deferred(); + var deferred = $.Deferred(), + search = term; + + try { + // Extract the title from a full URL when at least two characters are left. + search = decodeURIComponent( search.replace( /.*\/(?=[^\/]{2})/, '' ) ); + } catch ( ex ) { + } $.ajax( { url: 'https://commons.wikimedia.org/w/api.php', dataType: 'jsonp', data: { - search: term, + search: search, action: 'opensearch', namespace: 6 }, timeout: 8000 } ) .done( function( response ) { - deferred.resolve( response[1], response[0] ); + deferred.resolve( response[1], term ); } ) .fail( function( jqXHR, textStatus ) { // Since this is a JSONP request, this will always fail with a timeout... -- To view, visit https://gerrit.wikimedia.org/r/308548 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id8c6907f3a1b4301bdbf5f76240c0b8bfc75c8ee Gerrit-PatchSet: 1 Gerrit-Project: data-values/value-view Gerrit-Branch: master Gerrit-Owner: Thiemo Mättig (WMDE)___ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits