MediaWiki:TemplateTools.js

/* Template Tools, Version 0.5alpha, licensed under BY-NC-SA 2.0 only. * An alternate GDFL licensed version is available elsewhere. */

/* This should be loaded from MediaWiki:common.js * Modules currently installed: *    MediaWiki:SkillTools.js *  */ document.write(' ');

/*

templateToolsInit
*/

function templateToolsInit { if(queryString('action')!='edit' && queryString('action')!='submit') return;

/* hides the hard-wired links provided by MediaWiki:NewArticleText which is used (new articles only) if the user disables Javascript */ var hardlinkdiv = document.getElementById('template_tools_hard_links'); if(hardlinkdiv) { hardlinkdiv.style.display = 'none'; }

var editBuffer = document.getElementById("editform");

var debugDiv = document.createElement("div"); debugDiv.id = 'debugDiv'; editBuffer.parentNode.insertBefore(debugDiv, editBuffer); debugDiv.style.background='orange'; debugDiv.style.clear='both'; debugDiv.style.display = 'none';

var templateToolsDiv = document.createElement("div"); templateToolsDiv.id = 'templateToolsDiv'; templateToolsDiv.style.border = '1px solid black'; templateToolsDiv.style.clear='both'; templateToolsDiv.innerHTML = 'Template Tools version 0.5alpha \n'; templateToolsDiv.innerHTML = templateToolsDiv.innerHTML + ' report a bug \n'; templateToolsDiv.innerHTML = templateToolsDiv.innerHTML + 'Auto-detect template ';

/* Modular section. Add additional tools for other templates here. */	templateToolsDiv.innerHTML = templateToolsDiv.innerHTML + '   Skill template tool ';

editBuffer.parentNode.insertBefore(templateToolsDiv, editBuffer);

}

addOnloadHook(templateToolsInit);

/*

openTemplateToolBox(toolsDiv)
*/

function openTemplateToolBox(toolsDiv) { document.getElementById('templateToolsDiv').style.display='block'; document.getElementById(toolsDiv).style.display='none'; }

/*

autoDetectTemplate
*/ /* Modular section. Add additional tools for other templates here. */ function autoDetectTemplate{ if (extractSkillTemplate){ return; } } /*

oneSplit(inputString, separator)
*/ /* similar to split, but only at first occurance, and keep the rest intact */ function oneSplit(inputString, separator){ var idx = inputString.indexOf(separator); if (idx == -1){ return [,]; }	var car = inputString.slice(0, idx); var cdr = inputString.slice(idx+separator.length); return [car,cdr]; } /*

trimString(aString)
*/ // Removes whitespaces from the beginning and the end of a string, but not the middle // Thanks Datrio for the quick help! function trimString(aString){ return aString.replace(/^\s+|\s+$/g, ""); } /*

extractParameter(paramName, assignments)
*/ function extractParameter(paramName, assignments){ var result = ''; for (var i=0; i<assignments.length; i++){ var myAssign = 	assignments[i];

var Cons = oneSplit(myAssign,'=') var Car = trimString(Cons[0]); var Cdr = trimString(Cons[1]); if ( Car == (trimString(paramName)) && (Cdr != '') ){ result = Cdr; assignments[i] = ''; } 	}	return result; } /*

debug(message)
*/ function debug(message){ var debugDiv = document.getElementById('debugDiv'); debugDiv.style.display = 'block'; debugDiv.innerHTML = debugDiv.innerHTML + ' ' + message;

/* since debugging, javascript is probably buggy, so turn non-javascript version back on (for new articles only) */ var hardlinkdiv = document.getElementById('template_tools_hard_links'); if(hardlinkdiv) { hardlinkdiv.style.display = 'block'; } } /*

doubleSplit(input,break1,break2)
*/ /* Takes a string, break it at two locations by first occurance of two different criteria */ function doubleSplit(input,break1,break2){ var ConsCons = oneSplit(input,break1); var Cons = oneSplit(ConsCons[1],break2); return [ConsCons[0], Cons[0], Cons[1]]; } /*

queryString(p)
*/ /* Taken from wookiepdia */ function queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches;

if(matches = re.exec(document.location)) { try { return decodeURI(matches[1]); }       catch(e) { } }

return null; }

/* */