Wikipedysta:Marcimon/code.js

W dzisiejszym świecie Wikipedysta:Marcimon/code.js to temat, który przykuł uwagę milionów ludzi na całym świecie. Niezależnie od tego, czy ze względu na swój wpływ na społeczeństwo, znaczenie historyczne czy wpływ na codzienne życie ludzi, Wikipedysta:Marcimon/code.js stał się powracającym tematem w rozmowach, debatach i dyskusjach we wszystkich obszarach. Dzięki stałej obecności w mediach i sieciach społecznościowych Wikipedysta:Marcimon/code.js zdołał przekroczyć granice i kultury, wzbudzając zainteresowanie i niepokój u ludzi w każdym wieku i w każdym stanie. W tym artykule dokładnie zbadamy wpływ i znaczenie Wikipedysta:Marcimon/code.js, analizując jego implikacje i znaczenie we współczesnym społeczeństwie.
// see http://paperlined.org/apps/wikipedia/Tool2/ for instructions on adding this to your monobook.js

// To run this tool on other servers:
//  1. copy this script to the target server (this is required because of javascript cross-site security restrictions)

//  2. update the following URL
//      for example: "User:Interiot/Tool2/code.js"
var tool2_url = "User:Interiot/Tool2/code.js";

//  3. update this namespace list, extracted from something like http://en.wikiquote.orghttps://wikifreehand.com/pl/Special:Export//
var namespaces = [
"Talk",
"User",
"User talk",
"Wikiquote",
"Wikiquote talk",
"Image",
"Image talk",
"MediaWiki",
"MediaWiki talk",
"Template",
"Template talk",
"Help",
"Help talk",
"Category",
"Category talk"
];


// TODO:
//  - the current document.location method doesn't work when the page is accessed sans-mod_rewrite
//  - test with non-ASCII characters
//      - non-ascii usernames
//      - ??



var prefix = "";
var params = parse_params();

addOnloadFunction(function() {
  var path_len = document.location.pathname.length;
  // trigger once we view the right page
  if (document.location.pathname.substring(path_len - tool2_url.length, path_len) == tool2_url) {
    // get the prefix (needs to be fixed to work sans-mod_rewrite
    prefix = document.location.protocol + "//" + document.location.host + "/"
            + document.location.pathname.substring(1, path_len - tool2_url.length);

    // blank the inner contents of the page
    var bodyContent = document.getElementById("bodyContent");
    while (bodyContent.childNodes.length > 0) bodyContent.removeChild(bodyContent.lastChild);

    if (document.location.search.length == 0) {
      generate_input_form(bodyContent);
    } else {
      generate_main_report(bodyContent);
    }
  }
});


function generate_input_form(bodyContent) {
  bodyContent.innerHTML =
            "<form><table><tr><td>Username <td><input maxlength=128 name=username value='' title='username'>" +
            "             <tr><td>         <td><input type=submit value='Submit'>" +
            "</table></form>";

  var form = bodyContent.getElementsByTagName("form");
  form.method = "get";
  form.action = document.location;
}

function generate_main_report() {
  fetch_data(params, "", output_main_report, 0, );
}

function output_main_report(data) {
}



var offset_regexp = /href="+:Contributions+offset=(\d+)/gi;
function fetch_data(username, end_date, handler, offset, page_list) {
    var url = prefix + "Special:Contributions/" + username + "?offset=" + offset + "&limit=500";
    loadXMLDoc(url, 
        function (request) {
            var next_offset = 0;
            if (request.readyState != 4)   return;
            if (request.status == 200) {
                page_list.push(request.responseText);
                //dump_text(request.responseText);

                // see if there's another pageful to get
                var matches = map( function(p){
                        return p.match( /(\d+)$/ );
                    }, request.responseText.match( offset_regexp ) );
                for (var i=0; i<matches.length; i++) {
                    var v = matches * 1;
                    if (v != 0 && (offset == 0 || v < offset)) {
                        next_offset = v;
                        break;
                    }
                }
            }

            if (next_offset == 0) {
                parse_data(page_list, handler);
            } else {
                // tail recurse
                fetch_data(username, end_date, handler, next_offset, page_list);
            }
        });
}


function parse_data(page_list, handler) {
    //var total_len = 0;
    //for (var i=0; i<page_list.length; i++) total_len += page_list.length;
    //alert("parsing " + page_list.length + " pages comprising " + total_len + " total bytes");
}



// ===================================== test/debug functions =========================================

function dump_text(text) {
  //alert("dump_text, with text of size " + text.length);

  var pre = document.createElement("pre");

  var div = document.createElement("div");
  div.style.width = "60em";
  div.style.maxHeight = "40em";
  div.style.overflow = "auto";

  pre.appendChild(document.createTextNode(text));
  div.appendChild(pre);
  document.getElementById("bodyContent").appendChild(div);
}

function dump_lines(ary) {
  dump_text(ary.join("\n"));
}


// ===================================== utility functions =========================================

function addOnloadFunction(f) {
  if (window.addEventListener) window.addEventListener("load",f,false);
  else if (window.attachEvent) window.attachEvent("onload",f);
  else {
    var oldOnload='_old_onload_'+addOnloadFunction.uid;
    addOnloadFunction = window.onload ? window.onload : function () {};
    window.onload = function() { addOnloadFunction();  f(); }
    ++addOnloadFunction.uid;
  }
}

function parse_params() {
  var pairs = document.location.search.substring(1).split("&");
  var ret = ;
  for (var i=0; i < pairs.length; i++) {
    var values = pairs.split("=");
    ret] = unescape(values);
  }
  return ret; 
}

function loadXMLDoc(url, handler)
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    req.onreadystatechange = function () {handler(req)};
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function () {handler(req)};
            req.open("GET", url, true);
            req.send();
        }
    }
}

// see http://search.cpan.org/dist/perl/pod/perlfunc.pod#map
function map (handler, list) {
  var ret = new Array();
  for (var i=0; i<list.length; i++) {
    ret = handler( list );
    // ret.push( handler( list ) );
  }
  return ret;
}