User:Mdale/wikitrust.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Mdale/wikitrust. |
// to install: document.write('<script type="text/javascript" src="http://mammoth.dnip.net/mvWiki/extensions/MetavidWiki/skins/wikitrust.js.php?'+wgPageName+'">');
var trustServer = 'http://mammoth.dnip.net/mvWiki/index.php';
var wikitrust_api_loc = 'http://mammoth.dnip.net/mvWiki/api.php';
var TdoLoad = true;
//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<blink>...</blink>';
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);
}
function wiki_trust_callback(result){
js_log(result);
//@@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("got: " + );
do_sajax_request(result['query']['pages'][i]['revisions'][j]['*']);
break;
}
}
//do_sajax_request( [0]['revisions'][0]);
}
//uses the wikitrust_page global for content:
function do_sajax_request(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(/>/g,'>').replace(/</g,'<').replace(/"/g,'"').replace(/&/g,'&').replace(/'/g,"'");
//get rid of the preview note: first <h2> to close </dvi>
var sp = html.indexOf('<h2>');
var ep = html.indexOf('</div>');
html = html.substr(0,sp) + html.substr(ep);
bodyContent.innerHTML = html;
};
}
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 = '<a href="javascript:do_color_trust();" title="View Trust analysis">View Trust</a>';
//newLi.innerHTML = '<a href="'+trustServer+page_title+'" onclick="do_color_trust();" title="View Trust analysis">View Trust</a>';
lastLi = document.getElementById('ca-watch');
lastLi.parentNode.appendChild(newLi);
}
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);
}
}