Skip to content

Research: Wikidata

Ersun Sözen edited this page Feb 17, 2020 · 1 revision

Wikidata is a free and open knowledge base that can be read and edited by both humans and machines.

Wikidata acts as central storage for the structured data of its Wikimedia sister projects including Wikipedia, Wikivoyage, Wiktionary, Wikisource, and others.

Wikidata API

The MediaWiki action API is a web service that allows access to some wiki-features like authentication, page operations, and search.

It can provide meta information about the wiki and the logged-in user.

Endpoint

All Wikimedia wikis have endpoints that follow this pattern: https://www.example.org/w/api.php

Examples of Wikimedia Wiki Endpoints

API Endpoint Wiki
https://www.mediawiki.org/w/api.php MediaWiki API
https://meta.wikimedia.org/w/api.php Meta-Wiki API
https://en.wikipedia.org/w/api.php English Wikipedia API
https://nl.wikipedia.org/w/api.php Dutch Wikipedia API
https://commons.wikimedia.org/w/api.php Wikimedia Commons API
https://test.wikipedia.org/w/api.php Test Wiki API

Sample Code

var url = "https://en.wikipedia.org/w/api.php"; 

var params = {
    action: "query",
    list: "search",
    srsearch: "Nelson Mandela",
    format: "json"
};

url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});

fetch(url)
    .then(function(response){return response.json();})
    .then(function(response) {
        if (response.query.search[0].title === "Nelson Mandela"){
            console.log("Your search page 'Nelson Mandela' exists on English Wikipedia" );
        }
    })
    .catch(function(error){console.log(error);});

Sample Response

json
{
    "batchcomplete": "",
    "continue": {
        "sroffset": 10,
        "continue": "-||"
    },
    "query": {
        "searchinfo": {
            "totalhits": 5060
        },
        "search": [
            {
                "ns": 0,
                "title": "Nelson Mandela",
                "pageid": 21492751,
                "size": 196026,
                "wordcount": 23664,
                "snippet": "<span class=\"searchmatch\">Nelson</span> Rolihlahla <span class=\"searchmatch\">Mandela</span> (/mænˈdɛlə/, Xhosa: [xoliɬaˈɬa <span class=\"searchmatch\">manˈdɛla</span>]; 18 July 1918 – 5 December 2013) was a South African anti-apartheid revolutionary,",
                "timestamp": "2018-07-23T07:59:43Z"
            },
            {
                "ns": 0,
                "title": "Death of Nelson Mandela",
                "pageid": 41284488,
                "size": 133513,
                "wordcount": 13512,
                "snippet": "On December 5, 2013, <span class=\"searchmatch\">Nelson</span> <span class=\"searchmatch\">Mandela</span>, the first President of South Africa to be elected in a fully representative democratic election, as well as the country's",
                "timestamp": "2018-07-19T17:30:59Z"
            }
            ...
        ]
    }
}

List of Sister Projects

  • Wikimedia Commons
  • MediaWiki
  • Meta-Wiki
  • Wikispecies
  • Wikibooks
  • Wikimania
  • Wikinews
  • Wikipedia
  • Wikiquote
  • Wikisource
  • Wikiversity
  • Wikivoyage
  • Wiktionary

Resources

Clone this wiki locally