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
Line 5: Line 5:
 
);
 
);
  
var orphan = false;
+
var orphan = 0;
 
var inlinks = 0;
 
var inlinks = 0;
 
var redlinks = 0;
 
var redlinks = 0;
Line 11: Line 11:
 
var overlength = -1;
 
var overlength = -1;
 
var cats = 0;
 
var cats = 0;
var catapp = false;
+
var catapp = 0;
  
 
String.prototype.count=function(s1) {  
 
String.prototype.count=function(s1) {  
Line 37: Line 37:
 
document.getElementById('rater_div').innerHTML += '<div id="rater_length">How long (approximately) is the article......<span id="rater_length_resp"> </span><span id="rater_length_check" style=""> ..... Incorrect?<INPUT TYPE=CHECKBOX ID="rater_len_over" onClick="rater_toggle_len_over();"></span></div><div id="rater_len_over_div" style="display:none;"><form name="rawr" method="get" action="" onsubmit="return false;"><input type=radio id="vs_rad" onclick="len_over_change(0);" name="len_override" value="0">Very Short<br><input type=radio id="s_rad" onclick="len_over_change(0);" value="1" name="len_override" >Short<br><input type=radio id="m_rad" onclick="len_over_change(0);" name="len_override"  value="2">Medium<br><input type=radio id="l_rad" onclick="len_over_change(0);" name="len_override"  value="3">Long<br><input type=radio id="vl_rad" onclick="len_over_change(0);" name="len_override"  value="4">Very Long</form></div>';
 
document.getElementById('rater_div').innerHTML += '<div id="rater_length">How long (approximately) is the article......<span id="rater_length_resp"> </span><span id="rater_length_check" style=""> ..... Incorrect?<INPUT TYPE=CHECKBOX ID="rater_len_over" onClick="rater_toggle_len_over();"></span></div><div id="rater_len_over_div" style="display:none;"><form name="rawr" method="get" action="" onsubmit="return false;"><input type=radio id="vs_rad" onclick="len_over_change(0);" name="len_override" value="0">Very Short<br><input type=radio id="s_rad" onclick="len_over_change(0);" value="1" name="len_override" >Short<br><input type=radio id="m_rad" onclick="len_over_change(0);" name="len_override"  value="2">Medium<br><input type=radio id="l_rad" onclick="len_over_change(0);" name="len_override"  value="3">Long<br><input type=radio id="vl_rad" onclick="len_over_change(0);" name="len_override"  value="4">Very Long</form></div>';
 
document.getElementById('rater_div').innerHTML += '<div id="rater_cats">Is the page in any categories......<span id="rater_cats_resp"> </span><span id="rater_cats_check" style="display:none;"> ..... Are they appropriate?<INPUT TYPE=CHECKBOX NAME="rater_cat"></span></div>';
 
document.getElementById('rater_div').innerHTML += '<div id="rater_cats">Is the page in any categories......<span id="rater_cats_resp"> </span><span id="rater_cats_check" style="display:none;"> ..... Are they appropriate?<INPUT TYPE=CHECKBOX NAME="rater_cat"></span></div>';
 +
document.getElementById('rater_div').innerHTML += '<div id="rater_results"></div>';
  
 
rater_testorphan();
 
rater_testorphan();
Line 48: Line 49:
 
overlength = over;
 
overlength = over;
  
 +
rater_calc();
 +
}
 +
 +
function rater_calc{
 +
 +
var wlen = length
 +
if (overlength != -1) wlen = overlength;
 +
var result = orphan +  wlen * 3 + inlinks * 2 + redlinks * -4 + cats * 10
 +
 +
document.getElementById('rater_results').innerHTML = result;
 
}
 
}
  
Line 95: Line 106:
 
         if(api.responseText.indexOf("No pages link to") == -1){
 
         if(api.responseText.indexOf("No pages link to") == -1){
 
           document.getElementById('rater_orphan').innerHTML += '<span class="rater_green"> NO</span>';
 
           document.getElementById('rater_orphan').innerHTML += '<span class="rater_green"> NO</span>';
           orphan = false;
+
           orphan = 0;
 
         }else{
 
         }else{
 
           document.getElementById('rater_orphan').innerHTML += '<span class="rater_red"> YES</span>';         
 
           document.getElementById('rater_orphan').innerHTML += '<span class="rater_red"> YES</span>';         
           orphan = true;             
+
           orphan = -1000000;             
 
         }
 
         }
 
       } else {
 
       } else {

Revision as of 04:11, 22 May 2010

addOnloadHook(
  function rater_addLink() {
    addPortletLink("p-cactions", "javascript:rater_init()", "Rate", "ca-rater", "Rate");
  }
);

var orphan = 0;
var inlinks = 0;
var redlinks = 0;
var length = 0;
var overlength = -1;
var cats = 0;
var catapp = 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="rater_orphan">Is page orphaned</div>';
document.getElementById('rater_div').innerHTML += '<div id="rater_deadend">Is page deadend...... </div>';
document.getElementById('rater_div').innerHTML += '<div id="rater_redlink">How many redlinks does page contain...... </div>';
document.getElementById('rater_div').innerHTML += '<div id="rater_length">How long (approximately) is the article......<span id="rater_length_resp"> </span><span id="rater_length_check" style=""> ..... Incorrect?<INPUT TYPE=CHECKBOX ID="rater_len_over" onClick="rater_toggle_len_over();"></span></div><div id="rater_len_over_div" style="display:none;"><form name="rawr" method="get" action="" onsubmit="return false;"><input type=radio id="vs_rad" onclick="len_over_change(0);" name="len_override" value="0">Very Short<br><input type=radio id="s_rad" onclick="len_over_change(0);" value="1" name="len_override" >Short<br><input type=radio id="m_rad" onclick="len_over_change(0);" name="len_override"  value="2">Medium<br><input type=radio id="l_rad" onclick="len_over_change(0);" name="len_override"  value="3">Long<br><input type=radio id="vl_rad" onclick="len_over_change(0);" name="len_override"  value="4">Very Long</form></div>';
document.getElementById('rater_div').innerHTML += '<div id="rater_cats">Is the page in any categories......<span id="rater_cats_resp"> </span><span id="rater_cats_check" style="display:none;"> ..... Are they appropriate?<INPUT TYPE=CHECKBOX NAME="rater_cat"></span></div>';
document.getElementById('rater_div').innerHTML += '<div id="rater_results"></div>';

rater_testorphan();
rater_testredlink();
rater_testdeadend();
rater_testlength();
rater_testcats();
}

function len_over_change(over){
overlength = over;

rater_calc();
}

function rater_calc{

var wlen = length
if (overlength != -1) wlen = overlength;
var result = orphan +  wlen * 3 + inlinks * 2 + redlinks * -4 + cats * 10

document.getElementById('rater_results').innerHTML = result;
}

function rater_toggle_len_over(){
if (document.getElementById('rater_len_over').checked == true){
document.getElementById('rater_len_over_div').style.display = "inline";
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;
}

}else{
document.getElementById('rater_len_over_div').style.display = "none";
overlength = -1;
}
}

function rater_testorphan(){
var rater_PageName = wgPageName.replace(/_/g, ' ');
var api = sajax_init_object();
api.open('GET', 'http://df.magmawiki.com/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;
        }else{
          document.getElementById('rater_orphan').innerHTML += '<span class="rater_red"> YES</span>';         
          orphan = -1000000;             
        }
      } 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 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;
}


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;}

    document.getElementById('rater_length_resp').innerHTML += lol;    
}

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

  if(searchtxt.indexOf("catlinks") != -1){
    document.getElementById('rater_cats_resp').innerHTML += document.getElementById('mw-normal-catlinks').innerHTML;
    document.getElementById('rater_cats_check').style.display = "inline";
    cats = document.getElementById('mw-normal-catlinks').innerHTML.split("|").length;
  }else{
    document.getElementById('rater_cats_resp').innerHTML += "none!";
  }
}