User:Mdale/wikitrust.js

/* to install put in User:UserName/monobook.js * document.write(''); //weird loading order issue necessitates wgNotice: : var wgNotice = ""; var wgNoticeLocal = ""; var wgNoticeLang = "en"; var wgNoticeProject = "wikipedia";

var trustServer = 'http://enwiki-trust.cse.ucsc.edu/index.php'; var wikitrust_api_loc = 'http://enwiki-trust.cse.ucsc.edu/api.php'; //var wikitrust_api_loc = 'http://gaston.cse.ucsc.edu:81/api.php';

var TdoLoad = true;

var sample_returned = { "query": { "normalized": [ {				"from": "Computer_graphics", "to": "Computer graphics" }		],		"pages": { "6518": {				"pageid": 6518, "ns": 0, "title": "Computer graphics", "revisions": { "106858492": {						"revid": 106858492, "pageid": 6518, "oldid": 106858492, "*": "\nComputer graphics is a sub-field of computer science and is concerned with digitally synthesizing and manipulating visual content. Although the term often refers to three-dimensional computer graphics, it also encompasses two-dimensional graphics and image processing.  Graphics is often differentiated from the field of visualization, although the two have many similarities.  Entertainment (in the form of animated movies and video games) is perhaps the most well-known application of graphics.\n\nSome major subproblems in computer graphics include:\n\n# describing the shape of an object (modeling)\n# describing the motion of an object (animation)\n# creating an image of an object (rendering)\n\n\n\n== Branches of Computer Graphics ==\n\n=== Modeling ===\n\nModeling describes the shape of an object.  The two most common sources of 3D models are those created by an artist using some kind of 3D modeling tool, and those scanned into a computer from real-world objects. Models can also be produced procedurally or via physical simulation.\n\nBecause the appearance of an object depends largely on the exterior of the object, boundary representations are most common in computer graphics. Two dimensional surfaces are a good analogy for the objects used in graphics, though quite often these objects are non-manifold. Since surfaces are not finite, a discrete digital approximation is required: polygonal meshes (and to a lesser extent subdivision surfaces) are by far the most common representation, although point-based representations have been gaining some popularity in recent years. Level sets are a useful representation for deforming surfaces which undergo many topological changes such as fluids.\n\n==== Subfields ====\n\n* Subdivision surfaces\n\n* Digital geometry processing - surface reconstruction, mesh simplification, mesh repair, parameterization, remeshing, mesh generation, mesh compression, and mesh editing all fall under this heading.\n\n* Discrete differential geometry - DDG is a recent topic which defines geometric quantities for the discrete surfaces used in computer graphics.\n\n* Point-based graphics - a recent field which focuses on points as the fundamental representation of surfaces.\n\n=== Shading ===\n\nTexturing, or more generally, shading is the process of describing surface appearance. This description can be as simple as the specification of a color in some colorspace or as elaborate as a shader program which describes numerous appearance attributes across the surface. Simple shading is achieved with texture mapping, which uses a raster image to specify the diffuse color of a surface, giving it more apparent detail. A more generic description of surface appearance is given by the bidirectional scattering distribution function, which describes the relationship between incoming and outgoing illumination at a given point.\n\n=== Animation ===\n\nAnimation refers to the temporal description of an object, i.e., how it moves and deforms over time. There are numerous ways to describe these motion, many of which are used in conjunction with each-other. Popular methods include keyframing, inverse kinematics, and motion capture. As with modeling, physical simulation is another way of specifying motion.\n\n=== Rendering ===\n\nRendering converts a model into an image either by simulating light transport to get physically-based photorealistic images, or by applying some kind of style as in non-photorealistic rendering. See Rendering for more information.\n\n==== Subfields ====\n\n* physically-based rendering - concerned with generating images according to the laws of geometric optics\n* real time rendering - focuses on rendering for interactive applications, typically using specialized hardware like GPUs\n* non-photorealistic rendering\n* relighting - recent area concerned with quickly re-rendering scenes\n\n== History ==\n\nWilliam Fetter was credited with coining the term Computer Graphics in 1960, to describe his work at Boeing. One of the first displays of computer animation was Futureworld (1976), which included an animation of a human face and hand — produced by Ed Catmull and Fred Parke at the University of Utah.\n\nThere are several international conferences and journals where the most significant results in computer graphics are published. Among them are the SIGGRAPH and Eurographics conferences and the ACM Transactions on Graphics journal. The joint Eurographics and ACM SIGGRAPH symposium series features the major venues for the more specialized sub-fields: Symposium on Geometry Processing [http:\/\/www.geometryprocessing.org], Symposium on Rendering, and Symposium on Computer Animation.\n\nAn extensive history of computer graphics can be found at [http:\/\/accad.osu.edu\/~waynec\/history\/lessons.html].\n\n== Applications ==\n\n*Special effects\n*Video games\n\n\n\n== Connected Studies ==\n\n* Computer vision\n* Image processing\n\n\n\n== See also ==\n\nNumerous sub-areas of computer graphics can be found in Category:3D computer graphics.\n\n=== Miscellaneous ===\n* Computer facial animation\n* Digital geometry\n* Digital image editing\n* Graphics processing unit (GPU)\n* Graphical output devices\n* Utah Teapot\n* Stanford Bunny\n* SIGGRAPH\n* Timeline of CGI in films\n* ASCII art\n\n== External Links ==\n\n*[http:\/\/accad.osu.edu\/~waynec\/history\/lessons.html A Critical History of Computer Graphics and Animation] \n*[http:\/\/hem.passagen.se\/des\/hocg\/hocg_1960.htm History of Computer Graphics series of articles]\n*[http:\/\/www.acid.org\/radio\/index.html#ARTS-EP05 The ARTS: Episode 5] An in depth interview with Legalize on the subject of the History of Computer Graphics. (Available in MP3 audio format)\n*[http:\/\/www.cgsociety.org\/ CGSociety] The Computer Graphics Society\n\n \n\nRa\u010dunarska grafika\nComputergrafik\nComputergrafik\nGr\u00e1ficos por computadora\nKomputila grafiko\nSynth\u00e8se d'image\nra\u010dunalna grafika\nComputer grafica\n\ucef4\ud4e8\ud130 \uadf8\ub798\ud53d\uc2a4\nComputergraphics\n\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30b0\u30e9\u30d5\u30a3\u30c3\u30af\u30b9\n\u041a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u0430\u044f \u0433\u0440\u0430\u0444\u0438\u043a\u0430\nTietokonegrafiikka\ngrafika komputerowa\nDatorgrafik\n\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66"					}				}			}		}	} }

//only activate on "view" pages: if(wgAction=="view"){ addOnloadHook(do_disp_trust_link); } //do color trust function do_color_trust{ bodyContent = document.getElementById('bodyContent') bodyContent.innerHTML = 'loading ... ';      if(typeof sajax_init_object == 'undefined'){ if(TdoLoad)loadExternalJs('/skins-1.5/common/ajax.js'); TdoLoad=false; //js_log('still not set loading'); setTimeout('do_color_trust', 20); }else{ js_log('do sjax'); TdoLoad=true; do_get_trustpage; }         } /* * do the api call: */ function do_get_trustpage{ url = wikitrust_api_loc + '?format=json&action=query' + '&callback=wiki_trust_callback'+ '&titles='+wgPageName+'&prop=revisions&rvprop=content'; js_log('loading: ' + url); //loadExternalJs(url); wiki_trust_callback(sample_returned); } function wiki_trust_callback(result){ js_log('wiki_trust_callback'); //@@todo check if its an error or bad query for(i in result['query']['pages']){ for(j in result['query']['pages'][i]['revisions']){ js_log('path: result[\'query\'][\'pages\']['+i+'][\'revisions\']['+j+'][\'*\']'); get_preivew_html(result['query']['pages'][i]['revisions'][j]['*']); break; }	}	//do_sajax_request( [0]['revisions'][0]); } //uses the wikitrust_page global for content: function get_preivew_html(wikiturst_text){ wikiturst_text = swap_trust_template_for_span_color(wikiturst_text); a = sajax_init_object; a.open("POST", '/w/index.php?title='+wgPageName+'&action=submit&live', true); var Boundary = 'p1415'; a.setRequestHeader('Content-Type', 'multipart/form-data; boundary='+Boundary); var PostData = '--' + Boundary + '\nContent-Disposition: form-data; name="wpTextbox1"\n\n' + wikiturst_text; if (a.overrideMimeType) a.overrideMimeType('text/html'); js_log('send post data: ' + PostData); a.send(PostData); a.onreadystatechange = function{ if (a.readyState != 4) return; var html = a.responseText; html = html.replace(/&gt;/g,'>').replace(/&lt;/g,'<').replace(/&quot;/g,'"').replace(/&amp;/g,'&').replace(/&apos;/g,"'");						//get rid of the preview note: first to close 			var sp = html.indexOf(' ');			var ep = html.indexOf(' ');						html = html.substr(0,sp) + html.substr(ep);			bodyContent.innerHTML = html;											}; } function swap_trust_template_for_span_color(text){	/*text = text.replace('//g', ' ');	text = text.replace('//g', ' ');	text = text.replace('//g', ' ');	text = text.replace('//g', ' ');	text = text.replace('//g', ' ');*/	text = text.replace(/\{\{#trust:([0-9])\|begin\}\}/g, replace_callback);	return text; } function replace_callback(trust_string){	num = trust_string.substring(9,trust_string.indexOf('|',9));	var c='';	switch(num){		case '0':c='FF8888';break;		case '1':c='FF9999';break;		case '2':c='FF9898';break;		case '3':c='FFAAAA';break;		case '3':c='FFA8A8';break; case '4':c='FFBBBB';break; case '5':c='FFB8B8';break; case '6':c='FFCCCC';break; case '7':c='FFC8C8';break; case '8':c='FFEEEE';break; case '9':c='FFE8E8';break; case '10':c='FFFFFF';break; }	return ''; } // replace callback support for safari. (function{ var default_replace = String.prototype.replace;  String.prototype.replace = function(search,replace){        // replace is not function        if(typeof replace != "function"){                return default_replace.apply(this,arguments)        }        var str = "" + this;        var callback = replace;        // search string is not RegExp        if(!(search instanceof RegExp)){                var idx = str.indexOf(search);                return ( idx == -1 ? str : default_replace.apply(str,[search,callback(search, idx, str)]) )       }        var reg = search;        var result = [];        var lastidx = reg.lastIndex;        var re;        while((re = reg.exec(str)) != null){                var idx  = re.index;                var args = re.concat(idx, str);                result.push( str.slice(lastidx,idx), callback.apply(null,args).toString );               if(!reg.global){                        lastidx += RegExp.lastMatch.length;                        break                }else{                        lastidx = reg.lastIndex;                }        }        result.push(str.slice(lastidx));        return result.join("")  } });

function do_disp_trust_link{ newLi = document.createElement('li'); newLi.id = 'ca-trust'; var titlePos = document.URL.indexOf('/wiki/'); if( titlePos !=-1 ){ var page_title = document.URL.substr(titlePos+6); }	newLi.innerHTML = 'View Trust'; //newLi.innerHTML = 'View Trust';

lastLi = document.getElementById('ca-watch'); if(lastLi) lastLi.parentNode.appendChild(newLi); } /* * this won't work in some versions of Safari * you have to do your document.writes before the page is done rendering.. * ....so @@todo for safari: * have the view_trust issue a page refresh with flag in get request: * and check window.location.search paramaters to do the remote request * with a document.write insted of DOM injection. */ function loadExternalJs(url){ //js_log('load js: ' + url); var e = document.createElement("script"); e.src = url; e.type="text/javascript"; document.getElementsByTagName("head")[0].appendChild(e); } function js_log(string){ if( window.console ){ console.log(string); }else{ //disable alerts //alert(string); } }