Changes

Jump to navigation Jump to search
m
no edit summary
Line 1: Line 1: −
console.log('+');
+
// License: GPL
 +
// Experimental Main
 +
console.log("''");
   −
var controller_item_id = 96;
+
var mwEStruct = {
 +
wbXntity: 'config.values.wbEntity'
 +
},
   −
var wbEStruct = [
+
language = "en",
'claims.P3', // location of P3 relations in wbEntity
  −
'mainsnak.datavalue.value', // location of ID properties in related entity
  −
'numeric-id' // ID property name which checked
  −
];
     −
// check if we are on a page of a loaded Entity
+
WBEStructure = {
if ( typeof mw.config.values.wbEntity != "undefined" ) {
+
subclassOfRelations: 'claims.P4', // location of P4 relations in wbEntity
 +
defaultValRelation: 'claims.P108',
 +
concernsRelation: 'claims.P110',
 +
instanceOfRelations: 'claims.P3',
 +
IDPropLoc: 'mainsnak.datavalue.value', // location of ID properties in related entity
 +
IDName: 'numeric-id', // ID property name which checked
 +
qIDPropName: 'id',
 +
standardValue: 'labels' + '.' + language + '.' + 'value'
 +
},
 +
 
 +
Relational_id_list = {
 +
controller_id: [ WBEStructure['instanceOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 96 ],
 +
personal_data_id: [ WBEStructure['subclassOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 421 ],
 +
interface_button_id: [ WBEStructure ['instanceOfRelations'], WBEStructure['IDPropLoc'], WBEStructure['IDName'], 487 ]
 +
},
 +
 
 +
PDWikibaseProcessor,
 +
PDindexedDB,
 +
PDOOUI,
 +
Current_entity;
 +
 
 +
 
 +
// JQ.'when' loads the current scripts asynchronously, continues when loading is 'done'
 +
$.when(
 +
    $.getScript( "//wiki.personaldata.io/w/index.php?title=User:Abel/WbProcessor.js&action=raw&ctype=text/javascript" ),
 +
    $.getScript( "//wiki.personaldata.io/w/index.php?title=User:Abel/PersonalData.js&action=raw&ctype=text/javascript" ),
 +
    $.getScript( "//wiki.personaldata.io/w/index.php?title=User:Abel/OOInterface.js&action=raw&ctype=text/javascript" ),
 +
    $.Deferred( function( deferred ){
 +
        $( deferred.resolve );
 +
    })
 +
).done( function(){
 +
 
 +
console.log('Main thread');
 +
 
 +
// WBproc reads current mediawiki Entity upon instantiation
 +
PDWikibaseProcessor = new WikibaseProcessorContainer(mw, mwEStruct['wbXntity']);
 +
 
 +
// PDxDB takes mediawiki, reads user name from it, creates a hash, and 'checks in' the user upon instantiation
 +
// (i.e. read record belonging to user, if it does not exist, create it)
 +
PDindexedDB = new IndexedDBContainer( mw );
 
 
// get wbEntity as json
+
// Contains classes for creating UI elements, no instantiation consequences
var obj = JSON.parse ( mw.config.values.wbEntity );
+
PDOOUI = new InterfaceMediaContainer( PDWikibaseProcessor, PDindexedDB );
 +
 
 +
// Check if the current entity belongs to any path of interest.  
 +
// For each element in object argument, a corresponding element in the return object will contain one of the following:
 +
// - undefined - the path didn't exist even partly)
 +
// - [ value or object ] - if the path existed fully, it returns what is at the end of the path. If last element in path is a value, it will return the value if found
 +
 
 +
Current_entity = PDWikibaseProcessor.checkentity( Relational_id_list );
 
 
// check if we have P3 relations and iterate through
+
// Business logicish part.
if ( typeof obj.claims.P3 != "undefined" ) {
+
// If any path of interest returned anything...
for( var i = 0; i < dive(obj, wbEStruct[0]).length; i++ ) {
+
if ( Current_entity != undefined ) {
+
Object.keys(Current_entity).forEach( function ( entity_checked ){
// check if we have controller id constructed from wbEntity
+
//... for each path that returned something
if( dive(dive(obj, wbEStruct[0])[i] , wbEStruct[1])[wbEStruct[2]] === controller_item_id ) {
+
if ( Current_entity[entity_checked] != undefined ){
+
if ( Object.keys( Current_entity[entity_checked] ).length > 0 ) {
var $title2 = $( '.wikibase-title' ),
+
PDOOUI.renderInterface( entity_checked );
qId2 = $title2.find( '.wikibase-title-id' ).text().replace( /[()]/g, '' );
+
//... call the OOUI renderer to render what belongs to this input
 
+
}
api.get( {
  −
    action: 'expandtemplates',
  −
    text: '{{MailtoAccess|'+qId+'}}'
  −
} ).done( function ( data ) {
  −
    mw.notify( $('<span>Abel\'s <a href="https://wiki.personaldata.io/wiki/User:Abel/experimental.js">experimental script</a>, called from <a href="https://wiki.personaldata.io/wiki/MediaWiki:common.js">sitewide common.js</a>.</span> <a href="'+data.expandtemplates["*"]+'"> Do a SAR to this controller!</a>') , { autoHide: false } );
  −
} );
  −
   
}
 
}
}
+
});
 
}
 
}
// Else let's do nothing;
  −
}
  −
console.log("-");
  −
console.log(dive(obj, wbEStruct[1]));
  −
console.log(dive(obj, wbEStruct[2]));
  −
console.log("~");
  −
  −
// helper function for diving into a part of array
  −
function indexinterpolate(obj,i) { (obj[i] != undefined) ? return obj[i] : return obj};
     −
// dive selects mymatrix.a.b.c.d from mymatrix array and 'a.b.c.d' as string
+
});
function dive(array, read){
  −
return read.split('.').reduce(indexinterpolate, array);
  −
}
 
530

edits

Navigation menu