mediawiki.widgets: Use formatversion=2 for API requests
authorFomafix <fomafix@googlemail.com>
Fri, 5 Feb 2016 22:21:51 +0000 (22:21 +0000)
committer[[mw:User:Fomafix]] <gerritpatchuploader@gmail.com>
Fri, 5 Feb 2016 22:21:51 +0000 (22:21 +0000)
With formatversion=2 the JSON response uses UTF-8 instead of escape sequences
with hex for encoding of non-ASCII characters (e.g. "\u00e4" for "รค").

The processing of the response is adapted to the new format.

Change-Id: I2fc0a696a8aa4486c497ac25763f8e4ece671a26

resources/src/mediawiki.widgets/mw.widgets.CategoryCapsuleItemWidget.js
resources/src/mediawiki.widgets/mw.widgets.CategorySelector.js

index 6db7c12..29eaaad 100644 (file)
                        return;
                }
                this.currentRequest = this.api.get( {
+                       formatversion: 2,
                        action: 'query',
                        prop: [ 'info' ],
                        titles: titles
                } ).done( function ( response ) {
-                       var index, curr, title;
-                       for ( index in response.query.pages ) {
-                               curr = response.query.pages[ index ];
-                               title = new ForeignTitle( curr.title ).getPrefixedText();
-                               this.existenceCache[ title ] = curr.missing === undefined;
+                       $.each( response.query.pages, function ( index, page ) {
+                               var title = new ForeignTitle( page.title ).getPrefixedText();
+                               this.existenceCache[ title ] = !page.missing;
                                queue[ title ].resolve( this.existenceCache[ title ] );
-                       }
+                       } );
                }.bind( this ) );
        };
 
index c242b6c..5d7d115 100644 (file)
                switch ( searchType ) {
                        case CategorySelector.SearchType.OpenSearch:
                                this.api.get( {
+                                       formatversion: 2,
                                        action: 'opensearch',
                                        namespace: NS_CATEGORY,
                                        limit: this.limit,
 
                        case CategorySelector.SearchType.InternalSearch:
                                this.api.get( {
+                                       formatversion: 2,
                                        action: 'query',
                                        list: 'allpages',
                                        apnamespace: NS_CATEGORY,
                                }
 
                                this.api.get( {
+                                       formatversion: 2,
                                        action: 'query',
                                        prop: 'info',
                                        titles: 'Category:' + input
                                } ).done( function ( res ) {
-                                       var page,
-                                               categories = [];
+                                       var categories = [];
 
-                                       for ( page in res.query.pages ) {
-                                               if ( parseInt( page, 10 ) > -1 ) {
-                                                       categories.push( res.query.pages[ page ].title );
+                                       $.each( res.query.pages, function ( index, page ) {
+                                               if ( !page.missing ) {
+                                                       categories.push( page.title );
                                                }
-                                       }
+                                       } );
 
                                        deferred.resolve( categories );
                                } ).fail( deferred.reject.bind( deferred ) );
                                }
 
                                this.api.get( {
+                                       formatversion: 2,
                                        action: 'query',
                                        list: 'categorymembers',
                                        cmtype: 'subcat',
                                }
 
                                this.api.get( {
+                                       formatversion: 2,
                                        action: 'query',
                                        prop: 'categories',
                                        cllimit: this.limit,
                                        titles: 'Category:' + input
                                } ).done( function ( res )  {
-                                       var page,
-                                               categories = [];
+                                       var categories = [];
 
-                                       for ( page in res.query.pages ) {
-                                               if ( parseInt( page, 10 ) > -1 ) {
-                                                       if ( $.isArray( res.query.pages[ page ].categories ) ) {
-                                                               categories.push.apply( categories, res.query.pages[ page ].categories.map( function ( category ) {
+                                       $.each( res.query.pages, function ( index, page ) {
+                                               if ( !page.missing ) {
+                                                       if ( $.isArray( page.categories ) ) {
+                                                               categories.push.apply( categories, page.categories.map( function ( category ) {
                                                                        return category.title;
                                                                } ) );
                                                        }
                                                }
-                                       }
+                                       } );
 
                                        deferred.resolve( categories );
                                } ).fail( deferred.reject.bind( deferred ) );