mediawiki.api.category: Avoid exceptions
[lhc/web/wiklou.git] / resources / src / mediawiki / api / category.js
index 04462e3..85df90e 100644 (file)
                        var apiPromise = this.get( {
                                formatversion: 2,
                                prop: 'categoryinfo',
-                               titles: String( title )
+                               titles: [ String( title ) ]
                        } );
 
                        return apiPromise
                                .then( function ( data ) {
-                                       return !!data.query.pages[ 0 ].categoryinfo;
+                                       return !!(
+                                               data.query && // query is missing on title=""
+                                               data.query.pages && // query.pages is missing on title="#" or title="mw:"
+                                               data.query.pages[ 0 ].categoryinfo
+                                       );
                                } )
                                .promise( { abort: apiPromise.abort } );
                },
                        var apiPromise = this.get( {
                                formatversion: 2,
                                prop: 'categories',
-                               titles: String( title )
+                               titles: [ String( title ) ]
                        } );
 
                        return apiPromise
                                .then( function ( data ) {
-                                       var page = data.query.pages[ 0 ];
+                                       var page;
 
+                                       if ( !data.query || !data.query.pages ) {
+                                               return false;
+                                       }
+                                       page = data.query.pages[ 0 ];
                                        if ( !page.categories ) {
                                                return false;
                                        }