jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/405040 )
Change subject: mediawiki.api.category: Use formatversion=2 and simplify code
......................................................................
mediawiki.api.category: Use formatversion=2 and simplify code
Change-Id: Icc8a193d16cb375593196e9290968f6dac1bc021
---
M resources/src/mediawiki/api/category.js
1 file changed, 14 insertions(+), 29 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/resources/src/mediawiki/api/category.js
b/resources/src/mediawiki/api/category.js
index 14077e0..04462e3 100644
--- a/resources/src/mediawiki/api/category.js
+++ b/resources/src/mediawiki/api/category.js
@@ -14,21 +14,14 @@
*/
isCategory: function ( title ) {
var apiPromise = this.get( {
+ formatversion: 2,
prop: 'categoryinfo',
titles: String( title )
} );
return apiPromise
.then( function ( data ) {
- var exists = false;
- if ( data.query && data.query.pages ) {
- $.each( data.query.pages,
function ( id, page ) {
- if ( page.categoryinfo
) {
- exists = true;
- }
- } );
- }
- return exists;
+ return !!data.query.pages[ 0
].categoryinfo;
} )
.promise( { abort: apiPromise.abort } );
},
@@ -46,6 +39,7 @@
getCategoriesByPrefix: function ( prefix ) {
// Fetch with allpages to only get categories that have
a corresponding description page.
var apiPromise = this.get( {
+ formatversion: 2,
list: 'allpages',
apprefix: prefix,
apnamespace: mw.config.get( 'wgNamespaceIds'
).category
@@ -53,13 +47,9 @@
return apiPromise
.then( function ( data ) {
- var texts = [];
- if ( data.query && data.query.allpages
) {
- $.each( data.query.allpages,
function ( i, category ) {
- texts.push( new
mw.Title( category.title ).getMainText() );
- } );
- }
- return texts;
+ return data.query.allpages.map(
function ( category ) {
+ return new mw.Title(
category.title ).getMainText();
+ } );
} )
.promise( { abort: apiPromise.abort } );
},
@@ -75,26 +65,21 @@
*/
getCategories: function ( title ) {
var apiPromise = this.get( {
+ formatversion: 2,
prop: 'categories',
titles: String( title )
} );
return apiPromise
.then( function ( data ) {
- var titles = false;
- if ( data.query && data.query.pages ) {
- $.each( data.query.pages,
function ( id, page ) {
- if ( page.categories ) {
- if ( titles ===
false ) {
- titles
= [];
- }
- $.each(
page.categories, function ( i, cat ) {
-
titles.push( new mw.Title( cat.title ) );
- } );
- }
- } );
+ var page = data.query.pages[ 0 ];
+
+ if ( !page.categories ) {
+ return false;
}
- return titles;
+ return page.categories.map( function (
cat ) {
+ return new mw.Title( cat.title
);
+ } );
} )
.promise( { abort: apiPromise.abort } );
}
--
To view, visit https://gerrit.wikimedia.org/r/405040
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icc8a193d16cb375593196e9290968f6dac1bc021
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Fomafix <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits