This question already has an answer here:
I posted a oneboxed Wikipedia link in chat, and the image picked was seemingly a random image from the article.
- It wasn't the first image in source HTML
- it wasn't the first image in rendered HTML
- it wasn't the first image alphabetically.
The link was to main article, NOT to an anchor tag inside.
So, what is the algorithm for picking the image to use in Wikipedia's onebox?