Skip to content

Commit ab8d28b

Browse files
malbertsJeroenDeDauw
authored andcommitted
Use translated namespace name
1 parent 558224b commit ab8d28b

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

resources/jquery.ui.mediasuggester.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@
9393
_prioritiseMatchingFilename: function( resultList, term ) {
9494
return resultList.sort( function( a, b ) {
9595
// use indexOf() in favour of startsWith() for browser compatibility
96-
if ( a.title.indexOf( 'File:' + term ) === 0 ) {
96+
if ( a.title.indexOf( this._getFileNamespace() + ':' + term ) === 0 ) {
9797
return -1;
98-
} else if ( b.title.indexOf( 'File:' + term ) === 0 ) {
98+
} else if ( b.title.indexOf( this._getFileNamespace() + ':' + term ) === 0 ) {
9999
return 1;
100100
} else {
101101
return 0;
@@ -114,10 +114,10 @@
114114
_createMenuItemFromSuggestion: function( suggestion, requestTerm ) {
115115
suggestion = suggestion.title;
116116

117-
var isFile = /^File:/.test( suggestion );
117+
var isFile = this._getFileNamespaceRegex().test( suggestion );
118118

119119
if ( isFile ) {
120-
suggestion = suggestion.replace( /^File:/, '' );
120+
suggestion = suggestion.replace( this._getFileNamespaceRegex(), '' );
121121
}
122122

123123
var label = util.highlightSubstring(
@@ -163,6 +163,24 @@
163163
return 'url("' + this.options.indexPhpUrl + '?title=Special:Filepath/'
164164
+ encodeURIComponent( fileName )
165165
+ '&width=100&height=50")';
166+
},
167+
168+
/**
169+
* @private
170+
*
171+
* @returns {string}
172+
*/
173+
_getFileNamespace: function () {
174+
return mw.config.get('wgFormattedNamespaces')[6];
175+
},
176+
177+
/**
178+
* @private
179+
*
180+
* @returns {RegExp}
181+
*/
182+
_getFileNamespaceRegex: function () {
183+
return new RegExp( '^' + this._getFileNamespace() + ':' );
166184
}
167185

168186
} );

0 commit comments

Comments
 (0)