User:Skizzerz/scripts

addHTML
This script allows sysops to add raw HTML to fully protected pages.

Usage:
 * 1) Copy the code below into your local wiki's MediaWiki:Common.js
 * 2) Fully protect the page that you wish to use it on (click the Protect link/tab and choose "Sysops only" for editing)
 * 3) Use the following syntax to add HTML. Please note that if you want line breaks before or after the HTML, you will need to specify them explicitly with the &lt;br /&gt; tag. Otherwise, the HTML will appear "inline."

Syntax &lt;nowiki&gt; tag // lines beginning with "//" are treated as comments. // COMMENTS ARE NOT ALLOWED BEFORE THE TAG IS DEFINED! // The "tag" above is the tag to create, such as  or // The tag name must be valid or the rest of this won't be processed! attribute_name = attribute // Define attributes of the tag using the above syntax. // DO NOT PUT QUOTES AROUND THE ATTRIBUTE // For example, the following would be for making an  tag open in a new window target = _blank // Spaces are usually stripped, so add as many as you need to make it readable // Style can be handled as normal, too style = text-decoration: blink; color: #ff0000; // Both the styles valid in CSS as well as the styles valid in JavaScript are allowed // E.g. text-decoration and textDecoration // To define content inside of the tag, use the following content = Some content, including other raw HTML tags content = Insert multiple content= lines to create a line break in between // And that's it! Please note that no sanitization is done on the attributes, so if you // mis-spell something, then it is likely that the tag won't appear in your browser. &lt;/nowiki&gt;

Example &lt;nowiki&gt; a href = http://www.google.com target = _blank id = google_link class = external plainlinks content = google &lt;/nowiki&gt;

Code //********************************************************************* // Allow raw HTML on fully protected pages // by w:User:Skizzerz // See http://www.wikia.com/wiki/User:Skizzerz/scripts#addHTML for details // WARNING: output is NOT sanitized, so make sure the HTML is correct! //********************************************************************* function addHTML { //make sure that the page is fully protected var cont = false; for( var i = 0; i < wgRestrictionEdit.length; i++ ) { if( wgRestrictionEdit[i] == 'sysop' ) { cont = true; break; }	}	if(!cont) return; //get all div elements with class addHTML var html = getElementsByClassName(document, 'div', 'addHTML'); for(var i = 0; i < html.length; i++) { var attr = html[i].innerHTML.split("\n"); if(!attr) continue; var c = 0; for(var j = 0; j < attr.length; j++) { if(attr[j] == '') c++; else break; }		try { var tag = document.createElement(attr[c]); } catch(e) { continue; }		if(!tag) continue; for(var j = c + 1; j < attr.length; j++) { if(attr[j] == '' || attr[j].match(/^\/\//)) continue; var as = attr[j].split("=", 2); if(as.length == 2) { //build the attributes, special cases for class, style, and content //but first strip spaces as[0] = as[0].replace(/ /g, ''); if(as[0] != 'class' && as[0] != 'content') as[1] = as[1].replace(/ /g, ''); switch(as[0]) { case 'class': tag.className = as[1]; break; case 'style': var styles = as[1].split(';'); for(var k = 0; k < styles.length; k++) { var st = styles[k].split(':', 2); var cc = st[0].split('-'); if(cc.length > 1) { for(var x = 1; x < cc.length; x++) cc[x] = cc[x].charAt(0).toUpperCase + cc[x].substr(1, cc[x].length - 1); st[0] = cc.join(''); }							eval('tag.style.'+st[0]+' = "'+st[1]+'";'); //IE hack }						break; case 'content': if(tag.innerHTML != '') tag.innerHTML = tag.innerHTML + " "; tag.innerHTML = tag.innerHTML + as[1]; break; default: tag.setAttribute(as[0], as[1]); break; }			} else { tag.setAttribute(as[0], as[0]); }		}		//now insert the new element html[i].innerHTML = ''; html[i].style.display = 'inline'; html[i].appendChild(tag); } } addOnloadHook(addHTML);