Changes

Jump to navigation Jump to search
no edit summary
Line 1: Line 1:  
// taken from https://www.wikidata.org/wiki/User:MichaelSchoenitzer/quickpresets.js
 
// taken from https://www.wikidata.org/wiki/User:MichaelSchoenitzer/quickpresets.js
 +
// non exhaustive list of modifications:
 +
// P31 and P(subclass) ---> P3 and P4  (see #P31, pid == 3)
 +
// wd, wdt --> pdio, pdiot
 +
// importScript and importStyleSheet replaced
 +
// turned into a common script
 +
// see doc at [[Gadget-QuickPresets/doc]]
 +
 +
// 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' );
   −
importStylesheet( 'MediaWiki:quickpresets.css' );
   
if( typeof(quick_props)=="undefined" ) {
 
if( typeof(quick_props)=="undefined" ) {
     importScript( 'MediaWiki:quickpresets_defaultconf.js' );
+
     mw.loader.load( '/w/index.php?title=MediaWiki:Gadget-QuickPresets/defaultconf.js&action=raw&ctype=text/javascript' );
 
}
 
}
   Line 13: 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 52: Line 63:  
}
 
}
 
else if(dflt.type == "string") {
 
else if(dflt.type == "string") {
    quickpresets_addstringstatement(qid, dflt.pid, dflt.name, $(this).prev('input')[0].value);
+
quickpresets_addstringstatement(qid, dflt.pid, dflt.name, $(this).prev('input')[0].value);
 
}
 
}
 
    });
 
    });
Line 86: 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 92: 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 105: Line 117:  
  */
 
  */
 
function quickpresets_additemstatement(qid, pid, pname, toqid, toname) {
 
function quickpresets_additemstatement(qid, pid, pname, toqid, toname) {
    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 121: 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) { // MODIFIED LINE
+
     if(pid == 3) {
 
$('#quickpresets').remove();
 
$('#quickpresets').remove();
 
for( var t = 0; t<quick_props.length; t++) {
 
for( var t = 0; t<quick_props.length; t++) {
Line 141: Line 153:  
  */
 
  */
 
function quickpresets_addstringstatement(qid, pid, pname, str) {
 
function quickpresets_addstringstatement(qid, pid, pname, str) {
    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 154: Line 166:  
}
 
}
 
     };
 
     };
     quickpresets_addclaim(claim,  "<p>Added "+pname+" \""+str+"\"</p>");
+
     quickpresets_addclaim(claim,  "Added "+pname+" "+str+"");
 
}
 
}
   Line 161: 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
    var typefromdom=$.map($('#P3').find(".wikibase-snakview-value a"), function(value, index) {
+
  // for each "instance of" value, run this function
if(typeof value.attributes.href === "undefined")
+
  var typefromdom = $.map($("#P3").find(".wikibase-snakview-value a"), function(
    return [];
+
    value,
else  
+
    index
    return [value.attributes.href.value.substring(6)];
+
  ) {
     });
+
    if (typeof value.attributes.href === "undefined") {
    if ( typefromdom.length === 0) {
+
      return [];
if(typeqid === null)
+
    } else {
    quickpresets_addinterface(qid, prop);
+
      return [value.attributes.href.value.substring(6)];
 +
     }
 +
  });
 +
  // typefromdom is now a list of Item:Qxxx, possibly empty
 +
  if (typefromdom.length === 0) {
 +
    if (typeqid === null) {
 +
      // the null prescription for when there is no "instance of"
 +
      quickpresets_addinterface(qid, prop);
 
     }
 
     }
    else {
+
  } else {
if ( typeqid === 0 ) {
+
    if (typeqid === 0) {
    quickpresets_addinterface(qid, prop);
+
      // the 0 prescription, applicable to all items which are instance of something
}
+
      quickpresets_addinterface(qid, prop);
else if ( typefromdom.includes("Q"+typeqid) ) {
+
    } else if (typefromdom.includes("Item:Q" + typeqid)) {
    quickpresets_addinterface(qid, prop);
+
      // direct relevance
}
+
      quickpresets_addinterface(qid, prop);
else {
+
    } else {
    // Now check via sparql (much slower but includes subtypes)
+
      // indirect relevance, through subclassing
    const endpointUrl = 'https://query.personaldata.io/sparql',
+
      // Now check via sparql (much slower but includes subtypes)
sparqlQuery = 'Ask { wd:Q' + qid + ' wdt:P3/wdt:P4* wd:Q' + typeqid +
+
      const endpointUrl = "https://query.personaldata.io/proxy/wdqs/bigdata/namespace/wdq/sparql";
'. hint:Prior hint:gearing "forwards" }',
+
      const sparqlQuery = "Ask { pdio:Q" + qid + " pdiot:P3/pdiot:P4* pdio:Q" + typeqid + '. hint:Prior hint:gearing "forwards" }';
fullUrl = endpointUrl + '?query=' + encodeURIComponent( sparqlQuery ),
+
      const fullUrl = endpointUrl + "?query=" + encodeURIComponent(sparqlQuery);
headers = { 'Accept': 'application/sparql-results+json' };
+
      const myHeaders = { Accept: "application/sparql-results+json" };
    fetch( fullUrl, { headers } ).then( body => body.json() ).then( json => {
+
      debug("qid: " + qid + "\ntypeqid: " + typeqid + "\n" + fullUrl + "\n" + sparqlQuery );
if ( json.boolean )
+
      fetch(fullUrl, { headers: myHeaders })
    quickpresets_addinterface(qid, prop);
+
        .then(function(body) {body.json();})
    } );
+
        .then(function(json) {if (json && json.boolean) {quickpresets_addinterface(qid, prop);}});
}
   
     }
 
     }
 +
  }
 
}
 
}
   Line 215: Line 234:  
     var qid = mw.config.get( 'wbEntityId' );
 
     var qid = mw.config.get( 'wbEntityId' );
 
     if ( !qid ) {
 
     if ( !qid ) {
return;
+
    return;
 
     }
 
     }
 
     else {
 
     else {

Navigation menu