mediawiki.api: Don't apply file extension stripping to category names
authorrillke <rainerrillke@hotmail.com>
Sat, 3 May 2014 19:34:23 +0000 (21:34 +0200)
committerTimo Tijhof <krinklemail@gmail.com>
Sun, 4 May 2014 14:01:30 +0000 (16:01 +0200)
`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

resources/src/mediawiki.api/mediawiki.api.category.js
tests/qunit/QUnitTestResources.php
tests/qunit/suites/resources/mediawiki.api/mediawiki.api.category.test.js [new file with mode: 0644]

index a90617d..7dd9730 100644 (file)
@@ -73,7 +73,7 @@
                                        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;
index e861967..5cfd18f 100644 (file)
@@ -71,6 +71,7 @@ return array(
                        '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',
@@ -96,6 +97,7 @@ return array(
                        'jquery.tablesorter',
                        'jquery.textSelection',
                        'mediawiki.api',
+                       'mediawiki.api.category',
                        'mediawiki.api.parse',
                        'mediawiki.api.watch',
                        'mediawiki.jqueryMsg',
diff --git a/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.category.test.js b/tests/qunit/suites/resources/mediawiki.api/mediawiki.api.category.test.js
new file mode 100644 (file)
index 0000000..a0c7daf
--- /dev/null
@@ -0,0 +1,30 @@
+( 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 ) );