1

Learning to build Gadgets in Wikipedia

Posted by Priyanka Nag on 9:42 PM in , , ,
Building gadgets in MediaWiki is awesomely simple and real fun. Well, I wasn't actually aware of it, until I attended the Gadget building workshop in GNUnify last week, taken by Yuvi, Sucheta and Harsh. Initial step didn't sound much interesting to me, as they were mostly talking stuff which I was already aware of and tried hands on, but Yuvi probably understood my disappointment, and soon came to my rescue with some really cool and interesting stuff. Writing JavaScript files in my own MediaWiki was a regular job which I had tried a few times already, but blending some cool Ajax codes in those JavaScript files was a real fun thing to learn. It was like mixing some cream in my rich coffee :P
Learning to make use of Special:ApiSandbox made life so much easier for me. Coding made so much easy using the multiple options here.
Sitting right there, did manage to put some Ajax codes into a js file and make it work fine. 
The learning didn't stop there. The fun continued as Yuvi went ahead to teach, how to package our codes and make it available for anyone across Wikipedia platform. So much work done in such simple ways and made so easily available for others too.

Here I will go ahead and give you a small example for a small task that can be done so easily using the perfect blend of Ajax and JavaScript:

$.get("/w/api.php?action=query&meta=userinfo&format=json&uiprop=editcount") 
.done(function(data){alert(data.query.userinfo.editcount);});

#I had added this small code in a JavaScript file that I had created. This code will basically give an alert of the user's edit count every time.

I had simply called this JavaScript page from my common.js file. If any other user wants to use my code, all he needs to do is import the required JavaScript file like:
importScript("User:Priyanka Nag/EditPage.js");
 
This is how simple making and packaging a Gadget is in Wikipedia. Well, I am calling it simple cause I did a very simple job here. Now, depending on your codes and purpose of your gadget, your gadget can be simple or complicated.


1 Comments

Post a Comment

If you like the blog, you may also want to checkout Priyanka's website