- Main article: InfoWidgets/Quickstart_guide
The methods you call for the preconfigured widgets contain no active code - just data. Let's take
Widget.stubs as an example:
You may override all of these properties. There are other optional properties you can add. And you've already seen there's one property you must set yourself: the selector (see the Quickstart guide).
|traversal||array||see text||see text|
You can use this prop to deactivate and subsequently reactivate widgets. Just set it to
false if you want to prevent a widget from updating and back to
true when you want it to update again. All by itself this will not reset the upate-interval. So if you don't want to wait up to 60 seconds to see your reactivated widget load, you also need to call
This function is called when the widget is updated. It receives a plain array with the page titles as the first and the value of
maxResults as the second paramater. This function is expected to return the HTML that is written into the div container.
The most simple version would look like this:
Note however that titles may show up more than once. If a page has been edited twice in a short period of time e.g. it will also show up twice in the recentchanges listing. That's why the default function filters out doublettes:
Use this to specify how many links at most you want the widget to display. This prop is only used in
widget.format. So feel free to ignore it, if you intend to write
This function is called after the container is emptied and before the AJAX request is made. You can use it to give the visitor some feedback that new contents are loading. This is the default function:
And this is the default image:
If you want to use an alternative image, you might want to upload it to this wiki and put it into the category InfoWidgets.
This function is the counterpart to widget.preload. It is called after the AJAX request has finished - even if it failed - and after the container is filled with the results of
widget.format(). This is the default function
This value tells the InfoWidgets whether to make an API request (value: "api") or and atom request (value: "rss"). This property must be set.
This is where the real action takes place. This (sub)object contains all the query-parameters that are sent to Wikia to perform an API or an atom request. While this is the most interesting part, it is unfortuntely also the one that's way beyond the scope of this guide. Fortunately however the API is quite self-documenting.
Transcoding an API request to a widget configuration is pretty straight-forward. Let's take an example:
This query lists all the pages on this wiki that link to the main page ("Wikia Developers Wiki"). The widget configuration would look like this:
There's one parameter missing however:
bltitle (the page title). Manually entering a page name here would be silly of course. We want the current page's name. Fortunately every page on this and every other wiki includes a large set of global variables that provide lots of information about (among other things) the current page. We will use the variable
wgTitle which contains the current page's title:
All of the preconfigured widgets produce very similar replies from the API. This is the server's reply to the newPages widget e.g.:
widget.traversal tells the InfoWidgets how to read a reply like the above. The default value is:
which - in this case - results to:
The first items in
widget.traversal list the names of the objects that have to be traversed to get to the list of answers and the last item is the property to get from that list.
Let's look at an example where you would actually have to specify
widget.traversal. This widget will list the ten last editors of the current page:
And the server would reply like this (assuming the current page is this wiki's main page):
widget.traversal would have to look like this now:
Some queries are bound to come back empty. Trying to show the watchlist of a visitor who isn't logged in e.g. will produce an empty list. You can use this property to provide a link that will be shown instead. The preconfigured watchlist uses Special:UserLogin as fallback.
This function is meant for debugging purposes only. It directly patches the error callback from jQuery.ajax through to you. The default function is simply:
If you're using Firebug, you could use this function to log error messages: