From 3eae90d69d3c4d130f3e36a98624c9f25b055d90 Mon Sep 17 00:00:00 2001 From: Morne Alberts Date: Wed, 9 Oct 2024 13:14:50 +0200 Subject: [PATCH] Use translated namespace name --- resources/jquery.ui.mediasuggester.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/resources/jquery.ui.mediasuggester.js b/resources/jquery.ui.mediasuggester.js index b6b79b5..3b8f141 100644 --- a/resources/jquery.ui.mediasuggester.js +++ b/resources/jquery.ui.mediasuggester.js @@ -93,9 +93,9 @@ _prioritiseMatchingFilename: function( resultList, term ) { return resultList.sort( function( a, b ) { // use indexOf() in favour of startsWith() for browser compatibility - if ( a.title.indexOf( 'File:' + term ) === 0 ) { + if ( a.title.indexOf( this._getFileNamespace() + ':' + term ) === 0 ) { return -1; - } else if ( b.title.indexOf( 'File:' + term ) === 0 ) { + } else if ( b.title.indexOf( this._getFileNamespace() + ':' + term ) === 0 ) { return 1; } else { return 0; @@ -114,10 +114,10 @@ _createMenuItemFromSuggestion: function( suggestion, requestTerm ) { suggestion = suggestion.title; - var isFile = /^File:/.test( suggestion ); + var isFile = this._getFileNamespaceRegex().test( suggestion ); if ( isFile ) { - suggestion = suggestion.replace( /^File:/, '' ); + suggestion = suggestion.replace( this._getFileNamespaceRegex(), '' ); } var label = util.highlightSubstring( @@ -163,6 +163,24 @@ return 'url("' + this.options.indexPhpUrl + '?title=Special:Filepath/' + encodeURIComponent( fileName ) + '&width=100&height=50")'; + }, + + /** + * @private + * + * @returns {string} + */ + _getFileNamespace: function () { + return mw.config.get('wgFormattedNamespaces')[6]; + }, + + /** + * @private + * + * @returns {RegExp} + */ + _getFileNamespaceRegex: function () { + return new RegExp( '^' + this._getFileNamespace() + ':' ); } } );