How to include images in Wikipedia API search results?

How to include images in Wikipedia API search results?
0

#1

So, I see that I can complete the project using opensearch. It’s short, it’s sweet, it returns a manageable little 3-array result. But I keep thinking, wouldn’t it be sweet if our “viewer” included images? You know, like when you Google something and (at least in Chrome), alongside the Google results, Google puts together a little box with a Wikipedia entry’s title, snippet, and first image.

So I was looking into API:Query, using prop=images and list=search, but I don’t see any image URLs in the results (that would be /w/api.php?action=query&format=json&prop=images&list=search&srsearch=chrometry in sandbox. Anybody see a way to do this?


#2

I as well would love to know. I’m hitting the same wall here!


#3

same here, I found this page
https://www.mediawiki.org/wiki/API:Imageinfo

the propriete iiprop: ‘url’ doesn’t work?

$.ajax({
  url: '//en.wikipedia.org/w/api.php',
  data: { action: 'query', list: 'search', iiprop: 'url', srsearch: textSearch, format: 'json' },
  dataType: 'jsonp',

#4

Actually, looking closer, in the effect when a Google search page showcases a snippet of a Wikipedia article and an image, the images are being delivered by a Google Image search. Maybe the simplest solution actually would be to add a call to a Google Images API. Except that’s not quite simple…


#5

or a do another loop, I’m in the first $.each.


#6

Oh holy carp. Of course that’s not going to be feasible. I don’t want the same image next to all entries, which means I’m not feeding the user’s search term to Google; I’m harvesting (somehow) the titles of the Wikipedia articles and using them as queries, each in its own individual Google Custom Search call. And the free service caps out at 100 per day–you could run through that in one search!


#7

it’s not that, the first search don’t bring to a page but a list, so to do that you can nested another loop.
That logical for now for me.


#8

Egad, I found the perfect answer! https://www.mediawiki.org/wiki/API:Page_info_in_search_results !! Except for some reason when I try to integrate it that second call isn’t returning successfully. Anybody see what I’m doing wrong? http://codepen.io/AbdiViklas/pen/BzbVgd?editors=0011


#9

Wait, found it; lowercase “t” in “dataType” in line 23. And now it works!


#10

Okay, all implemented, made pretty and ready for prime time: http://codepen.io/AbdiViklas/pen/VjdXOm?editors=0010