2 * @class mw.Api.plugin.category
6 var msg
= 'Use of mediawiki.api callback params is deprecated. Use the Promise instead.';
7 $.extend( mw
.Api
.prototype, {
9 * Determine if a category exists.
10 * @param {mw.Title} title
11 * @param {Function} [ok] Success callback (deprecated)
12 * @param {Function} [err] Error callback (deprecated)
13 * @return {jQuery.Promise}
14 * @return {Function} return.done
15 * @return {boolean} return.done.isCategory Whether the category exists.
17 isCategory: function ( title
, ok
, err
) {
18 var apiPromise
= this.get( {
20 titles
: String( title
)
23 // Backwards compatibility (< MW 1.20)
25 mw
.track( 'mw.deprecate', 'api.cbParam' );
30 .then( function ( data
) {
32 if ( data
.query
&& data
.query
.pages
) {
33 $.each( data
.query
.pages
, function ( id
, page
) {
34 if ( page
.categoryinfo
) {
43 .promise( { abort
: apiPromise
.abort
} );
47 * Get a list of categories that match a certain prefix.
49 * E.g. given "Foo", return "Food", "Foolish people", "Foosball tables" ...
51 * @param {string} prefix Prefix to match.
52 * @param {Function} [ok] Success callback (deprecated)
53 * @param {Function} [err] Error callback (deprecated)
54 * @return {jQuery.Promise}
55 * @return {Function} return.done
56 * @return {string[]} return.done.categories Matched categories
58 getCategoriesByPrefix: function ( prefix
, ok
, err
) {
59 // Fetch with allpages to only get categories that have a corresponding description page.
60 var apiPromise
= this.get( {
63 apnamespace
: mw
.config
.get( 'wgNamespaceIds' ).category
66 // Backwards compatibility (< MW 1.20)
68 mw
.track( 'mw.deprecate', 'api.cbParam' );
73 .then( function ( data
) {
75 if ( data
.query
&& data
.query
.allpages
) {
76 $.each( data
.query
.allpages
, function ( i
, category
) {
77 texts
.push( new mw
.Title( category
.title
).getNameText() );
84 .promise( { abort
: apiPromise
.abort
} );
89 * Get the categories that a particular page on the wiki belongs to
90 * @param {mw.Title} title
91 * @param {Function} [ok] Success callback (deprecated)
92 * @param {Function} [err] Error callback (deprecated)
93 * @param {boolean} [async=true] Asynchronousness
94 * @return {jQuery.Promise}
95 * @return {Function} return.done
96 * @return {boolean|mw.Title[]} return.done.categories List of category titles or false
97 * if title was not found.
99 getCategories: function ( title
, ok
, err
, async
) {
100 var apiPromise
= this.get( {
102 titles
: String( title
)
104 async
: async
=== undefined ? true : async
107 // Backwards compatibility (< MW 1.20)
109 mw
.track( 'mw.deprecate', 'api.cbParam' );
114 .then( function ( data
) {
116 if ( data
.query
&& data
.query
.pages
) {
117 $.each( data
.query
.pages
, function ( id
, page
) {
118 if ( page
.categories
) {
119 if ( titles
=== false ) {
122 $.each( page
.categories
, function ( i
, cat
) {
123 titles
.push( new mw
.Title( cat
.title
) );
132 .promise( { abort
: apiPromise
.abort
} );
139 * @mixins mw.Api.plugin.category
142 }( mediaWiki
, jQuery
) );