Wikipedia article images URL and license extraction / get
Wikipedia article images URL and license extraction / get, using JSONP within the client browser.
by youtag
HTML
<div id="imgs"></div>
CSS
#imgs img {
width: 400px;
}
JavaScript
//Getting phenomenons images URL and licensing from Wikipedia, using the Wikipedia API: http://en.wikipedia.org/w/api.php
var page = "http://en.wikipedia.org/wiki/Luxembourg";
var title = page.split("/");
title = title[title.length - 1];
//Images and their licencing
$.getJSON("http://en.wikipedia.org/w/api.php?action=parse&page=" + title + "&prop=images&format=json&callback=?", function (data) {
var imgsHtml = "";
for (img in data["parse"]["images"]) {
$.getJSON("http://en.wikipedia.org/w/api.php?action=query&titles=Image:" + data["parse"]["images"][img] + "&prop=imageinfo&iiprop=url&meta=siteinfo&siprop=rightsinfo&format=json&callback=?", function (data) {
for (n in data["query"]["pages"]) {
imgsHtml += "<img src=\"" + data["query"]["pages"][n]["imageinfo"][0]["url"] + "\"><br><a href='http:"+data["query"]["rightsinfo"].url+"'>"+data["query"]["rightsinfo"].text+"</a><br><br><br>";
};
$("#imgs").html(imgsHtml);
});
}
});