MediaWiki:LootStatistics-Checker.js

//  /*jslint devel: true, browser: true, plusplus: true, white: true */ /*global $, wgPageName, addOnloadHook */

(function {  'use strict';  var sysop = false,  main_function = function  {    var current_tibia_version = '8.6',    lootparser_versions_ex =    {'8.6': {    /*changed*/      'Behemoth': '9.1',      'Blazing Fire Elemental': '9.1',      'Blistering Fire Elemental': '9.1',      'Carrion Worm': '9.1',      'Draken Abomination': '9.1',      'Draken Spellweaver': '9.1',      'Dwarf Guard': '9.1',      'Earth Elemental': '9.1',      'Eternal Guardian': '9.1',      'Fire Overlord': '9.1',      'Hellfire Fighter': '9.1',      'Jagged Earth Elemental': '9.1',      'Muddy Earth Elemental': '9.1',      'Stone Golem': '9.1',      'Swamp Troll': '9.1',      'Tarantula': '9.1',      'Vampire': '9.1',      'Witch': '9.1',      'Worker Golem': '9.1',    /*new*/      'Askarak Demon': '9.1',      'Askarak Lord': '9.1',      'Askarak Prince': '9.1',      'Bog Frog': '9.1',      'Clay Guardian': '9.1', 'Crystal Wolf': '9.1', 'Death Priest': '9.1', 'Deepling Scout': '9.1', 'Desperate White Deer': '9.1', 'Diamond Servant': '9.1', 'Donkey': '9.1', 'Dromedary': '9.1', 'Elder Mummy': '9.1', 'Elf Overseer': '9.1', 'Energized Raging Mage': '9.1', 'Enraged White Deer': '9.1', 'Feverish Citizen': '9.1', 'Filth Toad': '9.1', 'Firestarter': '9.1', 'Ghoulish Hyaena': '9.1', 'Golden Servant': '9.1', 'Grave Guard': '9.1', 'Groam': '9.1', 'Honour Guard': '9.1', 'Horestis': '9.1', 'Horse': '9.1', 'Insectoid Scout': '9.1', 'Iron Servant': '9.1', 'Kraknaknork': '9.1', 'Kraknaknork\'s Demon': '9.1', 'Mad Mage': '9.1', 'Raging Mage': '9.1', 'Sacred Spider': '9.1', 'Sandstone Scorpion': '9.1', 'Shaburak Demon': '9.1', 'Shaburak Lord': '9.1', 'Shaburak Prince': '9.1', 'Slug': '9.1', 'Spider Queen': '9.1', 'Starving Wolf': '9.1', 'Thornfire Wolf': '9.1', 'Tomb Servant': '9.1', 'Weakened Demon': '9.1', 'White Deer': '9.1', 'Yielothax': '9.1' } },   lootparser_creature_special_names = {'Arkhothep': 'Arkhothep (Creature)', 'Armenius': 'Armenius (Creature)', 'Avalanche': 'Avalanche (Creature)', 'Gamemaster': 'Gamemaster (Creature)', 'Hacker': 'Hacker (Creature)', 'Pythius the Rotten': 'Pythius the Rotten (Creature)', 'Slime': 'Slime (Creature)', 'Thief': 'Thief (Creature)', 'Yalahari': 'Yalahari (Creature)'}, requests_to_do, total_requests, requests_to_do_minus = function { $('#stats_doing1').html('Checking'); $('#stats_doing2').html(String(Math.abs(requests_to_do - total_requests)) + '/' + String(total_requests)); requests_to_do--; if (requests_to_do <= 0) { $('#stats_data').parents('div:first').find('input').removeAttr('disabled'); $('#stats_doing2').html('Complete'); }   },    check_all = function (filter_function) { var dook = function (c, r) { var i;       if (lootparser_creature_special_names.hasOwnProperty(c)) { c = lootparser_creature_special_names[c]; } i = $('#stats_result').find('a[title="Loot Statistics:'+c+'"]').parent; if(!i.size) { alert('couldn\'t find for remove\n'+'[title="Loot Statistics:'+c+'"]\n\n\n'+r); } else { i.remove; } },     doajax = function(id) { var tthis = $(this), t = $.trim($(this).text.replace('Loot Statistics:','').replace(' ', '_')); $.ajax({cache: false, async: true, url: '/index.php?title=Loot_Statistics:' + t + '&action=raw', success: function (r) {         if(r === ''){ window.setTimeout(function  { doajax(id); }, 3000); /*ret(id);*/ }          else {            var iserror, creature = r.match(/name\s*=\s*([\.\w \(\)]*)/);            creature = (creature === null ? false : creature[1]);           if(creature === false) { alert('problem with\n' + r); }            else {              iserror = filter_function(r, creature);              if (iserror === false) {                dook(creature, r);              }              else if (typeof iserror === 'object') {                tthis.parent.append(' ');   /*jslint unparam: true*/                $.each(iserror, function (i, v) { tthis.parent.append(v + ' '); });    /*jslint unparam: false*/              }            }            requests_to_do_minus;          }        }, error: function (a, b, c) {          if (a.status !== 404) { alert(a.status+b+c); window.setTimeout(function  { doajax(id); }, 3000); }          else { requests_to_do_minus; }        }        }); };     $('#stats_data').parents('div:first').find('input').attr('disabled', 'disabled'); $('#stats_result').html($('#stats_data').html); $('#stats_result').find('a.new').parent.remove; total_requests = requests_to_do = $('#stats_result').find('a').each(doajax).size; };   $('#stats_data').closest('table').before(      $(' ').append( $(' ').append(         $(' ').html('List pages that have more than one 8.6 or 9.1 with Loot2'),          $(' ').append( $(' ', {'value': 'Check','type': 'button'}).click(function { check_all(function (r) { var ret, tmp = [r.match(/\{\{\s*Loot2[\s\|]*version\s*=\s*9\.1[\s\|]/g), r.match(/\{\{\s*Loot2[\s\|]*version\s*=\s*8\.6[\s\|]/g)]; tmp = [(tmp[0] === null ? 0 : tmp[0].length), (tmp[1] === null ? 0:tmp[1].length)]; ret = (tmp[0] > 1 || tmp[1] > 1 ? true : false); return ret; }); })         )        ),        $(' ').append(          $(' ').html('List pages that have Loot2 with not 8.6 or 9.1 Note that some stats that have version lower than 8.6 are valid '),         $(' ').append( $(' ', {'value': 'Check','type': 'button'}).click(function { check_all(function (r) { var ret = false, tmp = (r.match(/\{\{\s*Loot2[\s\|]*version\s*=\s*(\d*\.\d*)[\s\|]/g) ? true : false); if (tmp) { /*jslint unparam: true*/ $.each(r.match(/\{\{\s*Loot2[\s\|]*version\s*=\s*(\d*\.\d*)[\s\|]/g), function (i, v) {                 if (v.match(/version\s*=\s*8\.6[\s\|]/) === null && v.match(/version\s*=\s*9\.1[\s\|]/) === null) { ret = true; return false; }                  else { ret = false; }                }); /*jslint unparam: false*/ }             return ret; }); })         )        ),        $(' ').append(          $(' ').html('List pages that have Loot2 with 9.1 and should not'),          $(' ').append( $(' ', {'value': 'Check','type': 'button'}).click(function { check_all(function (r, creature) { var ret, tmp = r.match(/\{\{\s*Loot2[\s\|]*version\s*=\s*9\.1[\s\|]/g); tmp = (tmp === null ? 0 : tmp[0].length); ret = (tmp > 0 ? true : false); if (ret && lootparser_versions_ex[current_tibia_version].hasOwnProperty(creature)) { ret = false; }             return ret; }); })         )        ),        $(' ').append(          $(' ').html('List pages that have parentheses in items Note that some items are valid even if they have parenthesis '),         $(' ').append( $(' ', {'value': 'Check','type': 'button'}).click(function { check_all(function (r) { var ret, tmp = r.match(/\|[\w\s]*[(]/);             ret = (tmp === null ? false : true);             return ret;            }); })          ) ),       $(' ').append( $(' ').html('List pages that have wrong number or wrong parameters Please note this only does some checks '), $(' ').append(           $(' ', {'value': 'Check','type': 'button'}).click(function  { check_all(function (r) {  /*jslint regexp: true*/              var tt, item, times, amount, total, x, y, ret = [], tmpt, tmps,              tmp = r.match(/\{\{\s*Loot2[\s\|]*version\s*=\s*(?:9\.1|8\.6)[\s\|]*[^}]*/g), tmpa = [];  /*jslint regexp: false*/              if (tmp !== null) { for (x = 0; x < tmp.length; x++) {                tmpa[x] = tmp[x].split(/[\r\n|]+/);                for (y = 0; y < tmpa[x].length; y++) {                  if (tmpa[x][y].indexOf(',') !== -1) {                    tmpt = $.trim(tmpa[x][y]);                    if (tmpt.match(/,/g).length !== 1 && tmpt.match(/,/g).length !== 3) { ret.push(tmpt + ' - (wrong number of parameters )'); }                    else if (tmpt.match(/,/g).length === 3) {                      tt = tmpt.match(/(.*?)\s*,\s*times\s*:\s*(\d*)\s*,\s*amount\s*:\s*([\d\-]*)\s*,\s*total\s*:\s*(\d*)/); if (tt !== null) { item = tt[1]; if (item === 'Empty') { ret.push(tmpt + ' - (wrong "Empty")'); } else if ((tmps = ('lala Boots').match(/\s+(?:boots|legs)$/i)) !== null) { ret.push(tmpt + ' - (wrong "' + tmps + '")'); }                       else { times = (parseInt(tt[2], 10) || 0); amount = tt[3]; total = (parseInt(tt[4], 10) || 0); if (times > total) { ret.push(tmpt + ' - (wrong "times" or "total")'); } else if (amount.indexOf('-') === -1 && ((parseInt(amount, 10) || 0) * times) !== total) { ret.push(tmpt + ' - (wrong "times" or "total")'); }                       }                      }                    }                  }                }              } }              ret = (ret.length === 0 ? false : ret); return ret; }); })         )        ),        $(' ').append(          $(' ', {'id': 'stats_doing1'}).html(' '),          $(' ', {'id': 'stats_doing2'}).html(' ')        ) )   );  };  $.ajax({    url: '/api.php', type: 'GET', dataType:'json',    data : {      'action':'query', 'format':'json',      'meta':'userinfo', 'uiprop':'groups'    },    success: function(obj) {      var x;      if (typeof obj.query !== 'undefined' && typeof obj.query.userinfo !== 'undefined' && obj.query.userinfo.groups !== 'undefined') {       for (x in obj.query.userinfo.groups) { if (obj.query.userinfo.groups.hasOwnProperty(x)) {          if ((obj.query.userinfo.groups[x]) === 'sysop') { sysop = true; break; }        } }      }      if (sysop) { main_function; }    }  }); }); //