Changes

Jump to navigation Jump to search
no edit summary
Line 7: Line 7:  
// see doc at [[Gadget-QuickPresets/doc]]
 
// see doc at [[Gadget-QuickPresets/doc]]
    +
// mw.notify("QuickPresets")
 
function debug(alert){
 
function debug(alert){
 
// mw.notify(alert)
 
// mw.notify(alert)
Line 103: Line 104:  
    if(aw.success == 1)
 
    if(aw.success == 1)
 
//$('.wikibase-statementgrouplistview').first().after( succtext );
 
//$('.wikibase-statementgrouplistview').first().after( succtext );
mw.notify(succtext)
+
mw.notify(succtext);
 
});  
 
});  
 
}
 
}
Line 172: Line 173:  
  */
 
  */
 
function quickpresets_checktype(qid, prop) {
 
function quickpresets_checktype(qid, prop) {
var typeqid=prop.qid;
+
  var typeqid = prop.qid;
    // Search in HTML-DOM
+
  // Search in HTML-DOM
    // for each "instance of" value, run this function
+
  // for each "instance of" value, run this function
    var typefromdom=$.map($('#P3').find(".wikibase-snakview-value a"), function(value, index) {
+
  var typefromdom = $.map($("#P3").find(".wikibase-snakview-value a"), function(
if(typeof value.attributes.href === "undefined")
+
    value,
    {
+
    index
        return [];
+
  ) {
    }
+
    if (typeof value.attributes.href === "undefined") {
else
+
      return [];
    {
+
    } else {
        return [value.attributes.href.value.substring(6)];
+
      return [value.attributes.href.value.substring(6)];
    }
+
    }
    });
+
  });
    // typefromdom is now a list of Item:Qxxx, possibly empty
+
  // typefromdom is now a list of Item:Qxxx, possibly empty
    if ( typefromdom.length === 0) {
+
  if (typefromdom.length === 0) {
    if(typeqid === null) // the null prescription for when there is no "instance of"
+
    if (typeqid === null) {
        {
+
      // the null prescription for when there is no "instance of"
            quickpresets_addinterface(qid, prop);
+
      quickpresets_addinterface(qid, prop);
        }
   
     }
 
     }
    else {
+
  } else {
    if ( typeqid === 0 ) {
+
    if (typeqid === 0) {
    // the 0 prescription, applicable to all items which are instance of something
+
      // the 0 prescription, applicable to all items which are instance of something
    quickpresets_addinterface(qid, prop);
+
      quickpresets_addinterface(qid, prop);
    }
+
    } else if (typefromdom.includes("Item:Q" + typeqid)) {
    else if ( typefromdom.includes("Item:Q"+typeqid) ) {
+
      // direct relevance
    // direct relevance
+
      quickpresets_addinterface(qid, prop);
    quickpresets_addinterface(qid, prop);
+
    } else {
    }
+
      // indirect relevance, through subclassing
    else {
+
      // Now check via sparql (much slower but includes subtypes)
    // indirect relevance, through subclassing
+
      const endpointUrl = "https://query.personaldata.io/proxy/wdqs/bigdata/namespace/wdq/sparql";
        // Now check via sparql (much slower but includes subtypes)
+
      const sparqlQuery = "Ask { pdio:Q" + qid + " pdiot:P3/pdiot:P4* pdio:Q" + typeqid + '. hint:Prior hint:gearing "forwards" }';
        const endpointUrl = 'https://query.personaldata.io/proxy/wdqs/bigdata/namespace/wdq/sparql',
+
      const fullUrl = endpointUrl + "?query=" + encodeURIComponent(sparqlQuery);
    sparqlQuery = 'Ask { pdio:Q' + qid + ' pdiot:P3/pdiot:P4* pdio:Q' + typeqid +
+
      const myHeaders = { Accept: "application/sparql-results+json" };
    '. hint:Prior hint:gearing "forwards" }',
+
      debug("qid: " + qid + "\ntypeqid: " + typeqid + "\n" + fullUrl + "\n" + sparqlQuery );
    fullUrl = endpointUrl + '?query=' + encodeURIComponent( sparqlQuery ),
+
      fetch(fullUrl, { headers: myHeaders })
    headers = { 'Accept': 'application/sparql-results+json' };
+
        .then(function(body) {body.json();})
    debug("qid: "+ qid + "\ntypeqid: " + typeqid + "\n" + fullUrl + "\n" + sparqlQuery)
+
        .then(function(json) {if (json && json.boolean) {quickpresets_addinterface(qid, prop);}});
        fetch( fullUrl, { headers } ).then( body => body.json() ).then( json => {
  −
    if ( json.boolean )
  −
        quickpresets_addinterface(qid, prop);
  −
      } );
  −
    }
   
     }
 
     }
 +
  }
 
}
 
}
  

Navigation menu