v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Difference between revisions of "User:Emi/review.js"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
 
(11 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
addOnloadHook(
 
addOnloadHook(
  function rater_addLink() {
+
function rater_addLink() {
  if (document.getElementById('bodyContent').innerHTML.indexOf('<div id="norate"></div>') == -1){
+
if ((document.getElementById('bodyContent').innerHTML.indexOf('<div id="norate"></div>') == -1) && (wgCanonicalNamespace == "DF2012" || wgCanonicalNamespace == "v0.31" || wgCanonicalNamespace == "40d" || wgCanonicalNamespace == "23a" || wgUserName == "Emi" || wgUserName == "Briess") && wgUserName) {
    if(wgCanonicalNamespace == "40d" || wgCanonicalNamespace == "DF2010" || wgCanonicalNamespace == "23a" || wgUserName == "Emi") {addPortletLink("p-cactions", "javascript:rater_init()", "Rate", "ca-rater", "Rate");}
+
var portletLink = addPortletLink("p-namespaces", "#", "Rate", "ca-rater", "Rate");
  }}
+
$(portletLink).click( function( e ) {
 +
        e.preventDefault();
 +
        rater_init();
 +
});
 +
}
 +
}
 
);
 
);
  
Line 22: Line 27:
  
 
function rater_init() {
 
function rater_init() {
var rater_PageName = wgPageName.replace(/_/g, ' ');
+
var rater_PageName = wgPageName.replace(/_/g, ' ');
  
  if (!wfSupportsAjax()) {
+
if (!wfSupportsAjax()) {
    jsMsg('<span style="color:red; font-size:120%">Your browser does not seem to support AJAX, which is required for the rating script.</span>');
+
jsMsg('<span style="color:red; font-size:120%">Your browser does not seem to support AJAX, which is required for the rating script.</span>');
    return;
+
return;
  }
+
}
  
jsMsg('<h3>Rating '+rater_PageName+'</h3><div id="rater_div"></div>');
+
jsMsg('<h3>Rating '+rater_PageName+'</h3><div id="rater_div"></div>');
rater_autotests();
+
rater_autotests();
 
}
 
}
  
 
function rater_autotests() {
 
function rater_autotests() {
var rater_PageName = wgPageName.replace(/_/g, ' ');
+
var rater_PageName = wgPageName.replace(/_/g, ' ');
  
document.getElementById('rater_div').innerHTML += '<div id="overall"><div class="rater_box"><h5>Automatic Criteria:</h5><div id="rater_orphan">Is page orphaned</div>' + '<div id="rater_deadend">Is page deadend...... </div>' + '<div id="rater_redlink">How many redlinks does page contain...... </div><span id="igred" style="display:none;">Ignore redlinks? <INPUT TYPE=CHECKBOX ID="ignorered" onClick="rater_calc();"> (Use this if the only redlink is in the AV template, so really, a "greylink")</span></div>';
+
document.getElementById('rater_div').innerHTML += '<div id="overall">' +
 +
'<div class="rater_box"><h5>Automatic Criteria:</h5>' +
 +
'<div id="rater_orphan">Is page orphaned</div>' +
 +
'<div id="rater_deadend">Is page deadend......</div>' +
 +
'<div id="rater_redlink">How many redlinks does page contain......</div>' +
 +
'<span id="igred" style="display:none;"><label>Ignore redlinks? <input type="checkbox" id="ignorered" onClick="rater_calc();" /></label> (Use this if the only redlink is in the AV template, so really, a "greylink")</span>' +
 +
'</div>';
  
rater_testorphan();
+
rater_testorphan();
rater_testredlink();
+
rater_testredlink();
rater_testdeadend();
+
rater_testdeadend();
  
document.getElementById('rater_div').innerHTML += '<div id="autoquickfail" style="display:none;"><div class="rater_box"><h5>Quick-fail</h5>Is the page obviously crappy?<INPUT TYPE=CHECKBOX ID="tempbox" onClick="rater_calc();"></div>' +
+
document.getElementById('rater_div').innerHTML +=
'<div class="rater_box"><div id="rater_cats"><h5>Categories</h5><span id="rater_cats_resp"> </span><span id="rater_cats_check" style="display:none; margin-top:8px;">Are the categories appropriate?<INPUT TYPE=CHECKBOX ID="rater_cat" onClick="rater_calc();"></span></div></div>' +
+
'<div id="autoquickfail" style="display:none;">' +
'<div class="rater_box"><h5>Information</h5><div id="rater_length">How long is the article?</div><span id="rater_len_over_div" style=""><form name="rawr" method="get" style="margin-bottom:10px;" action="" onsubmit="return false;"><input type=radio id="vs_rad" onclick="len_over_change(0);" name="len_override" value="0">Very Short <input type=radio id="s_rad" onclick="len_over_change(1);" value="1" name="len_override" >Short <input type=radio id="m_rad" onclick="len_over_change(2);" name="len_override" value="2">Medium <input type=radio id="l_rad" onclick="len_over_change(3);" name="len_override" value="3">Long <input type=radio id="vl_rad" onclick="len_over_change(4);" name="len_override" value="4">Very Long</form></span>' +
+
'<div class="rater_box"><h5>Quick-fail</h5><label>Is the page obviously crappy? <input type="checkbox" id="tempbox" onClick="rater_calc();" /></label></div>' +
'<div>Does the page contain a decent amount of information?<INPUT TYPE=CHECKBOX ID="info" onClick="rater_calc();"></div>' +
+
'<div class="rater_box">' +
'<div>Does the page contain any inaccurate information? <INPUT TYPE=CHECKBOX ID="inacc" onClick="inacc_toggle();"></div>' +
+
'<div id="rater_cats"><h5>Categories</h5><span id="rater_cats_resp"> </span><span id="rater_cats_check" style="display:none; margin-top:8px;"><label>Are the categories appropriate? <input type="checkbox" id="rater_cat" onClick="rater_calc();" /></label></span></div>' +
'<div id="inaccdiv" style="display:none;">Is it just a bit of inaccurate information? <INPUT TYPE=CHECKBOX ID="inaccg" onClick="rater_calc();"></div>' +
+
'</div>' +
'<div>Is some information unverified?<INPUT TYPE=CHECKBOX ID="ver" onClick="ver_toggle();"></div>' +
+
'<div class="rater_box"><h5>Information</h5>' +
'<div id="verdiv" style="display:none;">Is it just a bit of unverified information? <INPUT TYPE=CHECKBOX ID="verg" onClick="rater_calc();"></div>' +
+
'<div id="rater_length">How long is the article?</div>' +
'<div>Is the page relatively easy to understand? <INPUT TYPE=CHECKBOX ID="understand" onClick="rater_calc();"></div>' +
+
'<span id="rater_len_over_div" style=""><form name="rawr" method="get" style="margin-bottom:10px;" action="" onsubmit="return false;"><label><input type="radio" id="vs_rad" onclick="len_over_change(0);" name="len_override" value="0" />Very Short</label> <label><input type="radio" id="s_rad" onclick="len_over_change(1);" value="1" name="len_override" />Short</label> <label><input type="radio" id="m_rad" onclick="len_over_change(2);" name="len_override" value="2" />Medium</label> <label><input type="radio" id="l_rad" onclick="len_over_change(3);" name="len_override" value="3" />Long</label> <label><input type="radio" id="vl_rad" onclick="len_over_change(4);" name="len_override" value="4" />Very Long</label></form></span>' +
'<div>Does the page look at least reasonably good? <INPUT TYPE=CHECKBOX ID="looks" onClick="looks_toggle();"></div>' +
+
'<div><label>Does the page contain a decent amount of information? <input type="checkbox" id="info" onClick="rater_calc();" /></label></div>' +
'<div id="extremelooksdiv" style="display:none;">Does the page look extremely good? <INPUT TYPE=CHECKBOX ID="extremelooks" onClick="rater_calc();"></div></div></div>' +
+
'<div><label>Does the page contain any inaccurate information? <input type="checkbox" id="inacc" onClick="inacc_toggle();" /></label></div>' +
'<div id="rater_results"></div><span id="showup" style="display:none;"> Override? <INPUT TYPE=CHECKBOX ID="overrate" onClick="overrate_toggle();"></span>' +
+
'<div id="inaccdiv" style="display:none;"><label>Is it just a bit of inaccurate information? <input type="checkbox" id="inaccg" onClick="rater_calc();" /></label></div>' +
'<div id="overratediv" style="display:none;"><form name="overriderate" method="get" action="" onsubmit="return false;"><input type=radio id="tattered" onclick="rate_over_change(0);" name="rate_override" value="0"> Tattered <input type=radio id="fine" onclick="rate_over_change(1);" value="1" name="rate_override" >Fine <input type=radio id="exceptional" onclick="rate_over_change(2);" name="rate_override" value="2">Exceptional <input type=radio id="masterwork" onclick="rate_over_change(3);" name="rate_override" value="3">Masterwork</form></div>' +
+
'<div><label>Is some information unverified? <input type="checkbox" id="ver" onClick="ver_toggle();" /></label></div>' +
'<div id="suggest"><br><a onclick="rater_calcit();">Suggest!</a></div>' +
+
'<div id="verdiv" style="display:none;"><label>Is it just a bit of unverified information? <input type="checkbox" id="verg" onClick="rater_calc();" /></label></div>' +
'<div id="commit" style="display:none;"><br><a onclick="rate_this_shit_before();">Commit the rating!</a></div>' +
+
'<div><label>Is the page relatively easy to understand? <input type="checkbox" id="understand" onClick="rater_calc();" /></label></div>' +
'</div>';
+
'<div><label>Does the page look at least reasonably good? <input type="checkbox" id="looks" onClick="looks_toggle();" /></label></div>' +
 +
'<div id="extremelooksdiv" style="display:none;"><label>Does the page look extremely good? <input type="checkbox" id="extremelooks" onClick="rater_calc();" /></label></div>' +
 +
'</div>' +
 +
'</div>' +
 +
'<div id="rater_results"></div>' +
 +
'<span id="showup" style="display:none;"><label>Override? <input type="checkbox" id="overrate" onClick="overrate_toggle();" /></label></span>' +
 +
'<div id="overratediv" style="display:none;"><form name="overriderate" method="get" action="" onsubmit="return false;"><label><input type="radio" id="tattered" onclick="rate_over_change(0);" name="rate_override" value="0" />Tattered</label> <label><input type="radio" id="fine" onclick="rate_over_change(1);" value="1" name="rate_override" />Fine</label> <label><input type="radio" id="exceptional" onclick="rate_over_change(2);" name="rate_override" value="2" />Exceptional</label> <label><input type="radio" id="masterwork" onclick="rate_over_change(3);" name="rate_override" value="3" />Masterwork</label></form></div>' +
 +
'<div id="suggest"><br /><a onclick="rater_calcit();">Suggest!</a></div>' +
 +
'<div id="commit" style="display:none;"><br /><a onclick="rate_this_shit_before();">Commit the rating!</a></div>' +
 +
'</div>';
  
 
+
rater_testlength();
 
+
rater_testcats();
rater_testlength();
 
rater_testcats();
 
 
}
 
}
  
 
function rate_this_shit_before() {
 
function rate_this_shit_before() {
document.getElementById('rater_div').innerHTML = "Grabbing page...";
+
document.getElementById('rater_div').innerHTML = "Grabbing page...";
var rater_PageName = wgPageName.replace(/_/g, ' ');
+
var rater_PageName = wgPageName.replace(/_/g, ' ');
var api = sajax_init_object();
+
var api = sajax_init_object();
api.open('GET', 'http://df.magmawiki.com/index.php?title=' + rater_PageName + '&action=raw', true);
+
api.open('GET', 'http://dwarffortresswiki.org/index.php?title=' + rater_PageName + '&action=raw', true);
api.onreadystatechange = function() {
+
api.onreadystatechange = function() {
if(api.readyState==4) {
+
if ((api.readyState == 4) && (api.status == 200)) {
if(api.status==200) {
+
document.getElementById('rater_div').innerHTML += "<br />Making replacement...";
document.getElementById('rater_div').innerHTML += "<br>Making replacement...";
+
var re = new RegExp("\{\{[Qq]uality.*?\}\}", "g");
  var re = new RegExp("\{\{[Qq]uality.*?\}\}", "g");
+
var replaced = api.responseText.replace(re, "");
  var replaced = api.responseText.replace(re, "");
+
replaced = "{" + "{quality|" + current_rating + "|~" + "~~" + "~~}" + "}" + replaced;
  replaced = "{{quality|" + current_rating + "|~~" + "~~" + "~}}" + replaced;
+
rate_this_shit(replaced);
rate_this_shit(replaced);
+
}
}
+
};
}
+
api.send(null);
};
 
api.send(null);
 
 
}
 
}
  
 
function rate_this_shit(newtext) {
 
function rate_this_shit(newtext) {
document.getElementById('rater_div').innerHTML += "<br>Getting token...";
+
document.getElementById('rater_div').innerHTML += "<br />Getting token...";
var rater_PageName = wgPageName.replace(/_/g, ' ');
+
var rater_PageName = wgPageName.replace(/_/g, ' ');
var api = sajax_init_object();
+
var api = sajax_init_object();
api.open('GET', 'http://df.magmawiki.com/api.php?format=json&action=query&prop=info&indexpageids=1&intoken=edit&titles=' + rater_PageName, true);
+
api.open('GET', 'http://dwarffortresswiki.org/api.php?format=json&action=query&prop=info&indexpageids=1&intoken=edit&titles=' + rater_PageName, true);
api.onreadystatechange = function() {
+
api.onreadystatechange = function() {
if(api.readyState==4) {
+
if (api.readyState == 4) {
if(api.status==200) {
+
if (api.status == 200) {
var response = eval('(' + api.responseText + ')');
+
var response = eval('(' + api.responseText + ')');
var token = response['query']['pages'][response['query']['pageids'][0]]['edittoken'];
+
var token = response['query']['pages'][response['query']['pageids'][0]]['edittoken'];
edit_page(token, newtext);
+
edit_page(token, newtext);
}else {
+
} else
alert('The token query returned an error.');
+
alert('The token query returned an error.');
 
}
 
}
}
+
};
};
+
api.send(null);
api.send(null);
 
 
}
 
}
  
 
function edit_page(_token, _newtext) {
 
function edit_page(_token, _newtext) {
document.getElementById('rater_div').innerHTML += "<br>Editing page...";
+
document.getElementById('rater_div').innerHTML += "<br />Editing page...";
var rater_PageName = wgPageName.replace(/_/g, ' ');
+
var rater_PageName = wgPageName.replace(/_/g, ' ');
 
var parameters = 'action=edit&title=' + rater_PageName + '&text=' + encodeURIComponent(_newtext) + '&token=' + encodeURIComponent(_token) + '&minor=1&summary=' + encodeURIComponent('Rated article "' + current_rating + '" using the rating script');
 
var parameters = 'action=edit&title=' + rater_PageName + '&text=' + encodeURIComponent(_newtext) + '&token=' + encodeURIComponent(_token) + '&minor=1&summary=' + encodeURIComponent('Rated article "' + current_rating + '" using the rating script');
var api = sajax_init_object();
+
var api = sajax_init_object();
api.open('POST', 'http://df.magmawiki.com/api.php', true); // just reuse the same query object
+
api.open('POST', 'http://dwarffortresswiki.org/api.php', true); // just reuse the same query object
  
api.onreadystatechange = function(){
+
api.onreadystatechange = function() {
if(api.readyState==4) {
+
if (api.readyState == 4) {
 
+
if (api.status == 200) {
if(api.status==200) {
+
document.getElementById('rater_div').innerHTML += "<br /><br />Success!<br /><br />Refreshing page...";
document.getElementById('rater_div').innerHTML += "<br><br>Success!<br><br>Refreshing page...";
+
setTimeout("location.reload(true);", 2000);
setTimeout("location.reload(true);",2000);
+
} else
}else{
+
document.getElementById('rater_div').innerHTML += "<br /><br />Something went wrong!";
document.getElementById('rater_div').innerHTML += "<br><br>Something went wrong!";
 
}
 
 
}
 
}
 
};
 
};
  
 
api.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
 
api.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
 
 
api.setRequestHeader('Connection', 'keep-alive');
 
api.setRequestHeader('Connection', 'keep-alive');
 
api.setRequestHeader('Content-length', parameters.length);
 
api.setRequestHeader('Content-length', parameters.length);
 
api.send(parameters);
 
api.send(parameters);
 
 
}
 
}
  
 +
function len_over_change(over) {
 +
overlength = over;
  
function len_over_change(over){
+
rater_calc();
overlength = over;
 
 
 
rater_calc();
 
 
}
 
}
  
 
var rating_override = -1;
 
var rating_override = -1;
  
function rate_over_change(over){
+
function rate_over_change(over) {
rating_override = over;
+
rating_override = over;
  
rater_calc();
+
rater_calc();
 
}
 
}
  
 
var suggested = 0;
 
var suggested = 0;
  
function rater_calc(){
+
function rater_calc() {
if (suggested != 0){ rater_calcit();}
+
if (suggested != 0)
 +
rater_calcit();
 
}
 
}
  
function rater_calcit(){
+
function rater_calcit() {
document.getElementById('suggest').style.display = "none";
+
document.getElementById('suggest').style.display = "none";
document.getElementById('commit').style.display = "inline";
+
document.getElementById('commit').style.display = "inline";
suggested = 1;
+
suggested = 1;
 +
 
 +
var catapp = 0;
 +
if (document.getElementById('rater_cat').checked == true)
 +
catapp = 1;
  
var catapp = 0;
+
var wlen = length;
if (document.getElementById('rater_cat').checked == true) {catapp = 1;}
+
if (overlength != -1)
 +
wlen = overlength;
  
var wlen = length;
+
var wlink = inlinks;
if (overlength != -1) wlen = overlength;
+
if (wlink > 5)
var wlink = inlinks;
+
wlink = 5;
if (wlink > 5) {wlink = 5;}
+
if (wlink == 0)
if (wlink == 0) {wlink = -20;}
+
wlink = -20;
var wcats = cats;
 
if (wcats > 2) {wcats = 2;}
 
var catmod = catapp * 5;
 
if (wcats == 0) {catmod = -20; wcats = 1;}
 
  
var wred = redlinks;
+
var wcats = cats;
if (document.getElementById('ignorered').checked == true) {wred = 0;}
+
if (wcats > 2)
 +
wcats = 2;
  
var result = orphan +  wlen * 3 + wlink * 2 + wred * -5 + wcats * catmod;
+
var catmod = catapp * 5;
 +
if (wcats == 0) {
 +
catmod = -20;
 +
wcats = 1;
 +
}
  
if (document.getElementById('understand').checked == true) {result += 5;}
+
var wred = redlinks;
if (document.getElementById('looks').checked == true) {result += 5;}
+
if (document.getElementById('ignorered').checked == true)
if (document.getElementById('extremelooks').checked == true) {result += 5;}
+
wred = 0;
if (document.getElementById('ver').checked == true) {result -= 60;}
 
if (document.getElementById('verg').checked == true) {result += 55;}
 
if (document.getElementById('inacc').checked == true) {result -= 60;}
 
if (document.getElementById('inaccg').checked == true) {result += 18;}
 
if (document.getElementById('info').checked == true) {result += 20;}
 
if (document.getElementById('tempbox').checked == true) {result -= 200;}
 
  
if (result > 56 && wred > 0) {result -= result - 56 + 1;}
+
var result = orphan + wlen * 3 + wlink * 2 + wred * -5 + wcats * catmod;
if (result > 56 && document.getElementById('ver').checked == true) {result -= result - 56 + 1;}
 
if (result > 4 && (cats == 0 || catapp == 0)) {result -= result - 4 + 1;}
 
if (result > 4 && document.getElementById('inacc').checked == true) {result -= result - 4 + 1;}
 
if (result > 4 && document.getElementById('info').checked == false) {result -= result - 4 + 1;}
 
  
var txtresult = '<span id="tattered-quality" style="color: #333333;">xTATTEREDx</span>';
+
if (document.getElementById('understand').checked == true)
current_rating = "Tattered";
+
result += 5;
if ((result > -75 && rating_override == -1) || rating_override == 1) {txtresult = '<span id="fine-quality" style="color:#CA7A02;">+FINE+</span>'; current_rating = "Fine";}
+
if (document.getElementById('looks').checked == true)
if ((result > 4 && rating_override == -1) || rating_override == 2) {txtresult = '<span id="exceptional-quality" style="color: #0088CC;">≡EXCEPTIONAL≡</span>'; current_rating = "Exceptional";}
+
result += 5;
if ((result > 56 && rating_override == -1) || rating_override == 3) {txtresult = '<span id="masterwork-quality" style="color: #72A329;">☼MASTERWORK☼</span>'; current_rating = "Masterwork";}
+
if (document.getElementById('extremelooks').checked == true)
 +
result += 5;
 +
if (document.getElementById('ver').checked == true)
 +
result -= 60;
 +
if (document.getElementById('verg').checked == true)
 +
result += 55;
 +
if (document.getElementById('inacc').checked == true)
 +
result -= 60;
 +
if (document.getElementById('inaccg').checked == true)
 +
result += 18;
 +
if (document.getElementById('info').checked == true)
 +
result += 20;
 +
if (document.getElementById('tempbox').checked == true)
 +
result -= 200;
 +
 
 +
if (result > 56 && wred > 0)
 +
result -= result - 56 + 1;
 +
if (result > 56 && document.getElementById('ver').checked == true)
 +
result -= result - 56 + 1;
 +
if (result > 4 && (cats == 0 || catapp == 0))
 +
result -= result - 4 + 1;
 +
if (result > 4 && document.getElementById('inacc').checked == true)
 +
result -= result - 4 + 1;
 +
if (result > 4 && document.getElementById('info').checked == false)
 +
result -= result - 4 + 1;
 +
 
 +
var txtresult = '<span id="tattered-quality" style="color: #333333;">xTATTEREDx</span>';
 +
current_rating = "Tattered";
 +
if ((result > -75 && rating_override == -1) || rating_override == 1) {
 +
txtresult = '<span id="fine-quality" style="color:#CA7A02;">+FINE+</span>';
 +
current_rating = "Fine";
 +
}
 +
if ((result > 4 && rating_override == -1) || rating_override == 2) {
 +
txtresult = '<span id="exceptional-quality" style="color: #0088CC;">≡EXCEPTIONAL≡</span>';
 +
current_rating = "Exceptional";
 +
}
 +
if ((result > 56 && rating_override == -1) || rating_override == 3) {
 +
txtresult = '<span id="masterwork-quality" style="color: #72A329;">☼MASTERWORK☼</span>';
 +
current_rating = "Masterwork";
 +
}
  
document.getElementById('rater_results').innerHTML = '<br>The rating machine suggests a rating of <a onclick="show_num();"' + txtresult + '</a> <span id="numspan" style="display:none;">(' + result + ')</span>';
+
document.getElementById('rater_results').innerHTML = '<br />The rating machine suggests a rating of <a onclick="show_num();"' + txtresult + '</a> <span id="numspan" style="display:none;">(' + result + ')</span>';
document.getElementById('showup').style.display = "inline";
+
document.getElementById('showup').style.display = "inline";
 
}
 
}
  
function show_num(){
+
function show_num() {
document.getElementById('numspan').style.display = "inline";
+
document.getElementById('numspan').style.display = "inline";
 
}
 
}
  
function looks_toggle(){
+
function looks_toggle() {
if (document.getElementById('looks').checked == true){
+
if (document.getElementById('looks').checked == true) {
document.getElementById('extremelooksdiv').style.display = "inline";
+
document.getElementById('extremelooksdiv').style.display = "inline";
rater_calc();
+
rater_calc();
}else{
+
} else {
document.getElementById('extremelooksdiv').style.display = "none";
+
document.getElementById('extremelooksdiv').style.display = "none";
document.getElementById('extremelooks').checked = false;
+
document.getElementById('extremelooks').checked = false;
rater_calc();
+
rater_calc();
}
+
}
 
}
 
}
  
function overrate_toggle(){
+
function overrate_toggle() {
if (document.getElementById('overrate').checked == true){
+
if (document.getElementById('overrate').checked == true) {
document.getElementById('overratediv').style.display = "inline";
+
document.getElementById('overratediv').style.display = "inline";
rater_calc();
+
rater_calc();
}else{
+
} else {
document.getElementById('overratediv').style.display = "none";
+
document.getElementById('overratediv').style.display = "none";
rating_override = -1;
+
rating_override = -1;
rater_calc();
+
rater_calc();
}
+
}
 
}
 
}
  
 
+
function ver_toggle() {
function ver_toggle(){
+
if (document.getElementById('ver').checked == true) {
if (document.getElementById('ver').checked == true){
+
document.getElementById('verdiv').style.display = "inline";
document.getElementById('verdiv').style.display = "inline";
+
rater_calc();
rater_calc();
+
} else {
}else{
+
document.getElementById('verdiv').style.display = "none";
document.getElementById('verdiv').style.display = "none";
+
document.getElementById('verg').checked = false;
document.getElementById('verg').checked = false;
+
rater_calc();
rater_calc();
+
}
}
 
 
}
 
}
  
 
+
function inacc_toggle() {
function inacc_toggle(){
+
if (document.getElementById('inacc').checked == true) {
if (document.getElementById('inacc').checked == true){
+
document.getElementById('inaccdiv').style.display = "inline";
document.getElementById('inaccdiv').style.display = "inline";
+
rater_calc();
rater_calc();
+
} else {
}else{
+
document.getElementById('inaccdiv').style.display = "none";
document.getElementById('inaccdiv').style.display = "none";
+
document.getElementById('inaccg').checked = false;
document.getElementById('inaccg').checked = false;
+
rater_calc();
rater_calc();
+
}
}
 
 
}
 
}
  
 +
function rater_testorphan() {
 +
var rater_PageName = wgPageName.replace(/_/g, ' ');
 +
var api = sajax_init_object();
 +
api.open('GET', 'http://dwarffortresswiki.org/index.php/Special:WhatLinksHere/' + rater_PageName, true);
 +
api.onreadystatechange = function() {
 +
document.getElementById('rater_orphan').innerHTML += ".";
  
 
+
if (api.readyState == 4) {
function rater_testorphan(){
+
if (api.status == 200) {
var rater_PageName = wgPageName.replace(/_/g, ' ');
+
if (api.responseText.indexOf("No pages link to") == -1) {
var api = sajax_init_object();
+
document.getElementById('rater_orphan').innerHTML += '<span class="rater_green">NO</span>';
api.open('GET', 'http://df.magmawiki.com/index.php/Special:WhatLinksHere/' + rater_PageName, true);
+
orphan = 0;
api.onreadystatechange = function() {
+
document.getElementById('autoquickfail').style.display = "inline";
    document.getElementById('rater_orphan').innerHTML += ".";
+
} else {
 
+
document.getElementById('rater_orphan').innerHTML += '<span class="rater_red">YES</span>';
    if(api.readyState==4) {
+
orphan = -1000000;
      if(api.status==200) {
+
rater_calcit();  
        if(api.responseText.indexOf("No pages link to") == -1){
+
}
          document.getElementById('rater_orphan').innerHTML += '<span class="rater_green"> NO</span>';
+
} else
          orphan = 0;
+
document.getElementById('rater_orphan').innerHTML += 'Unknown (error)';
          document.getElementById('autoquickfail').style.display = "inline";
+
}
        }else{
+
};
          document.getElementById('rater_orphan').innerHTML += '<span class="rater_red"> YES</span>';        
+
api.send(null);
          orphan = -1000000;
 
          rater_calcit();  
 
        }
 
      } else {
 
        document.getElementById('rater_orphan').innerHTML += 'Unknown (error)';
 
      }
 
  }
 
};
 
api.send(null);
 
 
}
 
}
  
function rater_testdeadend(){
+
function rater_testdeadend() {
    var searchtxt = document.getElementById('bodyContent').innerHTML;
+
var searchtxt = document.getElementById('bodyContent').innerHTML;
  
    var cnt = searchtxt.count('<a href="/index.php/');
+
var cnt = searchtxt.count('<a href="/index.php/');
  
    if (cnt == 0){
+
if (cnt == 0)
        document.getElementById('rater_deadend').innerHTML += '<span class="rater_red">YES</span>';  
+
document.getElementById('rater_deadend').innerHTML += '<span class="rater_red">YES</span>';
    }else{
+
else
        document.getElementById('rater_deadend').innerHTML += '<span class="rater_green">NO</span> - ' + cnt + ' internal';  
+
document.getElementById('rater_deadend').innerHTML += '<span class="rater_green">NO</span> - ' + cnt + ' internal';
    }
 
  
    inlinks = cnt;
+
inlinks = cnt;
 
}
 
}
  
 +
function rater_testredlink() {
 +
var searchtxt = document.getElementById('bodyContent').innerHTML;
  
function rater_testredlink(){
+
var re = new RegExp('<table id="avtable"[^]*?</table>', "g");
 
+
searchtxt = searchtxt.replace(re, "");
    var searchtxt = document.getElementById('bodyContent').innerHTML;
 
  
  var re = new RegExp('<table id="avtable"[^]*?</table>', "g");
+
var cnt = searchtxt.count('class="new');
  searchtxt = searchtxt.replace(re, "");
 
  
    var cnt = searchtxt.count('class="new');
+
if (cnt == 0)
 +
document.getElementById('rater_redlink').innerHTML += '<span class="rater_green">0</span>';
 +
else
 +
document.getElementById('rater_redlink').innerHTML += '<span class="rater_red">' + cnt + '</span>';
  
    if (cnt == 0){
+
redlinks = cnt;
        document.getElementById('rater_redlink').innerHTML += '<span class="rater_green">0</span>';   
+
if (redlinks > 2)
    }else{
+
document.getElementById('igred').style.display = "none";
        document.getElementById('rater_redlink').innerHTML += '<span class="rater_red">' + cnt + '</span>';   
 
    }
 
 
 
    redlinks = cnt;
 
    if (redlinks > 2) {document.getElementById('igred').style.display = "none";}
 
 
}
 
}
  
 +
function rater_testlength() {
 +
var searchtxt = document.getElementById('bodyContent').innerHTML;
  
function rater_testlength(){
+
var re = new RegExp("<.*?>", "g");
 +
var replaced = searchtxt.replace(re, "");
 +
var splitted = replaced.split(" ");
  
    var searchtxt = document.getElementById('bodyContent').innerHTML;
+
var lol = "Very Short";
 +
length = 0;
 +
if (splitted.length > 100) {
 +
lol = "Short";
 +
length = 1;
 +
}
 +
if (splitted.length > 500) {
 +
lol = "Medium";
 +
length = 2;
 +
}
 +
if (splitted.length > 2000) {
 +
lol = "Long";
 +
length = 3;
 +
}
 +
if (splitted.length > 4000) {
 +
lol = "Very Long";
 +
length = 4;
 +
}
  
 +
//if (length == 0) {document.getElementById('tempbox').checked = true;}
  
  var re = new RegExp("<.*?>", "g");
+
//document.getElementById('rater_div').innerHTML += splitted.length;
  var replaced = searchtxt.replace(re, "");
+
overlength = length;
    var splitted = replaced.split(" ");
+
document.getElementById('vs_rad').checked = false;
 +
document.getElementById('s_rad').checked = false;
 +
document.getElementById('m_rad').checked = false;
 +
document.getElementById('l_rad').checked = false;
 +
document.getElementById('vl_rad').checked = false;
  
  var lol = "Very Short"
+
switch(overlength)
  length = 0;
+
{
  if (splitted.length > 100) {lol = "Short"; length = 1;}
+
case 0:
  if (splitted.length > 500) {lol = "Medium"; length = 2;}
+
document.getElementById('vs_rad').checked = true;
  if (splitted.length > 2000) {lol = "Long"; length = 3;}
+
break;
  if (splitted.length > 4000) {lol = "Very Long"; length = 4;}
+
case 1:
 
+
document.getElementById('s_rad').checked = true;
  //if (length == 0) {document.getElementById('tempbox').checked = true;}
+
break;
 
+
case 2:
    //document.getElementById('rater_div').innerHTML += splitted.length;   
+
document.getElementById('m_rad').checked = true;
overlength = length;
+
break;
document.getElementById('vs_rad').checked = false;
+
case 3:
document.getElementById('s_rad').checked = false;
+
document.getElementById('l_rad').checked = true;
document.getElementById('m_rad').checked = false;
+
break;
document.getElementById('l_rad').checked = false;
+
case 4:
document.getElementById('vl_rad').checked = false;
+
document.getElementById('vl_rad').checked = true;
 
+
break;
switch(overlength){
+
}
case 0:
 
document.getElementById('vs_rad').checked = true;
 
break;
 
case 1:
 
document.getElementById('s_rad').checked = true;
 
break;
 
case 2:
 
document.getElementById('m_rad').checked = true;
 
break;
 
case 3:
 
document.getElementById('l_rad').checked = true;
 
break;
 
case 4:
 
document.getElementById('vl_rad').checked = true;
 
break;}
 
 
}
 
}
  
function rater_testcats(){
+
function rater_testcats() {
  var searchtxt = document.getElementById('bodyContent').innerHTML;
+
var searchtxt = document.getElementById('bodyContent').innerHTML;
 
 
  if(searchtxt.indexOf("catlinks") != -1){
 
 
 
var cattext = document.getElementById('mw-normal-catlinks').innerHTML.substr(83);
 
 
 
var catstr1 = "<div style='margin-left:1em;'>";
 
 
 
cats = 0;
 
 
 
var catarr = cattext.split("|");
 
for (x in catarr)
 
  {
 
    if(catarr[x].indexOf(">Current<") == -1){
 
      if(catarr[x].indexOf(">Obsolete<") == -1){ 
 
        if(catarr[x].indexOf("Fine Quality Articles<") == -1){ 
 
          if(catarr[x].indexOf("Tattered Quality Articles<") == -1){ 
 
            if(catarr[x].indexOf("Exceptional Quality Articles<") == -1){ 
 
              if(catarr[x].indexOf("Masterwork Quality Articles<") == -1){ 
 
                if(catarr[x].indexOf(">Quality ranks without proper timestamps<") == -1){ 
 
                  if(catarr[x].indexOf(">Quality ranks older than 10 weeks<") == -1){ 
 
                    catstr1 += catarr[x] + "<br />";
 
                    cats += 1;
 
                  }
 
                }
 
              }
 
            }
 
          }
 
        }
 
      }
 
    }
 
  }
 
 
 
  document.getElementById('rater_cats_resp').innerHTML += catstr1 + "</div>";
 
 
 
  
 +
if (searchtxt.indexOf("catlinks") != -1) {
 +
var cattext = document.getElementById('mw-normal-catlinks').innerHTML.substr(83);
 +
var catstr1 = "<div style='margin-left:1em;'>";
 +
cats = 0;
  
 +
var catarr = cattext.split("|");
 +
for (x in catarr)
 +
{
 +
if ((catarr[x].indexOf(">Current<") == -1) &&
 +
    (catarr[x].indexOf(">Obsolete<") == -1) &&
 +
    (catarr[x].indexOf("Tattered Quality Articles<") == -1) &&
 +
    (catarr[x].indexOf("Fine Quality Articles<") == -1) &&
 +
    (catarr[x].indexOf("Exceptional Quality Articles<") == -1) &&
 +
    (catarr[x].indexOf("Masterwork Quality Articles<") == -1) &&
 +
    (catarr[x].indexOf("Unknown Quality Articles<") == -1) &&
 +
    (catarr[x].indexOf(">Quality ranks without proper timestamps<") == -1) &&
 +
    (catarr[x].indexOf(">Quality ranks older than 10 weeks<") == -1) &&
 +
    (catarr[x].indexOf(">Quality ranks with bad timestamps<") == -1) &&
 +
    (catarr[x].indexOf(">Quality ranks in invalid namespaces<") == -1)) {
 +
catstr1 += catarr[x] + "<br />";
 +
cats += 1;
 +
}
 +
}
  
    //document.getElementById('rater_cats_resp').innerHTML += document.getElementById('mw-normal-catlinks').innerHTML + ' - ' + cats;
+
document.getElementById('rater_cats_resp').innerHTML += catstr1 + "</div>";
    document.getElementById('rater_cats_check').style.display = "inline";
+
//document.getElementById('rater_cats_resp').innerHTML += document.getElementById('mw-normal-catlinks').innerHTML + ' - ' + cats;
  }else{
+
document.getElementById('rater_cats_check').style.display = "inline";
    document.getElementById('rater_cats_resp').innerHTML += "none!";
+
} else
  }
+
document.getElementById('rater_cats_resp').innerHTML += "none!";
 
}
 
}

Latest revision as of 21:21, 8 July 2012

addOnloadHook(
	function rater_addLink() {
		if ((document.getElementById('bodyContent').innerHTML.indexOf('<div id="norate"></div>') == -1) && (wgCanonicalNamespace == "DF2012" || wgCanonicalNamespace == "v0.31" || wgCanonicalNamespace == "40d" || wgCanonicalNamespace == "23a" || wgUserName == "Emi" || wgUserName == "Briess") && wgUserName) {
			var portletLink = addPortletLink("p-namespaces", "#", "Rate", "ca-rater", "Rate");
			$(portletLink).click( function( e ) {
			        e.preventDefault();
			        rater_init();
			});
		}
	}
);

var orphan = 0;
var inlinks = 0;
var redlinks = 0;
var length = 0;
var overlength = -1;
var cats = 0;

var current_rating = "";

var results = 0;

String.prototype.count=function(s1) { 
	return (this.length - this.replace(new RegExp(s1,"g"), '').length) / s1.length;
}

function rater_init() {
	var rater_PageName = wgPageName.replace(/_/g, ' ');

	if (!wfSupportsAjax()) {
		jsMsg('<span style="color:red; font-size:120%">Your browser does not seem to support AJAX, which is required for the rating script.</span>');
		return;
	}

	jsMsg('<h3>Rating '+rater_PageName+'</h3><div id="rater_div"></div>');
	rater_autotests();
}

function rater_autotests() {
	var rater_PageName = wgPageName.replace(/_/g, ' ');

	document.getElementById('rater_div').innerHTML += '<div id="overall">' +
		'<div class="rater_box"><h5>Automatic Criteria:</h5>' +
			'<div id="rater_orphan">Is page orphaned</div>' +
			'<div id="rater_deadend">Is page deadend......</div>' +
			'<div id="rater_redlink">How many redlinks does page contain......</div>' +
			'<span id="igred" style="display:none;"><label>Ignore redlinks? <input type="checkbox" id="ignorered" onClick="rater_calc();" /></label> (Use this if the only redlink is in the AV template, so really, a "greylink")</span>' +
		'</div>';

	rater_testorphan();
	rater_testredlink();
	rater_testdeadend();

	document.getElementById('rater_div').innerHTML +=
		'<div id="autoquickfail" style="display:none;">' +
			'<div class="rater_box"><h5>Quick-fail</h5><label>Is the page obviously crappy? <input type="checkbox" id="tempbox" onClick="rater_calc();" /></label></div>' +
			'<div class="rater_box">' +
				'<div id="rater_cats"><h5>Categories</h5><span id="rater_cats_resp"> </span><span id="rater_cats_check" style="display:none; margin-top:8px;"><label>Are the categories appropriate? <input type="checkbox" id="rater_cat" onClick="rater_calc();" /></label></span></div>' +
			'</div>' +
			'<div class="rater_box"><h5>Information</h5>' +
				'<div id="rater_length">How long is the article?</div>' +
				'<span id="rater_len_over_div" style=""><form name="rawr" method="get" style="margin-bottom:10px;" action="" onsubmit="return false;"><label><input type="radio" id="vs_rad" onclick="len_over_change(0);" name="len_override" value="0" />Very Short</label> <label><input type="radio" id="s_rad" onclick="len_over_change(1);" value="1" name="len_override" />Short</label> <label><input type="radio" id="m_rad" onclick="len_over_change(2);" name="len_override" value="2" />Medium</label> <label><input type="radio" id="l_rad" onclick="len_over_change(3);" name="len_override" value="3" />Long</label> <label><input type="radio" id="vl_rad" onclick="len_over_change(4);" name="len_override" value="4" />Very Long</label></form></span>' +
				'<div><label>Does the page contain a decent amount of information? <input type="checkbox" id="info" onClick="rater_calc();" /></label></div>' +
				'<div><label>Does the page contain any inaccurate information? <input type="checkbox" id="inacc" onClick="inacc_toggle();" /></label></div>' +
				'<div id="inaccdiv" style="display:none;"><label>Is it just a bit of inaccurate information? <input type="checkbox" id="inaccg" onClick="rater_calc();" /></label></div>' +
				'<div><label>Is some information unverified? <input type="checkbox" id="ver" onClick="ver_toggle();" /></label></div>' +
				'<div id="verdiv" style="display:none;"><label>Is it just a bit of unverified information? <input type="checkbox" id="verg" onClick="rater_calc();" /></label></div>' +
				'<div><label>Is the page relatively easy to understand? <input type="checkbox" id="understand" onClick="rater_calc();" /></label></div>' +
				'<div><label>Does the page look at least reasonably good? <input type="checkbox" id="looks" onClick="looks_toggle();" /></label></div>' +
				'<div id="extremelooksdiv" style="display:none;"><label>Does the page look extremely good? <input type="checkbox" id="extremelooks" onClick="rater_calc();" /></label></div>' +
			'</div>' +
		'</div>' +
		'<div id="rater_results"></div>' +
		'<span id="showup" style="display:none;"><label>Override? <input type="checkbox" id="overrate" onClick="overrate_toggle();" /></label></span>' +
		'<div id="overratediv" style="display:none;"><form name="overriderate" method="get" action="" onsubmit="return false;"><label><input type="radio" id="tattered" onclick="rate_over_change(0);" name="rate_override" value="0" />Tattered</label> <label><input type="radio" id="fine" onclick="rate_over_change(1);" value="1" name="rate_override" />Fine</label> <label><input type="radio" id="exceptional" onclick="rate_over_change(2);" name="rate_override" value="2" />Exceptional</label> <label><input type="radio" id="masterwork" onclick="rate_over_change(3);" name="rate_override" value="3" />Masterwork</label></form></div>' +
		'<div id="suggest"><br /><a onclick="rater_calcit();">Suggest!</a></div>' +
		'<div id="commit" style="display:none;"><br /><a onclick="rate_this_shit_before();">Commit the rating!</a></div>' +
	'</div>';

	rater_testlength();
	rater_testcats();
}

function rate_this_shit_before() {
	document.getElementById('rater_div').innerHTML = "Grabbing page...";
	var rater_PageName = wgPageName.replace(/_/g, ' ');
	var api = sajax_init_object();
	api.open('GET', 'http://dwarffortresswiki.org/index.php?title=' + rater_PageName + '&action=raw', true);
	api.onreadystatechange = function() {
		if ((api.readyState == 4) && (api.status == 200)) {
			document.getElementById('rater_div').innerHTML += "<br />Making replacement...";
			var re = new RegExp("\{\{[Qq]uality.*?\}\}", "g");
			var replaced = api.responseText.replace(re, "");
			replaced = "{" + "{quality|" + current_rating + "|~" + "~~" + "~~}" + "}" + replaced;
			rate_this_shit(replaced);
		}
	};
	api.send(null);
}

function rate_this_shit(newtext) {
	document.getElementById('rater_div').innerHTML += "<br />Getting token...";
	var rater_PageName = wgPageName.replace(/_/g, ' ');
	var api = sajax_init_object();
	api.open('GET', 'http://dwarffortresswiki.org/api.php?format=json&action=query&prop=info&indexpageids=1&intoken=edit&titles=' + rater_PageName, true);
	api.onreadystatechange = function() {
		if (api.readyState == 4) {
			if (api.status == 200) {
				var response = eval('(' + api.responseText + ')');
				var token = response['query']['pages'][response['query']['pageids'][0]]['edittoken'];
				edit_page(token, newtext);
			} else
				alert('The token query returned an error.');
		}
	};
	api.send(null);
}

function edit_page(_token, _newtext) {
	document.getElementById('rater_div').innerHTML += "<br />Editing page...";
	var rater_PageName = wgPageName.replace(/_/g, ' ');
	var parameters = 'action=edit&title=' + rater_PageName + '&text=' + encodeURIComponent(_newtext) + '&token=' + encodeURIComponent(_token) + '&minor=1&summary=' + encodeURIComponent('Rated article "' + current_rating + '" using the rating script');
	var api = sajax_init_object();
	api.open('POST', 'http://dwarffortresswiki.org/api.php', true); // just reuse the same query object

	api.onreadystatechange = function() {
		if (api.readyState == 4) {
			if (api.status == 200) {
				document.getElementById('rater_div').innerHTML += "<br /><br />Success!<br /><br />Refreshing page...";
				setTimeout("location.reload(true);", 2000);
			} else
				document.getElementById('rater_div').innerHTML += "<br /><br />Something went wrong!";
		}
	};

	api.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	api.setRequestHeader('Connection', 'keep-alive');
	api.setRequestHeader('Content-length', parameters.length);
	api.send(parameters);
}

function len_over_change(over) {
	overlength = over;

	rater_calc();
}

var rating_override = -1;

function rate_over_change(over) {
	rating_override = over;

	rater_calc();
}

var suggested = 0;

function rater_calc() {
	if (suggested != 0)
		rater_calcit();
}

function rater_calcit() {
	document.getElementById('suggest').style.display = "none";
	document.getElementById('commit').style.display = "inline";
	suggested = 1;

	var catapp = 0;
	if (document.getElementById('rater_cat').checked == true)
		catapp = 1;

	var wlen = length;
	if (overlength != -1)
		wlen = overlength;

	var wlink = inlinks;
	if (wlink > 5)
		wlink = 5;
	if (wlink == 0)
		wlink = -20;

	var wcats = cats;
	if (wcats > 2)
		wcats = 2;

	var catmod = catapp * 5;
	if (wcats == 0) {
		catmod = -20;
		wcats = 1;
	}

	var wred = redlinks;
	if (document.getElementById('ignorered').checked == true)
		wred = 0;

	var result = orphan + wlen * 3 + wlink * 2 + wred * -5 + wcats * catmod;

	if (document.getElementById('understand').checked == true)
		result += 5;
	if (document.getElementById('looks').checked == true)
		result += 5;
	if (document.getElementById('extremelooks').checked == true)
		result += 5;
	if (document.getElementById('ver').checked == true)
		result -= 60;
	if (document.getElementById('verg').checked == true)
		result += 55;
	if (document.getElementById('inacc').checked == true)
		result -= 60;
	if (document.getElementById('inaccg').checked == true)
		result += 18;
	if (document.getElementById('info').checked == true)
		result += 20;
	if (document.getElementById('tempbox').checked == true)
		result -= 200;

	if (result > 56 && wred > 0)
		result -= result - 56 + 1;
	if (result > 56 && document.getElementById('ver').checked == true)
		result -= result - 56 + 1;
	if (result > 4 && (cats == 0 || catapp == 0))
		result -= result - 4 + 1;
	if (result > 4 && document.getElementById('inacc').checked == true)
		result -= result - 4 + 1;
	if (result > 4 && document.getElementById('info').checked == false)
		result -= result - 4 + 1;

	var txtresult = '<span id="tattered-quality" style="color: #333333;">xTATTEREDx</span>';
	current_rating = "Tattered";
	if ((result > -75 && rating_override == -1) || rating_override == 1) {
		txtresult = '<span id="fine-quality" style="color:#CA7A02;">+FINE+</span>';
		current_rating = "Fine";
	}
	if ((result > 4 && rating_override == -1) || rating_override == 2) {
		txtresult = '<span id="exceptional-quality" style="color: #0088CC;">≡EXCEPTIONAL≡</span>';
		current_rating = "Exceptional";
	}
	if ((result > 56 && rating_override == -1) || rating_override == 3) {
		txtresult = '<span id="masterwork-quality" style="color: #72A329;">☼MASTERWORK☼</span>';
		current_rating = "Masterwork";
	}

	document.getElementById('rater_results').innerHTML = '<br />The rating machine suggests a rating of <a onclick="show_num();"' + txtresult + '</a> <span id="numspan" style="display:none;">(' + result + ')</span>';
	document.getElementById('showup').style.display = "inline";
}

function show_num() {
	document.getElementById('numspan').style.display = "inline";
}

function looks_toggle() {
	if (document.getElementById('looks').checked == true) {
		document.getElementById('extremelooksdiv').style.display = "inline";
		rater_calc();
	} else {
		document.getElementById('extremelooksdiv').style.display = "none";
		document.getElementById('extremelooks').checked = false;
		rater_calc();
	}
}

function overrate_toggle() {
	if (document.getElementById('overrate').checked == true) {
		document.getElementById('overratediv').style.display = "inline";
		rater_calc();
	} else {
		document.getElementById('overratediv').style.display = "none";
		rating_override = -1;
		rater_calc();
	}
}

function ver_toggle() {
	if (document.getElementById('ver').checked == true) {
		document.getElementById('verdiv').style.display = "inline";
		rater_calc();
	} else {
		document.getElementById('verdiv').style.display = "none";
		document.getElementById('verg').checked = false;
		rater_calc();
	}
}

function inacc_toggle() {
	if (document.getElementById('inacc').checked == true) {
		document.getElementById('inaccdiv').style.display = "inline";
		rater_calc();
	} else {
		document.getElementById('inaccdiv').style.display = "none";
		document.getElementById('inaccg').checked = false;
		rater_calc();
	}
}

function rater_testorphan() {
	var rater_PageName = wgPageName.replace(/_/g, ' ');
	var api = sajax_init_object();
	api.open('GET', 'http://dwarffortresswiki.org/index.php/Special:WhatLinksHere/' + rater_PageName, true);
	api.onreadystatechange = function() {
		document.getElementById('rater_orphan').innerHTML += ".";

		if (api.readyState == 4) {
			if (api.status == 200) {
				if (api.responseText.indexOf("No pages link to") == -1) {
					document.getElementById('rater_orphan').innerHTML += '<span class="rater_green">NO</span>';
					orphan = 0;
					document.getElementById('autoquickfail').style.display = "inline";
				} else {
					document.getElementById('rater_orphan').innerHTML += '<span class="rater_red">YES</span>';			
					orphan = -1000000;
					rater_calcit(); 
				}
			} else
				document.getElementById('rater_orphan').innerHTML += 'Unknown (error)';
		}
	};
	api.send(null);
}

function rater_testdeadend() {
	var searchtxt = document.getElementById('bodyContent').innerHTML;

	var cnt = searchtxt.count('<a href="/index.php/');

	if (cnt == 0)
		document.getElementById('rater_deadend').innerHTML += '<span class="rater_red">YES</span>';	 
	else
		document.getElementById('rater_deadend').innerHTML += '<span class="rater_green">NO</span> - ' + cnt + ' internal';	 

	inlinks = cnt;
}

function rater_testredlink() {
	var searchtxt = document.getElementById('bodyContent').innerHTML;

	var re = new RegExp('<table id="avtable"[^]*?</table>', "g");
	searchtxt = searchtxt.replace(re, "");

	var cnt = searchtxt.count('class="new');

	if (cnt == 0)
		document.getElementById('rater_redlink').innerHTML += '<span class="rater_green">0</span>';	 
	else
		document.getElementById('rater_redlink').innerHTML += '<span class="rater_red">' + cnt + '</span>';	 

	redlinks = cnt;
	if (redlinks > 2)
		document.getElementById('igred').style.display = "none";
}

function rater_testlength() {
	var searchtxt = document.getElementById('bodyContent').innerHTML;

	var re = new RegExp("<.*?>", "g");
	var replaced = searchtxt.replace(re, "");
	var splitted = replaced.split(" ");

	var lol = "Very Short";
	length = 0;
	if (splitted.length > 100) {
		lol = "Short";
		length = 1;
	}
	if (splitted.length > 500) {
		lol = "Medium";
		length = 2;
	}
	if (splitted.length > 2000) {
		lol = "Long";
		length = 3;
	}
	if (splitted.length > 4000) {
		lol = "Very Long";
		length = 4;
	}

	//if (length == 0) {document.getElementById('tempbox').checked = true;}

	//document.getElementById('rater_div').innerHTML += splitted.length;	 
	overlength = length;
	document.getElementById('vs_rad').checked = false;
	document.getElementById('s_rad').checked = false;
	document.getElementById('m_rad').checked = false;
	document.getElementById('l_rad').checked = false;
	document.getElementById('vl_rad').checked = false;

	switch(overlength)
	{
	case 0:
		document.getElementById('vs_rad').checked = true;
		break;
	case 1:
		document.getElementById('s_rad').checked = true;
		break;
	case 2:
		document.getElementById('m_rad').checked = true;
		break;
	case 3:
		document.getElementById('l_rad').checked = true;
		break;
	case 4:
		document.getElementById('vl_rad').checked = true;
		break;
	}
}

function rater_testcats() {
	var searchtxt = document.getElementById('bodyContent').innerHTML;

	if (searchtxt.indexOf("catlinks") != -1) {
		var cattext = document.getElementById('mw-normal-catlinks').innerHTML.substr(83);
		var catstr1 = "<div style='margin-left:1em;'>";
		cats = 0;

		var catarr = cattext.split("|");
		for (x in catarr)
		{
			if ((catarr[x].indexOf(">Current<") == -1) &&
			    (catarr[x].indexOf(">Obsolete<") == -1) &&
			    (catarr[x].indexOf("Tattered Quality Articles<") == -1) &&
			    (catarr[x].indexOf("Fine Quality Articles<") == -1) &&
			    (catarr[x].indexOf("Exceptional Quality Articles<") == -1) &&
			    (catarr[x].indexOf("Masterwork Quality Articles<") == -1) &&
			    (catarr[x].indexOf("Unknown Quality Articles<") == -1) &&
			    (catarr[x].indexOf(">Quality ranks without proper timestamps<") == -1) &&
			    (catarr[x].indexOf(">Quality ranks older than 10 weeks<") == -1) &&
			    (catarr[x].indexOf(">Quality ranks with bad timestamps<") == -1) &&
			    (catarr[x].indexOf(">Quality ranks in invalid namespaces<") == -1)) {
				catstr1 += catarr[x] + "<br />";
				cats += 1;
			}
		}

		document.getElementById('rater_cats_resp').innerHTML += catstr1 + "</div>";
		//document.getElementById('rater_cats_resp').innerHTML += document.getElementById('mw-normal-catlinks').innerHTML + ' - ' + cats;
		document.getElementById('rater_cats_check').style.display = "inline";
	} else
		document.getElementById('rater_cats_resp').innerHTML += "none!";
}