MediaWiki:Common.js/file.js: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
(you won't believe it. Secure server cannot use thumb.php :( If anyone has any smarter ideas (accept using ajax calls to the api) i welcome them))
(no need to do this multiple times)
Line 3: Line 3:
function SVGThumbs() {
function SVGThumbs() {
var file = document.getElementById("file"); // might fail if MediaWiki can't render the SVG
var file = document.getElementById("file"); // might fail if MediaWiki can't render the SVG
if (file && wgIsArticle && wgTitle.substring(wgTitle.lastIndexOf(".")).toLowerCase() == ".svg") {
if (file && wgIsArticle && wgTitle.substring(wgTitle.lastIndexOf(".")).toLowerCase() == ".svg") {
var path = 'http://en.wikipedia.org/w';
if( getElementsByClassName( file.parentNode, 'div', 'sharedUploadNotice' )[0] )
path = 'http://commons.wikimedia.org/w'
 
function svgAltSize( w, h, title) {
function svgAltSize( w, h, title) {
var path = 'http://en.wikipedia.org/w';
if( getElementsByClassName( file.parentNode, 'div', 'sharedUploadNotice' )[0] )
path = 'http://commons.wikimedia.org/w'
var a = document.createElement("A");
var a = document.createElement("A");
a.setAttribute("href", path + "/thumb.php?f=" + encodeURIComponent(wgTitle) + "&width="+w+"px&height="+h+"px");
a.setAttribute("href", path + "/thumb.php?f=" + encodeURIComponent(wgTitle) + "&width="+w+"px&height="+h+"px");

Revision as of 15:24, 26 November 2009

/* <source lang="javascript"><nowiki> */
// SVG images: adds links to rendered PNG images in different resolutions
function SVGThumbs() {
	var file = document.getElementById("file"); // might fail if MediaWiki can't render the SVG
	if (file && wgIsArticle && wgTitle.substring(wgTitle.lastIndexOf(".")).toLowerCase() == ".svg") {
		var path = 'http://en.wikipedia.org/w';
		if( getElementsByClassName( file.parentNode, 'div', 'sharedUploadNotice' )[0] )
			path = 'http://commons.wikimedia.org/w'

		function svgAltSize( w, h, title) {
			var a = document.createElement("A");
			a.setAttribute("href", path + "/thumb.php?f=" + encodeURIComponent(wgTitle) + "&width="+w+"px&height="+h+"px");
			a.appendChild(document.createTextNode(title));
			return a;
		}
		var p = document.createElement("p");
		p.className = "SVGThumbs";
		p.appendChild(document.createTextNode("This image rendered as PNG in some sizes"+": "));
		p.appendChild(svgAltSize(200,200,"200px"));
		p.appendChild(document.createTextNode(", "));
		p.appendChild(svgAltSize(500,500,"500px"));
		p.appendChild(document.createTextNode(", "));
		p.appendChild(svgAltSize(1000,1000,"1000px"));
		p.appendChild(document.createTextNode(", "));
		p.appendChild(svgAltSize(2000,2000,"2000px"));
		p.appendChild(document.createTextNode("."));
		var info = getElementsByClassName( file.parentNode, 'div', 'fullMedia' )[0];
		if( info ) info.appendChild(p);
	}
};
addOnloadHook( SVGThumbs )
/* </nowiki></source> */