r101601 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101600‎ | r101601 | r101602 >
Date:09:33, 2 November 2011
Author:neilk
Status:ok (Comments)
Tags:todo 
Comment:
add method to fetch categories of a title. remove some useless code making sure undefined stuff was undefined.
Modified paths:
  • /trunk/extensions/UploadWizard/resources/mw.Api.category.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UploadWizard/resources/mw.Api.category.js
@@ -2,9 +2,6 @@
33
44 ( function( mw, $ ) {
55
6 - // cached token so we don't have to keep fetching new ones for every single post
7 - var cachedToken = null;
8 -
96 $.extend( mw.Api.prototype, {
107 /**
118 * @param {mw.Title}
@@ -30,10 +27,8 @@
3128 callback( exists );
3229 };
3330
34 - var err = mw.isDefined( error ) ? error : undefined;
 31+ return this.get( params, { ok: ok, err: err } );
3532
36 - return this.get( params, ok, err );
37 -
3833 },
3934
4035 /**
@@ -61,10 +56,45 @@
6257 callback( texts );
6358 };
6459
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 } );
6861
 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+
6999 }
70100
71101 } );

Comments

#Comment by Raindrift (talk | contribs)   18:45, 10 November 2011

If you could describe this method, that'd be awesome.

#Comment by NeilK (talk | contribs)   01:29, 11 November 2011

done in r102730

Status & tagging log