User:Joshurtree/multicat.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.

//<pre><nowiki>
 
function PageQuery(q) {
    if (q.length > 1) 
        this.query = q.substring(1, q.length);
    else 
        this.query = null;
 
    this.values = new Object();
 
    if (q) {
         for (var i = 0; i < this.query.split("&").length; i++) {
             var pair = this.query.split("&")[i];
             this.values[pair.split("=")[0]] = pair.split("=")[1];
         }
 
    }
}
 
PageQuery.prototype.getValue = function(s) {
    return this.values[s];
}
 
PageQuery.prototype.getParameters = function() {
    return keys;
}
 
PageQuery.prototype.getLength = function() { 
    return this.values.length; 
}
 
PageQuery.create = function() {
    var retText =  prefix ? wgScriptPath + '/' + prefix + '?' : '';
 
    for (x in parameters) {
        if (parameters[x] != null)
            retText += x + '=' + parameters[x] + '&';
    }
 
    return retText.substring(0, retText.length - 1);
}
 
function CategoryIntersection() {
    var query = new PageQuery(location.search);
    this.category1 = wgTitle;
    this.category2 = query.getValue("intersection");
    this.from = query.getValue("from");
    this.request = sajax_init_object();
    this.request.parentObj = this;
    var query = {
        'action': 'query',
        'generator': 'categorymembers',
        'gcmtitle': this.category1,
        'gcmlimit': 500,
        'prop': 'categories',
        'clprop': 'sortkey'
    };
 
    this.request.open('GET', PageQuery.create(query), true);
    this.request.onload = function() { this.parentObj.handleCategoryQuery; };
    this.request.send();
}
 
CategoryIntersection.prototype.handleCategoryQuery = function() {
    var pages = this.request.responseXML.getElementsByTagName('page');
    XMLDocument output = 
    for (page in pages) {
        var sortkey;
        var intersection;
        var xmlDoc = loadXMLDoc();
 
        xmlDoc        
        for (category in page.firstChild.childNodes) {
            var title = category.getAttribute('title');
            if (title == this.category1)
                sortkey = category.getAttribute('sortkey');
            else if (title == this.category2)
                intersection = true;
 
            if (intersection) {
        }
 
 
 
function loadXMLDoc(fname)
{
    var xmlDoc;
    // code for IE
    if (window.ActiveXObject)
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    // code for Mozilla, Firefox, Opera, etc.
    else if (document.implementation && document.implementation.createDocument)
        xmlDoc=document.implementation.createDocument("","",null);
    else
      alert('Your browser cannot handle this script');
 
    xmlDoc.async = false;
 
    if (fname)
        xmlDoc.load(fname);
    return(xmlDoc);
}
 
addOnLoadHook(function() {
    if (wgNamespaceNumber == 14 && location.URL.indexOf("&intersection=") > 0)
        new CategoryIntersection();
}
 
//</pre></nowiki>