Changes

Jump to navigation Jump to search
no edit summary
Line 4: Line 4:  
// wd, wdt --> pdio, pdiot
 
// wd, wdt --> pdio, pdiot
 
// importScript and importStyleSheet replaced
 
// importScript and importStyleSheet replaced
//  
+
// turned into a common script
 +
// see doc at [[Gadget-QuickPresets/doc]]
   −
mw.loader.load( '/w/index.php?title=MediaWiki:quickpresets.css&action=raw&ctype=text/css', 'text/css' );
+
// mw.notify("QuickPresets")
 +
function debug(alert){
 +
// mw.notify(alert)
 +
}
 +
mw.loader.load( '/w/index.php?title=MediaWiki:Gadget-QuickPresets/defaultconf.css&action=raw&ctype=text/css', 'text/css' );
    
if( typeof(quick_props)=="undefined" ) {
 
if( typeof(quick_props)=="undefined" ) {
     mw.loader.load( '/w/index.php?title=MediaWiki:quickpresets_defaultconf.js&action=raw&ctype=text/javascript' );
+
     mw.loader.load( '/w/index.php?title=MediaWiki:Gadget-QuickPresets/defaultconf.js&action=raw&ctype=text/javascript' );
 
}
 
}
   Line 19: Line 24:  
     try {
 
     try {
 
$( ".quickpresetsiteminput input" ).entityselector( {
 
$( ".quickpresetsiteminput input" ).entityselector( {
    url: 'http://wiki.personaldata.io/w/api.php',
+
    url: 'https://wiki.personaldata.io/w/api.php',
 
    language: mw.config.get('wgUserLanguage')
 
    language: mw.config.get('wgUserLanguage')
 
} );
 
} );
Line 54: Line 59:  
e.preventDefault();
 
e.preventDefault();
 
if(dflt.type == "item") {
 
if(dflt.type == "item") {
            mw.notify("on click activated item")
   
    var selection = $(this).prev('input').data('entityselector').selectedEntity();
 
    var selection = $(this).prev('input').data('entityselector').selectedEntity();
 
    quickpresets_additemstatement(qid, dflt.pid, dflt.name, selection.id.substring(1), selection.label);
 
    quickpresets_additemstatement(qid, dflt.pid, dflt.name, selection.id.substring(1), selection.label);
 
}
 
}
 
else if(dflt.type == "string") {
 
else if(dflt.type == "string") {
mw.notify("on click activated string")
+
quickpresets_addstringstatement(qid, dflt.pid, dflt.name, $(this).prev('input')[0].value);
mw.notify("$(this).prev('input') "+$(this).prev('input'))
  −
    quickpresets_addstringstatement(qid, dflt.pid, dflt.name, $(this).prev('input')[0].value);
   
}
 
}
 
    });
 
    });
Line 95: Line 97:  
     api.post( {  
 
     api.post( {  
 
action: 'wbsetclaim',
 
action: 'wbsetclaim',
summary: "Added with [[User:Podehaye/quickpresets.js|Quickpresets]]",
+
summary: "Added with [[MediaWiki:Gadget-QuickPresets.js|Quickpresets]]",
 
claim: JSON.stringify(claim),
 
claim: JSON.stringify(claim),
 
token: token
 
token: token
Line 101: Line 103:  
function(aw){
 
function(aw){
 
    if(aw.success == 1)
 
    if(aw.success == 1)
$('.wikibase-statementgrouplistview').first().after( succtext );
+
//$('.wikibase-statementgrouplistview').first().after( succtext );
 +
mw.notify(succtext);
 
});  
 
});  
 
}
 
}
Line 114: Line 117:  
  */
 
  */
 
function quickpresets_additemstatement(qid, pid, pname, toqid, toname) {
 
function quickpresets_additemstatement(qid, pid, pname, toqid, toname) {
mw.notify("adding item statement")
+
var claim = {
    var claim = {
   
id: (new wb.utilities.ClaimGuidGenerator("q" + qid)).newGuid(),
 
id: (new wb.utilities.ClaimGuidGenerator("q" + qid)).newGuid(),
 
type: "claim",
 
type: "claim",
Line 131: Line 133:  
}
 
}
 
     };
 
     };
     quickpresets_addclaim(claim,  "<p>Added "+pname+" "+toname+"</p>");
+
     quickpresets_addclaim(claim,  "Added "+pname+" "+toname+"");
 
     // Check if we now support it with another element of the config
 
     // Check if we now support it with another element of the config
 
     if(pid == 3) {
 
     if(pid == 3) {
Line 151: Line 153:  
  */
 
  */
 
function quickpresets_addstringstatement(qid, pid, pname, str) {
 
function quickpresets_addstringstatement(qid, pid, pname, str) {
mw.notify("adding string statement")
+
var claim = {
mw.notify("adding str "+qid+" "+pid+" "+pname+" "+str)
  −
    var claim = {
   
id: (new wb.utilities.ClaimGuidGenerator("q" + qid)).newGuid(),
 
id: (new wb.utilities.ClaimGuidGenerator("q" + qid)).newGuid(),
 
type: "claim",
 
type: "claim",
Line 166: Line 166:  
}
 
}
 
     };
 
     };
     quickpresets_addclaim(claim,  "<p>Added "+pname+" \""+str+"\"</p>");
+
     quickpresets_addclaim(claim,  "Added "+pname+" "+str+"");
 
}
 
}
   Line 173: 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();})
        fetch( fullUrl, { headers } ).then( body => body.json() ).then( json => {
+
        .then(function(json) {if (json && json.boolean) {quickpresets_addinterface(qid, prop);}});
    if ( json.boolean )
  −
        quickpresets_addinterface(qid, prop);
  −
      } );
  −
    }
   
     }
 
     }
 +
  }
 
}
 
}
  

Navigation menu