| 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 58: |
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 92: |
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 98: |
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 111: |
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 127: |
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 147: |
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 160: |
Line 166: |
| | } | | } |
| | }; | | }; |
| − | quickpresets_addclaim(claim, "<p>Added "+pname+" \""+str+"\"</p>"); | + | quickpresets_addclaim(claim, "Added "+pname+" "+str+""); |
| | } | | } |
| | | | |
| Line 167: |
Line 173: |
| | */ | | */ |
| | function quickpresets_checktype(qid, prop) { | | function quickpresets_checktype(qid, prop) { |
| − | mw.notify(qid)
| + | var typeqid = prop.qid; |
| − | var typeqid=prop.qid;
| + | // Search in HTML-DOM |
| − | mw.notify(typeqid)
| + | // for each "instance of" value, run this function |
| − | // Search in HTML-DOM
| + | var typefromdom = $.map($("#P3").find(".wikibase-snakview-value a"), function( |
| − | var typefromdom=$.map($('#P3').find(".wikibase-snakview-value a"), function(value, index) {
| + | value, |
| − | if(typeof value.attributes.href === "undefined")
| + | index |
| − | {
| + | ) { |
| − | mw.notify("exit 1");
| + | if (typeof value.attributes.href === "undefined") { |
| − | return [];
| + | return []; |
| − | }
| + | } else { |
| − | else
| + | return [value.attributes.href.value.substring(6)]; |
| − | {
| + | } |
| − | mw.notify("exit 2");
| + | }); |
| − | return [value.attributes.href.value.substring(6)];
| + | // typefromdom is now a list of Item:Qxxx, possibly empty |
| − | }
| + | if (typefromdom.length === 0) { |
| − | });
| + | if (typeqid === null) { |
| − | mw.notify(typefromdom)
| + | // the null prescription for when there is no "instance of" |
| − | if ( typefromdom.length === 0) {
| + | quickpresets_addinterface(qid, prop); |
| − | if(typeqid === null)
| |
| − | {
| |
| − | mw.notify("exit 3")
| |
| − | quickpresets_addinterface(qid, prop);
| |
| − | }
| |
| | } | | } |
| − | else {
| + | } else { |
| − | mw.notify("exit 4") | + | if (typeqid === 0) { |
| − | if ( typeqid === 0 ) {
| + | // the 0 prescription, applicable to all items which are instance of something |
| − | mw.notify("exit 5")
| + | quickpresets_addinterface(qid, prop); |
| − | quickpresets_addinterface(qid, prop);
| + | } else if (typefromdom.includes("Item:Q" + typeqid)) { |
| − | }
| + | // direct relevance |
| − | else if ( typefromdom.includes("Item:Q"+typeqid) ) {
| + | quickpresets_addinterface(qid, prop); |
| − | mw.notify("exit 6")
| + | } else { |
| − | quickpresets_addinterface(qid, prop);
| + | // indirect relevance, through subclassing |
| − | }
| + | // Now check via sparql (much slower but includes subtypes) |
| − | else {
| + | const endpointUrl = "https://query.personaldata.io/proxy/wdqs/bigdata/namespace/wdq/sparql"; |
| − | mw.notify("exit 7")
| + | const sparqlQuery = "Ask { pdio:Q" + qid + " pdiot:P3/pdiot:P4* pdio:Q" + typeqid + '. hint:Prior hint:gearing "forwards" }'; |
| − | // Now check via sparql (much slower but includes subtypes)
| + | const fullUrl = endpointUrl + "?query=" + encodeURIComponent(sparqlQuery); |
| − | const endpointUrl = 'https://query.personaldata.io/proxy/wdqs/bigdata/namespace/wdq/sparql',
| + | const myHeaders = { Accept: "application/sparql-results+json" }; |
| − | sparqlQuery = 'Ask { pdio:Q' + qid + ' pdiot:P3/pdiot:P4* pdio:Q' + typeqid +
| + | debug("qid: " + qid + "\ntypeqid: " + typeqid + "\n" + fullUrl + "\n" + sparqlQuery ); |
| − | '. hint:Prior hint:gearing "forwards" }',
| + | fetch(fullUrl, { headers: myHeaders }) |
| − | fullUrl = endpointUrl + '?query=' + encodeURIComponent( sparqlQuery ),
| + | .then(function(body) {body.json();}) |
| − | headers = { 'Accept': 'application/sparql-results+json' };
| + | .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);
| |
| − | } );
| |
| − | }
| |
| | } | | } |
| | + | } |
| | } | | } |
| | | | |