MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
(New Version) |
||
Line 2: | Line 2: | ||
/*Code from https://www.mediawiki.org/w/index.php?title=User:TheDJ/common.js&oldid=2187846*/ | /*Code from https://www.mediawiki.org/w/index.php?title=User:TheDJ/common.js&oldid=2187846*/ | ||
function | function sideJSONMessage() { | ||
console.log("Entering"); | console.log("Entering"); | ||
jQuery.when(mw.loader.using(['mediawiki.api', 'mediawiki.jqueryMsg']), jQuery.ready ).done( function() { | jQuery.when(mw.loader.using(['mediawiki.api', 'mediawiki.jqueryMsg']), jQuery.ready ).done( function() { | ||
console.log("Entered"); | console.log("Entered"); | ||
new mediaWiki.Api().loadMessagesIfMissing( ['T-wb-json', 't-wb-json | new mediaWiki.Api().loadMessagesIfMissing(['T-wb-json', 't-wb-json']).done( function() { | ||
// | |||
//var node = document.getElementById('p-tb') .getElementsByTagName( 'div' )[0] .getElementsByTagName( 'ul' )[0]; | |||
/*var pNode = document.createElement( 'p' ); | |||
var pNode = document.createElement( 'p' ); | |||
console.log("t-wb-json: " + mw.message('t-wb-json').plain()); | console.log("t-wb-json: " + mw.message('t-wb-json').plain()); | ||
pNode.innerHTML = 'Test: ' + mw.message('t-wb-json').plain(); | pNode.innerHTML = 'Test: ' + mw.message('t-wb-json').plain();*/ | ||
AddJSONLinkToSidebar(); | AddJSONLinkToSidebar(); | ||
}); | }); | ||
} ); | } ); | ||
} | } | ||
Line 121: | Line 61: | ||
//menuMessage = new mw.Message(mw.messages, idName); | //menuMessage = new mw.Message(mw.messages, idName); | ||
//menuMessage = new mw.Message(idName, name); | //menuMessage = new mw.Message(idName, name); | ||
menuMessage = new mw.Message(messages, idName); | /*menuMessage = new mw.Message(messages, idName); | ||
console.log("menuMessage: " + menuMessage); | console.log("menuMessage: " + menuMessage); | ||
console.log("menuMessage.text(): " + menuMessage.text()); | console.log("menuMessage.text(): " + menuMessage.text()); | ||
console.log("menuMessage.escaped(): " + menuMessage.escaped()); | console.log("menuMessage.escaped(): " + menuMessage.escaped()); | ||
console.log("menuMessage.plain(): " + menuMessage.plain()); | console.log("menuMessage.plain(): " + menuMessage.plain()); | ||
console.log("menuMessage.parse(): " + menuMessage.parse()); | console.log("menuMessage.parse(): " + menuMessage.parse());*/ | ||
var node = document.getElementById( target ) | var node = document.getElementById( target ) | ||
Line 142: | Line 82: | ||
//aNode.text = menuMessage.escaped(); | //aNode.text = menuMessage.escaped(); | ||
//aNode.text = menuMessage.plain(); | //aNode.text = menuMessage.plain(); | ||
aNode.text = | aNode.text = mw.message('t-wb-json').plain(); | ||
aNode.setAttribute( 'href', link ); | aNode.setAttribute( 'href', link ); | ||
Line 154: | Line 94: | ||
return; | return; | ||
} | } | ||
} | } | ||
function AddJSONLinkToSidebar() { | function AddJSONLinkToSidebar() { | ||
/*Returns an array containing the variables requested. | /*Returns an array containing the variables requested. | ||
/*From https://www.mediawiki.org/wiki/ResourceLoader/Core_modules#mediaWiki.config*/ | /*From https://www.mediawiki.org/wiki/ResourceLoader/Core_modules#mediaWiki.config*/ | ||
Line 194: | Line 113: | ||
if (PageName.substr(0, 5).toLowerCase() == "item:") { | if (PageName.substr(0, 5).toLowerCase() == "item:") { | ||
var ItemName = PageName.split(':'); | var ItemName = PageName.split(':'); | ||
AddItemToSidebar('toolbox', 't-wb-json', 'JSON', conf.wgServer + '/wiki/Special:EntityData/' + ItemName[1] + '.json'); | AddItemToSidebar('toolbox', 't-wb-json', 'JSON', conf.wgServer + '/wiki/Special:EntityData/' + ItemName[1] + '.json'); | ||
AddItemToSidebar('toolbox', 't-wb-json2', 'JSON2', conf.wgServer + '/wiki/Special:EntityData/' + ItemName[1] + '.json'); | //AddItemToSidebar('toolbox', 't-wb-json2', 'JSON2', conf.wgServer + '/wiki/Special:EntityData/' + ItemName[1] + '.json'); | ||
} | } | ||
} | } | ||
/*jQuery( CustomizeModificationsOfSidebar );*/ | /*jQuery( CustomizeModificationsOfSidebar );*/ | ||
jQuery( | jQuery(sideJSONMessage); | ||
//jQuery(AddJSONLinkToSidebar); | //jQuery(AddJSONLinkToSidebar); |
Revision as of 23:06, 25 March 2021
/* Any JavaScript here will be loaded for all users on every page load. */
/*Code from https://www.mediawiki.org/w/index.php?title=User:TheDJ/common.js&oldid=2187846*/
function sideJSONMessage() {
console.log("Entering");
jQuery.when(mw.loader.using(['mediawiki.api', 'mediawiki.jqueryMsg']), jQuery.ready ).done( function() {
console.log("Entered");
new mediaWiki.Api().loadMessagesIfMissing(['T-wb-json', 't-wb-json']).done( function() {
//var node = document.getElementById('p-tb') .getElementsByTagName( 'div' )[0] .getElementsByTagName( 'ul' )[0];
/*var pNode = document.createElement( 'p' );
console.log("t-wb-json: " + mw.message('t-wb-json').plain());
pNode.innerHTML = 'Test: ' + mw.message('t-wb-json').plain();*/
AddJSONLinkToSidebar();
});
} );
}
function AddItemToSidebar(section, idName, name, link) {
var target
var menuMessage
try {
switch ( section ) {
case 'languages':
target = 'p-lang';
break;
case 'toolbox':
target = 'p-tb';
break;
case 'navigation':
target = 'p-navigation';
break;
default:
target = 'p-' + section;
break;
}
//See https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Message
//See https://www.mediawiki.org/wiki/Manual:Messages_API#Using_messages_in_JavaScript
console.log("idName: " + idName);
console.log("name: " + name);
messages = new mw.Map();
/*mw.messages.set( {
idName: name,
't-wb-json': 'JSON',
'hello': 'Hello world',
'hello-user': 'Hello, $1!',
'welcome-user': 'Welcome back to $2, $1! Last visit by $1: $3'
} );*/
//messages.set({idName: name});
//messages.set({'t-wb-json': 'JSON'});
//messages.set({idName: 'JSON'});
//messages.set({idName: name.toString()});
messages.set(idName, name);
//messages.set({name: idName});
//menuMessage = new mw.Message(mw.messages, idName);
//menuMessage = new mw.Message(idName, name);
/*menuMessage = new mw.Message(messages, idName);
console.log("menuMessage: " + menuMessage);
console.log("menuMessage.text(): " + menuMessage.text());
console.log("menuMessage.escaped(): " + menuMessage.escaped());
console.log("menuMessage.plain(): " + menuMessage.plain());
console.log("menuMessage.parse(): " + menuMessage.parse());*/
var node = document.getElementById( target )
.getElementsByTagName( 'div' )[0]
.getElementsByTagName( 'ul' )[0];
var aNode = document.createElement( 'a' );
var liNode = document.createElement( 'li' );
/*aNode.appendChild( document.createTextNode( name ) );*/
//aNode.text = mw.message(idName).text();
//aNode.text = menuMessage.text();
//aNode.text = menuMessage.toString();
//aNode.text = menuMessage.escaped();
//aNode.text = menuMessage.plain();
aNode.text = mw.message('t-wb-json').plain();
aNode.setAttribute( 'href', link );
liNode.appendChild( aNode );
/*liNode.className = 'plainlinks';*/
liNode.id = idName;
node.appendChild( liNode );
} catch( e ) {
// let's just ignore what's happened
return;
}
}
function AddJSONLinkToSidebar() {
/*Returns an array containing the variables requested.
/*From https://www.mediawiki.org/wiki/ResourceLoader/Core_modules#mediaWiki.config*/
var conf = mw.config.get([
'wgServer',
'wgWikibaseItemId',
'wgPageName'
]);
var PageName = conf.wgPageName;
/*
console.log(PageName);
console.log(PageName.substr(0, 5));
console.log(PageName.substr(0, 5).toLowerCase());
*/
if (PageName.substr(0, 5).toLowerCase() == "item:") {
var ItemName = PageName.split(':');
AddItemToSidebar('toolbox', 't-wb-json', 'JSON', conf.wgServer + '/wiki/Special:EntityData/' + ItemName[1] + '.json');
//AddItemToSidebar('toolbox', 't-wb-json2', 'JSON2', conf.wgServer + '/wiki/Special:EntityData/' + ItemName[1] + '.json');
}
}
/*jQuery( CustomizeModificationsOfSidebar );*/
jQuery(sideJSONMessage);
//jQuery(AddJSONLinkToSidebar);