4

I saw a couple of solution to get the Wikidata Item from Wikipedia page. Generally, they use this pageprop query API:

https://en.wikipedia.org/w/api.php?action=query&prop=pageprops&redirects=1&titles=LONDON

But in my small version of media wiki, when I perform the same query, the result does not contain any wikidata id even though the page is site-linked to a wikidata item.

Is there any data/script I need to run? What might be the possible cause of this?

Additional Info:

I found out also that when I do a list of prop name, the wikibase_item is not there. Below are the same example from wikipedia which works.

https://en.wikipedia.org/w/api.php?action=query&list=pagepropnames&ppnlimit=100
Loredra L
  • 1,485
  • 2
  • 16
  • 32
  • Quick link for others viewing: 1) [Wikipedia API Reference](https://en.wikipedia.org/w/api.php?action=help&modules=query), 2) [Wikidata API Reference](https://www.wikidata.org/w/api.php) – RichS Apr 24 '19 at 20:29

1 Answers1

0

If I understand your question correctly, you want to use webentityusage in your query to get the wikidata ids. So, for your particular example, with London, you would use:

https://en.wikipedia.org/w/api.php?action=query&prop=pageprops|wbentityusage&titles=London

The entry at the bottom has all the data associated with London: Scroll down in the JSON and you'll see:

"wbentityusage": {
    ...
    "Q84": {
      ...
    }
}

Q84 also shows as the "wikibase_item" under pageprops.

Then, all the data associated with london is at: https://www.wikidata.org/wiki/Q84

(which can also be accessed via wikidata apis)


EDIT: Here's yet another example. (for wikidata-specific items, it can sometimes help to work in reverse...i.e., list all the pages that reference data Q[nnn])

The following wikipedia page uses some wikidata item(s): https://en.wikipedia.org/wiki/Template:Pageid_to_title

Specifically, it uses Earth (Q2). So, if we use the wikipedia API: https://en.wikipedia.org/w/api.php?action=query&prop=pageprops|wbentityusage&titles=Template:Pageid_to_title

It will show Q2 under the wbentityusage for the pageId 49086285. Not under pageprops. Pageprops will only show the wikibase_item.

It's important to note that even though the query is identical on both wikipedia and wikidata, the results will be different based on which domain you run it on.

Also helpful (work in reverse): to see what wikipedia pages reference a particular wikidata item, you would use

https://en.wikipedia.org/w/api.php?action=query&list=wblistentityusage&wbeuentities=Q2&wbeuprop=url --> Shows all the wikipedia pages referencing Q2 (Earth)

https://wikidata.org/w/api.php?action=query&list=wblistentityusage&wbeuentities=Q2&wbeuprop=url --> Shows all the wikidata pages referencing Q2 (Earth)

And, just for fun, I edited that wikipedia page Template:Pageid_to_title to reference Q3 (Life) and...after a little bit of patience waiting for things to sync, the API now responds with Q3 as also being one of the wikidata items associated with that page.

RichS
  • 913
  • 4
  • 12
  • 1
    yes, I can do what you suggested. But that is not the correct way to get the associated wikidata item. It should use the pageprops query – Loredra L Apr 24 '19 at 09:01
  • With the particular page "London", there is only reference to the Q84 (see [source](https://en.wikipedia.org/w/index.php?title=London&action=edit)). Even though there are datatables (climate), those aren't wikidata ([manual entry :(](https://en.wikipedia.org/w/index.php?title=Climate_of_London&action=edit&section=2)), although it would be nice if they were. The Q84 shows up as being associated with the page 17867. – RichS Apr 24 '19 at 21:10
  • I've been trying to find a better wikipedia page with more wikidata items referenced ([Mount Everest](https://www.wikidata.org/wiki/Q513) maybe?) to provide an easier example to work with. – RichS Apr 24 '19 at 21:11