Index: trunk/extensions/UploadWizard/resources/mw.Api.category.js |
— | — | @@ -2,9 +2,6 @@ |
3 | 3 | |
4 | 4 | ( function( mw, $ ) { |
5 | 5 | |
6 | | - // cached token so we don't have to keep fetching new ones for every single post |
7 | | - var cachedToken = null; |
8 | | - |
9 | 6 | $.extend( mw.Api.prototype, { |
10 | 7 | /** |
11 | 8 | * @param {mw.Title} |
— | — | @@ -30,10 +27,8 @@ |
31 | 28 | callback( exists ); |
32 | 29 | }; |
33 | 30 | |
34 | | - var err = mw.isDefined( error ) ? error : undefined; |
| 31 | + return this.get( params, { ok: ok, err: err } ); |
35 | 32 | |
36 | | - return this.get( params, ok, err ); |
37 | | - |
38 | 33 | }, |
39 | 34 | |
40 | 35 | /** |
— | — | @@ -61,10 +56,45 @@ |
62 | 57 | callback( texts ); |
63 | 58 | }; |
64 | 59 | |
65 | | - var err = mw.isDefined( error ) ? error : undefined; |
66 | | - |
67 | | - return this.get( params, ok, err ); |
| 60 | + return this.get( params, { ok: ok, err: err } ); |
68 | 61 | |
| 62 | + }, |
| 63 | + |
| 64 | + |
| 65 | + /** |
| 66 | + * @param {mw.Title} |
| 67 | + * @param {Function} callback to pass categories to (or false, if title not found) |
| 68 | + * @param {Function} optional callback to run if api error |
| 69 | + * @return ajax call object |
| 70 | + */ |
| 71 | + getCategories: function( title, callback, error, async ) { |
| 72 | + var params = { |
| 73 | + prop: 'categories', |
| 74 | + titles: title.toString() |
| 75 | + }; |
| 76 | + if ( async === undefined ) { |
| 77 | + async = true; |
| 78 | + } |
| 79 | + |
| 80 | + var ok = function( data ) { |
| 81 | + var ret = false; |
| 82 | + if ( data.query && data.query.pages ) { |
| 83 | + $.each( data.query.pages, function( id, page ) { |
| 84 | + if ( page.categories ) { |
| 85 | + if ( typeof ret !== 'object' ) { |
| 86 | + ret = []; |
| 87 | + } |
| 88 | + $.each( page.categories, function( i, cat ) { |
| 89 | + ret.push( new mw.Title( cat.title ) ); |
| 90 | + } ); |
| 91 | + } |
| 92 | + } ); |
| 93 | + } |
| 94 | + callback( ret ); |
| 95 | + }; |
| 96 | + |
| 97 | + return this.get( params, { ok: ok, err: error, async: async } ); |
| 98 | + |
69 | 99 | } |
70 | 100 | |
71 | 101 | } ); |