MediaWiki

Sparql2data.js

Revision as of 10:50, 17 January 2022 by Yug (talk | contribs) (Created page with "var endpoint = 'https://lingualibre.org/sparql'; var sparql = 'SELECT ?item WHERE { ?item prop:P2 entity:Q5 } LIMIT 10'; var format = 'json'; var wikipage = 'MediaWiki:Mydata....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
var endpoint = 'https://lingualibre.org/sparql';
var sparql = 'SELECT ?item WHERE { ?item prop:P2 entity:Q5 } LIMIT 10';
var format = 'json';
var wikipage = 'MediaWiki:Mydata.js';


var data2wikipage = function(data,wikipage) {
    var params = {
            action: 'edit',
            title: wikipage,
            text: "Yug test!",
            format: 'json'
        },
    api = new mw.Api();

    api.postWithToken( 'csrf', params ).done( function ( data ) {
        console.log( data );
    } );
}

var sparql2data = async function(sparql, wikipage, format, endpoint) {
	wikipage = wikipage || 'Sandbox';
	format = format || 'json';
    endpoint = endpoint || 'https://lingualibre.org/sparql';
    var res = await $.getJSON(endpoint,
        { query: sparql, format: format },
        function(data, wikipage){ 
        	console.log('JQuery: ',data)
        	data2wikipage(data,wikipage);
        }
    );
}