`mw.Title#getNameText()` strips anything following a dot (.), assuming
it's a file name (which doesn't make sense for category names).
C.f. https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Title-method-getMainText
This causes some trouble in UploadWizard's category-suggestion system.
This bug has been there since the very first version (
cb0cf72eba9ff)
which, ironically, was specifically written for UploadWizard.
Bug: 64764
Change-Id: I2925e1050215272cdf03c8c6b1de6ba79348f6a5
var texts = [];
if ( data.query && data.query.allpages ) {
$.each( data.query.allpages, function ( i, category ) {
- texts.push( new mw.Title( category.title ).getNameText() );
+ texts.push( new mw.Title( category.title ).getMainText() );
} );
}
return texts;
'tests/qunit/suites/resources/mediawiki/mediawiki.user.test.js',
'tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js',
'tests/qunit/suites/resources/mediawiki.api/mediawiki.api.test.js',
+ 'tests/qunit/suites/resources/mediawiki.api/mediawiki.api.category.test.js',
'tests/qunit/suites/resources/mediawiki.api/mediawiki.api.parse.test.js',
'tests/qunit/suites/resources/mediawiki.api/mediawiki.api.watch.test.js',
'tests/qunit/suites/resources/mediawiki.special/mediawiki.special.recentchanges.test.js',
'jquery.tablesorter',
'jquery.textSelection',
'mediawiki.api',
+ 'mediawiki.api.category',
'mediawiki.api.parse',
'mediawiki.api.watch',
'mediawiki.jqueryMsg',
--- /dev/null
+( function ( mw ) {
+ QUnit.module( 'mediawiki.api.category', QUnit.newMwEnvironment( {
+ setup: function () {
+ this.server = this.sandbox.useFakeServer();
+ }
+ } ) );
+
+ QUnit.test( '.getCategoriesByPrefix()', function ( assert ) {
+ QUnit.expect( 1 );
+
+ var api = new mw.Api();
+
+ api.getCategoriesByPrefix( 'Foo' ).done( function ( matches ) {
+ assert.deepEqual(
+ matches,
+ [ 'Food', 'Fool Supermarine S.6', 'Fools' ]
+ );
+ } );
+
+ this.server.respond( function ( req ) {
+ req.respond( 200, { 'Content-Type': 'application/json' },
+ '{ "query": { "allpages": [ ' +
+ '{ "title": "Category:Food" },' +
+ '{ "title": "Category:Fool Supermarine S.6" },' +
+ '{ "title": "Category:Fools" }' +
+ '] } }'
+ );
+ } );
+ } );
+}( mediaWiki ) );