Skip to content

Commit

Permalink
Use translated namespace name
Browse files Browse the repository at this point in the history
  • Loading branch information
malberts committed Oct 9, 2024
1 parent 558224b commit 3eae90d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions resources/jquery.ui.mediasuggester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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() + ':' );
}

} );
Expand Down

0 comments on commit 3eae90d

Please sign in to comment.