2 * @class mw.Api.plugin.category
6 $.extend( mw
.Api
.prototype, {
8 * Determine if a category exists.
9 * @param {mw.Title} title
10 * @param {Function} [ok] Success callback (deprecated)
11 * @param {Function} [err] Error callback (deprecated)
12 * @return {jQuery.Promise}
13 * @return {Function} return.done
14 * @return {boolean} return.done.isCategory Whether the category exists.
16 isCategory: function ( title
, ok
, err
) {
18 // Backwards compatibility (< MW 1.20)
24 titles
: title
.toString()
26 .done( function ( data
) {
28 if ( data
.query
&& data
.query
.pages
) {
29 $.each( data
.query
.pages
, function ( id
, page
) {
30 if ( page
.categoryinfo
) {
43 * Get a list of categories that match a certain prefix.
44 * e.g. given "Foo", return "Food", "Foolish people", "Foosball tables" ...
45 * @param {string} prefix Prefix to match.
46 * @param {Function} [ok] Success callback (deprecated)
47 * @param {Function} [err] Error callback (deprecated)
48 * @return {jQuery.Promise}
49 * @return {Function} return.done
50 * @return {String[]} return.done.categories Matched categories
52 getCategoriesByPrefix: function ( prefix
, ok
, err
) {
54 // Backwards compatibility (< MW 1.20)
58 // Fetch with allpages to only get categories that have a corresponding description page.
62 apnamespace
: mw
.config
.get('wgNamespaceIds').category
64 .done( function ( data
) {
66 if ( data
.query
&& data
.query
.allpages
) {
67 $.each( data
.query
.allpages
, function ( i
, category
) {
68 texts
.push( new mw
.Title( category
.title
).getNameText() );
80 * Get the categories that a particular page on the wiki belongs to
81 * @param {mw.Title} title
82 * @param {Function} [ok] Success callback (deprecated)
83 * @param {Function} [err] Error callback (deprecated)
84 * @param {boolean} [async=true] Asynchronousness
85 * @return {jQuery.Promise}
86 * @return {Function} return.done
87 * @return {boolean|mw.Title[]} return.done.categories List of category titles or false
88 * if title was not found.
90 getCategories: function ( title
, ok
, err
, async
) {
92 // Backwards compatibility (< MW 1.20)
98 titles
: title
.toString()
100 async
: async
=== undefined ? true : async
102 .done( function ( data
) {
104 if ( data
.query
&& data
.query
.pages
) {
105 $.each( data
.query
.pages
, function ( id
, page
) {
106 if ( page
.categories
) {
107 if ( typeof ret
!== 'object' ) {
110 $.each( page
.categories
, function ( i
, cat
) {
111 ret
.push( new mw
.Title( cat
.title
) );
127 * @mixins mw.Api.plugin.category
130 }( mediaWiki
, jQuery
) );