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.
11 * @param {mw.Title|string} title
12 * @param {Function} [ok] Success callback (deprecated)
13 * @param {Function} [err] Error callback (deprecated)
14 * @return {jQuery.Promise}
15 * @return {Function} return.done
16 * @return {boolean} return.done.isCategory Whether the category exists.
18 isCategory: function ( title
, ok
, err
) {
19 var apiPromise
= this.get( {
21 titles
: String( title
)
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
67 mw
.track( 'mw.deprecate', 'api.cbParam' );
72 .then( function ( data
) {
74 if ( data
.query
&& data
.query
.allpages
) {
75 $.each( data
.query
.allpages
, function ( i
, category
) {
76 texts
.push( new mw
.Title( category
.title
).getNameText() );
83 .promise( { abort
: apiPromise
.abort
} );
87 * Get the categories that a particular page on the wiki belongs to.
89 * @param {mw.Title|string} title
90 * @param {Function} [ok] Success callback (deprecated)
91 * @param {Function} [err] Error callback (deprecated)
92 * @param {boolean} [async=true] Asynchronousness (deprecated)
93 * @return {jQuery.Promise}
94 * @return {Function} return.done
95 * @return {boolean|mw.Title[]} return.done.categories List of category titles or false
96 * if title was not found.
98 getCategories: function ( title
, ok
, err
, async
) {
99 var apiPromise
= this.get( {
101 titles
: String( title
)
103 async
: async
=== undefined ? true : async
107 mw
.track( 'mw.deprecate', 'api.cbParam' );
110 if ( async
!== undefined ) {
111 mw
.track( 'mw.deprecate', 'api.async' );
113 'Use of mediawiki.api async=false param is deprecated. ' +
114 'The sychronous mode will be removed in the future.'
119 .then( function ( data
) {
121 if ( data
.query
&& data
.query
.pages
) {
122 $.each( data
.query
.pages
, function ( id
, page
) {
123 if ( page
.categories
) {
124 if ( titles
=== false ) {
127 $.each( page
.categories
, function ( i
, cat
) {
128 titles
.push( new mw
.Title( cat
.title
) );
137 .promise( { abort
: apiPromise
.abort
} );
143 * @mixins mw.Api.plugin.category
146 }( mediaWiki
, jQuery
) );